Merge pull request #5482 from hsbt/rubygems-3-3-bundler-2-3

Merge RubyGems 3.3.x and Bundler 2.3.x
This commit is contained in:
Hiroshi SHIBATA 2022-02-02 16:57:34 +09:00 committed by GitHub
parent 69463805f0
commit 6794f8cf92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
115 changed files with 1701 additions and 889 deletions

View file

@ -117,12 +117,12 @@ If no gems are named all gems in GEM_HOME are cleaned.
def get_candidate_gems
@candidate_gems = unless options[:args].empty?
options[:args].map do |gem_name|
Gem::Specification.find_all_by_name gem_name
end.flatten
else
Gem::Specification.to_a
end
options[:args].map do |gem_name|
Gem::Specification.find_all_by_name gem_name
end.flatten
else
Gem::Specification.to_a
end
end
def get_gems_to_cleanup

View file

@ -53,41 +53,41 @@ use with other commands.
"#{program_name} REGEXP"
end
def fetch_remote_specs(dependency) # :nodoc:
def fetch_remote_specs(name, requirement, prerelease) # :nodoc:
fetcher = Gem::SpecFetcher.fetcher
ss, = fetcher.spec_for_dependency dependency
specs_type = prerelease ? :complete : :released
ss.map {|spec, _| spec }
ss = if name.nil?
fetcher.detect(specs_type) { true }
else
fetcher.detect(specs_type) do |name_tuple|
name === name_tuple.name && requirement.satisfied_by?(name_tuple.version)
end
end
ss.map {|tuple, source| source.fetch_spec(tuple) }
end
def fetch_specs(name_pattern, dependency) # :nodoc:
def fetch_specs(name_pattern, requirement, prerelease) # :nodoc:
specs = []
if local?
specs.concat Gem::Specification.stubs.find_all {|spec|
name_pattern =~ spec.name and
dependency.requirement.satisfied_by? spec.version
name_matches = name_pattern ? name_pattern =~ spec.name : true
version_matches = requirement.satisfied_by?(spec.version)
name_matches and version_matches
}.map(&:to_spec)
end
specs.concat fetch_remote_specs dependency if remote?
specs.concat fetch_remote_specs name_pattern, requirement, prerelease if remote?
ensure_specs specs
specs.uniq.sort
end
def gem_dependency(pattern, version, prerelease) # :nodoc:
dependency = Gem::Deprecate.skip_during do
Gem::Dependency.new pattern, version
end
dependency.prerelease = prerelease
dependency
end
def display_pipe(specs) # :nodoc:
specs.each do |spec|
unless spec.dependencies.empty?
@ -119,11 +119,9 @@ use with other commands.
ensure_local_only_reverse_dependencies
pattern = name_pattern options[:args]
requirement = Gem::Requirement.new options[:version]
dependency =
gem_dependency pattern, options[:version], options[:prerelease]
specs = fetch_specs pattern, dependency
specs = fetch_specs pattern, requirement, options[:prerelease]
reverse = reverse_dependencies specs
@ -162,14 +160,6 @@ use with other commands.
response
end
def remote_specs(dependency) # :nodoc:
fetcher = Gem::SpecFetcher.fetcher
ss, _ = fetcher.spec_for_dependency dependency
ss.map {|s,o| s }
end
def reverse_dependencies(specs) # :nodoc:
reverse = Hash.new {|h, k| h[k] = [] }
@ -205,7 +195,7 @@ use with other commands.
private
def name_pattern(args)
args << '' if args.empty?
return if args.empty?
if args.length == 1 and args.first =~ /\A(.*)(i)?\z/m
flags = $2 ? Regexp::IGNORECASE : nil

View file

@ -8,7 +8,12 @@ class Gem::Commands::FetchCommand < Gem::Command
include Gem::VersionOption
def initialize
super 'fetch', 'Download a gem and place it in the current directory'
defaults = {
:suggest_alternate => true,
:version => Gem::Requirement.default,
}
super 'fetch', 'Download a gem and place it in the current directory', defaults
add_bulk_threshold_option
add_proxy_option
@ -18,6 +23,10 @@ class Gem::Commands::FetchCommand < Gem::Command
add_version_option
add_platform_option
add_prerelease_option
add_option '--[no-]suggestions', 'Suggest alternates when gems are not found' do |value, options|
options[:suggest_alternate] = value
end
end
def arguments # :nodoc:
@ -42,15 +51,27 @@ then repackaging it.
"#{program_name} GEMNAME [GEMNAME ...]"
end
def check_version # :nodoc:
if options[:version] != Gem::Requirement.default and
get_all_gem_names.size > 1
alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \
" version requirements using `gem fetch 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`"
terminate_interaction 1
end
end
def execute
version = options[:version] || Gem::Requirement.default
check_version
version = options[:version]
platform = Gem.platforms.last
gem_names = get_all_gem_names
gem_names = get_all_gem_names_and_versions
gem_names.each do |gem_name|
dep = Gem::Dependency.new gem_name, version
gem_names.each do |gem_name, gem_version|
gem_version ||= version
dep = Gem::Dependency.new gem_name, gem_version
dep.prerelease = options[:prerelease]
suppress_suggestions = !options[:suggest_alternate]
specs_and_sources, errors =
Gem::SpecFetcher.fetcher.spec_for_dependency dep
@ -63,12 +84,10 @@ then repackaging it.
spec, source = specs_and_sources.max_by {|s,| s }
if spec.nil?
show_lookup_failure gem_name, version, errors, options[:domain]
show_lookup_failure gem_name, gem_version, errors, suppress_suggestions, options[:domain]
next
end
source.download spec
say "Downloaded #{spec.full_name}"
end
end

