[Rubygems-developers] extensions fall back option

Trans transfire at gmail.com
Wed Nov 7 11:45:33 EST 2007


Would this suffice for adding a fall back option to Installer? It also
requires that 'extensions_fallback' be added to the gemspec.

  # from installer.rb

  def build_extensions
    return if @spec.extensions.empty?
    say "Building native extensions.  This could take a while..."
    start_dir = Dir.pwd
    dest_path = File.join @gem_dir, @spec.require_paths.first
    ran_rake = false # only run rake once

    @spec.extensions.each do |extension|
      break if ran_rake
      results = []

      builder = case extension
                when /extconf/ then
                  Gem::Ext::ExtConfBuilder
                when /configure/ then
                  Gem::Ext::ConfigureBuilder
                when /rakefile/i, /mkrf_conf/i then
                  ran_rake = true
                  Gem::Ext::RakeBuilder
                else
                  results = ["No builder for extension '#{extension}'"]
                  nil
                end

      begin
        Dir.chdir File.join(@gem_dir, File.dirname(extension))
        results = builder.build(extension, @gem_dir, dest_path, results)
      rescue => ex
        results = results.join "\n"

        File.open('gem_make.out', 'wb') { |f| f.puts results }

        # ADDED IF CONDITION HERE

        if @spec.extensions_fallback
          message = <<-EOF
WARNING: Failed to build gem native extension.

#{results}

Results logged to #{File.join(Dir.pwd, 'gem_make.out')}

This Gem has a pure-ruby fallback. You can still proceed to use this
package without the native extension.
          EOF

        else

          message = <<-EOF
ERROR: Failed to build gem native extension.

#{results}

Gem files will remain installed in #{@gem_dir} for inspection.
Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
          EOF

          raise ExtensionBuildError, message
        end
      ensure
        Dir.chdir start_dir
      end
    end
  end


More information about the Rubygems-developers mailing list