Merge pull request #11179 from hyuraku/shims_repair-style

Shims repair style
This commit is contained in:
Mike McQuaid 2021-04-20 15:27:42 +01:00 committed by GitHub
commit 433407a2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 120 additions and 95 deletions

View File

@ -1,26 +1,29 @@
#!/bin/bash #!/bin/bash
# HOMEBREW_CCCFG is set by extend/ENV/super.rb
# HOMEBREW_LIBRARY is set by bin/brew
# shellcheck disable=SC2154,SC2250
pathremove() { pathremove() {
local IFS=':' NEWPATH="" DIR="" PATHVARIABLE=${2:-PATH} local IFS=':' NEWPATH="" DIR="" PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then if [ "${DIR}" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR NEWPATH=${NEWPATH:+$NEWPATH:}${DIR}
fi fi
done done
export "$PATHVARIABLE"="$NEWPATH" export "${PATHVARIABLE}"="${NEWPATH}"
} }
if [[ -n "$HOMEBREW_MAKE" && "$HOMEBREW_MAKE" != "make" ]] if [[ -n "${HOMEBREW_MAKE}" && "${HOMEBREW_MAKE}" != "make" ]]
then then
export MAKE="$HOMEBREW_MAKE" export MAKE="${HOMEBREW_MAKE}"
else else
SAVED_PATH="$PATH" SAVED_PATH="${PATH}"
pathremove "$HOMEBREW_LIBRARY/Homebrew/shims/linux/super" pathremove "${HOMEBREW_LIBRARY}/Homebrew/shims/linux/super"
MAKE="$(which make)" MAKE="$(command -v make)"
export MAKE export MAKE
export PATH="$SAVED_PATH" export PATH="${SAVED_PATH}"
fi fi
export HOMEBREW_CCCFG="O$HOMEBREW_CCCFG" export HOMEBREW_CCCFG="O${HOMEBREW_CCCFG}"
exec "$MAKE" "$@" exec "${MAKE}" "$@"

View File

@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
export HOMEBREW_CCCFG="O$HOMEBREW_CCCFG" export HOMEBREW_CCCFG="O${HOMEBREW_CCCFG}"
ant=/usr/bin/ant ant=/usr/bin/ant
[[ -x "$ant" ]] || ant="$("$HOMEBREW_BREW_FILE" --prefix ant)/bin/ant" # HOMEBREW_BREW_FILE is set by bin/brew
exec "$ant" "$@" # shellcheck disable=SC2154
[[ -x "${ant}" ]] || ant="$("${HOMEBREW_BREW_FILE}" --prefix ant)/bin/ant"
exec "${ant}" "$@"

View File

@ -1,12 +1,14 @@
#!/bin/bash #!/bin/bash
if [[ "$HOMEBREW_CCCFG" = *a* ]] # HOMEBREW_CCCFG and HOMEBREW_SDKROOT are set by extend/ENV/super.rb
# shellcheck disable=SC2154
if [[ "${HOMEBREW_CCCFG}" = *a* ]]
then then
case "$1" in case "$1" in
--cc) echo "cc" ;; --cc) echo "cc" ;;
--cpp) echo "cpp" ;; --cpp) echo "cpp" ;;
--includedir) echo "$HOMEBREW_SDKROOT/usr/include/apr-1" ;; --includedir) echo "${HOMEBREW_SDKROOT}/usr/include/apr-1" ;;
--includes) echo "-isystem$HOMEBREW_SDKROOT/usr/include/apr-1" ;; --includes) echo "-isystem${HOMEBREW_SDKROOT}/usr/include/apr-1" ;;
--apr-libtool) echo "glibtool" ;; --apr-libtool) echo "glibtool" ;;
*) *)
exec xcrun apr-1-config "$@" exec xcrun apr-1-config "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
export HOMEBREW_CCCFG="O$HOMEBREW_CCCFG" export HOMEBREW_CCCFG="O${HOMEBREW_CCCFG}"
exec xcrun bsdmake "$@" exec xcrun bsdmake "$@"

