aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorAdam Vandenberg2012-06-27 12:08:14 -0700
committerAdam Vandenberg2012-06-27 12:08:14 -0700
commitaa228d502a81f7c324deae23b18a81181c059ebf (patch)
treeeee4a2e40a3a64a4c4486764a776e9110f144e64 /Library/Homebrew
parentc54cfa5cb202793a3a540ca7240fa3f4b06e2588 (diff)
downloadhomebrew-aa228d502a81f7c324deae23b18a81181c059ebf.tar.bz2
Refactor MacOS.
* call `xcode-select` once and cache the result * reuse functions where appropriate
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/utils.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 6e3490236..0667b74ca 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -288,6 +288,17 @@ module MacOS extend self
end
end
+ # Locate the "current Xcode folder" via xcode-select. See:
+ # man xcode-select
+ def xcode_folder
+ @xcode_folder ||= `xcode-select -print-path 2>/dev/null`.strip
+ end
+
+ # Xcode 4.3 tools hang if "/" is set
+ def xctools_fucked?
+ xcode_folder == "/"
+ end
+
def locate tool
# Don't call tools (cc, make, strip, etc.) directly!
# Give the name of the binary you look for as a string to this method
@@ -363,8 +374,7 @@ module MacOS extend self
def sdk_path(v=MacOS.version)
# The path of the MacOSX SDK.
- p = `xcode-select -print-path 2>/dev/null`.chomp
- if !MacOS.xctools_fucked? and File.executable? "#{p}/usr/bin/make"
+ if !MacOS.xctools_fucked? and File.executable? "#{xcode_folder}/usr/bin/make"
path = `#{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)
@@ -380,11 +390,6 @@ module MacOS extend self
end
end
- def xctools_fucked?
- # Xcode 4.3 tools hang if "/" is set
- @xctools_fucked ||= `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp == "/"
- end
-
def default_cc
cc = locate 'cc'
Pathname.new(cc).realpath.basename.to_s rescue nil
@@ -424,8 +429,7 @@ module MacOS extend self
def xcode_prefix
@xcode_prefix ||= begin
- path = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
- path = Pathname.new path
+ path = Pathname.new xcode_folder
if $?.success? and path.absolute? and File.executable? "#{path}/usr/bin/make"
path
elsif File.executable? '/Developer/usr/bin/make'
@@ -473,7 +477,6 @@ module MacOS extend self
end
end
-
def xcode_version
# may return a version string
# that is guessed based on the compiler, so do not
@@ -490,7 +493,7 @@ module MacOS extend self
end
# Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus
- raise if `xcode-select -print-path 2>/dev/null`.chomp == "/"
+ raise if xctools_fucked?
raise unless which "xcodebuild"
`xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/