71 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2014-04-29 21:51:18 -05:00
# Historically, xcrun has had various bugs, and in some cases it didn't
# work at all (e.g. CLT-only in the Xcode 4.3 era). This script emulates
# it and attempts to avoid these issues.
# These could be used in conjunction with `--sdk` which ignores SDKROOT.
2021-04-20 22:52:07 +09:00
# HOMEBREW_DEVELOPER_DIR, HOMEBREW_SDKROOT and HOMEBREW_PREFER_CLT_PROXIES are set by extend/ENV/super.rb
2021-04-18 19:43:37 +09:00
# shellcheck disable=SC2154
if [[ "$*" =~ (^| )-?-show-sdk-(path|version|build) && -n "${HOMEBREW_DEVELOPER_DIR}" ]]; then
export DEVELOPER_DIR=${HOMEBREW_DEVELOPER_DIR}
else
# Some build tools set DEVELOPER_DIR, so discard it
unset DEVELOPER_DIR
fi
2021-04-18 19:43:37 +09:00
if [[ -z "${SDKROOT}" && -n "${HOMEBREW_SDKROOT}" ]]; then
export SDKROOT=${HOMEBREW_SDKROOT}
fi
2014-06-03 10:03:34 -05:00
if [ $# -eq 0 ]; then
exec /usr/bin/xcrun "$@"
fi
2021-04-18 19:43:37 +09:00
# shellcheck disable=SC2249
2014-06-03 10:03:34 -05:00
case "$1" in
-*) exec /usr/bin/xcrun "$@" ;;
esac
arg0=$1
shift
exe="/usr/bin/${arg0}"
2021-04-18 19:43:37 +09:00
if [[ -x "${exe}" ]]; then
if [[ -n "${HOMEBREW_PREFER_CLT_PROXIES}" ]]; then
exec "${exe}" "$@"
elif [[ -z "${HOMEBREW_SDKROOT}" || ! -d "${HOMEBREW_SDKROOT}" ]]; then
exec "${exe}" "$@"
2014-06-03 10:03:34 -05:00
fi
fi
SUPERBIN=$(cd "${0%/*}" && pwd -P)
2021-04-18 19:43:37 +09:00
exe=$(/usr/bin/xcrun --find "${arg0}" 2>/dev/null)
if [[ -x "${exe}" && "${exe%/*}" != "${SUPERBIN}" ]]; then
exec "${exe}" "$@"
2014-06-03 10:03:34 -05:00
fi
2021-04-18 19:43:37 +09:00
old_IFS=${IFS}
2014-06-03 10:03:34 -05:00
IFS=:
2021-04-18 19:43:37 +09:00
for path in ${PATH}; do
if [ "${path}" = "${SUPERBIN}" ]; then
2014-06-03 10:03:34 -05:00
continue
fi
exe="${path}/${arg0}"
2021-04-18 19:43:37 +09:00
if [ -x "${exe}" ]; then
exec "${exe}" "$@"
2014-06-03 10:03:34 -05:00
fi
done
2021-04-18 19:43:37 +09:00
IFS=${old_IFS}
2014-06-03 10:03:34 -05:00
echo >&2 "
Failed to execute ${arg0} ${*}
Xcode and/or the CLT appear to be misconfigured. Try one or both of the following:
xcodebuild -license
sudo xcode-select --switch /path/to/Xcode.app
2014-06-03 10:03:34 -05:00
"
exit 1