diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-09-25 16:53:34 +0900 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2024-09-25 10:56:17 -0700 |
| commit | 95f72a4a32396cae7475b39d7739fb534242b625 (patch) | |
| tree | 36659977598c75a869c8b1af924d24086003383d /lib | |
| parent | d8966416d010719ef8f1689137da31aa75e71198 (diff) | |
Merge RubyGems-3.5.17 and Bundler-2.5.17
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bundler/cli.rb | 36 | ||||
| -rw-r--r-- | lib/bundler/cli/check.rb | 2 | ||||
| -rw-r--r-- | lib/bundler/cli/gem.rb | 2 | ||||
| -rw-r--r-- | lib/bundler/definition.rb | 21 | ||||
| -rw-r--r-- | lib/bundler/force_platform.rb | 2 | ||||
| -rw-r--r-- | lib/bundler/plugin/api/source.rb | 1 | ||||
| -rw-r--r-- | lib/bundler/rubygems_ext.rb | 20 | ||||
| -rw-r--r-- | lib/bundler/runtime.rb | 5 | ||||
| -rw-r--r-- | lib/bundler/source/git.rb | 45 | ||||
| -rw-r--r-- | lib/bundler/spec_set.rb | 4 | ||||
| -rw-r--r-- | lib/bundler/version.rb | 2 | ||||
| -rw-r--r-- | lib/bundler/yaml_serializer.rb | 2 | ||||
| -rw-r--r-- | lib/rubygems.rb | 2 | ||||
| -rw-r--r-- | lib/rubygems/dependency.rb | 8 | ||||
| -rw-r--r-- | lib/rubygems/query_utils.rb | 2 | ||||
| -rw-r--r-- | lib/rubygems/uninstaller.rb | 16 | ||||
| -rw-r--r-- | lib/rubygems/yaml_serializer.rb | 2 |
17 files changed, 99 insertions, 73 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index b4aa36f246..743f32d014 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -110,8 +110,8 @@ module Bundler default_task(Bundler.feature_flag.default_cli_command) class_option "no-color", type: :boolean, desc: "Disable colorization in output" - class_option "retry", type: :numeric, aliases: "-r", banner: "NUM", - desc: "Specify the number of times you wish to attempt network commands" + class_option "retry", type: :numeric, aliases: "-r", banner: "NUM", + desc: "Specify the number of times you wish to attempt network commands" class_option "verbose", type: :boolean, desc: "Enable verbose output mode", aliases: "-V" def help(cli = nil) @@ -260,15 +260,15 @@ module Bundler method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" method_option "group", aliases: "-g", type: :array, banner: "Update a specific group" method_option "jobs", aliases: "-j", type: :numeric, banner: "Specify the number of jobs to run in parallel" - method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead" - method_option "quiet", type: :boolean, banner: "Only output warnings and errors." + method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "quiet", type: :boolean, banner: "Only output warnings and errors." method_option "source", type: :array, banner: "Update a specific source (and all gems associated with it)" method_option "redownload", type: :boolean, aliases: "--force", banner: "Force downloading every gem." method_option "ruby", type: :boolean, banner: "Update ruby specified in Gemfile.lock" method_option "bundler", type: :string, lazy_default: "> 0.a", banner: "Update the locked version of bundler" - method_option "patch", type: :boolean, banner: "Prefer updating only to next patch version" - method_option "minor", type: :boolean, banner: "Prefer updating only to next minor version" - method_option "major", type: :boolean, banner: "Prefer updating to next major version (default)" + method_option "patch", type: :boolean, banner: "Prefer updating only to next patch version" + method_option "minor", type: :boolean, banner: "Prefer updating only to next minor version" + method_option "major", type: :boolean, banner: "Prefer updating to next major version (default)" method_option "pre", type: :boolean, banner: "Always choose the highest allowed version when updating gems, regardless of prerelease status" method_option "strict", type: :boolean, banner: "Do not allow any gem to be updated past latest --patch | --minor | --major" method_option "conservative", type: :boolean, banner: "Use bundle install conservative update behavior and do not allow shared dependencies to be updated." @@ -397,11 +397,11 @@ module Bundler end desc "cache [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" - method_option "all", type: :boolean, - default: Bundler.feature_flag.cache_all?, - banner: "Include all sources (including path and git)." + method_option "all", type: :boolean, + default: Bundler.feature_flag.cache_all?, + banner: "Include all sources (including path and git)." method_option "all-platforms", type: :boolean, banner: "Include gems for all platforms present in the lockfile, not only the current one" - method_option "cache-path", type: :string, banner: "Specify a different cache path than the default (vendor/cache)." + method_option "cache-path", type: :string, banner: "Specify a different cache path than the default (vendor/cache)." method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" method_option "no-install", type: :boolean, banner: "Don't install the gems, only update the cache." method_option "no-prune", type: :boolean, banner: "Don't remove stale gems from the cache." @@ -605,7 +605,7 @@ module Bundler end desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile", hide: true - method_option "source", type: :string, banner: "Install gem from the given source" + method_option "source", type: :string, banner: "Install gem from the given source" method_option "group", type: :string, banner: "Install gem into a bundler group" def inject(name, version) SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command" @@ -615,16 +615,16 @@ module Bundler desc "lock", "Creates a lockfile without installing" method_option "update", type: :array, lazy_default: true, banner: "ignore the existing lockfile, update all gems by default, or update list of given gems" - method_option "local", type: :boolean, default: false, banner: "do not attempt to fetch remote gemspecs and use the local gem cache only" - method_option "print", type: :boolean, default: false, banner: "print the lockfile to STDOUT instead of writing to the file system" + method_option "local", type: :boolean, default: false, banner: "do not attempt to fetch remote gemspecs and use the local gem cache only" + method_option "print", type: :boolean, default: false, banner: "print the lockfile to STDOUT instead of writing to the file system" method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" method_option "lockfile", type: :string, default: nil, banner: "the path the lockfile should be written to" method_option "full-index", type: :boolean, default: false, banner: "Fall back to using the single-file index of all gems" method_option "add-platform", type: :array, default: [], banner: "Add a new platform to the lockfile" - method_option "remove-platform", type: :array, default: [], banner: "Remove a platform from the lockfile" - method_option "patch", type: :boolean, banner: "If updating, prefer updating only to next patch version" - method_option "minor", type: :boolean, banner: "If updating, prefer updating only to next minor version" - method_option "major", type: :boolean, banner: "If updating, prefer updating to next major version (default)" + method_option "remove-platform", type: :array, default: [], banner: "Remove a platform from the lockfile" + method_option "patch", type: :boolean, banner: "If updating, prefer updating only to next patch version" + method_option "minor", type: :boolean, banner: "If updating, prefer updating only to next minor version" + method_option "major", type: :boolean, banner: "If updating, prefer updating to next major version (default)" method_option "pre", type: :boolean, banner: "If updating, always choose the highest allowed version, regardless of prerelease status" method_option "strict", type: :boolean, banner: "If updating, do not allow any gem to be updated past latest --patch | --minor | --major" method_option "conservative", type: :boolean, banner: "If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated" diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 33d31cdd27..2adf59d5d5 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -17,7 +17,7 @@ module Bundler begin definition.resolve_only_locally! not_installed = definition.missing_specs - rescue GemNotFound, SolveFailure + rescue GemNotFound, GitError, SolveFailure Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies." Bundler.ui.warn "Install missing gems with `bundle install`." exit 1 diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 50288a02e7..a162c213f1 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -79,7 +79,7 @@ module Bundler ensure_safe_gem_name(name, constant_array) templates = { - "#{Bundler.preferred_gemfile_name}.tt" => Bundler.preferred_gemfile_name, + "Gemfile.tt" => Bundler.preferred_gemfile_name, "lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb", "lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb", "sig/newgem.rbs.tt" => "sig/#{namespaced_path}.rbs", diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index d403f2d586..4cae6cd892 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -115,7 +115,7 @@ module Bundler @originally_locked_specs = @locked_specs @locked_sources = [] @locked_platforms = [] - @locked_checksums = nil + @locked_checksums = Bundler.feature_flag.bundler_3_mode? end locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) } @@ -137,7 +137,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless Bundler.frozen_bundle? + @current_platform_missing = add_current_platform unless Bundler.frozen_bundle? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -484,6 +484,7 @@ module Bundler !@source_changes && !@dependency_changes && + !@current_platform_missing && @new_platforms.empty? && !@path_changes && !@local_changes && @@ -629,6 +630,7 @@ module Bundler def start_resolution local_platform_needed_for_resolvability = @most_specific_non_local_locked_ruby_platform && !@platforms.include?(local_platform) @platforms << local_platform if local_platform_needed_for_resolvability + add_platform(Gem::Platform::RUBY) if RUBY_ENGINE == "truffleruby" result = SpecSet.new(resolver.start) @@ -671,19 +673,19 @@ module Bundler end def add_current_platform - @most_specific_non_local_locked_ruby_platform = find_most_specific_non_local_locked_ruby_platform + return if @platforms.include?(local_platform) + + @most_specific_non_local_locked_ruby_platform = find_most_specific_locked_ruby_platform return if @most_specific_non_local_locked_ruby_platform - add_platform(local_platform) + @platforms << local_platform + true end - def find_most_specific_non_local_locked_ruby_platform + def find_most_specific_locked_ruby_platform return unless generic_local_platform_is_ruby? && current_platform_locked? - most_specific_locked_ruby_platform = most_specific_locked_platform - return unless most_specific_locked_ruby_platform != local_platform - - most_specific_locked_ruby_platform + most_specific_locked_platform end def change_reason @@ -705,6 +707,7 @@ module Bundler [ [@source_changes, "the list of sources changed"], [@dependency_changes, "the dependencies in your gemfile changed"], + [@current_platform_missing, "your lockfile does not include the current platform"], [@new_platforms.any?, "you added a new platform to your gemfile"], [@path_changes, "the gemspecs for path gems changed"], [@local_changes, "the gemspecs for git local gems changed"], diff --git a/lib/bundler/force_platform.rb b/lib/bundler/force_platform.rb index 249a24ecd1..7af33218cb 100644 --- a/lib/bundler/force_platform.rb +++ b/lib/bundler/force_platform.rb @@ -2,8 +2,6 @@ module Bundler module ForcePlatform - private - # The `:force_ruby_platform` value used by dependencies for resolution, and # by locked specifications for materialization is `false` by default, except # for TruffleRuby. TruffleRuby generally needs to force the RUBY platform diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb index 8563ee358a..f91b263875 100644 --- a/lib/bundler/plugin/api/source.rb +++ b/lib/bundler/plugin/api/source.rb @@ -196,6 +196,7 @@ module Bundler FileUtils.rm_rf(new_cache_path) FileUtils.cp_r(install_path, new_cache_path) + FileUtils.rm_rf(app_cache_path.join(".git")) FileUtils.touch(app_cache_path.join(".bundlecache")) end diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 2a18ce1c49..79bea01e6e 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -237,26 +237,20 @@ module Gem include ::Bundler::ForcePlatform + attr_reader :force_ruby_platform + attr_accessor :source, :groups alias_method :eql?, :== - def force_ruby_platform - return @force_ruby_platform if defined?(@force_ruby_platform) && !@force_ruby_platform.nil? - - @force_ruby_platform = default_force_ruby_platform - end - - def encode_with(coder) - to_yaml_properties.each do |ivar| - coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar) + unless method_defined?(:encode_with, false) + def encode_with(coder) + [:@name, :@requirement, :@type, :@prerelease, :@version_requirements].each do |ivar| + coder[ivar.to_s.sub(/^@/, "")] = instance_variable_get(ivar) + end end end - def to_yaml_properties - instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) } - end - def to_lock out = String.new(" #{name}") unless requirement.none? diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index fd7757d2c3..5f7dd7a848 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -128,11 +128,6 @@ module Bundler spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache) end - Dir[cache_path.join("*/.git")].each do |git_dir| - FileUtils.rm_rf(git_dir) - FileUtils.touch(File.expand_path("../.bundlecache", git_dir)) - end - prune_cache(cache_path) unless Bundler.settings[:no_prune] end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 174a24d358..3f69ea1e65 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -164,7 +164,8 @@ module Bundler "does not exist. Run `bundle config unset local.#{override_for(original_path)}` to remove the local override" end - set_local!(path) + @local = true + set_paths!(path) # Create a new git proxy without the cached revision # so the Gemfile.lock always picks up the new revision. @@ -187,13 +188,11 @@ module Bundler end def specs(*) - set_local!(app_cache_path) if has_app_cache? && !local? + set_cache_path!(app_cache_path) if has_app_cache? && !local? if requires_checkout? && !@copied fetch - git_proxy.copy_to(install_path, submodules) - serialize_gemspecs_in(install_path) - @copied = true + checkout end local_specs @@ -206,10 +205,7 @@ module Bundler print_using_message "Using #{version_message(spec, options[:previous_spec])} from #{self}" if (requires_checkout? && !@copied) || force - Bundler.ui.debug " * Checking out revision: #{ref}" - git_proxy.copy_to(install_path, submodules) - serialize_gemspecs_in(install_path) - @copied = true + checkout end generate_bin_options = { disable_extensions: !Bundler.rubygems.spec_missing_extensions?(spec), build_args: options[:build_args] } @@ -221,12 +217,13 @@ module Bundler def cache(spec, custom_path = nil) app_cache_path = app_cache_path(custom_path) return unless Bundler.feature_flag.cache_all? - return if path == app_cache_path + return if install_path == app_cache_path + return if cache_path == app_cache_path cached! FileUtils.rm_rf(app_cache_path) git_proxy.checkout if requires_checkout? - git_proxy.copy_to(app_cache_path, @submodules) - serialize_gemspecs_in(app_cache_path) + FileUtils.cp_r("#{cache_path}/.", app_cache_path) + FileUtils.touch(app_cache_path.join(".bundlecache")) end def load_spec_files @@ -270,6 +267,13 @@ module Bundler private + def checkout + Bundler.ui.debug " * Checking out revision: #{ref}" + git_proxy.copy_to(install_path, submodules) + serialize_gemspecs_in(install_path) + @copied = true + end + def humanized_ref if local? path @@ -298,10 +302,19 @@ module Bundler end end - def set_local!(path) - @local = true - @local_specs = @git_proxy = nil - @cache_path = @install_path = path + def set_paths!(path) + set_cache_path!(path) + set_install_path!(path) + end + + def set_cache_path!(path) + @git_proxy = nil + @cache_path = path + end + + def set_install_path!(path) + @local_specs = nil + @install_path = path end def has_app_cache? diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 5f513f3f22..96c36c2dec 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -94,7 +94,7 @@ module Bundler end def delete(specs) - specs.each {|spec| @specs.delete(spec) } + Array(specs).each {|spec| @specs.delete(spec) } reset! end @@ -280,7 +280,7 @@ module Bundler if platform GemHelpers.select_best_platform_match(specs_for_name, platform, force_ruby: dep.force_ruby_platform) else - GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform) + GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform || dep.default_force_ruby_platform) end end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 50b90355bb..7920aaec0f 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.5.16".freeze + VERSION = "2.5.17".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 93d08a05aa..ab1eb6dbcf 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -41,7 +41,7 @@ module Bundler HASH_REGEX = / ^ ([ ]*) # indentations - (.+) # key + ([^#]+) # key excludes comment char '#' (?::(?=(?:\s|$))) # : (without the lookahead the #key includes this when : is present in value) [ ]? (['"]?) # optional opening quote diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 3c629421cd..beaad57618 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -9,7 +9,7 @@ require "rbconfig" module Gem - VERSION = "3.5.16" + VERSION = "3.5.17" end # Must be first since it unloads the prelude from 1.9.2 diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb index 5ce9c5e840..ecb4824d7e 100644 --- a/lib/rubygems/dependency.rb +++ b/lib/rubygems/dependency.rb @@ -337,4 +337,12 @@ class Gem::Dependency :released end end + + def encode_with(coder) # :nodoc: + coder.add "name", @name + coder.add "requirement", @requirement + coder.add "type", @type + coder.add "prerelease", @prerelease + coder.add "version_requirements", @version_requirements + end end diff --git a/lib/rubygems/query_utils.rb b/lib/rubygems/query_utils.rb index a95a759401..ea05969422 100644 --- a/lib/rubygems/query_utils.rb +++ b/lib/rubygems/query_utils.rb @@ -132,7 +132,7 @@ module Gem::QueryUtils version_matches = show_prereleases? || !s.version.prerelease? name_matches && version_matches - end + end.uniq(&:full_name) spec_tuples = specs.map do |spec| [spec.name_tuple, spec] diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 214ba53a88..471c29b6e4 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -251,7 +251,15 @@ class Gem::Uninstaller raise Gem::FilePermissionError, spec.base_dir unless File.writable?(spec.base_dir) - safe_delete { FileUtils.rm_r spec.full_gem_path } + full_gem_path = spec.full_gem_path + exclusions = [] + + if default_spec_matches?(spec) && spec.executables.any? + exclusions = spec.executables.map {|exe| File.join(spec.bin_dir, exe) } + exclusions << File.dirname(exclusions.last) until exclusions.last == full_gem_path + end + + safe_delete { rm_r full_gem_path, exclusions: exclusions } safe_delete { FileUtils.rm_r spec.extension_dir } old_platform_name = spec.original_name @@ -378,6 +386,12 @@ class Gem::Uninstaller private + def rm_r(path, exclusions:) + FileUtils::Entry_.new(path).postorder_traverse do |ent| + ent.remove unless exclusions.include?(ent.path) + end + end + def specification_record @specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record end diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index af86c63ef7..f89004f32a 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -41,7 +41,7 @@ module Gem HASH_REGEX = / ^ ([ ]*) # indentations - (.+) # key + ([^#]+) # key excludes comment char '#' (?::(?=(?:\s|$))) # : (without the lookahead the #key includes this when : is present in value) [ ]? (['"]?) # optional opening quote |