View File

@ -1,10 +1,12 @@
#!/bin/bash #!/bin/bash
if [[ -n "$HOMEBREW_MAKE" && "$HOMEBREW_MAKE" != "make" ]] # shellcheck disable=SC2154
# HOMEBREW_CCCFG is set by extend/ENV/super.rb
if [[ -n "${HOMEBREW_MAKE}" && "${HOMEBREW_MAKE}" != "make" ]]
then then
export MAKE="$HOMEBREW_MAKE" export MAKE="${HOMEBREW_MAKE}"
else else
MAKE="make" MAKE="make"
fi fi
export HOMEBREW_CCCFG="O$HOMEBREW_CCCFG" export HOMEBREW_CCCFG="O${HOMEBREW_CCCFG}"
exec xcrun "$MAKE" "$@" exec xcrun "${MAKE}" "$@"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
pwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" pwd="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec xcrun mig -cc "$pwd/cc" "$@" exec xcrun mig -cc "${pwd}/cc" "$@"

View File

@ -1,11 +1,13 @@
#!/bin/sh #!/bin/sh
pkg_config="$HOMEBREW_OPT/pkg-config/bin/pkg-config" # HOMEBREW_OPT and HOMEBREW_SDKROOT are set by extend/ENV/super.rb
# shellcheck disable=SC2154
pkg_config="${HOMEBREW_OPT}/pkg-config/bin/pkg-config"
if [ -z "$HOMEBREW_SDKROOT" ]; then if [ -z "${HOMEBREW_SDKROOT}" ]; then
exec "$pkg_config" "$@" exec "${pkg_config}" "$@"
fi fi
exec "$pkg_config" \ exec "${pkg_config}" \
"--define-variable=homebrew_sdkroot=$HOMEBREW_SDKROOT" \ "--define-variable=homebrew_sdkroot=${HOMEBREW_SDKROOT}" \
"$@" "$@"

View File

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
# HOMEBREW_PREFIX is set by bin/brew
# shellcheck disable=SC2154
POD2MAN="$(type -P pod2man5.18 || POD2MAN="$(type -P pod2man5.18 ||
type -P pod2man5.16 || type -P pod2man5.16 ||
type -P pod2man5.12 || type -P pod2man5.12 ||
type -P "$HOMEBREW_PREFIX/opt/pod2man/bin/pod2man" || type -P "${HOMEBREW_PREFIX}/opt/pod2man/bin/pod2man" ||
echo /usr/bin/pod2man)" echo /usr/bin/pod2man)"
exec "$POD2MAN" "$@" exec "${POD2MAN}" "$@"

View File

@ -3,13 +3,15 @@
# System Ruby's mkmf on Mojave (10.14) and later require SDKROOT set to work correctly. # System Ruby's mkmf on Mojave (10.14) and later require SDKROOT set to work correctly.
# Don't need shellcheck to follow the `source`. # Don't need shellcheck to follow the `source`.
# shellcheck disable=SC1090 # HOMEBREW_LIBRARY is set by bin/brew
source "$HOMEBREW_LIBRARY/Homebrew/shims/utils.sh" # HOMEBREW_SDKROOT is set by extend/ENV/super.rb
# shellcheck disable=SC1090,SC2154
source "${HOMEBREW_LIBRARY}/Homebrew/shims/utils.sh"
try_exec_non_system "$SHIM_FILE" "$@" try_exec_non_system "${SHIM_FILE}" "$@"
if [[ -z "$SDKROOT" && -n "$HOMEBREW_SDKROOT" ]]; then if [[ -z "${SDKROOT}" && -n "${HOMEBREW_SDKROOT}" ]]; then
export SDKROOT=$HOMEBREW_SDKROOT export SDKROOT=${HOMEBREW_SDKROOT}
fi fi
safe_exec "/usr/bin/$SHIM_FILE" "$@" safe_exec "/usr/bin/${SHIM_FILE}" "$@"

