Remove Ruby 2.6 & macOS system Ruby support code

This commit is contained in:
Bo Anderson 2023-12-12 03:09:59 +00:00
parent 4c20298ea5
commit 688d87e839
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
13 changed files with 33 additions and 124 deletions

View File

@ -81,8 +81,3 @@ gem "plist"
gem "ruby-macho" gem "ruby-macho"
gem "sorbet-runtime" gem "sorbet-runtime"
gem "warning" gem "warning"
# TODO: remove when HOMEBREW_REQUIRED_RUBY_VERSION >= 2.7
install_if -> { RUBY_VERSION < "2.7" } do
gem "did_you_mean"
end

View File

@ -18,7 +18,6 @@ GEM
commander (4.6.0) commander (4.6.0)
highline (~> 2.0.0) highline (~> 2.0.0)
concurrent-ruby (1.2.2) concurrent-ruby (1.2.2)
did_you_mean (1.6.3)
diff-lcs (1.5.0) diff-lcs (1.5.0)
docile (1.4.0) docile (1.4.0)
elftools (1.2.0) elftools (1.2.0)
@ -193,7 +192,6 @@ DEPENDENCIES
addressable addressable
bootsnap bootsnap
byebug byebug
did_you_mean
json_schemer json_schemer
minitest minitest
parallel_tests parallel_tests

View File

@ -585,9 +585,6 @@ then
HOMEBREW_FORCE_BREWED_GIT="1" HOMEBREW_FORCE_BREWED_GIT="1"
fi fi
fi fi
# System Ruby usage is deprecated. TODO: clean this up once 2.6 is fully ditched.
unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
else else
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
# Don't try to follow /etc/os-release # Don't try to follow /etc/os-release
@ -651,7 +648,6 @@ Your Git executable: $(unset git && type -p "${HOMEBREW_GIT}")"
fi fi
HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION="2.13" HOMEBREW_LINUX_MINIMUM_GLIBC_VERSION="2.13"
unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
HOMEBREW_CORE_REPOSITORY_ORIGIN="$("${HOMEBREW_GIT}" -C "${HOMEBREW_CORE_REPOSITORY}" remote get-url origin 2>/dev/null)" HOMEBREW_CORE_REPOSITORY_ORIGIN="$("${HOMEBREW_GIT}" -C "${HOMEBREW_CORE_REPOSITORY}" remote get-url origin 2>/dev/null)"
if [[ "${HOMEBREW_CORE_REPOSITORY_ORIGIN}" =~ (/linuxbrew|Linuxbrew/homebrew)-core(\.git)?$ ]] if [[ "${HOMEBREW_CORE_REPOSITORY_ORIGIN}" =~ (/linuxbrew|Linuxbrew/homebrew)-core(\.git)?$ ]]
@ -742,7 +738,6 @@ export HOMEBREW_USER_AGENT
export HOMEBREW_USER_AGENT_CURL export HOMEBREW_USER_AGENT_CURL
export HOMEBREW_API_DEFAULT_DOMAIN export HOMEBREW_API_DEFAULT_DOMAIN
export HOMEBREW_BOTTLE_DEFAULT_DOMAIN export HOMEBREW_BOTTLE_DEFAULT_DOMAIN
export HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
export HOMEBREW_CURL_SPEED_LIMIT export HOMEBREW_CURL_SPEED_LIMIT
export HOMEBREW_CURL_SPEED_TIME export HOMEBREW_CURL_SPEED_TIME

View File

@ -33,9 +33,6 @@ module Homebrew
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":") ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")
# System Ruby does not pick up the correct SDK by default.
ENV["SDKROOT"] = MacOS.sdk_path if ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"]
ohai "cd #{HOMEBREW_LIBRARY_PATH}" ohai "cd #{HOMEBREW_LIBRARY_PATH}"
HOMEBREW_LIBRARY_PATH.cd do HOMEBREW_LIBRARY_PATH.cd do
if args.update if args.update

View File

@ -8,7 +8,7 @@ module Homebrew
def 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_MACOS_SYSTEM_RUBY_NEW_ENOUGH"].present? Homebrew::EnvConfig.developer? && ENV["HOMEBREW_USE_RUBY_FROM_PATH"].present?
end end
end end
end end

View File

@ -204,19 +204,6 @@ module Homebrew
EOS EOS
end end
def check_ruby_version
return unless ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"]
return if RUBY_VERSION == HOMEBREW_REQUIRED_RUBY_VERSION
return if Homebrew::EnvConfig.developer? && OS::Mac.version.prerelease?
<<~EOS
Ruby version #{RUBY_VERSION} is unsupported on macOS #{MacOS.version}. Homebrew
is developed and tested on Ruby #{HOMEBREW_REQUIRED_RUBY_VERSION}, and may not work correctly
on other Rubies. Patches are accepted as long as they don't cause breakage
on supported Rubies.
EOS
end
def check_xcode_prefix def check_xcode_prefix
prefix = MacOS::Xcode.prefix prefix = MacOS::Xcode.prefix
return if prefix.nil? return if prefix.nil?

