utils/ruby.sh: repair style

This commit is contained in:
hyuraku 2021-04-21 22:19:35 +09:00
parent d3b07d078f
commit 2b6afea8ed

View File

@ -1,5 +1,7 @@
export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3
# HOMEBREW_LIBRARY is from the user environment
# shellcheck disable=SC2154
test_ruby() {
if [[ ! -x $1 ]]
then
@ -7,20 +9,23 @@ test_ruby() {
fi
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt \
"$HOMEBREW_LIBRARY/Homebrew/utils/ruby_check_version_script.rb" \
"$HOMEBREW_REQUIRED_RUBY_VERSION" 2>/dev/null
"${HOMEBREW_LIBRARY}/Homebrew/utils/ruby_check_version_script.rb" \
"${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null
}
# HOMEBREW_MACOS is set by brew.sh
# HOMEBREW_PATH is set by global.rb
# shellcheck disable=SC2154
find_ruby() {
if [[ -n "$HOMEBREW_MACOS" ]]
if [[ -n "${HOMEBREW_MACOS}" ]]
then
echo "/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 2>/dev/null) $(PATH=$HOMEBREW_PATH which -a ruby 2>/dev/null)
for ruby_exec in $(command -v -a ruby 2>/dev/null) $(PATH=${HOMEBREW_PATH} command -v -a ruby 2>/dev/null)
do
if test_ruby "$ruby_exec"; then
echo "$ruby_exec"
if test_ruby "${ruby_exec}"; then
echo "${ruby_exec}"
break
fi
done
@ -28,14 +33,17 @@ find_ruby() {
fi
}
# HOMEBREW_FORCE_VENDOR_RUBY is from the user environment
# HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH are set by brew.sh
# shellcheck disable=SC2154
need_vendored_ruby() {
if [[ -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]]
then
return 0
elif [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]]
elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]]
then
return 1
elif [[ -z "$HOMEBREW_MACOS" ]] && test_ruby "$HOMEBREW_RUBY_PATH"
elif [[ -z "${HOMEBREW_MACOS}" ]] && test_ruby "${HOMEBREW_RUBY_PATH}"
then
return 1
else
@ -43,6 +51,8 @@ need_vendored_ruby() {
fi
}
# HOMEBREW_LINUX is set by brew.sh
# shellcheck disable=SC2154
setup-ruby-path() {
local vendor_dir
local vendor_ruby_root
@ -56,53 +66,53 @@ setup-ruby-path() {
local upgrade_fail
local install_fail
if [[ -n $HOMEBREW_MACOS ]]
if [[ -n ${HOMEBREW_MACOS} ]]
then
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!"
install_fail="Failed to install Homebrew Portable Ruby (and your system version is too old)!"
else
local advice="
If there's no Homebrew Portable Ruby available for your processor:
- install Ruby $HOMEBREW_REQUIRED_RUBY_VERSION with your system package manager (or rbenv/ruby-build)
- install Ruby ${HOMEBREW_REQUIRED_RUBY_VERSION} with your system package manager (or rbenv/ruby-build)
- make it first in your PATH
- try again
"
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!$advice"
install_fail="Failed to install Homebrew Portable Ruby and cannot find another Ruby $HOMEBREW_REQUIRED_RUBY_VERSION!$advice"
upgrade_fail="Failed to upgrade Homebrew Portable Ruby!${advice}"
install_fail="Failed to install Homebrew Portable Ruby and cannot find another Ruby ${HOMEBREW_REQUIRED_RUBY_VERSION}!${advice}"
fi
vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
vendor_ruby_root="$vendor_dir/portable-ruby/current"
vendor_ruby_path="$vendor_ruby_root/bin/ruby"
vendor_ruby_terminfo="$vendor_ruby_root/share/terminfo"
vendor_ruby_latest_version=$(<"$vendor_dir/portable-ruby-version")
vendor_ruby_current_version=$(readlink "$vendor_ruby_root")
vendor_dir="${HOMEBREW_LIBRARY}/Homebrew/vendor"
vendor_ruby_root="${vendor_dir}/portable-ruby/current"
vendor_ruby_path="${vendor_ruby_root}/bin/ruby"
vendor_ruby_terminfo="${vendor_ruby_root}/share/terminfo"
vendor_ruby_latest_version=$(<"${vendor_dir}/portable-ruby-version")
vendor_ruby_current_version=$(readlink "${vendor_ruby_root}")
unset HOMEBREW_RUBY_PATH
if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
if [[ "${HOMEBREW_COMMAND}" == "vendor-install" ]]
then
return 0
fi
if [[ -x "$vendor_ruby_path" ]]
if [[ -x "${vendor_ruby_path}" ]]
then
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
TERMINFO_DIRS="$vendor_ruby_terminfo"
if [[ $vendor_ruby_current_version != "$vendor_ruby_latest_version" ]]
HOMEBREW_RUBY_PATH="${vendor_ruby_path}"
TERMINFO_DIRS="${vendor_ruby_terminfo}"
if [[ ${vendor_ruby_current_version} != "${vendor_ruby_latest_version}" ]]
then
brew vendor-install ruby || odie "$upgrade_fail"
brew vendor-install ruby || odie "${upgrade_fail}"
fi
else
HOMEBREW_RUBY_PATH=$(find_ruby)
if need_vendored_ruby
then
brew vendor-install ruby || odie "$install_fail"
HOMEBREW_RUBY_PATH="$vendor_ruby_path"
TERMINFO_DIRS="$vendor_ruby_terminfo"
brew vendor-install ruby || odie "${install_fail}"
HOMEBREW_RUBY_PATH="${vendor_ruby_path}"
TERMINFO_DIRS="${vendor_ruby_terminfo}"
fi
fi
export HOMEBREW_RUBY_PATH
[[ -n "$HOMEBREW_LINUX" && -n "$TERMINFO_DIRS" ]] && export TERMINFO_DIRS
[[ -n "${HOMEBREW_LINUX}" && -n "${TERMINFO_DIRS}" ]] && export TERMINFO_DIRS
}