brew.sh: new HOMEBREW_RUBY_PATH resolution logic

* Use vendor Ruby if it's present
* Install vendor Ruby for system without Ruby 2.x
This commit is contained in:
Xu Cheng 2016-06-28 23:41:28 +08:00
parent a35e3f1fc1
commit 534bf08ec3
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE
2 changed files with 62 additions and 20 deletions

View File

@ -0,0 +1,57 @@
setup-ruby-path() {
local vendor_dir
local vendor_ruby_current_version
local vendor_ruby_path
local ruby_version_major
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 [[ -z "$HOMEBREW_DEVELOPER" ]]
then
unset HOMEBREW_RUBY_PATH
fi
if [[ -z "$HOMEBREW_RUBY_PATH" && "$HOMEBREW_COMMAND" != "vendor-install" ]]
then
if [[ -x "$vendor_ruby_path" ]]
then
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]]
then
if ! brew vendor-install ruby --quiet
then
onoe "Failed to upgrade vendor Ruby."
fi
fi
else
if [[ -n "$HOMEBREW_OSX" ]]
then
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else
HOMEBREW_RUBY_PATH="$(which ruby)"
fi
if [[ -n "$HOMEBREW_RUBY_PATH" ]]
then
ruby_version_major="$("$HOMEBREW_RUBY_PATH" --version)"
ruby_version_major="${ruby_version_major#ruby }"
ruby_version_major="${ruby_version_major%%.*}"
fi
if [[ "$ruby_version_major" != "2" ]]
then
brew vendor-install ruby --quiet
if [[ ! -x "$vendor_ruby_path" ]]
then
odie "Failed to install vendor Ruby."
fi
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
fi
fi
fi
export HOMEBREW_RUBY_PATH
}

View File

@ -64,31 +64,12 @@ fi
unset GEM_HOME
unset GEM_PATH
if [[ -z "$HOMEBREW_DEVELOPER" ]]
then
unset HOMEBREW_RUBY_PATH
fi
HOMEBREW_SYSTEM="$(uname -s)"
case "$HOMEBREW_SYSTEM" in
Darwin) HOMEBREW_OSX="1";;
Linux) HOMEBREW_LINUX="1";;
esac
if [[ -z "$HOMEBREW_RUBY_PATH" ]]
then
if [[ -n "$HOMEBREW_OSX" ]]
then
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else
HOMEBREW_RUBY_PATH="$(which ruby)"
if [[ -z "$HOMEBREW_RUBY_PATH" ]]
then
odie "No Ruby found, cannot proceed."
fi
fi
fi
HOMEBREW_CURL="/usr/bin/curl"
if [[ -n "$HOMEBREW_OSX" ]]
then
@ -131,7 +112,6 @@ export HOMEBREW_LIBRARY
export HOMEBREW_VERSION
export HOMEBREW_CACHE
export HOMEBREW_CELLAR
export HOMEBREW_RUBY_PATH
export HOMEBREW_SYSTEM
export HOMEBREW_CURL
export HOMEBREW_PROCESSOR
@ -229,6 +209,11 @@ EOS
esac
fi
# Hide shellcheck complaint:
# shellcheck source=/dev/null
source "$HOMEBREW_LIBRARY/Homebrew/utils/ruby.sh"
setup-ruby-path
# Hide shellcheck complaint:
# shellcheck source=/dev/null
source "$HOMEBREW_LIBRARY/Homebrew/utils/analytics.sh"