1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Added --platform option to build command

This commit is contained in:
Nobuyoshi Nakada 2020-01-10 20:18:31 +09:00 committed by Hiroshi SHIBATA
parent 67ae1d441d
commit 0629e695e3
Notes: git 2020-09-28 14:54:58 +09:00
3 changed files with 37 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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