diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-02-05 23:51:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-05 14:51:04 +0000 |
| commit | ac526abcd6d82545b8dc3586efb55d75f45f7417 (patch) | |
| tree | 437dbd39424f87611523feed739b788a4b4a118b /lib | |
| parent | 7f97e3540ce448b501bcbee15afac5f94bb22dd9 (diff) | |
Merge RubyGems 3.5.5 and Bundler 2.5.5 (#9676)
* Merge RubyGems-3.5.4 and Bundler-2.5.4
* Merge RubyGems-3.5.5 and Bundler-2.5.5
* Make tests play with upstream Ruby tests
CI broke in https://github.com/ruby/ruby/pull/9604 because if any Ruby
tests run `require 'net/http'`, they will pollute the
`$LOADED_FEATURES` for the RubyGems tests. We can fix this by renaming
the test default gem from `net-http` to `my-http`.
See https://github.com/rubygems/rubygems/pull/7379#issuecomment-1901241299
for more details.
---------
Co-authored-by: Stan Hu <stanhu@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bundler/compact_index_client/updater.rb | 8 | ||||
| -rw-r--r-- | lib/bundler/definition.rb | 12 | ||||
| -rw-r--r-- | lib/bundler/dsl.rb | 14 | ||||
| -rw-r--r-- | lib/bundler/man/bundle-config.1 | 4 | ||||
| -rw-r--r-- | lib/bundler/man/bundle-config.1.ronn | 4 | ||||
| -rw-r--r-- | lib/bundler/spec_set.rb | 81 | ||||
| -rw-r--r-- | lib/bundler/version.rb | 2 | ||||
| -rw-r--r-- | lib/rubygems.rb | 9 | ||||
| -rw-r--r-- | lib/rubygems/commands/update_command.rb | 8 | ||||
| -rw-r--r-- | lib/rubygems/core_ext/kernel_require.rb | 13 | ||||
| -rw-r--r-- | lib/rubygems/defaults.rb | 2 | ||||
| -rw-r--r-- | lib/rubygems/specification.rb | 2 |
12 files changed, 98 insertions, 61 deletions
diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 84a606dc34..36f6b81db8 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -42,7 +42,7 @@ module Bundler else file.write(response.body) end - CacheFile.write(etag_path, etag(response)) + CacheFile.write(etag_path, etag_from_response(response)) true end end @@ -53,13 +53,13 @@ module Bundler response = @fetcher.call(remote_path, request_headers(etag)) return true if response.is_a?(Gem::Net::HTTPNotModified) CacheFile.write(local_path, response.body, parse_digests(response)) - CacheFile.write(etag_path, etag(response)) + CacheFile.write(etag_path, etag_from_response(response)) end def request_headers(etag, range_start = nil) headers = {} headers["Range"] = "bytes=#{range_start}-" if range_start - headers["If-None-Match"] = etag if etag + headers["If-None-Match"] = %("#{etag}") if etag headers end @@ -77,7 +77,7 @@ module Bundler etag end - def etag(response) + def etag_from_response(response) return unless response["ETag"] etag = response["ETag"].delete_prefix("W/") return if etag.delete_prefix!('"') && !etag.delete_suffix!('"') diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 9b905db1f9..0b0e63f77e 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -312,10 +312,6 @@ module Bundler end end - def should_complete_platforms? - !lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform] - end - def spec_git_paths sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact end @@ -517,6 +513,10 @@ module Bundler private + def should_add_extra_platforms? + !lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform] + end + def lockfile_exists? lockfile && File.exist?(lockfile) end @@ -600,7 +600,9 @@ module Bundler result = SpecSet.new(resolver.start) @resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version - @platforms = result.complete_platforms!(platforms) if should_complete_platforms? + @platforms = result.add_extra_platforms!(platforms) if should_add_extra_platforms? + + result.complete_platforms!(platforms) SpecSet.new(result.for(dependencies, false, @platforms)) end diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 1eca749617..1460b9f52f 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -102,9 +102,6 @@ module Bundler # if there's already a dependency with this name we try to prefer one if current = @dependencies.find {|d| d.name == dep.name } - # Always prefer the dependency from the Gemfile - @dependencies.delete(current) if current.gemspec_dev_dep? - if current.requirement != dep.requirement current_requirement_open = current.requirements_list.include?(">= 0") @@ -116,8 +113,6 @@ module Bundler Bundler.ui.warn "A gemspec development dependency (#{gemspec_dep.name}, #{gemspec_dep.requirement}) is being overridden by a Gemfile dependency (#{gemfile_dep.name}, #{gemfile_dep.requirement}).\n" \ "This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement\n" end - - return if dep.gemspec_dev_dep? else update_prompt = "" @@ -135,8 +130,13 @@ module Bundler "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ "#{update_prompt}" end - elsif current.gemspec_dev_dep? || dep.gemspec_dev_dep? - return if dep.gemspec_dev_dep? + end + + # Always prefer the dependency from the Gemfile + if current.gemspec_dev_dep? + @dependencies.delete(current) + elsif dep.gemspec_dev_dep? + return elsif current.source != dep.source raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \ "You specified that #{dep.name} (#{dep.requirement}) should come from " \ diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 8090e03f7d..c5a976da46 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -302,9 +302,9 @@ Note that any configured credentials will be redacted by informative commands su .P Also note that to guarantee a sane mapping between valid environment variable names and valid host names, bundler makes the following transformations: .IP "\(bu" 4 -Any \fB\-\fR characters in a host name are mapped to a triple dash (\fB___\fR) in the corresponding environment variable\. +Any \fB\-\fR characters in a host name are mapped to a triple underscore (\fB___\fR) in the corresponding environment variable\. .IP "\(bu" 4 -Any \fB\.\fR characters in a host name are mapped to a double dash (\fB__\fR) in the corresponding environment variable\. +Any \fB\.\fR characters in a host name are mapped to a double underscore (\fB__\fR) in the corresponding environment variable\. .IP "" 0 .P This means that if you have a gem server named \fBmy\.gem\-host\.com\fR, you'll need to use the \fBBUNDLE_MY__GEM___HOST__COM\fR variable to configure credentials for it through ENV\. diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn index b935329b4e..587d31dbad 100644 --- a/lib/bundler/man/bundle-config.1.ronn +++ b/lib/bundler/man/bundle-config.1.ronn @@ -388,10 +388,10 @@ copy-pasting bundler output. Also note that to guarantee a sane mapping between valid environment variable names and valid host names, bundler makes the following transformations: -* Any `-` characters in a host name are mapped to a triple dash (`___`) in the +* Any `-` characters in a host name are mapped to a triple underscore (`___`) in the corresponding environment variable. -* Any `.` characters in a host name are mapped to a double dash (`__`) in the +* Any `.` characters in a host name are mapped to a double underscore (`__`) in the corresponding environment variable. This means that if you have a gem server named `my.gem-host.com`, you'll need to diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index ceaac2cec5..cc649abaf8 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -52,32 +52,14 @@ module Bundler specs.uniq end - def complete_platforms!(platforms) + def add_extra_platforms!(platforms) return platforms.concat([Gem::Platform::RUBY]).uniq if @specs.empty? - new_platforms = @specs.flat_map {|spec| spec.source.specs.search([spec.name, spec.version]).map(&:platform) }.uniq.select do |platform| + new_platforms = all_platforms.select do |platform| next if platforms.include?(platform) next unless GemHelpers.generic(platform) == Gem::Platform::RUBY - new_specs = [] - - valid_platform = lookup.all? do |_, specs| - spec = specs.first - matching_specs = spec.source.specs.search([spec.name, spec.version]) - platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find do |s| - s.matches_current_metadata? && valid_dependencies?(s) - end - - if platform_spec - new_specs << LazySpecification.from_spec(platform_spec) - true - else - false - end - end - next unless valid_platform - - @specs.concat(new_specs.uniq) + complete_platform(platform) end return platforms if new_platforms.empty? @@ -86,12 +68,15 @@ module Bundler less_specific_platform = new_platforms.find {|platform| platform != Gem::Platform::RUBY && platform === Bundler.local_platform } platforms.delete(Bundler.local_platform) if less_specific_platform - @sorted = nil - @lookup = nil - platforms end + def complete_platforms!(platforms) + platforms.each do |platform| + complete_platform(platform) + end + end + def validate_deps(s) s.runtime_dependencies.each do |dep| next if dep.name == "bundler" @@ -110,14 +95,14 @@ module Bundler def []=(key, value) @specs << value - @lookup = nil - @sorted = nil + + reset! end def delete(specs) specs.each {|spec| @specs.delete(spec) } - @lookup = nil - @sorted = nil + + reset! end def sort! @@ -175,8 +160,8 @@ module Bundler def delete_by_name(name) @specs.reject! {|spec| spec.name == name } - @lookup = nil - @sorted = nil + + reset! end def what_required(spec) @@ -212,6 +197,42 @@ module Bundler private + def reset! + @sorted = nil + @lookup = nil + end + + def complete_platform(platform) + new_specs = [] + + valid_platform = lookup.all? do |_, specs| + spec = specs.first + matching_specs = spec.source.specs.search([spec.name, spec.version]) + platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find do |s| + s.matches_current_metadata? && valid_dependencies?(s) + end + + if platform_spec + new_specs << LazySpecification.from_spec(platform_spec) unless specs.include?(platform_spec) + true + else + false + end + end + + if valid_platform && new_specs.any? + @specs.concat(new_specs) + + reset! + end + + valid_platform + end + + def all_platforms + @specs.flat_map {|spec| spec.source.specs.search([spec.name, spec.version]).map(&:platform) }.uniq + end + def valid_dependencies?(s) validate_deps(s) == :valid end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index a0ef931d07..05b6c66ce4 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.5.3".freeze + VERSION = "2.5.5".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 fa3da5cc1a..d4138b2d8f 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -9,7 +9,7 @@ require "rbconfig" module Gem - VERSION = "3.5.3" + VERSION = "3.5.5" end # Must be first since it unloads the prelude from 1.9.2 @@ -1216,6 +1216,13 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} ## # Find a Gem::Specification of default gem from +path+ + def find_default_spec(path) + @path_to_default_spec_map[path] + end + + ## + # Find an unresolved Gem::Specification of default gem from +path+ + def find_unresolved_default_spec(path) default_spec = @path_to_default_spec_map[path] return default_spec if default_spec && loaded_specs[default_spec.name] != default_spec diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 10ae6d9a93..3d6fecaa40 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -244,7 +244,7 @@ command to remove old versions. @installer = Gem::DependencyInstaller.new update_options - say "Updating #{name}" unless options[:system] && options[:silent] + say "Updating #{name}" unless options[:system] begin @installer.install name, Gem::Requirement.new(version) rescue Gem::InstallError, Gem::DependencyError => e @@ -282,7 +282,7 @@ command to remove old versions. check_oldest_rubygems version installed_gems = Gem::Specification.find_all_by_name "rubygems-update", requirement - installed_gems = update_gem("rubygems-update", version) if installed_gems.empty? || installed_gems.first.version != version + installed_gems = update_gem("rubygems-update", requirement) if installed_gems.empty? || installed_gems.first.version != version return if installed_gems.empty? install_rubygems installed_gems.first @@ -294,9 +294,7 @@ command to remove old versions. args << "--prefix" << Gem.prefix if Gem.prefix args << "--no-document" unless options[:document].include?("rdoc") || options[:document].include?("ri") args << "--no-format-executable" if options[:no_format_executable] - args << "--previous-version" << Gem::VERSION if - options[:system] == true || - Gem::Version.new(options[:system]) >= Gem::Version.new(2) + args << "--previous-version" << Gem::VERSION args end diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index bbd7852e92..073966b696 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -39,7 +39,14 @@ module Kernel RUBYGEMS_ACTIVATION_MONITOR.synchronize do path = File.path(path) - if spec = Gem.find_unresolved_default_spec(path) + # If +path+ belongs to a default gem, we activate it and then go straight + # to normal require + + if spec = Gem.find_default_spec(path) + name = spec.name + + next if Gem.loaded_specs[name] + # Ensure -I beats a default gem resolved_path = begin rp = nil @@ -57,8 +64,10 @@ module Kernel rp end - Kernel.send(:gem, spec.name, Gem::Requirement.default_prerelease) unless + Kernel.send(:gem, name, Gem::Requirement.default_prerelease) unless resolved_path + + next end # If there are no unresolved deps, then we can use just try diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 00dc5707c3..19cf306f88 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -24,7 +24,7 @@ module Gem default_spec_cache_dir = File.join Gem.user_home, ".gem", "specs" unless File.exist?(default_spec_cache_dir) - default_spec_cache_dir = File.join Gem.data_home, "gem", "specs" + default_spec_cache_dir = File.join Gem.cache_home, "gem", "specs" end default_spec_cache_dir diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index a0c7faa133..169002d7c7 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -301,7 +301,7 @@ class Gem::Specification < Gem::BasicSpecification # # Usage: # - # spec.description = <<-EOF + # spec.description = <<~EOF # Rake is a Make-like program implemented in Ruby. Tasks and # dependencies are specified in standard Ruby syntax. # EOF |