View File

@ -5,21 +5,24 @@
# it and attempts to avoid these issues. # it and attempts to avoid these issues.
# These could be used in conjunction with `--sdk` which ignores SDKROOT. # These could be used in conjunction with `--sdk` which ignores SDKROOT.
if [[ "$*" =~ (^| )-?-show-sdk-(path|version|build) && -n "$HOMEBREW_DEVELOPER_DIR" ]]; then # HOMEBREW_DEVELOPER_DIR, HOMEBREW_SDKROOT and HOMEBREW_PREFER_CLT_PROXIES are set by extend/ENV/super.rb
export DEVELOPER_DIR=$HOMEBREW_DEVELOPER_DIR # shellcheck disable=SC2154
if [[ "$*" =~ (^| )-?-show-sdk-(path|version|build) && -n "${HOMEBREW_DEVELOPER_DIR}" ]]; then
export DEVELOPER_DIR=${HOMEBREW_DEVELOPER_DIR}
else else
# Some build tools set DEVELOPER_DIR, so discard it # Some build tools set DEVELOPER_DIR, so discard it
unset DEVELOPER_DIR unset DEVELOPER_DIR
fi fi
if [[ -z "$SDKROOT" && -n "$HOMEBREW_SDKROOT" ]]; then if [[ -z "${SDKROOT}" && -n "${HOMEBREW_SDKROOT}" ]]; then
export SDKROOT=$HOMEBREW_SDKROOT export SDKROOT=${HOMEBREW_SDKROOT}
fi fi
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
exec /usr/bin/xcrun "$@" exec /usr/bin/xcrun "$@"
fi fi
# shellcheck disable=SC2249
case "$1" in case "$1" in
-*) exec /usr/bin/xcrun "$@" ;; -*) exec /usr/bin/xcrun "$@" ;;
esac esac
@ -28,34 +31,34 @@ arg0=$1
shift shift
exe="/usr/bin/${arg0}" exe="/usr/bin/${arg0}"
if [[ -x "$exe" ]]; then if [[ -x "${exe}" ]]; then
if [[ -n "$HOMEBREW_PREFER_CLT_PROXIES" ]]; then if [[ -n "${HOMEBREW_PREFER_CLT_PROXIES}" ]]; then
exec "$exe" "$@" exec "${exe}" "$@"
elif [[ -z "$HOMEBREW_SDKROOT" || ! -d "$HOMEBREW_SDKROOT" ]]; then elif [[ -z "${HOMEBREW_SDKROOT}" || ! -d "${HOMEBREW_SDKROOT}" ]]; then
exec "$exe" "$@" exec "${exe}" "$@"
fi fi
fi fi
SUPERBIN=$(cd "${0%/*}" && pwd -P) SUPERBIN=$(cd "${0%/*}" && pwd -P)
exe=$(/usr/bin/xcrun --find "$arg0" 2>/dev/null) exe=$(/usr/bin/xcrun --find "${arg0}" 2>/dev/null)
if [[ -x "$exe" && "${exe%/*}" != "$SUPERBIN" ]]; then if [[ -x "${exe}" && "${exe%/*}" != "${SUPERBIN}" ]]; then
exec "$exe" "$@" exec "${exe}" "$@"
fi fi
old_IFS=$IFS old_IFS=${IFS}
IFS=: IFS=:
for path in $PATH; do for path in ${PATH}; do
if [ "$path" = "$SUPERBIN" ]; then if [ "${path}" = "${SUPERBIN}" ]; then
continue continue
fi fi
exe="${path}/${arg0}" exe="${path}/${arg0}"
if [ -x "$exe" ]; then if [ -x "${exe}" ]; then
exec "$exe" "$@" exec "${exe}" "$@"
fi fi
done done
IFS=$old_IFS IFS=${old_IFS}
echo >&2 " echo >&2 "
Failed to execute ${arg0} ${*} Failed to execute ${arg0} ${*}

