Sha256: 176fafe97d931b3af9e3c8f43b32f90bea5c5813633c6413c2a3e2296cc35d29

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

class Gem::Ext::Builder

  def self.class_name
    name =~ /Ext::(.*)Builder/
    $1.downcase
  end

  def self.make(dest_path, results)
    unless File.exist? 'Makefile' then
      raise Gem::InstallError, "Makefile not found:\n\n#{results.join "\n"}"
    end

    mf = Gem.read_binary 'Makefile'
    mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$[^$]*/, "RUBYARCHDIR = #{dest_path}")
    mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$[^$]*/, "RUBYLIBDIR = #{dest_path}")

    File.open('Makefile', 'wb') {|f| f.print mf}

    # try to find make program from Ruby configure arguments first
    RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/
    make_program = $1 || ENV['MAKE'] || ENV['make']
    unless make_program then
      make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
    end

    ['', ' install'].each do |target|
      cmd = "#{make_program}#{target}"
      run(cmd, results, "make#{target}")
    end
  end

  def self.redirector
    '2>&1'
  end

  def self.run(command, results, command_name = nil)
    verbose = Gem.configuration.really_verbose

    if verbose
      puts(command)
      system(command)
    else
      results << command
      results << `#{command} #{redirector}`
    end

    unless $?.success? then
      results << "Building has failed. See above output for more information on the failure." if verbose
      raise Gem::InstallError, "#{command_name || class_name} failed:\n\n#{results.join "\n"}"
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubygems-update-2.0.0.rc.1 lib/rubygems/ext/builder.rb
rubygems-update-2.0.0.preview2.2 lib/rubygems/ext/builder.rb
rubygems-update-2.0.0.preview2.1 lib/rubygems/ext/builder.rb
rubygems-update-2.0.0.preview2 lib/rubygems/ext/builder.rb