Merge RubyGems/Bundler master from 4076391fce5847689bf2ec402b17133fe4e32285

This commit is contained in:
Hiroshi SHIBATA 2023-05-30 20:25:29 +09:00
parent 30b960ba34
commit 4bbeed6134
Notes: git 2023-05-30 12:50:27 +00:00
17 changed files with 78 additions and 46 deletions

View File

@ -210,9 +210,10 @@ module Bundler
end end
def frozen_bundle? def frozen_bundle?
frozen = settings[:deployment] frozen = settings[:frozen]
frozen ||= settings[:frozen] return frozen unless frozen.nil?
frozen
settings[:deployment]
end end
def locked_gems def locked_gems

View File

@ -361,10 +361,8 @@ module Bundler
"updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control." "updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."
unless explicit_flag unless explicit_flag
suggested_command = if Bundler.settings.locations("frozen").keys.&([:global, :local]).any? suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
"bundle config unset frozen" "bundle config set frozen false"
elsif Bundler.settings.locations("deployment").keys.&([:global, :local]).any?
"bundle config unset deployment"
end end
msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \ msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
"freeze \nby running `#{suggested_command}`." if suggested_command "freeze \nby running `#{suggested_command}`." if suggested_command
@ -886,7 +884,8 @@ module Bundler
if preserve_unknown_sections if preserve_unknown_sections
sections_to_ignore = LockfileParser.sections_to_ignore(@locked_bundler_version) sections_to_ignore = LockfileParser.sections_to_ignore(@locked_bundler_version)
sections_to_ignore += LockfileParser.unknown_sections_in_lockfile(current) sections_to_ignore += LockfileParser.unknown_sections_in_lockfile(current)
sections_to_ignore += LockfileParser::ENVIRONMENT_VERSION_SECTIONS sections_to_ignore << LockfileParser::RUBY
sections_to_ignore << LockfileParser::BUNDLED unless @unlocking_bundler
pattern = /#{Regexp.union(sections_to_ignore)}\n(\s{2,}.*\n)+/ pattern = /#{Regexp.union(sections_to_ignore)}\n(\s{2,}.*\n)+/
whitespace_cleanup = /\n{2,}/ whitespace_cleanup = /\n{2,}/
current = current.gsub(pattern, "\n").gsub(whitespace_cleanup, "\n\n").strip current = current.gsub(pattern, "\n").gsub(whitespace_cleanup, "\n\n").strip

View File

@ -90,7 +90,7 @@ module Bundler
Gem::Specification.reset # invalidate gem specification cache so that installed gems are immediately available Gem::Specification.reset # invalidate gem specification cache so that installed gems are immediately available
lock unless Bundler.frozen_bundle? lock
Standalone.new(options[:standalone], @definition).generate if options[:standalone] Standalone.new(options[:standalone], @definition).generate if options[:standalone]
end end
end end

View File

@ -26,6 +26,7 @@ module Bundler
KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze
ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze
deprecate_constant(:ENVIRONMENT_VERSION_SECTIONS)
def self.sections_in_lockfile(lockfile_contents) def self.sections_in_lockfile(lockfile_contents)
lockfile_contents.scan(/^\w[\w ]*$/).uniq lockfile_contents.scan(/^\w[\w ]*$/).uniq

View File

@ -245,7 +245,7 @@ By default, this RubyGems will install gem as:
def install_executables(bin_dir) def install_executables(bin_dir)
prog_mode = options[:prog_mode] || 0o755 prog_mode = options[:prog_mode] || 0o755
executables = { "gem" => "bin" } executables = { "gem" => "exe" }
executables.each do |tool, path| executables.each do |tool, path|
say "Installing #{tool} executable" if @verbose say "Installing #{tool} executable" if @verbose

View File

