Skip to content

Commit

Permalink
Remove Ruby 2.6 & macOS system Ruby support code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Dec 12, 2023
1 parent 4c20298 commit 688d87e
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 123 deletions.
5 changes: 0 additions & 5 deletions Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,3 @@ gem "plist"
gem "ruby-macho"
gem "sorbet-runtime"
gem "warning"

# TODO: remove when HOMEBREW_REQUIRED_RUBY_VERSION >= 2.7
install_if -> { RUBY_VERSION < "2.7" } do
gem "did_you_mean"
end
2 changes: 0 additions & 2 deletions Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ GEM
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.2.2)
did_you_mean (1.6.3)
diff-lcs (1.5.0)
docile (1.4.0)
elftools (1.2.0)
Expand Down Expand Up @@ -193,7 +192,6 @@ DEPENDENCIES
addressable
bootsnap
byebug
did_you_mean
json_schemer
minitest
parallel_tests
Expand Down
5 changes: 0 additions & 5 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,6 @@ then
HOMEBREW_FORCE_BREWED_GIT="1"
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
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
# Don't try to follow /etc/os-release
Expand Down Expand Up @@ -651,7 +648,6 @@ Your Git executable: $(unset git && type -p "${HOMEBREW_GIT}")"
fi

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)"
if [[ "${HOMEBREW_CORE_REPOSITORY_ORIGIN}" =~ (/linuxbrew|Linuxbrew/homebrew)-core(\.git)?$ ]]
Expand Down Expand Up @@ -742,7 +738,6 @@ export HOMEBREW_USER_AGENT
export HOMEBREW_USER_AGENT_CURL
export HOMEBREW_API_DEFAULT_DOMAIN
export HOMEBREW_BOTTLE_DEFAULT_DOMAIN
export HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
export HOMEBREW_CURL_SPEED_LIMIT
export HOMEBREW_CURL_SPEED_TIME

Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/dev-cmd/vendor-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def vendor_gems

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}"
HOMEBREW_LIBRARY_PATH.cd do
if args.update
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Cleanup
def use_system_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?

Check warning on line 11 in Library/Homebrew/extend/os/mac/cleanup.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/cleanup.rb#L11

Added line #L11 was not covered by tests
end
end
end
13 changes: 0 additions & 13 deletions Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,6 @@ def check_if_xcode_needs_clt_installed
EOS
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
prefix = MacOS::Xcode.prefix
return if prefix.nil?
Expand Down
13 changes: 2 additions & 11 deletions Library/Homebrew/extend/os/mac/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@ module SystemConfig
class << self
include SystemCommand::Mixin

undef describe_homebrew_ruby, 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
undef describe_clang

sig { returns(String) }
def describe_clang
return "N/A" if clang.null?

Expand Down
5 changes: 0 additions & 5 deletions Library/Homebrew/standalone/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,4 @@
require_relative "../vendor/bundle/bundler/setup"
$LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
"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!
12 changes: 1 addition & 11 deletions Library/Homebrew/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,9 @@ def describe_path(path)
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) }
def describe_homebrew_ruby
"#{describe_homebrew_ruby_version} => #{RUBY_PATH}"
"#{RUBY_VERSION} => #{RUBY_PATH}"
end

