aboutsummaryrefslogtreecommitdiffstats
path: root/Library/ENV/4.3/xcrun
blob: a4d2beacfcef3552b0f1343f326555ff0d9405d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0

# 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"

if ARGV.empty? || ARGV[0][0..0] == "-"
  exec "/usr/bin/xcrun", *ARGV
end

arg0 = ARGV.shift

exe = "/usr/bin/#{arg0}"
if File.executable?(exe)
  sdkroot = ENV["HOMEBREW_SDKROOT"]
  exec(exe, *ARGV) unless sdkroot && File.directory?(sdkroot)
end

$:.unshift "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8"
require "pathname"

def canonical_dirname path
  Pathname.new(path).dirname.realpath.to_s
end

SUPERBIN = canonical_dirname(__FILE__)

exe = `/usr/bin/xcrun --find #{arg0} 2>/dev/null`.chomp
if File.executable?(exe) && canonical_dirname(exe) != SUPERBIN
  exec(exe, *ARGV)
end

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

abort <<-EOS
Failed to execute: #{arg0} #{ARGV.join(" ")}

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