From c6b0b563e8a5b39c1e1a433446e00c28d15548df Mon Sep 17 00:00:00 2001 From: Samuel John Date: Wed, 20 Mar 2013 18:20:18 +0100 Subject: [PATCH] Better superenv support for Xcode elsewhere - The Library/ENV/4.3/xcrun shim now respects ENV['DEVELOPER_DIR'] instead assuming the location of /Applications/Xcode.app/Contents/Developer. - The env var DEVELOPER_DIR is set if it is not already. So, during superenv this var is always set and we no longer have to care about people with unset or wrongly set xcode-select stuff. This has been a major PITA in the past. - determine_developer_dir (which is used to set the DEVELOPER_DIR var) now uses MacOS::Xcode.prefix which is proven and very capable and uses splotlight correctly. - Replace (and remove) MacSystem.xcode43_developer_dir with Xcode.prefix Closes Homebrew/homebrew#18618 --- Library/ENV/4.3/xcrun | 4 ++-- Library/Homebrew/os/mac/xcode.rb | 2 +- Library/Homebrew/superenv.rb | 15 ++++----------- Library/Homebrew/superenv/macsystem.rb | 12 +----------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/Library/ENV/4.3/xcrun b/Library/ENV/4.3/xcrun index 14176a5a71..6afb6cf162 100755 --- a/Library/ENV/4.3/xcrun +++ b/Library/ENV/4.3/xcrun @@ -19,8 +19,8 @@ end arg0 = ARGV.shift try `/usr/bin/xcrun --find #{arg0}`.chomp # Nuts, Xcode is not setup properly or something. Try to find the tools anyway! -try "/Applications/Xcode.app/Contents/Developer/usr/bin/#{arg0}" -try "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/#{arg0}" +try "#{ENV['DEVELOPER_DIR']}/usr/bin/#{arg0}" +try "#{ENV['DEVELOPER_DIR']}/Toolchains/XcodeDefault.xctoolchain/usr/bin/#{arg0}" try "/usr/bin/#{arg0}" abort <<-EOS diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 40bc1e87d6..a89faa0023 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -76,7 +76,7 @@ module MacOS::Xcode extend self # this shortcut makes version work for people who don't realise you # need to install the CLI tools - xcode43build = V4_BUNDLE_PATH/'Contents/Developer/usr/bin/xcodebuild' + xcode43build = prefix/'usr/bin/xcodebuild' if xcode43build.file? `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ return $1 if $1 diff --git a/Library/Homebrew/superenv.rb b/Library/Homebrew/superenv.rb index fb494c10e1..0fd5973912 100644 --- a/Library/Homebrew/superenv.rb +++ b/Library/Homebrew/superenv.rb @@ -18,10 +18,7 @@ end def superenv? not (MacSystem.xcode43_without_clt? and - MacOS.sdk_path.nil?) and # because superenv will fail to find stuff - not (MacSystem.xcode43_without_clt? and - !MacSystem.xcode43_developer_dir) and # because superenv's logic might not find it - not MacOS::Xcode.folder.nil? and # because xcrun won't work + MacOS.sdk_path.nil?) and # because superenv will fail to find stuff superbin and superbin.directory? and not ARGV.include? "--env=std" rescue # blanket rescue because there are naked raises @@ -112,8 +109,8 @@ class << ENV def determine_path paths = [superbin] if MacSystem.xcode43_without_clt? - paths << "#{MacSystem.xcode43_developer_dir}/usr/bin" - paths << "#{MacSystem.xcode43_developer_dir}/Toolchains/XcodeDefault.xctoolchain/usr/bin" + paths << "#{MacOS::Xcode.prefix}/usr/bin" + paths << "#{MacOS::Xcode.prefix}/Toolchains/XcodeDefault.xctoolchain/usr/bin" end paths += deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/bin" } paths << "#{HOMEBREW_PREFIX}/opt/python/bin" if brewed_python? @@ -197,11 +194,7 @@ class << ENV # If Xcode path is fucked then this is basically a fix. In the case where # nothing is valid, it still fixes most usage to supply a valid path that # is not "/". - if MacOS::Xcode.bad_xcode_select_path? - (MacOS::Xcode.prefix || HOMEBREW_PREFIX).to_s - elsif ENV['DEVELOPER_DIR'] - ENV['DEVELOPER_DIR'] - end + MacOS::Xcode.prefix || ENV['DEVELOPER_DIR'] end def brewed_python? diff --git a/Library/Homebrew/superenv/macsystem.rb b/Library/Homebrew/superenv/macsystem.rb index 5f16b8fade..7d2a7880f8 100644 --- a/Library/Homebrew/superenv/macsystem.rb +++ b/Library/Homebrew/superenv/macsystem.rb @@ -1,7 +1,7 @@ # new code because I don't really trust the Xcode code now having researched it more module MacSystem extend self def xcode_clt_installed? - File.executable? "/usr/bin/clang" and File.executable? "/usr/bin/lldb" + File.executable? "/usr/bin/clang" and File.executable? "/usr/bin/lldb" and File.executable? "/usr/bin/make" end def xcode43_without_clt? @@ -13,16 +13,6 @@ module MacSystem extend self #{MacOS.sdk_path}/usr/X11].find{|path| File.directory? "#{path}/include" } end - def xcode43_developer_dir - @xcode43_developer_dir ||= - tst(ENV['DEVELOPER_DIR']) || - tst(`xcode-select -print-path 2>/dev/null`) || - tst("/Applications/Xcode.app/Contents/Developer") || - MacOS.mdfind("com.apple.dt.Xcode").find{|path| tst(path) } - raise unless @xcode43_developer_dir - @xcode43_developer_dir - end - private def tst prefix