sig { returns(T.nilable(String)) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/dev-cmd/irb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# 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.
# 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
11 changes: 0 additions & 11 deletions Library/Homebrew/test/os/mac/diagnostic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@
.to match("Xcode alone is not sufficient on El Capitan")
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
let(:macos_version) { MacOSVersion.new("11") }

Expand Down
26 changes: 1 addition & 25 deletions Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,6 @@ def install_bundler!
def user_gem_groups
@user_gem_groups ||= if GEM_GROUPS_FILE.exist?
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
[]
end
Expand Down Expand Up @@ -213,14 +205,7 @@ def write_user_gem_groups(groups)
end

def forget_user_gem_groups!
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
GEM_GROUPS_FILE.truncate(0) if GEM_GROUPS_FILE.exist?
@user_gem_groups = []
end

Expand All @@ -239,7 +224,6 @@ def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups:
old_bundle_gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
old_bundle_with = ENV.fetch("BUNDLE_WITH", nil)
old_bundle_frozen = ENV.fetch("BUNDLE_FROZEN", nil)
old_sdkroot = ENV.fetch("SDKROOT", nil)

invalid_groups = groups - valid_gem_groups
raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty?
Expand Down Expand Up @@ -267,13 +251,6 @@ def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups:
ENV["BUNDLE_WITH"] = groups.join(" ")
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
bundle = File.join(find_in_path("bundle"), "bundle")
bundle_check_output = `#{bundle} check 2>&1`
Expand Down Expand Up @@ -367,6 +344,5 @@ def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups:
ENV["BUNDLE_WITH"] = old_bundle_with
ENV["BUNDLE_FROZEN"] = old_bundle_frozen
end
ENV["SDKROOT"] = old_sdkroot
end
end
56 changes: 26 additions & 30 deletions Library/Homebrew/utils/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ test_ruby() {
"${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null
}

system_ruby_supported() {
([[ -z "${HOMEBREW_MACOS}" ]] || can_use_ruby_from_path)
}

can_use_ruby_from_path() {
if [[ -n "${HOMEBREW_DEVELOPER}" || -n "${HOMEBREW_TESTS}" ]] && [[ -n "${HOMEBREW_USE_RUBY_FROM_PATH}" ]]
then
Expand All @@ -39,47 +43,37 @@ find_first_valid_ruby() {
done
}

# HOMEBREW_MACOS is set by brew.sh
# HOMEBREW_PATH is set by global.rb
# shellcheck disable=SC2154
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.
if ! can_use_ruby_from_path
then
# function which() is set by brew.sh
# it is aliased to `type -P`
# shellcheck disable=SC2230
valid_ruby=$(find_first_valid_ruby < <(which -a ruby))
fi

if [[ -z "${valid_ruby}" ]]
then
# Same as above
# shellcheck disable=SC2230
valid_ruby=$(find_first_valid_ruby < <(PATH="${HOMEBREW_PATH}" which -a ruby))
fi
# Prioritise rubies from the filtered path (/usr/bin etc) unless explicitly overridden.
if ! can_use_ruby_from_path
then
# function which() is set by brew.sh
# it is aliased to `type -P`
# shellcheck disable=SC2230
valid_ruby=$(find_first_valid_ruby < <(which -a ruby))
fi

echo "${valid_ruby}"
if [[ -z "${valid_ruby}" ]]
then
# Same as above
# shellcheck disable=SC2230
valid_ruby=$(find_first_valid_ruby < <(PATH="${HOMEBREW_PATH}" which -a ruby))
fi

echo "${valid_ruby}"
}

# HOMEBREW_FORCE_VENDOR_RUBY is from the user environment
# HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH are set by brew.sh
# shellcheck disable=SC2154
need_vendored_ruby() {
if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]]
then
return 0
elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]] && ! can_use_ruby_from_path
then
return 1
elif ([[ -z "${HOMEBREW_MACOS}" ]] || can_use_ruby_from_path) && test_ruby "${HOMEBREW_RUBY_PATH}"
elif system_ruby_supported && test_ruby "${HOMEBREW_RUBY_PATH}"
then
return 1
else
Expand All @@ -96,8 +90,6 @@ setup-ruby-path() {
local vendor_ruby_terminfo
local vendor_ruby_latest_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 upgrade_fail
local install_fail
Expand Down Expand Up @@ -140,7 +132,11 @@ If there's no Homebrew Portable Ruby available for your processor:
brew vendor-install ruby || odie "${upgrade_fail}"
fi
else
HOMEBREW_RUBY_PATH="$(find_ruby)"
if system_ruby_supported
then
HOMEBREW_RUBY_PATH="$(find_ruby)"
fi

if need_vendored_ruby
then
brew vendor-install ruby || odie "${install_fail}"
Expand Down

0 comments on commit 688d87e

Please sign in to comment.