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

Merge rubygems@21f12a8 from upstream.

* [BudlerVersionFinder] set .filter! and .compatible? to match only on major versions https://github.com/rubygems/rubygems/pull/2515
  * Fix broken symlink that points to ../* https://github.com/rubygems/rubygems/pull/2516

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2018-12-12 05:07:50 +00:00
parent 53a5b276b8
commit 7f9bf068fc
12 changed files with 90 additions and 54 deletions

View file

@ -37,20 +37,14 @@ To install the missing version, run `gem install bundler:#{vr.first}`
def self.compatible?(spec)
return true unless spec.name == "bundler".freeze
return true unless bundler_version = self.bundler_version
if bundler_version.segments.first >= 2
spec.version == bundler_version
else # 1.x
spec.version.segments.first < 2
end
spec.version.segments.first == bundler_version.segments.first
end
def self.filter!(specs)
return unless bundler_version = self.bundler_version
if bundler_version.segments.first >= 2
specs.reject! { |spec| spec.version != bundler_version }
else # 1.x
specs.reject! { |spec| spec.version.segments.first >= 2}
end
specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first }
end
def self.bundle_update_bundler_version

View file

@ -14,6 +14,10 @@ class Gem::Commands::BuildCommand < Gem::Command
add_option '--strict', 'consider warnings as errors when validating the spec' do |value, options|
options[:strict] = true
end
add_option '-o', '--output FILE', 'output gem with the given filename' do |value, options|
options[:output] = value
end
end
def arguments # :nodoc:
@ -36,6 +40,11 @@ with gem spec:
$ cd my_gem-1.0
[edit gem contents]
$ gem build my_gem-1.0.gemspec
Gems can be saved to a specified filename with the output option:
$ gem build my_gem-1.0.gemspec --output=release.gem
EOF
end
@ -58,7 +67,8 @@ with gem spec:
Gem::Package.build(
spec,
options[:force],
options[:strict]
options[:strict],
options[:output]
)
else
alert_error "Error loading gemspec. Aborting."

View file

@ -119,8 +119,8 @@ class Gem::Package
# Permission for other files
attr_accessor :data_mode
def self.build(spec, skip_validation = false, strict_validation = false)
gem_file = spec.file_name
def self.build(spec, skip_validation = false, strict_validation = false, file_name = nil)
gem_file = file_name || spec.file_name
package = new gem_file
package.spec = spec
@ -223,8 +223,13 @@ class Gem::Package
stat = File.lstat file
if stat.symlink?
relative_dir = File.dirname(file).sub("#{Dir.pwd}/", '')
target_path = File.join(relative_dir, File.readlink(file))
target_path = File.readlink(file)
unless target_path.start_with? '.'
relative_dir = File.dirname(file).sub("#{Dir.pwd}/", '')
target_path = File.join(relative_dir, target_path)
end
tar.add_symlink file, target_path, stat.mode
end
@ -281,7 +286,7 @@ class Gem::Package
Successfully built RubyGem
Name: #{@spec.name}
Version: #{@spec.version}
File: #{File.basename @spec.cache_file}
File: #{File.basename @gem.path}
EOM
ensure
@signer = nil

View file

@ -45,7 +45,6 @@ class Gem::Request
end
def self.configure_connection_for_https(connection, cert_files)
require 'net/https'
connection.use_ssl = true
connection.verify_mode =
Gem.configuration.ssl_verify_mode || OpenSSL::SSL::VERIFY_PEER

View file

@ -156,7 +156,6 @@ class Gem::Specification < Gem::BasicSpecification
:required_ruby_version => Gem::Requirement.default,
:required_rubygems_version => Gem::Requirement.default,
:requirements => [],
:rubyforge_project => nil,
:rubygems_version => Gem::VERSION,
:signing_key => nil,
:specification_version => CURRENT_SPECIFICATION_VERSION,
@ -730,12 +729,11 @@ class Gem::Specification < Gem::BasicSpecification
attr_writer :original_platform # :nodoc:
##
# The rubyforge project this gem lives under. i.e. RubyGems'
# rubyforge_project is "rubygems".
# Deprecated and ignored.
#
# This option is deprecated.
# Formerly used to set rubyforge project.
attr_accessor :rubyforge_project
attr_writer :rubyforge_project
##
# The Gem::Specification version of this gemspec.
@ -1347,7 +1345,7 @@ class Gem::Specification < Gem::BasicSpecification
spec.instance_variable_set :@required_rubygems_version, array[7]
spec.instance_variable_set :@original_platform, array[8]
spec.instance_variable_set :@dependencies, array[9]
spec.instance_variable_set :@rubyforge_project, array[10]
# offset due to rubyforge_project removal
spec.instance_variable_set :@email, array[11]
spec.instance_variable_set :@authors, array[12]
spec.instance_variable_set :@description, array[13]
@ -1392,7 +1390,7 @@ class Gem::Specification < Gem::BasicSpecification
@required_rubygems_version,
@original_platform,
@dependencies,
@rubyforge_project,
'', # rubyforge_project
@email,
@authors,
@description,

View file

@ -150,19 +150,24 @@ duplicate dependency on #{dep}, (#{prev.requirement}) use:
if open_ended
op, dep_version = dep.requirement.requirements.first
base = dep_version.segments.first 2
segments = dep_version.segments
bugfix = if op == '>'
", '> #{dep_version}'"
elsif op == '>=' and base != dep_version.segments
", '>= #{dep_version}'"
end
base = segments.first 2
warning_messages << <<-WARNING
open-ended dependency on #{dep} is not recommended
if #{dep.name} is semantically versioned, use:
add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}
WARNING
recommendation = if (op == '>' || op == '>=') && segments == [0]
" use a bounded requirement, such as '~> x.y'"
else
bugfix = if op == '>'
", '> #{dep_version}'"
elsif op == '>=' and base != segments
", '>= #{dep_version}'"
end
" if #{dep.name} is semantically versioned, use:\n" \
" add_#{dep.type}_dependency '#{dep.name}', '~> #{base.join '.'}'#{bugfix}"
end
warning_messages << ["open-ended dependency on #{dep} is not recommended", recommendation].join("\n") + "\n"
end
end
if error_messages.any?

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'rubygems/test_case'
require 'net/https'
require 'net/http'
require 'rubygems/request'
# = Testing Bundled CA

View file

@ -88,20 +88,21 @@ class TestGemBundlerVersionFinder < Gem::TestCase
bvf.stub(:bundler_version, v("2.1.1.1")) do
assert bvf.compatible?(util_spec("foo"))
assert bvf.compatible?(util_spec("bundler", "2.1.1.1"))
refute bvf.compatible?(util_spec("bundler", "2.1.1.a"))
assert bvf.compatible?(util_spec("bundler", "2.1.1.a"))
assert bvf.compatible?(util_spec("bundler", "2.999"))
refute bvf.compatible?(util_spec("bundler", "1.999"))
refute bvf.compatible?(util_spec("bundler", "2.999"))
refute bvf.compatible?(util_spec("bundler", "3.0.0"))
end
end
def test_filter
versions = %w[1 1.0 1.0.1.1 2.a 3 3.0]
versions = %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1]
specs = versions.map { |v| util_spec("bundler", v) }
assert_equal %w[1 1.0 1.0.1.1 2.a 3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s)
assert_equal %w[1 1.0 1.0.1.1 2 2.a 2.0 2.1.1 3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
bvf.stub(:bundler_version, v("2.1.1.1")) do
assert_empty util_filter_specs(specs).map(&:version).map(&:to_s)
assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
end
bvf.stub(:bundler_version, v("1.1.1.1")) do
assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
@ -110,10 +111,10 @@ class TestGemBundlerVersionFinder < Gem::TestCase
assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
end
bvf.stub(:bundler_version, v("2.a")) do
assert_equal %w[2.a], util_filter_specs(specs).map(&:version).map(&:to_s)
assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
end
bvf.stub(:bundler_version, v("3")) do
assert_equal %w[3 3.0], util_filter_specs(specs).map(&:version).map(&:to_s)
assert_equal %w[3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)
end
end

View file

@ -22,7 +22,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
@gem = util_spec 'some_gem' do |s|
s.rubyforge_project = 'example'
s.license = 'AGPL-3.0'
s.files = ['README.md']
end
@ -37,11 +36,39 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert @cmd.options[:strict]
end
def test_options_filename
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]
@cmd.options[:output] = "test.gem"
use_ui @ui do
Dir.chdir @tempdir do
@cmd.execute
end
end
file = File.join(@tempdir, File::SEPARATOR, "test.gem")
assert File.exist?(file)
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: test.gem", output.shift
assert_equal [], output
end
def test_handle_options_defaults
@cmd.handle_options []
refute @cmd.options[:force]
refute @cmd.options[:strict]
assert_nil @cmd.options[:output]
end
def test_execute
@ -97,7 +124,6 @@ class TestGemCommandsBuildCommand < Gem::TestCase
def test_execute_strict_with_warnings
bad_gem = util_spec 'some_bad_gem' do |s|
s.rubyforge_project = 'example'
s.files = ['README.md']
end

View file

@ -151,7 +151,7 @@ class TestGemPackage < Gem::Package::TarTestCase
def test_add_files_symlink
spec = Gem::Specification.new
spec.files = %w[lib/code.rb lib/code_sym.rb]
spec.files = %w[lib/code.rb lib/code_sym.rb lib/code_sym2.rb]
FileUtils.mkdir_p 'lib'
File.open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end
@ -159,6 +159,7 @@ class TestGemPackage < Gem::Package::TarTestCase
# NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb
begin
File.symlink('code.rb', 'lib/code_sym.rb')
File.symlink('../lib/code.rb', 'lib/code_sym2.rb')
rescue Errno::EACCES => e
if win_platform?
skip "symlink - must be admin with no UAC on Windows"
@ -189,7 +190,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
assert_equal %w[lib/code.rb], files
assert_equal [{'lib/code_sym.rb' => 'lib/code.rb'}], symlinks
assert_equal [{'lib/code_sym.rb' => 'lib/code.rb'}, {'lib/code_sym2.rb' => '../lib/code.rb'}], symlinks
end
def test_build

View file

@ -51,7 +51,6 @@ gems:
author: Jim Weirich
email: jim@weirichhouse.org
homepage: http://rake.rubyforge.org
rubyforge_project: rake
description: Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax.
autorequire:
default_executable: rake

View file

@ -48,7 +48,6 @@ end
s.extensions << 'ext/a/extconf.rb'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
s.license = 'MIT'
s.add_dependency 'rake', '> 0.4'
@ -80,7 +79,6 @@ end
s.executable = 'exec'
s.test_file = 'test/suite.rb'
s.requirements << 'A working computer'
s.rubyforge_project = 'example'
s.license = 'MIT'
s.mark_version
@ -701,7 +699,6 @@ end
required_ruby_version
required_rubygems_version
requirements
rubyforge_project
rubygems_version
signing_key
specification_version
@ -871,7 +868,6 @@ require_paths:
author: Austin Ziegler
email: diff-lcs@halostatue.ca
homepage: http://rubyforge.org/projects/ruwiki/
rubyforge_project: ruwiki
description: "Test"
bindir: bin
has_rdoc: true
@ -1215,7 +1211,7 @@ dependencies: []
data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
assert_nil data.rubyforge_project
assert_nil data.signing_key
end
def test_initialize
@ -2506,7 +2502,6 @@ Gem::Specification.new do |s|
s.homepage = "http://example.com".freeze
s.licenses = ["MIT".freeze]
s.requirements = ["A working computer".freeze]
s.rubyforge_project = "example".freeze
s.rubygems_version = "#{Gem::VERSION}".freeze
s.summary = "this is a summary".freeze
s.test_files = ["test/suite.rb".freeze]
@ -2699,6 +2694,7 @@ end
@a1.add_runtime_dependency 'l', '> 1.2.3'
@a1.add_runtime_dependency 'm', '~> 2.1.0'
@a1.add_runtime_dependency 'n', '~> 0.1.0'
@a1.add_runtime_dependency 'o'
use_ui @ui do
@a1.validate
@ -2719,6 +2715,8 @@ end
#{w}: open-ended dependency on l (> 1.2.3) is not recommended
if l is semantically versioned, use:
add_runtime_dependency 'l', '~> 1.2', '> 1.2.3'
#{w}: open-ended dependency on o (>= 0) is not recommended
use a bounded requirement, such as '~> x.y'
#{w}: See http://guides.rubygems.org/specification-reference/ for help
EXPECTED