@ -659,21 +659,21 @@ RSpec.describe "bundle update" do
expect(last_command).to be_failure expect(last_command).to be_failure
expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m) expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m)
expect(err).to match(/freeze \nby running `bundle config unset deployment`./m) expect(err).to match(/freeze \nby running `bundle config set frozen false`./m)
end end
it "should suggest different command when frozen is set globally", :bundler => "< 3" do it "should fail loudly when frozen is set globally" do
bundle "config set --global frozen 1" bundle "config set --global frozen 1"
bundle "update", :all => true, :raise_on_error => false bundle "update", :all => true, :raise_on_error => false
expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m). expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m).
and match(/freeze \nby running `bundle config unset frozen`./m) and match(/freeze \nby running `bundle config set frozen false`./m)
end end
it "should suggest different command when frozen is set globally", :bundler => "3" do it "should fail loudly when deployment is set globally" do
bundle "config set --global deployment true" bundle "config set --global deployment true"
bundle "update", :all => true, :raise_on_error => false bundle "update", :all => true, :raise_on_error => false
expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m). expect(err).to match(/You are trying to install in deployment mode after changing.your Gemfile/m).
and match(/freeze \nby running `bundle config unset deployment`./m) and match(/freeze \nby running `bundle config set frozen false`./m)
end end
it "should not suggest any command to unfreeze bundler if frozen is set through ENV" do it "should not suggest any command to unfreeze bundler if frozen is set through ENV" do
@ -1451,6 +1451,31 @@ RSpec.describe "bundle update --bundler" do
expect(out).to include("Using bundler 2.3.9") expect(out).to include("Using bundler 2.3.9")
end end
end end
it "prints an error when trying to update bundler in frozen mode" do
system_gems "bundler-2.3.9"
gemfile <<~G
source "#{file_uri_for(gem_repo2)}"
G
lockfile <<-L
GEM
remote: #{file_uri_for(gem_repo2)}/
specs:
PLATFORMS
ruby
DEPENDENCIES
BUNDLED WITH
2.1.4
L
bundle "update --bundler=2.3.9", :env => { "BUNDLE_FROZEN" => "true" }
expect(err).to include("Cannot write a changed lockfile while frozen")
end
end end
# these specs are slow and focus on integration and therefore are not exhaustive. unit specs elsewhere handle that. # these specs are slow and focus on integration and therefore are not exhaustive. unit specs elsewhere handle that.

View File

@ -1148,7 +1148,7 @@ RSpec.describe "bundle install with git sources" do
it "gives a helpful error message when the remote branch no longer exists" do it "gives a helpful error message when the remote branch no longer exists" do
build_git "foo" build_git "foo"
install_gemfile <<-G, :raise_on_error => false install_gemfile <<-G, :env => { "LANG" => "en" }, :raise_on_error => false
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :branch => "deadbeef" gem "foo", :git => "#{file_uri_for(lib_path("foo-1.0"))}", :branch => "deadbeef"
G G

View File

@ -28,7 +28,7 @@ RSpec.describe "bundle lock with git gems" do
gem 'foo', :git => "#{lib_path("foo-1.0")}", :branch => "bad" gem 'foo', :git => "#{lib_path("foo-1.0")}", :branch => "bad"
G G
bundle "lock --update foo", :raise_on_error => false bundle "lock --update foo", :env => { "LANG" => "en" }, :raise_on_error => false
expect(err).to include("Revision bad does not exist in the repository") expect(err).to include("Revision bad does not exist in the repository")
end end

View File

@ -302,7 +302,7 @@ module Spec
def install_gem(path, default = false) def install_gem(path, default = false)
raise "OMG `#{path}` does not exist!" unless File.exist?(path) raise "OMG `#{path}` does not exist!" unless File.exist?(path)
args = "--no-document --ignore-dependencies" args = "--no-document --ignore-dependencies --verbose --local"
args += " --default --install-dir #{system_gem_path}" if default args += " --default --install-dir #{system_gem_path}" if default
gem_command "install #{args} '#{path}'" gem_command "install #{args} '#{path}'"

View File

@ -42,7 +42,8 @@ module Spec
end end
def dev_gemfile def dev_gemfile
@dev_gemfile ||= tool_dir.join("dev_gems.rb") name = RUBY_VERSION.start_with?("2.6") ? "dev26_gems.rb" : "dev_gems.rb"
@dev_gemfile ||= tool_dir.join(name)
end end
def bindir def bindir

View File

@ -18,7 +18,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@cmd.options[:document] = [] @cmd.options[:document] = []
filelist = %w[ filelist = %w[
bin/gem exe/gem
lib/rubygems.rb lib/rubygems.rb
lib/rubygems/requirement.rb lib/rubygems/requirement.rb
lib/rubygems/ssl_certs/rubygems.org/foo.pem lib/rubygems/ssl_certs/rubygems.org/foo.pem

View File

@ -100,7 +100,7 @@ class TestGemExtCargoBuilder < Gem::TestCase
require "tmpdir" require "tmpdir"
env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home) env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home)
gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path("../../bin/gem", __dir__)] gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path("../../exe/gem", __dir__)]
Dir.mktmpdir("rust_ruby_example") do |dir| Dir.mktmpdir("rust_ruby_example") do |dir|
built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem")) built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem"))
@ -122,7 +122,7 @@ class TestGemExtCargoBuilder < Gem::TestCase
require "tmpdir" require "tmpdir"
env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home) env_for_subprocess = @rust_envs.merge("GEM_HOME" => Gem.paths.home)
gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path("../../bin/gem", __dir__)] gem = [env_for_subprocess, *ruby_with_rubygems_in_load_path, File.expand_path("../../exe/gem", __dir__)]
Dir.mktmpdir("custom_name") do |dir| Dir.mktmpdir("custom_name") do |dir|
built_gem = File.expand_path(File.join(dir, "custom_name.gem")) built_gem = File.expand_path(File.join(dir, "custom_name.gem"))

