Skip to content

Commit

Permalink
Restore gem build behavior and introdcue the "-C" flag to gem build
Browse files Browse the repository at this point in the history
  • Loading branch information
bronzdoc committed Jan 14, 2019
1 parent 0f6fd4a commit f406135
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
41 changes: 28 additions & 13 deletions lib/rubygems/commands/build_command.rb
Expand Up @@ -18,6 +18,10 @@ def initialize
add_option '-o', '--output FILE', 'output gem with the given filename' do |value, options|
options[:output] = value
end

add_option '-C PATH', '', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
options[:build_path] = value
end
end

def arguments # :nodoc:
Expand Down Expand Up @@ -60,25 +64,36 @@ def execute
end

if File.exist? gemspec
Dir.chdir(File.dirname(gemspec)) do
spec = Gem::Specification.load File.basename(gemspec)

if spec
Gem::Package.build(
spec,
options[:force],
options[:strict],
options[:output]
)
else
alert_error "Error loading gemspec. Aborting."
terminate_interaction 1
spec = Gem::Specification.load(gemspec)

if options[:build_path]
Dir.chdir(File.dirname(gemspec)) do
spec = Gem::Specification.load File.basename(gemspec)
build_package(spec)
end
else
build_package(spec)
end

else
alert_error "Gemspec file not found: #{gemspec}"
terminate_interaction 1
end
end

private

def build_package(spec)
if spec
Gem::Package.build(
spec,
options[:force],
options[:strict],
options[:output]
)
else
alert_error "Error loading gemspec. Aborting."
terminate_interaction 1
end
end
end
1 change: 1 addition & 0 deletions test/rubygems/test_gem_commands_build_command.rb
Expand Up @@ -207,6 +207,7 @@ def test_execute_outside_dir
gs.write @gem.to_ruby
end

@cmd.options[:build_path] = gemspec_dir
@cmd.options[:args] = [gemspec_file]

use_ui @ui do
Expand Down

0 comments on commit f406135

Please sign in to comment.