OTT handling for various Xcode-4.3/CLI-Tools edge cases

Also xcrun can only exist at /usr/bin/xcrun.

Most of these edges are non-buildable environments, but I didn't know that when writing it, so it may as well stay, since it still does make brew --env more correct.
This commit is contained in:
Max Howell 2012-02-18 01:53:42 +00:00
parent 1e9a4dbfe4
commit e1461b9d20
2 changed files with 27 additions and 17 deletions

View File

@ -89,7 +89,7 @@ module HomebrewEnvExtension
def xcrun tool
if File.executable? "/usr/bin/#{tool}"
"/usr/bin/#{tool}"
elsif system "#{MacOS.xcrun} -find #{tool} 2>1 1>/dev/null"
elsif system "/usr/bin/xcrun -find #{tool} 2>1 1>/dev/null"
# xcrun was provided first with Xcode 4.3 and allows us to proxy
# tool usage thus avoiding various bugs
"/usr/bin/xcrun #{tool}"
@ -99,17 +99,26 @@ module HomebrewEnvExtension
if File.executable? fn
fn
else
nil
# This is for the use-case where xcode-select is not set up with
# Xcode 4.3. The tools in Xcode 4.3 are split over two locations,
# usually xcrun would figure that out for us, but it won't work if
# xcode-select is not configured properly.
fn = "#{MacOS.xcode_prefix}/Toolchains/XcodeDefault.xctoolchain/usr/bin/#{tool}"
if File.executable? fn
fn
else
nil
end
end
end
end
# if your formula doesn't like CC having spaces use this
def expand_xcrun
ENV['CC'] =~ %r{#{MacOS.xcrun} (.*)}
ENV['CC'] = `#{MacOS.xcrun} -find #{$1}`.chomp if $1
ENV['CXX'] =~ %r{#{MacOS.xcrun} (.*)}
ENV['CXX'] = `#{MacOS.xcrun} -find #{$1}`.chomp if $1
ENV['CC'] =~ %r{/usr/bin/xcrun (.*)}
ENV['CC'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
ENV['CXX'] =~ %r{/usr/bin/xcrun (.*)}
ENV['CXX'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
end
def gcc args = {}
@ -126,7 +135,7 @@ module HomebrewEnvExtension
raise "GCC could not be found" if not File.exist? ENV['CC']
end
if not ENV['CC'] =~ /^[^\s]*xcrun /
if not ENV['CC'] =~ %{^/usr/bin/xcrun }
raise "GCC could not be found" if Pathname.new(ENV['CC']).realpath.to_s =~ /llvm/
end

View File

@ -266,17 +266,18 @@ module MacOS extend self
end
end
def xcrun
@xcrun ||= begin
path = "#{xcode_prefix}/usr/bin/xcrun"
path = "xcrun" unless File.file? path # just in case
path
end
end
def default_cc
cc = `#{xcrun} -find cc 2> /dev/null`.chomp
cc = "#{dev_tools_path}/cc" if cc.empty?
cc = `/usr/bin/xcrun -find cc 2> /dev/null`.chomp
cc = "#{dev_tools_path}/cc" if cc.empty? or not $?.success?
unless File.executable? cc
# If xcode-select isn't setup then xcrun fails and on Xcode 4.3
# the cc binary is not at #{dev_tools_path}. This return is almost
# worthless however since in this particular setup nothing much builds
# but I wrote the code now and maybe we'll fix the other issues later.
cc = "#{xcode_prefix}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
end
Pathname.new(cc).realpath.basename.to_s rescue nil
end