View File

@ -3,7 +3,13 @@
# This script because we support $HOMEBREW_GIT, $HOMEBREW_SVN, etc., Xcode-only and # This script because we support $HOMEBREW_GIT, $HOMEBREW_SVN, etc., Xcode-only and
# no Xcode/CLT configurations. Order is careful to be what the user would want. # no Xcode/CLT configurations. Order is careful to be what the user would want.
if [ -z "$HOMEBREW_LIBRARY" ] # HOMEBREW_LIBRARY is set by bin/brew
# SHIM_FILE is set by shims/utils.sh
# HOMEBREW_GIT is set by brew.sh
# HOMEBREW_SVN is from the user environment.
# HOMEBREW_PREFIX is set extend/ENV/super.rb
# shellcheck disable=SC2154
if [ -z "${HOMEBREW_LIBRARY}" ]
then then
echo "${0##*/}: This shim is internal and must be run via brew." >&2 echo "${0##*/}: This shim is internal and must be run via brew." >&2
exit 1 exit 1
@ -11,27 +17,28 @@ fi
# Don't need shellcheck to follow the `source`. # Don't need shellcheck to follow the `source`.
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$HOMEBREW_LIBRARY/Homebrew/shims/utils.sh" source "${HOMEBREW_LIBRARY}/Homebrew/shims/utils.sh"
case "$(lowercase "$SHIM_FILE")" in # shellcheck disable=SC2249
case "$(lowercase "${SHIM_FILE}")" in
git) git)
if [[ -n "$HOMEBREW_GIT" && "$HOMEBREW_GIT" != git ]] if [[ -n "${HOMEBREW_GIT}" && "${HOMEBREW_GIT}" != git ]]
then then
safe_exec "$(type -P "$HOMEBREW_GIT")" "$@" safe_exec "$(type -P "${HOMEBREW_GIT}")" "$@"
fi fi
;; ;;
svn) svn)
if [[ -n "$HOMEBREW_SVN" && "$HOMEBREW_SVN" != svn ]] if [[ -n "${HOMEBREW_SVN}" && "${HOMEBREW_SVN}" != svn ]]
then then
safe_exec "$(type -P "$HOMEBREW_SVN")" "$@" safe_exec "$(type -P "${HOMEBREW_SVN}")" "$@"
fi fi
;; ;;
esac esac
brew_prefix_version="$HOMEBREW_PREFIX/bin/$SHIM_FILE" brew_prefix_version="${HOMEBREW_PREFIX}/bin/${SHIM_FILE}"
safe_exec "$brew_prefix_version" "$@" safe_exec "${brew_prefix_version}" "$@"
try_exec_non_system "$SHIM_FILE" "$@" try_exec_non_system "${SHIM_FILE}" "$@"
if executable "/usr/bin/xcode-select" if executable "/usr/bin/xcode-select"
then then
@ -39,28 +46,28 @@ then
# /usr/bin/<tool> will be a popup stub under such configuration. # /usr/bin/<tool> will be a popup stub under such configuration.
# xcrun hangs if xcode-select is set to "/" # xcrun hangs if xcode-select is set to "/"
xcode_path="$(/usr/bin/xcode-select -print-path 2>/dev/null)" xcode_path="$(/usr/bin/xcode-select -print-path 2>/dev/null)"
if [[ -z "$xcode_path" ]] if [[ -z "${xcode_path}" ]]
then then
if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -ge "100900" ]] if [[ "${HOMEBREW_MACOS_VERSION_NUMERIC}" -ge "100900" ]]
then then
popup_stub=1 popup_stub=1
fi fi
fi fi
if [[ -z "$popup_stub" && "$xcode_path" != "/" ]] if [[ -z "${popup_stub}" && "${xcode_path}" != "/" ]]
then then
path="$(/usr/bin/xcrun -find "$SHIM_FILE" 2>/dev/null)" path="$(/usr/bin/xcrun -find "${SHIM_FILE}" 2>/dev/null)"
safe_exec "$path" "$@" safe_exec "${path}" "$@"
fi fi
fi fi
path="/Applications/Xcode.app/Contents/Developer/usr/bin/$SHIM_FILE" path="/Applications/Xcode.app/Contents/Developer/usr/bin/${SHIM_FILE}"
safe_exec "$path" "$@" safe_exec "${path}" "$@"
if [[ -z "$popup_stub" && "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101500" ]] if [[ -z "${popup_stub}" && "${HOMEBREW_MACOS_VERSION_NUMERIC}" -lt "101500" ]]
then then
path="/usr/bin/$SHIM_FILE" path="/usr/bin/${SHIM_FILE}"
safe_exec "$path" "$@" safe_exec "${path}" "$@"
fi fi
echo "You must: brew install $SHIM_FILE" >&2 echo "You must: brew install ${SHIM_FILE}" >&2
exit 1 exit 1

