Merge rubygems/rubygems HEAD

Pick from 880dd95996
This commit is contained in:
Hiroshi SHIBATA 2023-06-20 12:04:04 +09:00
parent 44ad176fc2
commit 1edbaa850f
Notes: git 2023-06-20 04:35:32 +00:00
14 changed files with 99 additions and 59 deletions

View File

@ -76,8 +76,11 @@ module Bundler
@lockfile = lockfile @lockfile = lockfile
@lockfile_contents = String.new @lockfile_contents = String.new
@locked_bundler_version = nil @locked_bundler_version = nil
@locked_ruby_version = nil @resolved_bundler_version = nil
@locked_ruby_version = nil
@new_platform = nil @new_platform = nil
@removed_platform = nil @removed_platform = nil
@ -318,7 +321,7 @@ module Bundler
if @locked_bundler_version if @locked_bundler_version
locked_major = @locked_bundler_version.segments.first locked_major = @locked_bundler_version.segments.first
current_major = Bundler.gem_version.segments.first current_major = bundler_version_to_lock.segments.first
updating_major = locked_major < current_major updating_major = locked_major < current_major
end end
@ -358,6 +361,10 @@ module Bundler
end end
end end
def bundler_version_to_lock
@resolved_bundler_version || Bundler.gem_version
end
def to_lock def to_lock
require_relative "lockfile_generator" require_relative "lockfile_generator"
LockfileGenerator.generate(self) LockfileGenerator.generate(self)
@ -471,7 +478,7 @@ module Bundler
private :sources private :sources
def nothing_changed? def nothing_changed?
!@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@missing_lockfile_dep !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@missing_lockfile_dep && !@unlocking_bundler
end end
def no_resolve_needed? def no_resolve_needed?
@ -489,7 +496,14 @@ module Bundler
end end
def expanded_dependencies def expanded_dependencies
dependencies + metadata_dependencies dependencies_with_bundler + metadata_dependencies
end
def dependencies_with_bundler
return dependencies unless @unlocking_bundler
return dependencies if dependencies.map(&:name).include?("bundler")
[Dependency.new("bundler", @unlocking_bundler)] + dependencies
end end
def resolution_packages def resolution_packages
@ -555,6 +569,8 @@ module Bundler
def start_resolution def start_resolution
result = resolver.start result = resolver.start
@resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version
SpecSet.new(SpecSet.new(result).for(dependencies, false, @platforms)) SpecSet.new(SpecSet.new(result).for(dependencies, false, @platforms))
end end
@ -613,6 +629,7 @@ module Bundler
[@path_changes, "the gemspecs for path gems changed"], [@path_changes, "the gemspecs for path gems changed"],
[@local_changes, "the gemspecs for git local gems changed"], [@local_changes, "the gemspecs for git local gems changed"],
[@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""], [@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""],
[@unlocking_bundler, "an update to the version of Bundler itself was requested"],
].select(&:first).map(&:last).join(", ") ].select(&:first).map(&:last).join(", ")
end end
@ -868,8 +885,16 @@ module Bundler
metadata_dependencies.each do |dep| metadata_dependencies.each do |dep|
source_requirements[dep.name] = sources.metadata_source source_requirements[dep.name] = sources.metadata_source
end end
source_requirements[:default_bundler] = source_requirements["bundler"] || sources.default_source
source_requirements["bundler"] = sources.metadata_source # needs to come last to override default_bundler_source = source_requirements["bundler"] || sources.default_source
if @unlocking_bundler
default_bundler_source.add_dependency_names("bundler")
else
source_requirements[:default_bundler] = default_bundler_source
source_requirements["bundler"] = sources.metadata_source # needs to come last to override
end
verify_changed_sources! verify_changed_sources!
source_requirements source_requirements
end end

View File

@ -71,7 +71,7 @@ module Bundler
end end
def add_bundled_with def add_bundled_with
add_section("BUNDLED WITH", Bundler::VERSION) add_section("BUNDLED WITH", definition.bundler_version_to_lock.to_s)
end end
def add_section(name, value) def add_section(name, value)

View File

