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,13 +89,21 @@ module HomebrewEnvExtension
def xcrun tool def xcrun tool
if File.executable? "/usr/bin/#{tool}" if File.executable? "/usr/bin/#{tool}"
"/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 # xcrun was provided first with Xcode 4.3 and allows us to proxy
# tool usage thus avoiding various bugs # tool usage thus avoiding various bugs
"/usr/bin/xcrun #{tool}" "/usr/bin/xcrun #{tool}"
else else
# otherwise lets try and figure it out ourselves # otherwise lets try and figure it out ourselves
fn = "#{MacOS.dev_tools_path}/#{tool}" fn = "#{MacOS.dev_tools_path}/#{tool}"
if File.executable? fn
fn
else
# 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 if File.executable? fn
fn fn
else else
@ -103,13 +111,14 @@ module HomebrewEnvExtension
end end
end end
end end
end
# if your formula doesn't like CC having spaces use this # if your formula doesn't like CC having spaces use this
def expand_xcrun def expand_xcrun
ENV['CC'] =~ %r{#{MacOS.xcrun} (.*)} ENV['CC'] =~ %r{/usr/bin/xcrun (.*)}
ENV['CC'] = `#{MacOS.xcrun} -find #{$1}`.chomp if $1 ENV['CC'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
ENV['CXX'] =~ %r{#{MacOS.xcrun} (.*)} ENV['CXX'] =~ %r{/usr/bin/xcrun (.*)}
ENV['CXX'] = `#{MacOS.xcrun} -find #{$1}`.chomp if $1 ENV['CXX'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
end end
def gcc args = {} def gcc args = {}
@ -126,7 +135,7 @@ module HomebrewEnvExtension
raise "GCC could not be found" if not File.exist? ENV['CC'] raise "GCC could not be found" if not File.exist? ENV['CC']
end 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/ raise "GCC could not be found" if Pathname.new(ENV['CC']).realpath.to_s =~ /llvm/
end end

View File

@ -266,17 +266,18 @@ module MacOS extend self
end end
end end
def xcrun def default_cc
@xcrun ||= begin cc = `/usr/bin/xcrun -find cc 2> /dev/null`.chomp
path = "#{xcode_prefix}/usr/bin/xcrun" cc = "#{dev_tools_path}/cc" if cc.empty? or not $?.success?
path = "xcrun" unless File.file? path # just in case
path unless File.executable? cc
end # 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 end
def default_cc
cc = `#{xcrun} -find cc 2> /dev/null`.chomp
cc = "#{dev_tools_path}/cc" if cc.empty?
Pathname.new(cc).realpath.basename.to_s rescue nil Pathname.new(cc).realpath.basename.to_s rescue nil
end end