MacOS.xcode_prefix

More robust code than before, and replaces all usage of `xcode-select -print-path`.
This commit is contained in:
Max Howell 2010-11-13 22:45:22 +00:00 committed by Adam Vandenberg
parent 48fe922456
commit d78b89dd2e
2 changed files with 26 additions and 9 deletions

View File

@ -121,10 +121,8 @@ module HomebrewEnvExtension
end
def llvm
xcode_path = `/usr/bin/xcode-select -print-path`.chomp
xcode_path = "/Developer" if xcode_path.to_s.empty?
self['CC'] = "#{xcode_path}/usr/bin/llvm-gcc"
self['CXX'] = "#{xcode_path}/usr/bin/llvm-g++"
self['CC'] = "#{MacOS.xcode_prefix}/usr/bin/llvm-gcc"
self['CXX'] = "#{MacOS.xcode_prefix}/usr/bin/llvm-g++"
self['LD'] = self['CC']
self.O4
end

View File

@ -232,12 +232,31 @@ module MacOS extend self
end
end
# usually /Developer
def xcode_prefix
@xcode_prefix ||= begin
path = `/usr/bin/xcode-select -print-path 2>&1`.chomp
path = Pathname.new path
if path.directory? and path.absolute?
path
elsif File.directory? '/Developer'
# we do this to support cowboys who insist on installing
# only a subset of Xcode
'/Developer'
else
nil
end
end
end
def llvm_build_version
if MACOS_VERSION >= 10.6
xcode_path = `/usr/bin/xcode-select -print-path`.chomp
return nil if xcode_path.empty?
`#{xcode_path}/usr/bin/llvm-gcc -v 2>&1` =~ /LLVM build (\d{4,})/
$1.to_i
unless xcode_prefix.to_s.empty?
llvm_gcc_path = xcode_prefix/"usr/bin/llvm-gcc"
# for Xcode 3 on OS X 10.5 this will not exist
if llvm_gcc_path.file?
`#{llvm_gcc_path} -v 2>&1` =~ /LLVM build (\d{4,})/
$1.to_i # if nil this raises and then you fix the regex
end
end
end