ruby-changes:70612
From: Hiroshi <ko1@a...>
Date: Mon, 27 Dec 2021 10:46:01 +0900 (JST)
Subject: [ruby-changes:70612] d6311cb1ca (master): Track RubyGems 3.4.0dev and Bundler 2.4.0dev
https://git.ruby-lang.org/ruby.git/commit/?id=d6311cb1ca From d6311cb1ca5860a6e0cbf6f87c1e0ae9e099f61e Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Mon, 27 Dec 2021 09:41:55 +0900 Subject: Track RubyGems 3.4.0dev and Bundler 2.4.0dev --- lib/bundler/definition.rb | 16 +++--- lib/bundler/dsl.rb | 2 +- lib/bundler/rubygems_ext.rb | 2 +- lib/bundler/self_manager.rb | 23 ++++++-- lib/bundler/shared_helpers.rb | 10 ++-- lib/bundler/source/git.rb | 2 +- lib/bundler/version.rb | 2 +- lib/rubygems.rb | 2 +- spec/bundler/commands/binstubs_spec.rb | 22 ++++---- spec/bundler/commands/install_spec.rb | 24 ++++++++- spec/bundler/lock/lockfile_spec.rb | 16 ++---- .../realworld/fixtures/warbler/Gemfile.lock | 2 +- spec/bundler/runtime/self_management_spec.rb | 62 ++++++++++------------ tool/bundler/rubocop_gems.rb.lock | 2 +- tool/bundler/standard_gems.rb.lock | 2 +- tool/bundler/test_gems.rb.lock | 2 +- 16 files changed, 105 insertions(+), 86 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 5cde1285a66..f985e6a3742 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -87,10 +87,11 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L87 @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version @locked_ruby_version = @locked_gems.ruby_version + @originally_locked_specs = SpecSet.new(@locked_gems.specs) if unlock != true @locked_deps = @locked_gems.dependencies - @locked_specs = SpecSet.new(@locked_gems.specs) + @locked_specs = @originally_locked_specs @locked_sources = @locked_gems.sources else @unlock = {} @@ -688,13 +689,16 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L689 def converge_specs(specs) deps = [] converged = [] - specs.each do |s| - # Replace the locked dependency's source with the equivalent source from the Gemfile - dep = @dependencies.find {|d| s.satisfies?(d) } - if dep && (!dep.source || s.source.include?(dep.source)) + @dependencies.each do |dep| + if specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) } deps << dep end + end + + specs.each do |s| + # Replace the locked dependency's source with the equivalent source from the Gemfile + dep = @dependencies.find {|d| s.satisfies?(d) } s.source = (dep && dep.source) || sources.get(s.source) || sources.default_source unless Bundler.frozen_bundle? @@ -827,7 +831,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L831 def additional_base_requirements_for_resolve return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources) - converge_specs(@locked_gems.specs).map do |locked_spec| + converge_specs(@originally_locked_specs).map do |locked_spec| name = locked_spec.name dep = Gem::Dependency.new(name, ">= #{locked_spec.version}") DepProxy.get_proxy(dep, locked_spec.platform) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 7b0db79de6b..f7922b1fba0 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -46,7 +46,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/dsl.rb#L46 @gemfile = expanded_gemfile_path @gemfiles << expanded_gemfile_path contents ||= Bundler.read_file(@gemfile.to_s) - instance_eval(contents.dup.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }, gemfile.to_s, 1) + instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1) rescue Exception => e # rubocop:disable Lint/RescueException message = "There was an error " \ "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \ diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 97d1c957ca3..5d572aa73d6 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -29,7 +29,7 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L29 # gems at that time, this method could be called inside another require, # thus raising with that constant being undefined. Better to check a method if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?) - Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if Kernel.method_defined?(:untaint) } + Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" } else rg_full_gem_path end diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index d62ef6ca12e..2169d814e59 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -15,10 +15,6 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/self_manager.rb#L15 def install_locked_bundler_and_restart_with_it_if_needed return unless needs_switching? - Bundler.ui.info \ - "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ - "Installing Bundler #{lockfile_version} and restarting using that version." - install_and_restart_with_locked_bundler end @@ -26,8 +22,14 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/self_manager.rb#L22 def install_and_restart_with_locked_bundler bundler_dep = Gem::Dependency.new("bundler", lockfile_version) + spec = fetch_spec_for(bundler_dep) + return if spec.nil? - Gem.install(bundler_dep) + Bundler.ui.info \ + "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ + "Installing Bundler #{lockfile_version} and restarting using that version." + + spec.source.install(spec) rescue StandardError => e Bundler.ui.trace e Bundler.ui.warn "There was an error installing the locked bundler version (#{lockfile_version}), rerun with the `--verbose` flag for more details. Going on using bundler #{current_version}." @@ -35,6 +37,17 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/self_manager.rb#L37 restart_with_locked_bundler end + def fetch_spec_for(bundler_dep) + source = Bundler::Source::Rubygems.new("remotes" => "https://rubygems.org") + source.remote! + source.add_dependency_names("bundler") + spec = source.specs.search(bundler_dep).first + if spec.nil? + Bundler.ui.warn "Your lockfile is locked to a version of bundler (#{lockfile_version}) that doesn't exist at https://rubygems.org/. Going on using #{current_version}" + end + spec + end + def restart_with_locked_bundler configured_gem_home = ENV["GEM_HOME"] configured_gem_path = ENV["GEM_PATH"] diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index a9de1625aa7..e48010232a8 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -13,13 +13,13 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/shared_helpers.rb#L13 def root gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).tap{|x| x.untaint if Kernel.method_defined?(:untaint) }.expand_path.parent + Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path.parent end def default_gemfile gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).tap{|x| x.untaint if Kernel.method_defined?(:untaint) }.expand_path + Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path end def default_lockfile @@ -28,7 +28,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/shared_helpers.rb#L28 case gemfile.basename.to_s when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked")) else Pathname.new("#{gemfile}.lock") - end.tap{|x| x.untaint if Kernel.method_defined?(:untaint) } + end.tap{|x| x.untaint if RUBY_VERSION < "2.7" } end def default_bundle_dir @@ -100,7 +100,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/shared_helpers.rb#L100 # # @see {Bundler::PermissionError} def filesystem_access(path, action = :write, &block) - yield(path.dup.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }) + yield(path.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }) rescue Errno::EACCES raise PermissionError.new(path, action) rescue Errno::EAGAIN @@ -236,7 +236,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/shared_helpers.rb#L236 def search_up(*names) previous = nil - current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if Kernel.method_defined?(:untaint) } + current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if RUBY_VERSION < "2.7" } until !File.directory?(current) || current == previous if ENV["BUNDLER_SPEC_RUN"] diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 35ae6329c7b..a41a2f23e96 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -336,7 +336,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/git.rb#L336 (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/