diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-10-06 15:43:48 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-10-08 12:27:30 +0900 |
commit | d77e6e653d32fa6287286cc68300abc0d1a299da (patch) | |
tree | 5eba1ad51312bb634e7660607e6cb699fad54607 /lib | |
parent | d2f4cbf04215e536bcd06fde9cc7cec3b5566707 (diff) |
Merge RubyGems-3.3.23 and Bundler-2.3.23
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli/init.rb | 6 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 14 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 1 | ||||
-rw-r--r-- | lib/bundler/gem_version_promoter.rb | 13 | ||||
-rw-r--r-- | lib/bundler/index.rb | 29 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 18 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 13 | ||||
-rw-r--r-- | lib/bundler/spec_set.rb | 2 | ||||
-rw-r--r-- | lib/bundler/templates/newgem/gitlab-ci.yml.tt | 9 | ||||
-rw-r--r-- | lib/bundler/version.rb | 2 | ||||
-rw-r--r-- | lib/rubygems.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 9 | ||||
-rw-r--r-- | lib/rubygems/package.rb | 13 | ||||
-rw-r--r-- | lib/rubygems/platform.rb | 18 | ||||
-rw-r--r-- | lib/rubygems/resolver.rb | 2 |
15 files changed, 78 insertions, 73 deletions
diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb index e4f8229c48..bc96507c29 100644 --- a/lib/bundler/cli/init.rb +++ b/lib/bundler/cli/init.rb @@ -32,7 +32,11 @@ module Bundler file << spec.to_gemfile end else - FileUtils.cp(File.expand_path("../templates/#{gemfile}", __dir__), gemfile) + File.open(File.expand_path("../templates/#{gemfile}", __dir__), "r") do |template| + File.open(gemfile, "wb") do |destination| + IO.copy_stream(template, destination) + end + end end puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}" diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 79369ec374..a46d7387de 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -106,6 +106,7 @@ module Bundler @locked_gems = nil @locked_deps = {} @locked_specs = SpecSet.new([]) + @originally_locked_specs = @locked_specs @locked_sources = [] @locked_platforms = [] end @@ -149,18 +150,7 @@ module Bundler end def gem_version_promoter - @gem_version_promoter ||= begin - locked_specs = - if unlocking? && @locked_specs.empty? && !@lockfile_contents.empty? - # Definition uses an empty set of locked_specs to indicate all gems - # are unlocked, but GemVersionPromoter needs the locked_specs - # for conservative comparison. - Bundler::SpecSet.new(@locked_gems.specs) - else - @locked_specs - end - GemVersionPromoter.new(locked_specs, @unlock[:gems]) - end + @gem_version_promoter ||= GemVersionPromoter.new(@originally_locked_specs, @unlock[:gems]) end def resolve_only_locally! diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 385fdd4383..547db16190 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -67,7 +67,6 @@ module Bundler gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact gemspecs.reject! {|s| s.name != name } if name - Index.sort_specs(gemspecs) specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] } case specs_by_name_and_version.size diff --git a/lib/bundler/gem_version_promoter.rb b/lib/bundler/gem_version_promoter.rb index 1ae41e2928..ee2c38a6ec 100644 --- a/lib/bundler/gem_version_promoter.rb +++ b/lib/bundler/gem_version_promoter.rb @@ -116,15 +116,14 @@ module Bundler end def sort_dep_specs(spec_groups, locked_spec) - return spec_groups unless locked_spec - @gem_name = locked_spec.name - @locked_version = locked_spec.version + @locked_version = locked_spec&.version + @gem_name = locked_spec&.name result = spec_groups.sort do |a, b| @a_ver = a.version @b_ver = b.version - unless @prerelease_specified[@gem_name] + unless @gem_name && @prerelease_specified[@gem_name] a_pre = @a_ver.prerelease? b_pre = @b_ver.prerelease? @@ -148,7 +147,7 @@ module Bundler end def either_version_older_than_locked - @a_ver < @locked_version || @b_ver < @locked_version + @locked_version && (@a_ver < @locked_version || @b_ver < @locked_version) end def segments_do_not_match(level) @@ -157,7 +156,7 @@ module Bundler end def unlocking_gem? - unlock_gems.empty? || unlock_gems.include?(@gem_name) + unlock_gems.empty? || (@gem_name && unlock_gems.include?(@gem_name)) end # Specific version moves can't always reliably be done during sorting @@ -165,7 +164,7 @@ module Bundler def post_sort(result) # default :major behavior in Bundler does not do this return result if major? - if unlocking_gem? + if unlocking_gem? || @locked_version.nil? result else move_version_to_end(result, @locked_version) diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index 00c7a9e00d..d3743adb68 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -57,36 +57,13 @@ module Bundler # Search this index's specs, and any source indexes that this index knows # about, returning all of the results. def search(query) - sort_specs(unsorted_search(query)) - end - - def unsorted_search(query) results = local_search(query) - - seen = results.map(&:full_name).uniq unless @sources.empty? + return results unless @sources.any? @sources.each do |source| - source.unsorted_search(query).each do |spec| - next if seen.include?(spec.full_name) - - seen << spec.full_name - results << spec - end + results.concat(source.search(query)) end - - results - end - protected :unsorted_search - - def self.sort_specs(specs) - specs.sort_by do |s| - platform_string = s.platform.to_s - [s.version, platform_string == RUBY ? NULL : platform_string] - end - end - - def sort_specs(specs) - self.class.sort_specs(specs) + results.uniq(&:full_name) end def local_search(query) diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index fcb3812c5a..161a3c0518 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -42,8 +42,7 @@ module Bundler remove_from_candidates(spec) end - @gem_version_promoter.prerelease_specified = @prerelease_specified = {} - requirements.each {|dep| @prerelease_specified[dep.name] ||= dep.prerelease? } + requirements.each {|dep| prerelease_specified[dep.name] ||= dep.prerelease? } verify_gemfile_dependencies_are_found!(requirements) result = @resolver.resolve(requirements). @@ -127,13 +126,6 @@ module Bundler results = results_for(dependency) + locked_results results = results.select {|spec| requirement_satisfied_by?(locked_requirement, nil, spec) } if locked_requirement - if !@prerelease_specified[name] && locked_results.empty? - # Move prereleases to the beginning of the list, so they're considered - # last during resolution. - pre, results = results.partition {|spec| spec.version.prerelease? } - results = pre + results - end - if results.any? results = @gem_version_promoter.sort_versions(dependency, results) @@ -221,6 +213,10 @@ module Bundler @base.base_requirements end + def prerelease_specified + @gem_version_promoter.prerelease_specified + end + def remove_from_candidates(spec) @base.delete(spec) @@ -255,7 +251,7 @@ module Bundler all - 1_000_000 else search = search_for(dependency) - search = @prerelease_specified[dependency.name] ? search.count : search.count {|s| !s.version.prerelease? } + search = prerelease_specified[dependency.name] ? search.count : search.count {|s| !s.version.prerelease? } search - all end end @@ -284,7 +280,7 @@ module Bundler end def gem_not_found_message(name, requirement, source, extra_message = "") - specs = source.specs.search(name) + specs = source.specs.search(name).sort_by {|s| [s.version, s.platform.to_s] } matching_part = name requirement_label = SharedHelpers.pretty_dependency(requirement) cache_message = begin diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 8b46d7ece4..d53d688009 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -261,10 +261,21 @@ module Gem # version ( (@os != "linux" && (@version.nil? || other.version.nil?)) || - (@os == "linux" && (other.version == "gnu#{@version}" || other.version == "musl#{@version}" || @version == "gnu#{other.version}")) || + (@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) || @version == other.version ) end + + # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`. + # Once only 3.3.23 is supported, we can use the method in RubyGems. + def normalized_linux_version_ext + return nil unless @version + + without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "") + return nil if without_gnu_nor_abi_modifiers.empty? + + without_gnu_nor_abi_modifiers + end end end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 1d0b7a460d..21d57fdab4 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -176,7 +176,7 @@ module Bundler def lookup @lookup ||= begin lookup = Hash.new {|h, k| h[k] = [] } - Index.sort_specs(@specs).reverse_each do |s| + @specs.each do |s| lookup[s.name] << s end lookup diff --git a/lib/bundler/templates/newgem/gitlab-ci.yml.tt b/lib/bundler/templates/newgem/gitlab-ci.yml.tt index 0e71ff26a4..42e00392de 100644 --- a/lib/bundler/templates/newgem/gitlab-ci.yml.tt +++ b/lib/bundler/templates/newgem/gitlab-ci.yml.tt @@ -1,8 +1,9 @@ -image: ruby:<%= RUBY_VERSION %> +default: + image: ruby:<%= RUBY_VERSION %> -before_script: - - gem install bundler -v <%= Bundler::VERSION %> - - bundle install + before_script: + - gem install bundler -v <%= Bundler::VERSION %> + - bundle install example_job: script: diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 75760528fe..22ce7daab9 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.3.22".freeze + VERSION = "2.3.23".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index d3a32b773f..e2e78a41ac 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -8,7 +8,7 @@ require "rbconfig" module Gem - VERSION = "3.3.22".freeze + VERSION = "3.3.23".freeze end # Must be first since it unloads the prelude from 1.9.2 diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index a785159196..3477422b79 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -201,7 +201,8 @@ module Gem::GemcutterUtilities # block was given or shows the response body to the user. # # If the response was not successful, shows an error to the user including - # the +error_prefix+ and the response body. + # the +error_prefix+ and the response body. If the response was a permanent redirect, + # shows an error to the user including the redirect location. def with_response(response, error_prefix = nil) case response @@ -211,6 +212,12 @@ module Gem::GemcutterUtilities else say clean_text(response.body) end + when Net::HTTPPermanentRedirect, Net::HTTPRedirection then + message = "The request has redirected permanently to #{response['location']}. Please check your defined push host URL." + message = "#{error_prefix}: #{message}" if error_prefix + + say clean_text(message) + terminate_interaction(ERROR_CODE) else message = response.body message = "#{error_prefix}: #{message}" if error_prefix diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 084dc5d2d9..4672866985 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -444,10 +444,10 @@ EOM directories << mkdir end - File.open destination, "wb" do |out| - out.write entry.read + if entry.file? + File.open(destination, "wb") {|out| out.write entry.read } FileUtils.chmod file_mode(entry.header.mode), destination - end if entry.file? + end verbose destination end @@ -467,7 +467,12 @@ EOM end def file_mode(mode) # :nodoc: - ((mode & 0111).zero? ? data_mode : prog_mode) || mode + ((mode & 0111).zero? ? data_mode : prog_mode) || + # If we're not using one of the default modes, then we're going to fall + # back to the mode from the tarball. In this case we need to mask it down + # to fit into 2^16 bits (the maximum value for a mode in CRuby since it + # gets put into an unsigned short). + (mode & ((1 << 16) - 1)) end ## diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 06de5ded8d..6f4ead1af8 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -22,6 +22,7 @@ class Gem::Platform end def self.match_platforms?(platform, platforms) + platform = Gem::Platform.new(platform) unless platform.is_a?(Gem::Platform) platforms.any? do |local_platform| platform.nil? || local_platform == platform || @@ -162,6 +163,9 @@ class Gem::Platform # runtime platform "no version" stands for 'gnu'. To be able to disinguish # these, the method receiver is the gem platform, while the argument is # the runtime platform. + # + #-- + # NOTE: Until it can be removed, changes to this method must also be reflected in `bundler/lib/bundler/rubygems_ext.rb` def ===(other) return nil unless Gem::Platform === other @@ -180,11 +184,23 @@ class Gem::Platform # version ( (@os != "linux" && (@version.nil? || other.version.nil?)) || - (@os == "linux" && (other.version == "gnu#{@version}" || other.version == "musl#{@version}" || @version == "gnu#{other.version}")) || + (@os == "linux" && (normalized_linux_version == other.normalized_linux_version || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) || @version == other.version ) end + #-- + # NOTE: Until it can be removed, changes to this method must also be reflected in `bundler/lib/bundler/rubygems_ext.rb` + + def normalized_linux_version + return nil unless @version + + without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "") + return nil if without_gnu_nor_abi_modifiers.empty? + + without_gnu_nor_abi_modifiers + end + ## # Does +other+ match this platform? If +other+ is a String it will be # converted to a Gem::Platform first. See #=== for matching rules. diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb index bf7d6d943b..76d1e9d0cc 100644 --- a/lib/rubygems/resolver.rb +++ b/lib/rubygems/resolver.rb @@ -246,7 +246,7 @@ class Gem::Resolver sources.each do |source| groups[source]. - sort_by {|spec| [spec.version, Gem::Platform.local =~ spec.platform ? 1 : 0] }. + sort_by {|spec| [spec.version, spec.platform =~ Gem::Platform.local ? 1 : 0] }. map {|spec| ActivationRequest.new spec, dependency }. each {|activation_request| activation_requests << activation_request } end |