@ -160,7 +160,7 @@ module Bundler
constraint_string = constraint.constraint_string constraint_string = constraint.constraint_string
requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) } requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) }
if name == "bundler" if name == "bundler" && bundler_pinned_to_current_version?
custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}" custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}"
extended_explanation = bundler_not_found_message(requirements) extended_explanation = bundler_not_found_message(requirements)
else else
@ -230,6 +230,12 @@ module Bundler
def all_versions_for(package) def all_versions_for(package)
name = package.name name = package.name
results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] } results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] }
if name == "bundler" && !bundler_pinned_to_current_version?
bundler_spec = Gem.loaded_specs["bundler"]
results << bundler_spec if bundler_spec
end
locked_requirement = base_requirements[name] locked_requirement = base_requirements[name]
results = filter_matching_specs(results, locked_requirement) if locked_requirement results = filter_matching_specs(results, locked_requirement) if locked_requirement
@ -254,6 +260,14 @@ module Bundler
@source_requirements[name] || @source_requirements[:default] @source_requirements[name] || @source_requirements[:default]
end end
def default_bundler_source
@source_requirements[:default_bundler]
end
def bundler_pinned_to_current_version?
!default_bundler_source.nil?
end
def name_for_explicit_dependency_source def name_for_explicit_dependency_source
Bundler.default_gemfile.basename.to_s Bundler.default_gemfile.basename.to_s
rescue StandardError rescue StandardError
@ -398,7 +412,7 @@ module Bundler
end end
def bundler_not_found_message(conflict_dependencies) def bundler_not_found_message(conflict_dependencies)
candidate_specs = filter_matching_specs(source_for(:default_bundler).specs.search("bundler"), conflict_dependencies) candidate_specs = filter_matching_specs(default_bundler_source.specs.search("bundler"), conflict_dependencies)
if candidate_specs.any? if candidate_specs.any?
target_version = candidate_specs.last.version target_version = candidate_specs.last.version

View File

@ -10,22 +10,22 @@ module Bundler
s.required_rubygems_version = Gem::Requirement.default s.required_rubygems_version = Gem::Requirement.default
end end
idx << Gem::Specification.new do |s| if local_spec = Gem.loaded_specs["bundler"]
s.name = "bundler"
s.version = VERSION
s.license = "MIT"
s.platform = Gem::Platform::RUBY
s.authors = ["bundler team"]
s.bindir = "exe"
s.homepage = "https://bundler.io"
s.summary = "The best way to manage your application's dependencies"
s.executables = %w[bundle]
# can't point to the actual gemspec or else the require paths will be wrong
s.loaded_from = __dir__
end
if local_spec = Bundler.rubygems.find_bundler(VERSION)
idx << local_spec idx << local_spec
else
idx << Gem::Specification.new do |s|
s.name = "bundler"
s.version = VERSION
s.license = "MIT"
s.platform = Gem::Platform::RUBY
s.authors = ["bundler team"]
s.bindir = "exe"
s.homepage = "https://bundler.io"
s.summary = "The best way to manage your application's dependencies"
s.executables = %w[bundle]
# can't point to the actual gemspec or else the require paths will be wrong
s.loaded_from = __dir__
end
end end
idx.each {|s| s.source = self } idx.each {|s| s.source = self }

View File

@ -381,7 +381,6 @@ module Bundler
idx = @allow_local ? installed_specs.dup : Index.new idx = @allow_local ? installed_specs.dup : Index.new
Dir["#{cache_path}/*.gem"].each do |gemfile| Dir["#{cache_path}/*.gem"].each do |gemfile|
next if /^bundler\-[\d\.]+?\.gem/.match?(gemfile)
s ||= Bundler.rubygems.spec_from_gem(gemfile) s ||= Bundler.rubygems.spec_from_gem(gemfile)
s.source = self s.source = self
idx << s idx << s

View File

@ -297,24 +297,27 @@ RSpec.describe "bundle lock" do
end end
end end
it "updates the bundler version in the lockfile without re-resolving", :rubygems => ">= 3.3.0.dev" do it "updates the bundler version in the lockfile to the latest bundler version" do
build_repo4 do build_repo4 do
build_gem "rack", "1.0" build_gem "bundler", "55"
end end
install_gemfile <<-G system_gems "bundler-55", :gem_repo => gem_repo4
source "#{file_uri_for(gem_repo4)}"
gem "rack" install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
source "https://gems.repo4"
G G
lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2')
FileUtils.rm_r gem_repo4 bundle "lock --update --bundler --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(lockfile).to end_with("BUNDLED WITH\n 55\n")
bundle "lock --update --bundler" update_repo4 do
expect(the_bundle).to include_gem "rack 1.0" build_gem "bundler", "99"
end
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) bundle "lock --update --bundler --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(the_bundle.locked_gems.bundler_version).to eq v(Bundler::VERSION) expect(lockfile).to end_with("BUNDLED WITH\n 99\n")
end end
it "supports adding new platforms" do it "supports adding new platforms" do

View File

