From 1555436f70162a2da6dc0b4b96008c21f1de2a1a Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 31 Aug 2012 09:51:08 -0400 Subject: [PATCH] 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. --- Library/Homebrew/macos.rb | 21 +++++++++------------ Library/Homebrew/macos/xcode.rb | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index a50639d203..cf80d1dd6f 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -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 diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb index b7a3a26c9d..120d9b3d26 100644 --- a/Library/Homebrew/macos/xcode.rb +++ b/Library/Homebrew/macos/xcode.rb @@ -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'