View file

@ -10,7 +10,7 @@ class Gem::Commands::ListCommand < Gem::Command
def initialize
super 'list', 'Display local gems whose name matches REGEXP',
:name => //, :domain => :local, :details => false, :versions => true,
:domain => :local, :details => false, :versions => true,
:installed => nil, :version => Gem::Requirement.default
add_query_options

View file

@ -98,20 +98,20 @@ extensions will be restored.
def execute
specs = if options[:all]
Gem::Specification.map
Gem::Specification.map
# `--extensions` must be explicitly given to pristine only gems
# with extensions.
elsif options[:extensions_set] and
# `--extensions` must be explicitly given to pristine only gems
# with extensions.
elsif options[:extensions_set] and
options[:extensions] and options[:args].empty?
Gem::Specification.select do |spec|
spec.extensions and not spec.extensions.empty?
end
else
get_all_gem_names.sort.map do |gem_name|
Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse
end.flatten
end
Gem::Specification.select do |spec|
spec.extensions and not spec.extensions.empty?
end
else
get_all_gem_names.sort.map do |gem_name|
Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse
end.flatten
end
specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform || spec.platform == Gem::Platform::RUBY }

View file

@ -52,14 +52,14 @@ The push command will use ~/.gem/credentials to authenticate to a server, but yo
default_gem_server, push_host = get_hosts_for(gem_name)
@host = if @user_defined_host
options[:host]
elsif default_gem_server
default_gem_server
elsif push_host
push_host
else
options[:host]
end
options[:host]
elsif default_gem_server
default_gem_server
elsif push_host
push_host
else
options[:host]
end
sign_in @host, scope: get_push_scope

View file

@ -20,7 +20,7 @@ class Gem::Commands::QueryCommand < Gem::Command
def initialize(name = 'query',
summary = 'Query gem information in local or remote repositories')
super name, summary,
:name => //, :domain => :local, :details => false, :versions => true,
:domain => :local, :details => false, :versions => true,
:installed => nil, :version => Gem::Requirement.default
add_option('-n', '--name-matches REGEXP',

View file

@ -61,12 +61,12 @@ Use --overwrite to force rebuilding of documentation.
def execute
specs = if options[:all]
Gem::Specification.to_a
else
get_all_gem_names.map do |name|
Gem::Specification.find_by_name name, options[:version]
end.flatten.uniq
end
Gem::Specification.to_a
else
get_all_gem_names.map do |name|
Gem::Specification.find_by_name name, options[:version]
end.flatten.uniq
end
if specs.empty?
alert_error 'No matching gems found'

View file

@ -7,7 +7,7 @@ class Gem::Commands::SearchCommand < Gem::Command
def initialize
super 'search', 'Display remote gems whose name matches REGEXP',
:name => //, :domain => :remote, :details => false, :versions => true,
:domain => :remote, :details => false, :versions => true,
:installed => nil, :version => Gem::Requirement.default
add_query_options

View file

@ -54,10 +54,10 @@ class Gem::Commands::SetupCommand < Gem::Command
'List the documentation types you wish to',
'generate. For example: rdoc,ri' do |value, options|
options[:document] = case value
when nil then %w[rdoc ri]
when false then []
else value
end
when nil then %w[rdoc ri]
when false then []
else value
end
end
add_option '--[no-]rdoc',
@ -666,10 +666,10 @@ abort "#{deprecation_message}"
def target_bin_path(bin_dir, bin_file)
bin_file_formatted = if options[:format_executable]
Gem.default_exec_format % bin_file
else
bin_file
end
Gem.default_exec_format % bin_file
else
bin_file
end
File.join bin_dir, bin_file_formatted
end

View file

@ -140,10 +140,10 @@ Specific fields in the specification can be extracted in YAML format:
s = s.send field if field
say case options[:format]
when :ruby then s.to_ruby
when :marshal then Marshal.dump s
else s.to_yaml
end
when :ruby then s.to_ruby
when :marshal then Marshal.dump s
else s.to_yaml
end
say "\n"
end

View file

@ -233,10 +233,10 @@ command to remove old versions.
up_ver = gems_to_update.first.version
target = if update_latest
up_ver
else
version
end
up_ver
else
version
end
return target, requirement
end
@ -286,10 +286,11 @@ command to remove old versions.
check_oldest_rubygems version
update_gem 'rubygems-update', version
installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
version = installed_gems.first.version
installed_gems = update_gem('rubygems-update', version) if installed_gems.empty? || installed_gems.first.version != version
return if installed_gems.empty?
version = installed_gems.first.version
install_rubygems version
end
@ -335,7 +336,9 @@ command to remove old versions.
#
def oldest_supported_version
@oldest_supported_version ||=
if Gem.ruby_version > Gem::Version.new("3.0.a")
if Gem.ruby_version > Gem::Version.new("3.1.a")
Gem::Version.new("3.3.3")
elsif Gem.ruby_version > Gem::Version.new("3.0.a")
Gem::Version.new("3.2.3")
elsif Gem.ruby_version > Gem::Version.new("2.7.a")
Gem::Version.new("3.1.2")