View File

@ -11,7 +11,7 @@ absdir() {
dirbasepath() { dirbasepath() {
local dir="$1" local dir="$1"
local base="${2##*/}" local base="${2##*/}"
echo "$dir/$base" echo "${dir}/${base}"
} }
realpath() { realpath() {
@ -19,28 +19,28 @@ realpath() {
local dir local dir
local dest local dest
dir="$(absdir "$path")" dir="$(absdir "${path}")"
path="$(dirbasepath "$dir" "$path")" path="$(dirbasepath "${dir}" "${path}")"
while [[ -L "$path" ]] while [[ -L "${path}" ]]
do do
dest="$(readlink "$path")" dest="$(readlink "${path}")"
if [[ "$dest" = "/"* ]] if [[ "${dest}" = "/"* ]]
then then
path="$dest" path="${dest}"
else else
path="$dir/$dest" path="${dir}/${dest}"
fi fi
dir="$(absdir "$path")" dir="$(absdir "${path}")"
path="$(dirbasepath "$dir" "$path")" path="$(dirbasepath "${dir}" "${path}")"
done done
echo "$path" echo "${path}"
} }
executable() { executable() {
local file="$1" local file="$1"
[[ -f "$file" && -x "$file" ]] [[ -f "${file}" && -x "${file}" ]]
} }
lowercase() { lowercase() {
@ -49,22 +49,22 @@ lowercase() {
safe_exec() { safe_exec() {
local arg0="$1" local arg0="$1"
if ! executable "$arg0" if ! executable "${arg0}"
then then
return return
fi fi
# prevent fork-bombs # prevent fork-bombs
if [[ "$(lowercase "$arg0")" = "$SHIM_FILE" || "$(realpath "$arg0")" = "$SHIM_REAL" ]] if [[ "$(lowercase "${arg0}")" = "${SHIM_FILE}" || "$(realpath "${arg0}")" = "${SHIM_REAL}" ]]
then then
return return
fi fi
if [[ "$HOMEBREW" = "print-path" ]] if [[ "${HOMEBREW}" = "print-path" ]]
then then
local dir local dir
dir="$(quiet_safe_cd "${arg0%/*}/" && pwd)" dir="$(quiet_safe_cd "${arg0%/*}/" && pwd)"
local path local path
path="$(dirbasepath "$dir" "$arg0")" path="$(dirbasepath "${dir}" "${arg0}")"
echo "$path" echo "${path}"
exit exit
fi fi
exec "$@" exec "$@"
@ -75,11 +75,11 @@ try_exec_non_system() {
shift shift
IFS=$'\n' IFS=$'\n'
for path in $(type -aP "$file") for path in $(type -aP "${file}")
do do
if [[ "$path" != "/usr/bin/$file" ]] if [[ "${path}" != "/usr/bin/${file}" ]]
then then
safe_exec "$path" "$@" safe_exec "${path}" "$@"
fi fi
done done
unset IFS unset IFS