Skip to content

Commit

Permalink
fix bug #23210 - move processing of build args out of gem binary so t…
Browse files Browse the repository at this point in the history
…hey are handled correctly via API usage

git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@1987 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information
thewoolleyman committed Jan 5, 2009
1 parent 39dc93a commit 159af05
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
16 changes: 16 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# -*- coding: utf-8 -*-

2009-01-05 Chad Woolley <thewoolleyman@gmail.com>

* move processing of build args out of gem binary so they are handled correctly via API usage.
* lib/rubygems/command.rb: Add class accessor for build_args.
* lib/rubygems/ext/rake_builder.rb: Use Gem::Command.build_args instead of ARGV.
* lib/rubygems/ext/ext_conf_builder.rb: Use Gem::Command.build_args instead of ARGV.
* lib/rubygems/gem_runner.rb: Move build arg processing from gem binary.
* lib/rubygems/commands/contents_command.rb: Use nonzero return code (required to make tests pass).
* bin/gem: Move build arg processing to gem_runner.rb.
[RubyForge: bug #23210]

* lib/rubygems/config_file.rb: Fix --config-file option with no
equals and subsequent options to properly assign config file.
Previously config file was overwritten by subsequent option.
Fixes bug #16688.

2009-1-4 Daniel Berger <djberg96@gmail.com>
* lib/rubygems/installer.rb: Remove existing path if it already
exists before installing.
Expand Down
5 changes: 1 addition & 4 deletions bin/gem
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ unless required_version.satisfied_by? Gem.ruby_version then
abort "Expected Ruby Version #{required_version}, was #{Gem.ruby_version}"
end

# We need to preserve the original ARGV to use for passing gem options
# to source gems. If there is a -- in the line, strip all options after
# it...its for the source building process.
args = !ARGV.include?("--") ? ARGV.clone : ARGV[0...ARGV.index("--")]
args = ARGV.clone

begin
Gem::GemRunner.new.run args
Expand Down
9 changes: 9 additions & 0 deletions lib/rubygems/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ def wrap(text, width)
##################################################################
# Class methods for Command.
class << self
# arguments used when building gems
def build_args
@build_args ||= []
end

def build_args=(value)
@build_args = value
end

def common_options
@common_options ||= []
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/contents_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def execute
s.each { |dir| say dir }
end

terminate_interaction
terminate_interaction 1
end

files = options[:lib_only] ? gem_spec.lib_files : gem_spec.files
Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/ext/ext_conf_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#++

require 'rubygems/ext/builder'
require 'rubygems/command'

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

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

run cmd, results

Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/ext/rake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#++

require 'rubygems/ext/builder'
require 'rubygems/command'

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

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

Expand Down
8 changes: 8 additions & 0 deletions lib/rubygems/gem_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def initialize(options={})
# Run the gem command with the following arguments.
def run(args)
start_time = Time.now
if args.include?('--')
# We need to preserve the original ARGV to use for passing gem options
# to source gems. If there is a -- in the line, strip all options after
# it...its for the source building process.
build_args = args[args.index("--") + 1...args.length]
args = args[0...args.index("--")]
end
Command.build_args = build_args if build_args
do_configuration(args)
cmd = @command_manager_class.instance
cmd.command_names.each do |command_name|
Expand Down
3 changes: 2 additions & 1 deletion test/mockgemui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def terminated?
def terminate_interaction(status=0)
@terminated = true

raise TermError
raise TermError unless status == 0
raise Gem::SystemExitException, status
end

end
Expand Down
11 changes: 11 additions & 0 deletions test/test_gem_gem_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ def test_do_configuration
assert_equal %w[--all], Gem::DocManager.configured_args
end

def test_build_args__are_handled
Gem.clear_paths

gr = Gem::GemRunner.new
assert_raises(Gem::SystemExitException) do
gr.run(%W[--help -- --build_arg1 --build_arg2])
end

assert_equal %w[--build_arg1 --build_arg2], Gem::Command.build_args
end

end

0 comments on commit 159af05

Please sign in to comment.