summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-10 20:18:31 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-28 14:54:22 +0900
commit0629e695e3130f875641542ad2593b19b56703ef (patch)
tree9fcab4edb8df8c74c695118838b48ab6a44d7a22
parent67ae1d441dbc2d944a08b95178f99d2cf67169e1 (diff)
Added `--platform` option to `build` command
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3599
-rw-r--r--lib/rubygems/commands/build_command.rb5
-rw-r--r--lib/rubygems/specification.rb4
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb32
3 files changed, 37 insertions, 4 deletions
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb
index decdca06bb..eaf8573d8f 100644
--- a/lib/rubygems/commands/build_command.rb
+++ b/lib/rubygems/commands/build_command.rb
@@ -1,11 +1,16 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/package'
+require 'rubygems/version_option'
class Gem::Commands::BuildCommand < Gem::Command
+ include Gem::VersionOption
+
def initialize
super 'build', 'Build a gem from a gemspec'
+ add_platform_option
+
add_option '--force', 'skip validation of the spec' do |value, options|
options[:force] = true
end
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 883cad35f9..dc93adb5ab 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1991,6 +1991,10 @@ class Gem::Specification < Gem::BasicSpecification
self.name = name if name
self.version = version if version
+ if platform = Gem.platforms.last and platform != Gem::Platform::RUBY and platform != Gem::Platform.local
+ self.platform = platform
+ end
+
yield self if block_given?
end
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 3d1f7596a4..01f3487ad4 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -37,6 +37,8 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert @cmd.options[:force]
assert @cmd.options[:strict]
+ assert @cmd.handles?(%W[--platform #{Gem::Platform.local}])
+ assert_includes Gem.platforms, Gem::Platform.local
end
def test_options_filename
@@ -86,6 +88,26 @@ class TestGemCommandsBuildCommand < Gem::TestCase
util_test_build_gem @gem
end
+ def test_execute_platform
+ gemspec_file = File.join(@tempdir, @gem.spec_name)
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ @cmd.options[:args] = [gemspec_file]
+
+ platforms = Gem.platforms.dup
+ begin
+ Gem.platforms << Gem::Platform.new("java")
+
+ spec = util_test_build_gem @gem, suffix: "java"
+ ensure
+ Gem.platforms.replace(platforms)
+ end
+ assert_match spec.platform, "java"
+ end
+
def test_execute_bad_name
[".", "-", "_"].each do |special_char|
gem = util_spec 'some_gem_with_bad_name' do |s|
@@ -327,27 +349,29 @@ class TestGemCommandsBuildCommand < Gem::TestCase
refute File.exist?(expected_gem)
end
- def util_test_build_gem(gem)
+ def util_test_build_gem(gem, suffix: nil)
use_ui @ui do
Dir.chdir @tempdir do
@cmd.execute
end
end
-
+ suffix &&= "-#{suffix}"
+ gem_file = "some_gem-2#{suffix}.gem"
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 " File: #{gem_file}", output.shift
assert_equal [], output
- gem_file = File.join(@tempdir, File.basename(gem.cache_file))
+ gem_file = File.join(@tempdir, gem_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
+ spec
end
def test_execute_force