Move logic related to HOMEBREW_RUBY_PATH to utils/ruby.sh

This commit is contained in:
Maxim Belkin 2020-05-15 10:30:45 -05:00
parent 1cba5821fd
commit 328c75fc33
No known key found for this signature in database
GPG Key ID: AC71560D4C5F2338
2 changed files with 33 additions and 9 deletions

View File

@ -599,13 +599,6 @@ EOS
-d "$HOMEBREW_LIBRARY/LinkedKegs" || -d "$HOMEBREW_LIBRARY/LinkedKegs" ||
(-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]]
then then
if [[ -n $HOMEBREW_FORCE_VENDOR_RUBY &&
-x $HOMEBREW_LIBRARY/Homebrew/vendor/portable-ruby/current/bin/ruby ]]
then
export HOMEBREW_RUBY_PATH="$HOMEBREW_LIBRARY/Homebrew/vendor/portable-ruby/current/bin/ruby"
elif [[ -z $HOMEBREW_DEVELOPER ]]; then
unset HOMEBREW_RUBY_PATH
fi
brew update-report "$@" brew update-report "$@"
return $? return $?
elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]]

View File

@ -1,3 +1,7 @@
test-ruby () {
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e "puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)"
}
setup-ruby-path() { setup-ruby-path() {
local vendor_dir local vendor_dir
local vendor_ruby_current_version local vendor_ruby_current_version
@ -6,11 +10,19 @@ setup-ruby-path() {
# When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
# also needs to be changed. # also needs to be changed.
local required_ruby_version="2.6" local required_ruby_version="2.6"
local old_ruby_path
local old_ruby_usable
vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor" vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
vendor_ruby_current_version="$vendor_dir/portable-ruby/current" vendor_ruby_current_version="$vendor_dir/portable-ruby/current"
vendor_ruby_path="$vendor_ruby_current_version/bin/ruby" vendor_ruby_path="$vendor_ruby_current_version/bin/ruby"
if [[ -n $HOMEBREW_RUBY_PATH ]]
then
old_ruby_path="$HOMEBREW_RUBY_PATH"
old_ruby_usable=$(test-ruby "$HOMEBREW_RUBY_PATH")
fi
if [[ -z "$HOMEBREW_DEVELOPER" ]] if [[ -z "$HOMEBREW_DEVELOPER" ]]
then then
unset HOMEBREW_RUBY_PATH unset HOMEBREW_RUBY_PATH
@ -45,7 +57,26 @@ EOS
then then
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else else
HOMEBREW_RUBY_PATH="$(type -P ruby)" HOMEBREW_RUBY_PATH=$(type -P ruby)
if [[ $(test-ruby $HOMEBREW_RUBY_PATH) != "true" ]]
then
HOMEBREW_RUBY_PATH=$(PATH="$HOMEBREW_PATH" type -P ruby)
if [[ $(test-ruby "$HOMEBREW_RUBY_PATH") != "true" ]]
then
if [[ $old_ruby_usable != true ]]
then
odie <<-EOS
Failed to find usable Ruby $required_ruby_version!
If there's no Homebrew Portable Ruby available for your processor:
- install $required_ruby_version with your system package manager (or rbenv/ruby-build)
- make it first in your PATH
- try again
EOS
else
HOMEBREW_RUBY_PATH="$old_ruby_path"
fi
fi
fi
fi fi
if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]]
@ -53,7 +84,7 @@ EOS
usable_ruby_version="true" usable_ruby_version="true"
elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
then then
usable_ruby_version="$("$HOMEBREW_RUBY_PATH" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e "puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)")" usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH")
fi fi
if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]]