diff --git a/Library/Homebrew/Gemfile b/Library/Homebrew/Gemfile index 2c494287fc..4f2872b628 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" # The default case (no envs), should always be a restrictive bound on the lowest supported minor version. # This is the branch that Dependabot will use. -if ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", "").empty? +if ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", "").empty? && ENV.fetch("HOMEBREW_RUBY3", "").empty? ruby "~> 2.6.0" else ruby ">= 2.6.0" diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 8c39af2c64..50cbba762f 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -465,7 +465,11 @@ module Homebrew def cleanup_portable_ruby vendor_dir = HOMEBREW_LIBRARY/"Homebrew/vendor" - portable_ruby_latest_version = (vendor_dir/"portable-ruby-version").read.chomp + portable_ruby_latest_version = if ENV["HOMEBREW_RUBY3"] + (vendor_dir/"portable-ruby-version").read.chomp + else + "2.6.10_1" + end portable_rubies_to_remove = [] Pathname.glob(vendor_dir/"portable-ruby/*.*").select(&:directory?).each do |path| @@ -488,7 +492,9 @@ module Homebrew end end - def use_system_ruby?; end + def use_system_ruby? + false + end def cleanup_bootsnap bootsnap = cache/"bootsnap" diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 285bf698b1..b0b1ece3f2 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -20,19 +20,37 @@ then # use a x86_64 Portable Ruby. [[ "${HOMEBREW_PHYSICAL_PROCESSOR}" == "arm64" && "${HOMEBREW_PREFIX}" == "/usr/local" ]] then - ruby_FILENAME="portable-ruby-2.6.10_1.el_capitan.bottle.tar.gz" - ruby_SHA="61029cec31c68a1fae1fa90fa876adf43d0becff777da793f9b5c5577f00567a" + if [[ -n "${HOMEBREW_RUBY3}" ]] + then + ruby_FILENAME="portable-ruby-3.1.4.el_capitan.bottle.tar.gz" + ruby_SHA="02180ca8b8295422ae84921bcf034b7ee8ce5575488bd5e6a37a192e53cd5d34" + else + ruby_FILENAME="portable-ruby-2.6.10_1.el_capitan.bottle.tar.gz" + ruby_SHA="61029cec31c68a1fae1fa90fa876adf43d0becff777da793f9b5c5577f00567a" + fi elif [[ "${HOMEBREW_PHYSICAL_PROCESSOR}" == "arm64" ]] then - ruby_FILENAME="portable-ruby-2.6.10_1.arm64_big_sur.bottle.tar.gz" - ruby_SHA="905b0c3896164ae8067a22fff2fd0b80b16d3c8bb72441403eedf69da71ec717" + if [[ -n "${HOMEBREW_RUBY3}" ]] + then + ruby_FILENAME="portable-ruby-3.1.4.arm64_big_sur.bottle.tar.gz" + ruby_SHA="d783cbeb6e6ef0d71c0b442317b54554370decd6fac66bf2d4938c07a63f67be" + else + ruby_FILENAME="portable-ruby-2.6.10_1.arm64_big_sur.bottle.tar.gz" + ruby_SHA="905b0c3896164ae8067a22fff2fd0b80b16d3c8bb72441403eedf69da71ec717" + fi fi elif [[ -n "${HOMEBREW_LINUX}" ]] then case "${HOMEBREW_PROCESSOR}" in x86_64) - ruby_FILENAME="portable-ruby-2.6.10_1.x86_64_linux.bottle.tar.gz" - ruby_SHA="68923daf3e139482b977c3deba63a3b54ea37bb5f716482948878819ef911bad" + if [[ -n "${HOMEBREW_RUBY3}" ]] + then + ruby_FILENAME="portable-ruby-3.1.4.x86_64_linux.bottle.tar.gz" + ruby_SHA="f7be167f7ac4f296b9f4c5874ceeea4aafd9999c3c7f2b0378cae7dd273e2322" + else + ruby_FILENAME="portable-ruby-2.6.10_1.x86_64_linux.bottle.tar.gz" + ruby_SHA="68923daf3e139482b977c3deba63a3b54ea37bb5f716482948878819ef911bad" + fi ;; *) ;; esac @@ -53,8 +71,13 @@ then fi ruby_URLs+=( "https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:${ruby_SHA}" - "https://github.com/Homebrew/homebrew-portable-ruby/releases/download/2.6.10_1/${ruby_FILENAME}" ) + if [[ -n "${HOMEBREW_RUBY3}" ]] + then + ruby_URLs+=("https://github.com/Homebrew/homebrew-portable-ruby/releases/download/3.1.4/${ruby_FILENAME}") + else + ruby_URLs+=("https://github.com/Homebrew/homebrew-portable-ruby/releases/download/2.6.10_1/${ruby_FILENAME}") + fi ruby_URL="${ruby_URLs[0]}" fi @@ -300,7 +323,12 @@ homebrew-vendor-install() { VENDOR_FILENAME="${!filename_var}" VENDOR_SHA="${!sha_var}" VENDOR_URL="${!url_var}" - VENDOR_VERSION="$(cat "${VENDOR_DIR}/portable-${VENDOR_NAME}-version")" + if [[ -z "${HOMEBREW_RUBY3}" && "${VENDOR_NAME}" == "ruby" ]] + then + VENDOR_VERSION="2.6.10_1" # EOL - phasing out + else + VENDOR_VERSION="$(cat "${VENDOR_DIR}/portable-${VENDOR_NAME}-version")" + fi if [[ -z "${VENDOR_URL}" || -z "${VENDOR_SHA}" ]] then diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index d170366784..100f39d922 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -208,6 +208,7 @@ module Homebrew HOMEBREW_CACHE HOMEBREW_LOGS HOMEBREW_TEMP + HOMEBREW_RUBY3 ] allowed_test_env << "HOMEBREW_USE_RUBY_FROM_PATH" if Homebrew::EnvConfig.developer? Homebrew::EnvConfig::ENVS.keys.map(&:to_s).each do |env| diff --git a/Library/Homebrew/extend/os/linux/cleanup.rb b/Library/Homebrew/extend/os/linux/cleanup.rb index d486f6a112..17eb8c162c 100644 --- a/Library/Homebrew/extend/os/linux/cleanup.rb +++ b/Library/Homebrew/extend/os/linux/cleanup.rb @@ -6,7 +6,7 @@ module Homebrew undef use_system_ruby? def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? || ENV["HOMEBREW_RUBY3"] rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact system_ruby = Pathname.new("/usr/bin/ruby") diff --git a/Library/Homebrew/extend/os/mac/cleanup.rb b/Library/Homebrew/extend/os/mac/cleanup.rb index 8fa20b62af..ea63f03095 100644 --- a/Library/Homebrew/extend/os/mac/cleanup.rb +++ b/Library/Homebrew/extend/os/mac/cleanup.rb @@ -6,7 +6,7 @@ module Homebrew undef use_system_ruby? def use_system_ruby? - return false if Homebrew::EnvConfig.force_vendor_ruby? + return false if Homebrew::EnvConfig.force_vendor_ruby? || ENV["HOMEBREW_RUBY3"] ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"].present? end diff --git a/Library/Homebrew/startup/bootsnap.rb b/Library/Homebrew/startup/bootsnap.rb index 30064f196e..3bc34ea970 100644 --- a/Library/Homebrew/startup/bootsnap.rb +++ b/Library/Homebrew/startup/bootsnap.rb @@ -3,7 +3,9 @@ # Disable Rails cops, as we haven't required active_support yet. # rubocop:disable Rails -homebrew_bootsnap_enabled = ENV["HOMEBREW_NO_BOOTSNAP"].nil? && !ENV["HOMEBREW_BOOTSNAP"].nil? +homebrew_bootsnap_enabled = ENV["HOMEBREW_NO_BOOTSNAP"].nil? && + !ENV["HOMEBREW_BOOTSNAP"].nil? && + ENV["HOMEBREW_RUBY3"].nil? # we need some development tools to build bootsnap native code homebrew_bootsnap_enabled &&= if ENV["HOMEBREW_MACOS_VERSION"] diff --git a/Library/Homebrew/test/rubocop_spec.rb b/Library/Homebrew/test/rubocop_spec.rb index ce163c2d98..1d62593814 100644 --- a/Library/Homebrew/test/rubocop_spec.rb +++ b/Library/Homebrew/test/rubocop_spec.rb @@ -9,6 +9,7 @@ describe "RuboCop" do allowlist = %w[ HOMEBREW_TESTS HOMEBREW_USE_RUBY_FROM_PATH + HOMEBREW_RUBY3 ] ENV.delete(key) if key.start_with?("HOMEBREW_") && allowlist.exclude?(key) end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index bf488562d7..3bb9b4ae5a 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -78,13 +78,15 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin ].compact.join(File::PATH_SEPARATOR) env.merge!( - "PATH" => path, - "HOMEBREW_PATH" => path, - "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew", - "HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args), - "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR, - "HOMEBREW_DEV_CMD_RUN" => "true", - "GEM_HOME" => nil, + "PATH" => path, + "HOMEBREW_PATH" => path, + "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew", + "HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args), + "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR, + "HOMEBREW_DEV_CMD_RUN" => "true", + "HOMEBREW_USE_RUBY_FROM_PATH" => ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", nil), + "HOMEBREW_RUBY3" => ENV.fetch("HOMEBREW_RUBY3", nil), + "GEM_HOME" => nil, ) @ruby_args ||= begin @@ -129,8 +131,12 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin end def brew_sh(*args) + env = { + "HOMEBREW_USE_RUBY_FROM_PATH" => ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", nil), + "HOMEBREW_RUBY3" => ENV.fetch("HOMEBREW_RUBY3", nil), + } Bundler.with_unbundled_env do - stdout, stderr, status = Open3.capture3("#{ENV.fetch("HOMEBREW_PREFIX")}/bin/brew", *args) + stdout, stderr, status = Open3.capture3(env, "#{ENV.fetch("HOMEBREW_PREFIX")}/bin/brew", *args) $stdout.print stdout $stderr.print stderr status diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index b8573b1705..ec76d66933 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -70,7 +70,7 @@ find_ruby() { # HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH are set by brew.sh # shellcheck disable=SC2154 need_vendored_ruby() { - if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]] + if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" || -n "${HOMEBREW_RUBY3}" ]] then return 0 elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]] && ! can_use_ruby_from_path @@ -118,7 +118,12 @@ If there's no Homebrew Portable Ruby available for your processor: vendor_ruby_root="${vendor_dir}/portable-ruby/current" vendor_ruby_path="${vendor_ruby_root}/bin/ruby" vendor_ruby_terminfo="${vendor_ruby_root}/share/terminfo" - vendor_ruby_latest_version="$(cat "${vendor_dir}/portable-ruby-version")" + if [[ -n "${HOMEBREW_RUBY3}" ]] + then + vendor_ruby_latest_version="$(cat "${vendor_dir}/portable-ruby-version")" + else + vendor_ruby_latest_version="2.6.10_1" # EOL - phasing out + fi vendor_ruby_current_version="$(readlink "${vendor_ruby_root}")" unset HOMEBREW_RUBY_PATH diff --git a/Library/Homebrew/vendor/portable-ruby-version b/Library/Homebrew/vendor/portable-ruby-version index 7d8b9aebdf..0aec50e6ed 100644 --- a/Library/Homebrew/vendor/portable-ruby-version +++ b/Library/Homebrew/vendor/portable-ruby-version @@ -1 +1 @@ -2.6.10_1 +3.1.4