View File

@ -7,18 +7,9 @@ module SystemConfig
class << self class << self
include SystemCommand::Mixin include SystemCommand::Mixin
undef describe_homebrew_ruby, describe_clang undef describe_clang
def describe_homebrew_ruby
s = describe_homebrew_ruby_version
if RUBY_PATH.to_s.match?(%r{^/System/Library/Frameworks/Ruby\.framework/Versions/[12]\.[089]/usr/bin/ruby})
s
else
"#{s} => #{RUBY_PATH}"
end
end
sig { returns(String) }
def describe_clang def describe_clang
return "N/A" if clang.null? return "N/A" if clang.null?

View File

@ -40,9 +40,4 @@ $LOAD_PATH.push HOMEBREW_LIBRARY_PATH.to_s unless $LOAD_PATH.include?(HOMEBREW_L
require_relative "../vendor/bundle/bundler/setup" require_relative "../vendor/bundle/bundler/setup"
$LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \ $LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
"bundler-#{Homebrew::HOMEBREW_BUNDLER_VERSION}/lib" "bundler-#{Homebrew::HOMEBREW_BUNDLER_VERSION}/lib"
if ruby_major == 2 && ruby_minor == 6
# TEMP: Ruby 3 transition
$LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
"did_you_mean-1.6.3/lib"
end
$LOAD_PATH.uniq! $LOAD_PATH.uniq!

View File

@ -92,19 +92,9 @@ module SystemConfig
end end
end end
sig { returns(String) }
def describe_homebrew_ruby_version
case RUBY_VERSION
when /^1\.[89]/, /^2\.0/
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
else
RUBY_VERSION
end
end
sig { returns(String) } sig { returns(String) }
def describe_homebrew_ruby def describe_homebrew_ruby
"#{describe_homebrew_ruby_version} => #{RUBY_PATH}" "#{RUBY_VERSION} => #{RUBY_PATH}"
end end
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }

View File

@ -30,7 +30,7 @@ describe "brew irb" do
# TODO: newer Ruby only supports history saving in interactive sessions # TODO: newer Ruby only supports history saving in interactive sessions
# and not if you feed in data from a file or stdin like we are doing here. # and not if you feed in data from a file or stdin like we are doing here.
# The test will need to be adjusted for this to work. # The test will need to be adjusted for this to work.
expect(history_file).to exist if RUBY_VERSION < "2.7" # expect(history_file).to exist
end end
end end
end end

View File

@ -30,17 +30,6 @@ describe Homebrew::Diagnostic::Checks do
.to match("Xcode alone is not sufficient on El Capitan") .to match("Xcode alone is not sufficient on El Capitan")
end end
specify "#check_ruby_version" do
macos_version = MacOSVersion.new("10.12")
allow(OS::Mac).to receive(:version).and_return(macos_version)
allow(OS::Mac).to receive(:full_version).and_return(macos_version)
stub_const("RUBY_VERSION", "1.8.6")
ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"] = "1"
expect(checks.check_ruby_version)
.to match "Ruby version 1.8.6 is unsupported on macOS 10.12"
end
describe "#check_if_supported_sdk_available" do describe "#check_if_supported_sdk_available" do
let(:macos_version) { MacOSVersion.new("11") } let(:macos_version) { MacOSVersion.new("11") }

View File

