Skip to content

Commit

Permalink
Support system Ruby 3 on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Nov 7, 2023
1 parent ff404fe commit 386fd05
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ then

# Set a variable when the macOS system Ruby is new enough to avoid spawning
# a Ruby process unnecessarily.
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "120601" ]]
if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "120601" || -n "${HOMEBREW_RUBY3}" ]]
then
unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
else
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/extend/os/linux/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Cleanup
undef use_system_ruby?

def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby? || ENV["HOMEBREW_RUBY3"]
return false if Homebrew::EnvConfig.force_vendor_ruby?

rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
system_ruby = Pathname.new("/usr/bin/ruby")
Expand All @@ -15,7 +15,7 @@ def use_system_ruby?
check_ruby_version = HOMEBREW_LIBRARY_PATH/"utils/ruby_check_version_script.rb"
rubies.uniq.any? do |ruby|
quiet_system ruby, "--enable-frozen-string-literal", "--disable=gems,did_you_mean,rubyopt",
check_ruby_version, HOMEBREW_REQUIRED_RUBY_VERSION
check_ruby_version, RUBY_VERSION
end
end
end
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 @@ -6,7 +6,7 @@ class Cleanup
undef use_system_ruby?

def use_system_ruby?
return false if Homebrew::EnvConfig.force_vendor_ruby? || ENV["HOMEBREW_RUBY3"]
return false if Homebrew::EnvConfig.force_vendor_ruby?

ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"].present?
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def check_if_xcode_needs_clt_installed
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?

Expand Down
11 changes: 9 additions & 2 deletions Library/Homebrew/utils/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ test_ruby() {
return 1
fi

if [[ -n "${HOMEBREW_RUBY3}" ]]
then
required_ruby_version="3.1.0"
else
required_ruby_version="${HOMEBREW_REQUIRED_RUBY_VERSION}"
fi

"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt \
"${HOMEBREW_LIBRARY}/Homebrew/utils/ruby_check_version_script.rb" \
"${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null
"${required_ruby_version}" 2>/dev/null
}

can_use_ruby_from_path() {
Expand Down Expand Up @@ -70,7 +77,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}" || -n "${HOMEBREW_RUBY3}" ]]
if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]]
then
return 0
elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]] && ! can_use_ruby_from_path
Expand Down

0 comments on commit 386fd05

Please sign in to comment.