Skip to content

Commit

Permalink
Allow build_args to be directly specified
Browse files Browse the repository at this point in the history
Eventually, I'd like to get rid of Gem::Command.build_args all together.
For now, this is a good compromise.
  • Loading branch information
evanphx committed Mar 10, 2012
1 parent 31f7fea commit 488c20c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 28 deletions.
5 changes: 2 additions & 3 deletions lib/rubygems/commands/pristine_command.rb
Expand Up @@ -97,13 +97,12 @@ def execute
install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
installer_env_shebang = install_defaults.to_s['--env-shebang']

Gem::Command.build_args = spec.build_args

installer = Gem::Installer.new(gem,
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
:env_shebang => installer_env_shebang)
:env_shebang => installer_env_shebang,
:build_args => spec.build_args)
installer.install

say "Restored #{spec.full_name}"
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/ext/configure_builder.rb
Expand Up @@ -8,10 +8,10 @@

class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder

def self.build(extension, directory, dest_path, results)
def self.build(extension, directory, dest_path, results, args=[])
unless File.exist?('Makefile') then
cmd = "sh ./configure --prefix=#{dest_path}"
cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty?
cmd << " #{args.join ' '}" unless args.empty?

run cmd, results
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/ext/ext_conf_builder.rb
Expand Up @@ -9,9 +9,9 @@

class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder

def self.build(extension, directory, dest_path, results)
def self.build(extension, directory, dest_path, results, args=[])
cmd = "#{Gem.ruby} #{File.basename extension}"
cmd << " #{Gem::Command.build_args.join ' '}" unless Gem::Command.build_args.empty?
cmd << " #{args.join ' '}" unless args.empty?

run cmd, results

Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/ext/rake_builder.rb
Expand Up @@ -9,10 +9,10 @@

class Gem::Ext::RakeBuilder < Gem::Ext::Builder

def self.build(extension, directory, dest_path, results)
def self.build(extension, directory, dest_path, results, args=[])
if File.basename(extension) =~ /mkrf_conf/i then
cmd = "#{Gem.ruby} #{File.basename extension}"
cmd << " #{Gem::Command.build_args.join " "}" unless Gem::Command.build_args.empty?
cmd << " #{args.join " "}" unless args.empty?
run cmd, results
end

Expand Down
18 changes: 10 additions & 8 deletions lib/rubygems/installer.rb
Expand Up @@ -94,6 +94,8 @@ def exec_format
# :only_install_dir:: Only validate dependencies against what is in the
# install_dir
# :wrappers:: Install wrappers if true, symlinks if false.
# :build_args:: An Array of arguments to pass to the extension builder
# process. If not set, then Gem::Command.build_args is used

def initialize(gem, options={})
require 'fileutils'
Expand Down Expand Up @@ -230,10 +232,9 @@ def install
generate_bin
write_spec

args = Gem::Command.build_args
unless args.empty?
unless @build_args.empty?
File.open spec.build_info_file, "w" do |f|
args.each { |a| f.puts a }
@build_args.each { |a| f.puts a }
end
end

Expand Down Expand Up @@ -560,6 +561,8 @@ def process_options
# (or use) a new bin dir under the gem_home.
@bin_dir = options[:bin_dir] || Gem.bindir(gem_home)
@development = options[:development]

@build_args = options[:build_args] || Gem::Command.build_args
end

# DOC: Missing docs or :nodoc:.
Expand Down Expand Up @@ -631,12 +634,10 @@ def windows_stub_script(bindir, bin_file_name)
def build_extensions
return if spec.extensions.empty?

args = Gem::Command.build_args

if args.empty?
if @build_args.empty?
say "Building native extensions. This could take a while..."
else
say "Building native extensions with: '#{args.join(' ')}'"
say "Building native extensions with: '#{@build_args.join(' ')}'"
say "This could take a while..."
end

Expand Down Expand Up @@ -665,7 +666,8 @@ def build_extensions

begin
Dir.chdir extension_dir do
results = builder.build(extension, gem_dir, dest_path, results)
results = builder.build(extension, gem_dir, dest_path,
results, @build_args)

say results.join("\n") if Gem.configuration.really_verbose
end
Expand Down
5 changes: 5 additions & 0 deletions lib/rubygems/installer_test_case.rb
Expand Up @@ -11,6 +11,11 @@ class Gem::Installer
##
# Available through requiring rubygems/installer_test_case

attr_writer :build_args

##
# Available through requiring rubygems/installer_test_case

attr_writer :gem_dir

##
Expand Down
14 changes: 3 additions & 11 deletions test/rubygems/test_gem_commands_pristine_command.rb
Expand Up @@ -6,12 +6,6 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def setup
super
@cmd = Gem::Commands::PristineCommand.new
@orig_args = Gem::Command.build_args
end

def teardown
super
Gem::Command.build_args = @orig_args
end

def test_execute
Expand Down Expand Up @@ -97,8 +91,6 @@ def test_execute_no_extension
end

def test_execute_with_extension_with_build_args
Gem::Command.build_args = %w!--with-awesome=true --sweet!

a = quick_spec 'a' do |s| s.extensions << 'ext/a/extconf.rb' end

ext_path = File.join @tempdir, 'ext', 'a', 'extconf.rb'
Expand All @@ -111,11 +103,11 @@ def test_execute_with_extension_with_build_args
RUBY
end

install_gem a
build_args = %w!--with-awesome=true --sweet!

@cmd.options[:args] = %w[a]
install_gem a, :build_args => build_args

Gem::Command.build_args = @orig_args
@cmd.options[:args] = %w[a]

use_ui @ui do
@cmd.execute
Expand Down
29 changes: 29 additions & 0 deletions test/rubygems/test_gem_installer.rb
Expand Up @@ -106,6 +106,35 @@ def test_build_extensions_unsupported
FileUtils.rm_f gem_make_out
end

def test_build_extensions_with_build_args
args = ["--aa", "--bb"]
@installer.build_args = args
@installer.spec = @spec
@spec.extensions << 'extconf.rb'

File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f|
f.write <<-'RUBY'
puts "IN EXTCONF"
File.open 'extconf_args', 'w' do |f|
f.puts ARGV.inspect
end
File.open 'Makefile', 'w' do |f|
f.puts "default:\n\techo built"
f.puts "install:\n\techo installed"
end
RUBY
end

use_ui @ui do
@installer.build_extensions
end

path = File.join @spec.gem_dir, "extconf_args"

assert_equal args.inspect, File.read(path).strip
end

def test_check_executable_overwrite
@installer.generate_bin

Expand Down

0 comments on commit 488c20c

Please sign in to comment.