aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/macos/xcode.rb
diff options
context:
space:
mode:
authorMax Howell2012-08-06 13:46:02 -0400
committerMax Howell2012-08-06 13:46:47 -0400
commit97acbe8f66648ca5939c92e61c90ab21ee4c8cb2 (patch)
treef2ffd5821d779a0b87fa26ffa6ef8413358e195e /Library/Homebrew/macos/xcode.rb
parenta8a9388062d3ee32aa5fbf438303e02a50646174 (diff)
downloadbrew-97acbe8f66648ca5939c92e61c90ab21ee4c8cb2.tar.bz2
Actually cache Xcode.version
The short-circuit returns would cause the caching ||= syntax to be skipped. For me on my CLT-less install, this was noticeably slowing down brew for some operations due to the frequent calls to xcodebuild.
Diffstat (limited to 'Library/Homebrew/macos/xcode.rb')
-rw-r--r--Library/Homebrew/macos/xcode.rb115
1 files changed, 60 insertions, 55 deletions
diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb
index 0c8139c62..844926ede 100644
--- a/Library/Homebrew/macos/xcode.rb
+++ b/Library/Homebrew/macos/xcode.rb
@@ -56,65 +56,70 @@ module MacOS::Xcode extend self
# may return a version string
# that is guessed based on the compiler, so do not
# use it in order to check if Xcode is installed.
- @version ||= begin
- return "0" unless MACOS
-
- # 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'
- if xcode43build.file?
- `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
- return $1 if $1
- end
+ @version ||= uncached_version
+ end
+
+ def uncached_version
+ # This is a separate function as you can't cache the value out of a block
+ # if return is used in the middle, which we do many times in here.
- # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus
- raise if bad_xcode_select_path?
-
- raise unless which "xcodebuild"
- `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
- raise if $1.nil? or not $?.success?
- $1
- rescue
- # For people who's xcode-select is unset, or who have installed
- # xcode-gcc-installer or whatever other combinations we can try and
- # supprt. See https://github.com/mxcl/homebrew/wiki/Xcode
- case MacOS.llvm_build_version.to_i
- when 1..2063 then "3.1.0"
- when 2064..2065 then "3.1.4"
- when 2366..2325
- # we have no data for this range so we are guessing
- "3.2.0"
- when 2326
- # also applies to "3.2.3"
+ return "0" unless MACOS
+
+ # 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'
+ if xcode43build.file?
+ `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
+ $1 if $1
+ end
+
+ # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus
+ raise if bad_xcode_select_path?
+
+ raise unless which "xcodebuild"
+ `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
+ raise if $1.nil? or not $?.success?
+ $1
+ rescue
+ # For people who's xcode-select is unset, or who have installed
+ # xcode-gcc-installer or whatever other combinations we can try and
+ # supprt. See https://github.com/mxcl/homebrew/wiki/Xcode
+ case MacOS.llvm_build_version.to_i
+ when 1..2063 then "3.1.0"
+ when 2064..2065 then "3.1.4"
+ when 2366..2325
+ # we have no data for this range so we are guessing
+ "3.2.0"
+ when 2326
+ # also applies to "3.2.3"
+ "3.2.4"
+ when 2327..2333 then "3.2.5"
+ when 2335
+ # this build number applies to 3.2.6, 4.0 and 4.1
+ # https://github.com/mxcl/homebrew/wiki/Xcode
+ "4.0"
+ else
+ case (MacOS.clang_version.to_f * 10).to_i
+ when 0
+ "dunno"
+ when 1..14
+ "3.2.2"
+ when 15
"3.2.4"
- when 2327..2333 then "3.2.5"
- when 2335
- # this build number applies to 3.2.6, 4.0 and 4.1
- # https://github.com/mxcl/homebrew/wiki/Xcode
+ when 16
+ "3.2.5"
+ when 17..20
"4.0"
+ when 21
+ "4.1"
+ when 22..30
+ "4.2"
+ when 31
+ "4.3"
+ when 40
+ "4.4"
else
- case (MacOS.clang_version.to_f * 10).to_i
- when 0
- "dunno"
- when 1..14
- "3.2.2"
- when 15
- "3.2.4"
- when 16
- "3.2.5"
- when 17..20
- "4.0"
- when 21
- "4.1"
- when 22..30
- "4.2"
- when 31
- "4.3"
- when 40
- "4.4"
- else
- "4.4"
- end
+ "4.4"
end
end
end