View File

@ -4,9 +4,6 @@ require_relative "helper"
class TestGemGemRunner < Gem::TestCase class TestGemGemRunner < Gem::TestCase
def setup def setup
@orig_gem_home = ENV["GEM_HOME"]
ENV["GEM_HOME"] = @gemhome
require "rubygems/command" require "rubygems/command"
@orig_args = Gem::Command.build_args @orig_args = Gem::Command.build_args
@orig_specific_extra_args = Gem::Command.specific_extra_args_hash.dup @orig_specific_extra_args = Gem::Command.specific_extra_args_hash.dup
@ -24,8 +21,6 @@ class TestGemGemRunner < Gem::TestCase
Gem::Command.build_args = @orig_args Gem::Command.build_args = @orig_args
Gem::Command.specific_extra_args_hash = @orig_specific_extra_args Gem::Command.specific_extra_args_hash = @orig_specific_extra_args
Gem::Command.extra_args = @orig_extra_args Gem::Command.extra_args = @orig_extra_args
ENV["GEM_HOME"] = @orig_gem_home
end end
def test_do_configuration def test_do_configuration

View File

@ -7,7 +7,8 @@ gem "rake", "~> 13.0"
gem "rb_sys" gem "rb_sys"
gem "webrick", "~> 1.6" gem "webrick", "~> 1.6"
gem "parallel_tests", "~> 2.29" gem "turbo_tests", "~> 2.1"
gem "parallel_tests", "< 3.9.0"
gem "parallel", "~> 1.19" gem "parallel", "~> 1.19"
gem "rspec-core", "~> 3.12" gem "rspec-core", "~> 3.12"
gem "rspec-expectations", "~> 3.12" gem "rspec-expectations", "~> 3.12"

View File

@ -5,34 +5,42 @@ GEM
hpricot (0.8.6) hpricot (0.8.6)
hpricot (0.8.6-java) hpricot (0.8.6-java)
mustache (1.1.1) mustache (1.1.1)
parallel (1.22.1) parallel (1.23.0)
parallel_tests (2.32.0) parallel_tests (3.8.1)
parallel parallel
power_assert (2.0.2) power_assert (2.0.3)
rake (13.0.6) rake (13.0.6)
rb_sys (0.9.63) rb_sys (0.9.78)
rdiscount (2.2.7) rdiscount (2.2.7)
ronn (0.7.3) ronn (0.7.3)
hpricot (>= 0.8.2) hpricot (>= 0.8.2)
mustache (>= 0.7.0) mustache (>= 0.7.0)
rdiscount (>= 1.5.8) rdiscount (>= 1.5.8)
rspec-core (3.12.0) rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-expectations (3.12.0) rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-mocks (3.12.1) rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-support (3.12.0) rspec-support (3.12.0)
test-unit (3.5.5) test-unit (3.5.9)
power_assert power_assert
uri (0.12.0) turbo_tests (2.1.0)
webrick (1.7.0) bundler (>= 2.1)
parallel_tests (>= 3.3.0, < 5)
rspec (>= 3.10)
uri (0.12.1)
webrick (1.8.1)
PLATFORMS PLATFORMS
arm64-darwin-22
java java
ruby
universal-java-11 universal-java-11
universal-java-18 universal-java-18
x64-mingw-ucrt x64-mingw-ucrt
@ -42,7 +50,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
parallel (~> 1.19) parallel (~> 1.19)
parallel_tests (~> 2.29) parallel_tests (< 3.9.0)
rake (~> 13.0) rake (~> 13.0)
rb_sys rb_sys
ronn (~> 0.7.3) ronn (~> 0.7.3)
@ -50,6 +58,7 @@ DEPENDENCIES
rspec-expectations (~> 3.12) rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12) rspec-mocks (~> 3.12)
test-unit (~> 3.0) test-unit (~> 3.0)
turbo_tests (~> 2.1)
uri (~> 0.12.0) uri (~> 0.12.0)
webrick (~> 1.6) webrick (~> 1.6)

View File

@ -21,12 +21,12 @@ GEM
rspec-core (~> 3.12.0) rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0) rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0) rspec-mocks (~> 3.12.0)
rspec-core (3.12.0) rspec-core (3.12.2)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-expectations (3.12.0) rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-mocks (3.12.1) rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-support (3.12.0) rspec-support (3.12.0)

View File

@ -22,12 +22,12 @@ GEM
rspec-core (~> 3.12.0) rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0) rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0) rspec-mocks (~> 3.12.0)
rspec-core (3.12.0) rspec-core (3.12.2)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-expectations (3.12.0) rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-mocks (3.12.1) rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0) rspec-support (~> 3.12.0)
rspec-support (3.12.0) rspec-support (3.12.0)