@ -177,14 +177,6 @@ module Homebrew
def user_gem_groups def user_gem_groups
@user_gem_groups ||= if GEM_GROUPS_FILE.exist? @user_gem_groups ||= if GEM_GROUPS_FILE.exist?
GEM_GROUPS_FILE.readlines(chomp: true) GEM_GROUPS_FILE.readlines(chomp: true)
elsif RUBY_VERSION < "2.7"
# Backwards compatibility. This elsif block removed by the end of 2023.
# We will not support this in Ruby >=2.7.
require "settings"
groups = Homebrew::Settings.read(:gemgroups)&.split(";") || []
write_user_gem_groups(groups)
Homebrew::Settings.delete(:gemgroups)
groups
else else
[] []
end end
@ -213,14 +205,7 @@ module Homebrew
end end
def forget_user_gem_groups! def forget_user_gem_groups!
if GEM_GROUPS_FILE.exist? GEM_GROUPS_FILE.truncate(0) if GEM_GROUPS_FILE.exist?
GEM_GROUPS_FILE.truncate(0)
elsif RUBY_VERSION < "2.7"
# Backwards compatibility. This else block can be removed by the end of 2023.
# We will not support this in Ruby >=2.7.
require "settings"
Homebrew::Settings.delete(:gemgroups)
end
@user_gem_groups = [] @user_gem_groups = []
end end
@ -239,7 +224,6 @@ module Homebrew
old_bundle_gemfile = ENV.fetch("BUNDLE_GEMFILE", nil) old_bundle_gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
old_bundle_with = ENV.fetch("BUNDLE_WITH", nil) old_bundle_with = ENV.fetch("BUNDLE_WITH", nil)
old_bundle_frozen = ENV.fetch("BUNDLE_FROZEN", nil) old_bundle_frozen = ENV.fetch("BUNDLE_FROZEN", nil)
old_sdkroot = ENV.fetch("SDKROOT", nil)
invalid_groups = groups - valid_gem_groups invalid_groups = groups - valid_gem_groups
raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty? raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty?
@ -267,13 +251,6 @@ module Homebrew
ENV["BUNDLE_WITH"] = groups.join(" ") ENV["BUNDLE_WITH"] = groups.join(" ")
ENV["BUNDLE_FROZEN"] = "true" ENV["BUNDLE_FROZEN"] = "true"
# System Ruby does not pick up the correct SDK by default.
if ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"]
macos_major = ENV.fetch("HOMEBREW_MACOS_VERSION").partition(".").first
sdkroot = "/Library/Developer/CommandLineTools/SDKs/MacOSX#{macos_major}.sdk"
ENV["SDKROOT"] = sdkroot if Dir.exist?(sdkroot)
end
if @bundle_installed_groups != groups if @bundle_installed_groups != groups
bundle = File.join(find_in_path("bundle"), "bundle") bundle = File.join(find_in_path("bundle"), "bundle")
bundle_check_output = `#{bundle} check 2>&1` bundle_check_output = `#{bundle} check 2>&1`
@ -367,6 +344,5 @@ module Homebrew
ENV["BUNDLE_WITH"] = old_bundle_with ENV["BUNDLE_WITH"] = old_bundle_with
ENV["BUNDLE_FROZEN"] = old_bundle_frozen ENV["BUNDLE_FROZEN"] = old_bundle_frozen
end end
ENV["SDKROOT"] = old_sdkroot
end end
end end

View File

@ -18,6 +18,10 @@ test_ruby() {
"${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null "${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null
} }
system_ruby_supported() {
([[ -z "${HOMEBREW_MACOS}" ]] || can_use_ruby_from_path)
}
can_use_ruby_from_path() { can_use_ruby_from_path() {
if [[ -n "${HOMEBREW_DEVELOPER}" || -n "${HOMEBREW_TESTS}" ]] && [[ -n "${HOMEBREW_USE_RUBY_FROM_PATH}" ]] if [[ -n "${HOMEBREW_DEVELOPER}" || -n "${HOMEBREW_TESTS}" ]] && [[ -n "${HOMEBREW_USE_RUBY_FROM_PATH}" ]]
then then
@ -39,14 +43,9 @@ find_first_valid_ruby() {
done done
} }
# HOMEBREW_MACOS is set by brew.sh
# HOMEBREW_PATH is set by global.rb # HOMEBREW_PATH is set by global.rb
# shellcheck disable=SC2154 # shellcheck disable=SC2154
find_ruby() { find_ruby() {
if [[ -n "${HOMEBREW_MACOS}" ]] && ! can_use_ruby_from_path
then
echo "/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else
local valid_ruby local valid_ruby
# Prioritise rubies from the filtered path (/usr/bin etc) unless explicitly overridden. # Prioritise rubies from the filtered path (/usr/bin etc) unless explicitly overridden.
@ -66,20 +65,15 @@ find_ruby() {
fi fi
echo "${valid_ruby}" echo "${valid_ruby}"
fi
} }
# HOMEBREW_FORCE_VENDOR_RUBY is from the user environment # HOMEBREW_FORCE_VENDOR_RUBY is from the user environment
# HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH are set by brew.sh
# shellcheck disable=SC2154 # shellcheck disable=SC2154
need_vendored_ruby() { need_vendored_ruby() {
if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]] if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]]
then then
return 0 return 0
elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]] && ! can_use_ruby_from_path elif system_ruby_supported && test_ruby "${HOMEBREW_RUBY_PATH}"
then
return 1
elif ([[ -z "${HOMEBREW_MACOS}" ]] || can_use_ruby_from_path) && test_ruby "${HOMEBREW_RUBY_PATH}"
then then
return 1 return 1
else else
@ -96,8 +90,6 @@ setup-ruby-path() {
local vendor_ruby_terminfo local vendor_ruby_terminfo
local vendor_ruby_latest_version local vendor_ruby_latest_version
local vendor_ruby_current_version local vendor_ruby_current_version
# When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
# also needs to be changed.
local ruby_exec local ruby_exec
local upgrade_fail local upgrade_fail
local install_fail local install_fail
@ -140,7 +132,11 @@ If there's no Homebrew Portable Ruby available for your processor:
brew vendor-install ruby || odie "${upgrade_fail}" brew vendor-install ruby || odie "${upgrade_fail}"
fi fi
else else
if system_ruby_supported
then
HOMEBREW_RUBY_PATH="$(find_ruby)" HOMEBREW_RUBY_PATH="$(find_ruby)"
fi
if need_vendored_ruby if need_vendored_ruby
then then
brew vendor-install ruby || odie "${install_fail}" brew vendor-install ruby || odie "${install_fail}"