[rubygems/rubygems] Allow enabling "Bundler 3 mode" more easily

Currently to test Bundler 3 mode we have to actually edit the version
file to simulate we're running a future version. This is inconvenient.

Instead, allow passing an environment variable, `BUNDLER_3_MODE`, to set
the "working mode" Bundler should use.

This can now be set easily by end users to enable them to try out the
changes in the future version and give us feedback.

It's unclear how version auto-switching should work when this
environment variable is set, so the auto-switching feature will be
disabled in that case.

4e92e9b209
This commit is contained in:
David Rodríguez 2023-03-13 14:28:27 +01:00 committed by Hiroshi SHIBATA
parent af0b184e83
commit 4245d522b2
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
8 changed files with 10 additions and 13 deletions

View file

@ -6,6 +6,7 @@ module Bundler
BUNDLER_KEYS = %w[
BUNDLE_BIN_PATH
BUNDLE_GEMFILE
BUNDLER_3_MODE
BUNDLER_VERSION
BUNDLER_SETUP
GEM_HOME

View file

@ -105,6 +105,7 @@ module Bundler
def autoswitching_applies?
ENV["BUNDLER_VERSION"].nil? &&
ENV["BUNDLER_3_MODE"].nil? &&
ruby_can_restart_with_same_arguments? &&
lockfile_version
end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: false
module Bundler
VERSION = "2.7.0.dev".freeze
VERSION = (ENV["BUNDLER_3_MODE"] == "true" ? "3.0.0" : "2.7.0.dev").freeze
def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i

View file

@ -1558,7 +1558,7 @@ RSpec.describe "bundle update --bundler" do
G
lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.99.9")
bundle :update, bundler: true, verbose: true, preserve_ruby_flags: true
bundle :update, bundler: true, verbose: true, preserve_ruby_flags: true, env: { "BUNDLER_3_MODE" => nil }
expect(out).to include("Updating bundler to 999.0.0")
expect(out).to include("Running `bundle update --bundler \"> 0.a\" --verbose` with bundler 999.0.0")

View file

@ -109,7 +109,7 @@ RSpec.describe "the lockfile format" do
#{version}
L
install_gemfile <<-G, verbose: true, preserve_ruby_flags: true
install_gemfile <<-G, verbose: true, preserve_ruby_flags: true, env: { "BUNDLER_3_MODE" => nil }
source "https://gem.repo4"
gem "myrack"

View file

@ -10,7 +10,7 @@ RSpec.describe "Self management" do
"9.4.0"
end
before do
around do |example|
build_repo4 do
build_bundler previous_minor
@ -26,6 +26,8 @@ RSpec.describe "Self management" do
G
pristine_system_gems "bundler-#{current_version}"
with_env_vars("BUNDLER_3_MODE" => nil, &example)
end
it "installs locked version when using system path and uses it" do

View file

@ -265,7 +265,7 @@ module Spec
def replace_version_file(version, dir: source_root)
version_file = File.expand_path("lib/bundler/version.rb", dir)
contents = File.read(version_file)
contents.sub!(/(^\s+VERSION\s*=\s*)"#{Gem::Version::VERSION_PATTERN}"/, %(\\1"#{version}"))
contents.sub!(/(^\s+VERSION\s*=\s*).*$/, %(\\1"#{version}"))
File.open(version_file, "w") {|f| f << contents }
end

View file

@ -4,13 +4,6 @@ require_relative "helper"
require "rubygems/commands/setup_command"
class TestGemCommandsSetupCommand < Gem::TestCase
bundler_gemspec = File.expand_path("../../bundler/lib/bundler/version.rb", __dir__)
if File.exist?(bundler_gemspec)
BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1]
else
BUNDLER_VERS = "2.0.1"
end
def setup
super
@ -35,7 +28,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
create_dummy_files(filelist)
gemspec = util_spec "bundler", BUNDLER_VERS do |s|
gemspec = util_spec "bundler", "9.9.9" do |s|
s.bindir = "exe"
s.executables = ["bundle", "bundler"]
end