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
 }
This commit is contained in:
Maxim Belkin 2020-05-21 15:06:21 -05:00
parent 8dcb1636ce
commit db561eb7b9
No known key found for this signature in database
GPG Key ID: AC71560D4C5F2338

View File

@ -27,63 +27,65 @@ If there's no Homebrew Portable Ruby available for your processor:
unset HOMEBREW_RUBY_PATH unset HOMEBREW_RUBY_PATH
if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]] if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
then 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 then
HOMEBREW_RUBY_PATH="$vendor_ruby_path" if ! brew vendor-install ruby
if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]]
then then
if ! brew vendor-install ruby if [[ -n "$HOMEBREW_MACOS" ]]
then then
if [[ -n "$HOMEBREW_MACOS" ]] odie "Failed to upgrade Homebrew Portable Ruby!"
then else
odie "Failed to upgrade Homebrew Portable Ruby!" odie "Failed to upgrade Homebrew Portable Ruby!$advice"
else
odie "Failed to upgrade Homebrew Portable Ruby!$advice"
fi
fi fi
fi fi
fi
else
if [[ -n "$HOMEBREW_MACOS" ]]
then
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else else
if [[ -n "$HOMEBREW_MACOS" ]] IFS=$'\n' # Do word splitting on new lines only
then for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby)
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" do
else if [[ $(test-ruby "$ruby_exec") == "true" ]]; then
IFS=$'\n' # Do word splitting on new lines only HOMEBREW_RUBY_PATH=$ruby_exec
for ruby_exec in $(which -a ruby) $(PATH=$HOMEBREW_PATH which -a ruby) break
do fi
if [[ $(test-ruby "$ruby_exec") == "true" ]]; then done
HOMEBREW_RUBY_PATH=$ruby_exec IFS=$' \t\n' # Restore IFS to its default value
break [[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!"
fi fi
done
IFS=$' \t\n' # Restore IFS to its default value if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]]
[[ -z $HOMEBREW_RUBY_PATH ]] && onoe "Failed to find usable Ruby $required_ruby_version!" then
fi usable_ruby_version="true"
elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] then
then usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH")
usable_ruby_version="true" fi
elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
then if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]]
usable_ruby_version=$(test-ruby "$HOMEBREW_RUBY_PATH") then
fi brew vendor-install ruby
if [[ ! -x "$vendor_ruby_path" ]]
if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] then
then if [[ -n "$HOMEBREW_MACOS" ]]
brew vendor-install ruby then
if [[ ! -x "$vendor_ruby_path" ]] odie "Failed to install Homebrew Portable Ruby (and your system version is too old)!"
then else
if [[ -n "$HOMEBREW_MACOS" ]] odie "Failed to install Homebrew Portable Ruby and cannot find another Ruby $required_ruby_version!$advice"
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
fi fi
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
fi fi
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
fi fi
fi fi