Merge pull request #16192 from Bo98/system-ruby-3

Support system Ruby 3 on Linux
This commit is contained in:
Bo Anderson 2023-11-07 21:07:42 +00:00 committed by GitHub
commit 3baec056e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -6,7 +6,7 @@ module Homebrew
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")
@ -15,7 +15,7 @@ module Homebrew
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

View File

@ -6,7 +6,7 @@ module Homebrew
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

View File

@ -205,6 +205,7 @@ module Homebrew
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?

View File

@ -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() {
@ -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