From 58f3e49c0b1df2d448bb9c8df2529a5ff78cd2ef Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 3 Jun 2020 18:01:38 -0500 Subject: [PATCH 1/3] utils/ruby.sh: rename test-ruby to test_ruby. Cosmetic changes --- Library/Homebrew/utils/ruby.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 1792359767..f26beaaaed 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,8 +1,15 @@ -test-ruby () { - [[ ! -x $1 ]] && { echo "false"; return 1; } - "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \ +test_ruby () { + if [[ ! -x $1 ]] + then + return 1 + fi + + local ruby_status + ruby_status=$("$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 + Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null) + + test "$ruby_status" = true } setup-ruby-path() { @@ -57,7 +64,7 @@ If there's no Homebrew Portable Ruby available for your processor: 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 + if [[ $(test_ruby "$ruby_exec") == "true" ]]; then HOMEBREW_RUBY_PATH=$ruby_exec break fi @@ -71,7 +78,7 @@ If there's no Homebrew Portable Ruby available for your processor: usable_ruby_version="true" elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] then - usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH") + usable_ruby_version=$(test_ruby "$HOMEBREW_RUBY_PATH") fi if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] From 9751d3bb8c884f6994739160bfaa40aee831b3e6 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Sat, 6 Jun 2020 12:03:51 -0500 Subject: [PATCH 2/3] Fix calls to 'test_ruby' in conditional statements Co-authored-by: Shaun Jackman --- Library/Homebrew/utils/ruby.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index f26beaaaed..36ea8d817b 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -64,7 +64,7 @@ If there's no Homebrew Portable Ruby available for your processor: 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 + if test_ruby "$ruby_exec"; then HOMEBREW_RUBY_PATH=$ruby_exec break fi @@ -76,9 +76,9 @@ If there's no Homebrew Portable Ruby available for your processor: if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] then usable_ruby_version="true" - elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] + elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] && test_ruby "$HOMEBREW_RUBY_PATH" then - usable_ruby_version=$(test_ruby "$HOMEBREW_RUBY_PATH") + usable_ruby_version=true fi if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] From 23d24dfed7668844f2b0ee833ccb02b8cbf414a1 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 10 Jun 2020 07:56:37 -0500 Subject: [PATCH 3/3] utils/ruby.sh: rely on test_ruby's exit code Instead of printing "true" or "false", test_ruby now returns 1 when tested Ruby is not usable and 0 if it is. --- Library/Homebrew/utils/ruby.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 36ea8d817b..8d70bba5d0 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -4,12 +4,9 @@ test_ruby () { return 1 fi - local ruby_status - ruby_status=$("$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) - - test "$ruby_status" = true + "$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \ + "abort if 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 } setup-ruby-path() { @@ -17,7 +14,7 @@ setup-ruby-path() { local vendor_ruby_path local vendor_ruby_latest_version local vendor_ruby_current_version - local usable_ruby_version + local usable_ruby # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) # also needs to be changed. local required_ruby_version="2.6" @@ -75,13 +72,13 @@ If there's no Homebrew Portable Ruby available for your processor: if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] then - usable_ruby_version="true" + usable_ruby=true elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] && test_ruby "$HOMEBREW_RUBY_PATH" then - usable_ruby_version=true + usable_ruby=true 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" || -z $usable_ruby ]] then brew vendor-install ruby if [[ ! -x "$vendor_ruby_path" ]]