@ -1239,7 +1239,7 @@ RSpec.describe "bundle update --ruby" do
end end
RSpec.describe "bundle update --bundler" do RSpec.describe "bundle update --bundler" do
it "updates the bundler version in the lockfile without re-resolving" do it "updates the bundler version in the lockfile" do
build_repo4 do build_repo4 do
build_gem "rack", "1.0" build_gem "rack", "1.0"
end end
@ -1250,8 +1250,6 @@ RSpec.describe "bundle update --bundler" do
G G
lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2')
FileUtils.rm_r gem_repo4
bundle :update, :bundler => true, :artifice => "compact_index", :verbose => true bundle :update, :bundler => true, :artifice => "compact_index", :verbose => true
expect(out).to include("Using bundler #{Bundler::VERSION}") expect(out).to include("Using bundler #{Bundler::VERSION}")
@ -1473,8 +1471,8 @@ RSpec.describe "bundle update --bundler" do
2.1.4 2.1.4
L L
bundle "update --bundler=2.3.9", :env => { "BUNDLE_FROZEN" => "true" } bundle "update --bundler=2.3.9", :env => { "BUNDLE_FROZEN" => "true" }, :raise_on_error => false
expect(err).to include("Cannot write a changed lockfile while frozen") expect(err).to include("An update to the version of bundler itself was requested, but the lockfile can't be updated because frozen mode is set")
end end
end end

View File

@ -115,8 +115,6 @@ RSpec.describe "bundle install with specific platforms" do
s.platform = "arm64-darwin" s.platform = "arm64-darwin"
s.required_ruby_version = "< #{Gem.ruby_version}" s.required_ruby_version = "< #{Gem.ruby_version}"
end end
build_gem "bundler", "2.1.4"
end end
gemfile <<~G gemfile <<~G
@ -137,22 +135,21 @@ RSpec.describe "bundle install with specific platforms" do
DEPENDENCIES DEPENDENCIES
nokogiri nokogiri
RUBY VERSION
2.5.3p105
BUNDLED WITH BUNDLED WITH
2.1.4 #{Bundler::VERSION}
L L
simulate_platform "arm64-darwin-22", &example simulate_platform "arm64-darwin-22", &example
end end
it "still installs the generic RUBY variant if necessary" do it "still installs the generic RUBY variant if necessary" do
bundle "update --bundler", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
expect(out).to include("Installing nokogiri 1.3.10")
end end
it "still installs the generic RUBY variant if necessary, even in frozen mode" do it "still installs the generic RUBY variant if necessary, even in frozen mode" do
bundle "update --bundler", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s, "BUNDLE_FROZEN" => "true" } bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s, "BUNDLE_FROZEN" => "true" }
expect(out).to include("Installing nokogiri 1.3.10")
end end
end end

View File

@ -144,6 +144,7 @@ RSpec.describe "Bundler.setup" do
ruby <<-RUBY ruby <<-RUBY
require 'bundler' require 'bundler'
gem "bundler", "#{Bundler::VERSION}" if #{ruby_core?}
Bundler.setup Bundler.setup
puts $LOAD_PATH puts $LOAD_PATH
RUBY RUBY

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
require "rubygems"
Gem.instance_variable_set(:@ruby, ENV["RUBY"]) if ENV["RUBY"]
require_relative "path"
bundler_gemspec = Spec::Path.loaded_gemspec
bundler_gemspec.instance_variable_set(:@full_gem_path, Spec::Path.source_root)
bundler_gemspec.activate if bundler_gemspec.respond_to?(:activate)

View File

@ -208,10 +208,8 @@ module Spec
update_repo(gem_repo4, &blk) update_repo(gem_repo4, &blk)
end end
def update_repo2 def update_repo2(&blk)
update_repo gem_repo2 do update_repo(gem_repo2, &blk)
yield if block_given?
end
end end
def build_security_repo def build_security_repo

View File

@ -1,10 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require "rubygems" require_relative "activate"
Gem.instance_variable_set(:@ruby, ENV["RUBY"]) if ENV["RUBY"]
require_relative "path"
bundler_gemspec = Spec::Path.loaded_gemspec
bundler_gemspec.instance_variable_set(:@full_gem_path, Spec::Path.source_root)
bundler_gemspec.activate if bundler_gemspec.respond_to?(:activate)
load File.expand_path("bundle", Spec::Path.bindir) load File.expand_path("bundle", Spec::Path.bindir)

View File

@ -118,6 +118,7 @@ module Spec
end end
def gem_activate(gem_name) def gem_activate(gem_name)
require_relative "activate"
require "bundler" require "bundler"
gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).specs.find {|spec| spec.name == gem_name }.version gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).specs.find {|spec| spec.name == gem_name }.version
gem gem_name, gem_requirement gem gem_name, gem_requirement

View File

@ -11,7 +11,7 @@ GEM
power_assert (2.0.3) power_assert (2.0.3)
rake (13.0.6) rake (13.0.6)
rb_sys (0.9.79) rb_sys (0.9.79)
rdiscount (2.2.7) rdiscount (2.2.7.1)
ronn (0.7.3) ronn (0.7.3)
hpricot (>= 0.8.2) hpricot (>= 0.8.2)
mustache (>= 0.7.0) mustache (>= 0.7.0)