[前][次][番号順一覧][スレッド一覧]

ruby-changes:63156

From: Nobuyoshi <ko1@a...>
Date: Mon, 28 Sep 2020 14:54:42 +0900 (JST)
Subject: [ruby-changes:63156] 0629e695e3 (master): Added `--platform` option to `build` command

https://git.ruby-lang.org/ruby.git/commit/?id=0629e695e3

From 0629e695e3130f875641542ad2593b19b56703ef Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 10 Jan 2020 20:18:31 +0900
Subject: Added `--platform` option to `build` command


diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb
index decdca0..eaf8573 100644
--- a/lib/rubygems/commands/build_command.rb
+++ b/lib/rubygems/commands/build_command.rb
@@ -1,11 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/build_command.rb#L1
 # 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 883cad3..dc93adb 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1991,6 +1991,10 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1991
     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 3d1f759..01f3487 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L37
 
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L88
     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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_build_command.rb#L349
     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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]