Rewrite xcrun wrapper in shell

This commit is contained in:
Jack Nagel 2014-06-03 10:03:34 -05:00
parent 6e616b29c5
commit 3ccca7720f

View File

@ -1,50 +1,57 @@
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
#!/bin/sh
# 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.
# Some build tools set DEVELOPER_DIR, so discard it
ENV.delete "DEVELOPER_DIR"
unset DEVELOPER_DIR
if ARGV.empty? || ARGV[0][0..0] == "-"
exec "/usr/bin/xcrun", *ARGV
end
if [ $# -eq 0 ]; then
exec /usr/bin/xcrun "$@"
fi
arg0 = ARGV.shift
case "$1" in
-*) exec /usr/bin/xcrun "$@" ;;
esac
exe = "/usr/bin/#{arg0}"
if File.executable?(exe)
exec(exe, *ARGV) if ENV["HOMEBREW_PREFER_CLT_PROXIES"]
sdkroot = ENV["HOMEBREW_SDKROOT"]
exec(exe, *ARGV) unless sdkroot && File.directory?(sdkroot)
end
arg0=$1
shift
$:.unshift "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8"
require "pathname"
exe="/usr/bin/${arg0}"
if [ -x "$exe" ]; then
if [ -n "$HOMEBREW_PREFER_CLT_PROXIES" ]; then
exec "$exe" "$@"
elif [ -z "$HOMEBREW_SDKROOT" -o ! -d "$HOMEBREW_SDKROOT" ]; then
exec "$exe" "$@"
fi
fi
def canonical_dirname path
Pathname.new(path).dirname.realpath.to_s
end
SUPERBIN=$(cd "${0%/*}" && pwd -P)
SUPERBIN = canonical_dirname(__FILE__)
exe=$(/usr/bin/xcrun --find "$arg0" 2>/dev/null)
if [ -x "$exe" -a "${exe%/*}" != "$SUPERBIN" ]; then
exec "$exe" "$@"
fi
exe = `/usr/bin/xcrun --find #{arg0} 2>/dev/null`.chomp
if File.executable?(exe) && canonical_dirname(exe) != SUPERBIN
exec(exe, *ARGV)
end
old_IFS=$IFS
IFS=:
for path in $PATH; do
if [ "$path" = "$SUPERBIN" ]; then
continue
fi
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
paths.delete(SUPERBIN)
paths.each do |path|
exe = File.join(path, arg0)
exec(exe, *ARGV) if File.executable?(exe)
end
exe="${path}/${arg0}"
if [ -x "$exe" ]; then
exec "$exe" "$@"
fi
done
IFS=$old_IFS
abort <<-EOS
Failed to execute: #{arg0} #{ARGV.join(" ")}
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
EOS
"
exit 1