MacOS.sdk_path is unlicensed Xcode aware

Now we should get an sdk_path, but tools like xcodebuild, xcode-select and xcrun will still error out. But at least more of Homebrew will work.

Also putting the Xcode 3 path finder last. We get bug reports because newer Xcodes are installed in parallel to older Xcodes. We want to find and use the newer Xcode's first. Xcode.prefix is pretty smart about that.

Refs Homebrew/homebrew#14558.
This commit is contained in:
Max Howell 2012-08-31 09:51:08 -04:00
parent d39b7b6b99
commit 1555436f70
2 changed files with 11 additions and 13 deletions

View File

@ -65,20 +65,17 @@ module MacOS extend self
end
end
def sdk_path v=version
def sdk_path(v = version)
@sdk_path ||= {}
@sdk_path[v.to_s] ||= begin
path = if not Xcode.bad_xcode_select_path? and File.executable? "#{Xcode.folder}/usr/bin/make"
`#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.strip
elsif File.directory? "/Developer/SDKs/MacOS#{v}.sdk"
# the old default (or wild wild west style)
"/Developer/SDKs/MacOS#{v}.sdk"
elsif File.directory? "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk"
# Xcode.prefix is pretty smart, so lets look inside to find the sdk
"#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk"
end
Pathname.new(path) unless path.nil? or path.empty? or not File.directory? path
opts = []
# First query Xcode itself
opts << `#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.chomp unless Xcode.bad_xcode_select_path?
# Xcode.prefix is pretty smart, so lets look inside to find the sdk
opts << "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk"
# Xcode < 4.3 style
opts << "/Developer/SDKs/MacOS#{v}.sdk"
opts.map{|a| Pathname.new(a) }.detect(&:directory?)
end
end

View File

@ -7,6 +7,7 @@ module MacOS::Xcode extend self
# Locate the "current Xcode folder" via xcode-select. See:
# man xcode-select
# NOTE!! use Xcode.prefix rather than this generally!
def folder
@folder ||= `xcode-select -print-path 2>/dev/null`.strip
end
@ -31,7 +32,7 @@ module MacOS::Xcode extend self
def prefix
@prefix ||= begin
path = Pathname.new folder
path = Pathname.new(folder)
if path.absolute? and (path/'usr/bin/make').executable?
path
elsif File.executable? '/Developer/usr/bin/make'