From 9124e07b541722c53f3bc266f8d70ae1c64a5cb1 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 11 May 2020 10:47:03 -0500 Subject: [PATCH 01/14] cmd/update.sh: keep HOMEBREW_RUBY_PATH set when updating --- Library/Homebrew/cmd/update.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index a7c384a5af..19ece3f2d0 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -599,7 +599,6 @@ EOS -d "$HOMEBREW_LIBRARY/LinkedKegs" || (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] then - unset HOMEBREW_RUBY_PATH brew update-report "$@" return $? elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] From 1cba5821fd8d26c1e9ba55e368644c529838c404 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 12 May 2020 11:50:12 -0500 Subject: [PATCH 02/14] cmd/update.sh: define conditions for unsetting HOMEBREW_RUBY_PATH --- Library/Homebrew/cmd/update.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 19ece3f2d0..216729e5ed 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -599,6 +599,13 @@ EOS -d "$HOMEBREW_LIBRARY/LinkedKegs" || (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] 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 "$@" return $? elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] From 328c75fc33440de6da650dfb5b6208cb051e99b4 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 10:30:45 -0500 Subject: [PATCH 03/14] Move logic related to HOMEBREW_RUBY_PATH to utils/ruby.sh --- Library/Homebrew/cmd/update.sh | 7 ------- Library/Homebrew/utils/ruby.sh | 35 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 216729e5ed..19ece3f2d0 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -599,13 +599,6 @@ EOS -d "$HOMEBREW_LIBRARY/LinkedKegs" || (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] 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 "$@" return $? elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index bd36c4d7d7..a15893d8ce 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -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() { local vendor_dir 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) # also needs to be changed. local required_ruby_version="2.6" + local old_ruby_path + local old_ruby_usable vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor" vendor_ruby_current_version="$vendor_dir/portable-ruby/current" 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" ]] then unset HOMEBREW_RUBY_PATH @@ -45,7 +57,26 @@ EOS then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" 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 if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] @@ -53,7 +84,7 @@ EOS usable_ruby_version="true" elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] 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 if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] From cbc266bf0e56dd2edf587acf630719bd3fdf9ede Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 13:49:22 -0500 Subject: [PATCH 04/14] utils/ruby.sh: split long line in test-ruby() function Co-authored-by: Mike McQuaid --- Library/Homebrew/utils/ruby.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index a15893d8ce..46353571fd 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,5 +1,6 @@ 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)" + "$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() { From d21ecffae61b189bfd65ec6492bfa77f82409906 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 14:20:03 -0500 Subject: [PATCH 05/14] utils/ruby.sh: break down long ruby code in test-ruby --- Library/Homebrew/utils/ruby.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 46353571fd..66da2b313e 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,6 +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)" + "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() { From ec6e449f4fd3f5e9938e0a362577653aedafa8d2 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 14:21:51 -0500 Subject: [PATCH 06/14] utils/ruby.sh: unset HOMEBREW_RUBY_PATH unconditionally --- Library/Homebrew/utils/ruby.sh | 37 ++++++++++------------------------ 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 66da2b313e..24694121e3 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -14,6 +14,12 @@ setup-ruby-path() { local required_ruby_version="2.6" local old_ruby_path local old_ruby_usable + local advice=" +If there's no Homebrew Portable Ruby available for your processor: +- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build) +- make it first in your PATH +- try again +" vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor" vendor_ruby_current_version="$vendor_dir/portable-ruby/current" @@ -25,12 +31,9 @@ setup-ruby-path() { old_ruby_usable=$(test-ruby "$HOMEBREW_RUBY_PATH") fi - if [[ -z "$HOMEBREW_DEVELOPER" ]] - then - unset HOMEBREW_RUBY_PATH - fi + unset HOMEBREW_RUBY_PATH - if [[ -z "$HOMEBREW_RUBY_PATH" && "$HOMEBREW_COMMAND" != "vendor-install" ]] + if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] then if [[ -x "$vendor_ruby_path" ]] then @@ -44,13 +47,7 @@ setup-ruby-path() { then odie "Failed to upgrade Homebrew Portable Ruby!" else - odie <<-EOS -Failed to upgrade Homebrew Portable Ruby! -If there's no Homebrew Portable Ruby available for your processor: -- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build) -- make it first in your PATH -- try again -EOS + odie "Failed to upgrade Homebrew Portable Ruby!$advice" fi fi fi @@ -67,13 +64,7 @@ EOS 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 + odie "Failed to find usable Ruby $required_ruby_version!$advice" else HOMEBREW_RUBY_PATH="$old_ruby_path" fi @@ -98,13 +89,7 @@ EOS then odie "Failed to install Homebrew Portable Ruby (and your system version is too old)!" else - odie <<-EOS -Failed to install Homebrew Portable Ruby and cannot find another 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 + odie "Failed to install Homebrew Portable Ruby and cannot find another Ruby $required_ruby_version!$advice" fi fi HOMEBREW_RUBY_PATH="$vendor_ruby_path" From 44ef1abd1f9b02453ba802b8b0f286e48c981838 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 15:04:06 -0500 Subject: [PATCH 07/14] utils/ruby.sh: suppress standard error in test-ruby --- Library/Homebrew/utils/ruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 24694121e3..bd571e51ed 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,7 +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)" + Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null } setup-ruby-path() { From f7e0705164678cb68b30f1c2838410ba4e085b91 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 15:12:20 -0500 Subject: [PATCH 08/14] utils/ruby.sh: try installing portable Ruby ... when no usable Ruby is found. --- Library/Homebrew/utils/ruby.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index bd571e51ed..6074e01d1a 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -64,7 +64,8 @@ If there's no Homebrew Portable Ruby available for your processor: then if [[ $old_ruby_usable != true ]] then - odie "Failed to find usable Ruby $required_ruby_version!$advice" + onoe "Failed to find usable Ruby $required_ruby_version!" + unset HOMEBREW_RUBY_PATH else HOMEBREW_RUBY_PATH="$old_ruby_path" fi From 083f56fafeb0089ddd4d4148a1d86a2a145695e7 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 15 May 2020 16:35:42 -0500 Subject: [PATCH 09/14] utils/ruby.sh: quote HOMEBREW_RUBY_PATH when calling test-ruby --- Library/Homebrew/utils/ruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 6074e01d1a..3aa08ad467 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -57,7 +57,7 @@ If there's no Homebrew Portable Ruby available for your processor: HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else HOMEBREW_RUBY_PATH=$(type -P ruby) - if [[ $(test-ruby $HOMEBREW_RUBY_PATH) != "true" ]] + if [[ $(test-ruby "$HOMEBREW_RUBY_PATH") != "true" ]] then HOMEBREW_RUBY_PATH=$(PATH="$HOMEBREW_PATH" type -P ruby) if [[ $(test-ruby "$HOMEBREW_RUBY_PATH") != "true" ]] From b4267d80e476649492c24f525fc3d6416acf03dd Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Sun, 17 May 2020 16:32:06 -0500 Subject: [PATCH 10/14] utils/ruby.sh: avoid nested ifs --- Library/Homebrew/utils/ruby.sh | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 3aa08ad467..d596ce2d91 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,4 +1,5 @@ test-ruby () { + [[ ! -x $1 ]] && { echo "false"; return 1; } "$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)" 2>/dev/null @@ -12,8 +13,7 @@ setup-ruby-path() { # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) # also needs to be changed. local required_ruby_version="2.6" - local old_ruby_path - local old_ruby_usable + local old_ruby_path ruby_clean_path ruby_user_path local advice=" If there's no Homebrew Portable Ruby available for your processor: - install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build) @@ -25,11 +25,7 @@ If there's no Homebrew Portable Ruby available for your processor: vendor_ruby_current_version="$vendor_dir/portable-ruby/current" 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 + [[ -n $HOMEBREW_RUBY_PATH ]] && old_ruby_path=$HOMEBREW_RUBY_PATH unset HOMEBREW_RUBY_PATH @@ -56,20 +52,16 @@ If there's no Homebrew Portable Ruby available for your processor: then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - 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 - onoe "Failed to find usable Ruby $required_ruby_version!" - unset HOMEBREW_RUBY_PATH - else - HOMEBREW_RUBY_PATH="$old_ruby_path" - fi - fi + ruby_clean_path=$(type -P ruby) + ruby_user_path=$(PATH="$HOMEBREW_PATH" type -P ruby) + if [[ $(test-ruby "$old_ruby_path") == "true" ]]; then + HOMEBREW_RUBY_PATH=$old_ruby_path + elif [[ $(test-ruby "$ruby_clean_path") == "true" ]]; then + HOMEBREW_RUBY_PATH=$ruby_clean_path + elif [[ $(test-ruby "$ruby_user_path") == "true" ]]; then + HOMEBREW_RUBY_PATH=$ruby_user_path + else + onoe "Failed to find usable Ruby $required_ruby_version!" fi fi From dcc486fa9effd7c8c03d7a8ba940170fd192e8db Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 19 May 2020 12:24:00 -0500 Subject: [PATCH 11/14] utils/ruby.sh: find usable Ruby from PATH only --- Library/Homebrew/utils/ruby.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index d596ce2d91..284a8e581b 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -13,7 +13,7 @@ setup-ruby-path() { # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) # also needs to be changed. local required_ruby_version="2.6" - local old_ruby_path ruby_clean_path ruby_user_path + local ruby_exec local advice=" If there's no Homebrew Portable Ruby available for your processor: - install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build) @@ -25,8 +25,6 @@ If there's no Homebrew Portable Ruby available for your processor: vendor_ruby_current_version="$vendor_dir/portable-ruby/current" vendor_ruby_path="$vendor_ruby_current_version/bin/ruby" - [[ -n $HOMEBREW_RUBY_PATH ]] && old_ruby_path=$HOMEBREW_RUBY_PATH - unset HOMEBREW_RUBY_PATH if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] @@ -52,17 +50,16 @@ If there's no Homebrew Portable Ruby available for your processor: then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - ruby_clean_path=$(type -P ruby) - ruby_user_path=$(PATH="$HOMEBREW_PATH" type -P ruby) - if [[ $(test-ruby "$old_ruby_path") == "true" ]]; then - HOMEBREW_RUBY_PATH=$old_ruby_path - elif [[ $(test-ruby "$ruby_clean_path") == "true" ]]; then - HOMEBREW_RUBY_PATH=$ruby_clean_path - elif [[ $(test-ruby "$ruby_user_path") == "true" ]]; then - HOMEBREW_RUBY_PATH=$ruby_user_path - else - onoe "Failed to find usable Ruby $required_ruby_version!" - fi + IFS=$'\n' + for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby) + do + if [[ $(test-ruby "$ruby_exec") == "true" ]]; then + HOMEBREW_RUBY_PATH=$ruby_exec + break + fi + done + IFS=$' \t\n' + [[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!" fi if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] From 8dcb1636ce40425e29c0408a8a366889ef02e8c0 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 20 May 2020 12:29:45 -0500 Subject: [PATCH 12/14] utils/ruby.sh: add explanatory comments --- Library/Homebrew/utils/ruby.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 284a8e581b..7974e909c2 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -50,7 +50,7 @@ If there's no Homebrew Portable Ruby available for your processor: then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - IFS=$'\n' + IFS=$'\n' # Do word splitting on new lines only for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby) do if [[ $(test-ruby "$ruby_exec") == "true" ]]; then @@ -58,7 +58,7 @@ If there's no Homebrew Portable Ruby available for your processor: break fi done - IFS=$' \t\n' + IFS=$' \t\n' # Restore IFS to its default value [[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!" fi From db561eb7b93bb8c14bb70ee868eba0973f11d109 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Thu, 21 May 2020 15:06:21 -0500 Subject: [PATCH 13/14] utils/ruby.sh: setup-ruby: handle 'vendor-install' cmd early Exit from the 'setup-ruby' function when user issued `vendor-install` command. We do so instead of wrapping everything in ```sh if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] ``` `git diff` when whitespaces are ignored: $ git diff -w diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 7974e909c..4be204309 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -27,8 +27,11 @@ If there's no Homebrew Portable Ruby available for your processor: unset HOMEBREW_RUBY_PATH - if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] + if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]] then + return 0 + fi + if [[ -x "$vendor_ruby_path" ]] then HOMEBREW_RUBY_PATH="$vendor_ruby_path" @@ -85,7 +88,6 @@ If there's no Homebrew Portable Ruby available for your processor: HOMEBREW_RUBY_PATH="$vendor_ruby_path" fi fi - fi export HOMEBREW_RUBY_PATH } --- Library/Homebrew/utils/ruby.sh | 98 +++++++++++++++++----------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 7974e909c2..4be204309a 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -27,63 +27,65 @@ If there's no Homebrew Portable Ruby available for your processor: unset HOMEBREW_RUBY_PATH - if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] + if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]] then - if [[ -x "$vendor_ruby_path" ]] + return 0 + fi + + if [[ -x "$vendor_ruby_path" ]] + then + HOMEBREW_RUBY_PATH="$vendor_ruby_path" + + if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]] then - HOMEBREW_RUBY_PATH="$vendor_ruby_path" - - if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]] + if ! brew vendor-install ruby then - if ! brew vendor-install ruby + if [[ -n "$HOMEBREW_MACOS" ]] then - if [[ -n "$HOMEBREW_MACOS" ]] - then - odie "Failed to upgrade Homebrew Portable Ruby!" - else - odie "Failed to upgrade Homebrew Portable Ruby!$advice" - fi + odie "Failed to upgrade Homebrew Portable Ruby!" + else + odie "Failed to upgrade Homebrew Portable Ruby!$advice" fi fi + fi + else + if [[ -n "$HOMEBREW_MACOS" ]] + then + HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - if [[ -n "$HOMEBREW_MACOS" ]] - then - HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" - else - IFS=$'\n' # Do word splitting on new lines only - for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby) - do - if [[ $(test-ruby "$ruby_exec") == "true" ]]; then - HOMEBREW_RUBY_PATH=$ruby_exec - break - fi - done - IFS=$' \t\n' # Restore IFS to its default value - [[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!" - fi - - if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] - then - usable_ruby_version="true" - elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] - then - usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH") - fi - - if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] - then - brew vendor-install ruby - if [[ ! -x "$vendor_ruby_path" ]] - then - if [[ -n "$HOMEBREW_MACOS" ]] - then - odie "Failed to install Homebrew Portable Ruby (and your system version is too old)!" - else - odie "Failed to install Homebrew Portable Ruby and cannot find another Ruby $required_ruby_version!$advice" - fi + IFS=$'\n' # Do word splitting on new lines only + for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby) + do + if [[ $(test-ruby "$ruby_exec") == "true" ]]; then + HOMEBREW_RUBY_PATH=$ruby_exec + break + fi + done + IFS=$' \t\n' # Restore IFS to its default value + [[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!" + fi + + if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] + then + usable_ruby_version="true" + elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] + then + usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH") + fi + + if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] + then + brew vendor-install ruby + if [[ ! -x "$vendor_ruby_path" ]] + then + if [[ -n "$HOMEBREW_MACOS" ]] + then + odie "Failed to install Homebrew Portable Ruby (and your system version is too old)!" + else + odie "Failed to install Homebrew Portable Ruby and cannot find another Ruby $required_ruby_version!$advice" fi - HOMEBREW_RUBY_PATH="$vendor_ruby_path" fi + HOMEBREW_RUBY_PATH="$vendor_ruby_path" fi fi From 5d3456f4856b3aa2606afd5fe3050293d6732c6b Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Thu, 21 May 2020 17:15:14 -0500 Subject: [PATCH 14/14] utils/ruby.sh: make code more readable 1. Repurpose 'vendor_ruby_current_version' variable: now this is not a pointer to a file but actual version number 2. Introduce 'vendor_ruby_latest_version' variable: it holds the value of the latest version of portable Ruby --- Library/Homebrew/utils/ruby.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 4be204309a..1792359767 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -7,8 +7,9 @@ test-ruby () { setup-ruby-path() { local vendor_dir - local vendor_ruby_current_version local vendor_ruby_path + local vendor_ruby_latest_version + local vendor_ruby_current_version local usable_ruby_version # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) # also needs to be changed. @@ -22,8 +23,9 @@ If there's no Homebrew Portable Ruby available for your processor: " vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor" - vendor_ruby_current_version="$vendor_dir/portable-ruby/current" - vendor_ruby_path="$vendor_ruby_current_version/bin/ruby" + vendor_ruby_path="$vendor_dir/portable-ruby/current/bin/ruby" + vendor_ruby_latest_version=$(<"$vendor_dir/portable-ruby-version") + vendor_ruby_current_version=$(readlink "$vendor_dir/portable-ruby/current") unset HOMEBREW_RUBY_PATH @@ -35,8 +37,7 @@ If there's no Homebrew Portable Ruby available for your processor: if [[ -x "$vendor_ruby_path" ]] then HOMEBREW_RUBY_PATH="$vendor_ruby_path" - - if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]] + if [[ $vendor_ruby_current_version != $vendor_ruby_latest_version ]] then if ! brew vendor-install ruby then