Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gem build -C #3954

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/rubygems/commands/build_command.rb
Expand Up @@ -23,7 +23,9 @@ def initialize
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|
add_option '-C PATH', '', 'Look for the code of the gem to be built',
'in <PATH>. The GEMSPEC_FILE given as an',
'argument is not influenced by this option' do |value, options|
options[:build_path] = value
end
end
Expand Down Expand Up @@ -85,8 +87,7 @@ def build_gem(gem_name)
spec = Gem::Specification.load(gemspec)

if options[:build_path]
Dir.chdir(File.dirname(gemspec)) do
spec = Gem::Specification.load(File.basename(gemspec))
Dir.chdir(options[:build_path]) do
build_package(spec)
end
else
Expand Down
41 changes: 41 additions & 0 deletions test/rubygems/test_gem_commands_build_command.rb
Expand Up @@ -272,6 +272,47 @@ def test_execute_outside_dir
assert_equal "this is a summary", spec.summary
end

def test_execute_outside_dir_with_external_gemspec
gemspec_dir = File.join @tempdir, 'gemspec_dir'
gemspec_file = File.join gemspec_dir, @gem.spec_name

gemcode_dir = File.join @tempdir, 'build_command_gem'
readme_file = File.join gemcode_dir, 'README.md'

FileUtils.mkdir_p gemspec_dir
FileUtils.mkdir_p gemcode_dir

File.open readme_file, 'w' do |f|
f.write "My awesome gem in nested directory"
end

File.open gemspec_file, 'w' do |gs|
gs.write @gem.to_ruby
end

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

use_ui @ui do
@cmd.execute
end

output = @ui.output.split "\n"
assert_equal " Successfully built RubyGem", output.shift
assert_equal " Name: some_gem", output.shift
assert_equal " Version: 2", output.shift
assert_equal " File: some_gem-2.gem", output.shift
assert_equal [], output

gem_file = File.join gemcode_dir, File.basename(@gem.cache_file)
assert File.exist?(gem_file)

spec = Gem::Package.new(gem_file).spec

assert_equal "some_gem", spec.name
assert_equal "this is a summary", spec.summary
end

def test_can_find_gemspecs_without_dot_gemspec
gemspec_file = File.join(@tempdir, @gem.spec_name)

Expand Down