From 97acbe8f66648ca5939c92e61c90ab21ee4c8cb2 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 6 Aug 2012 13:46:02 -0400 Subject: [PATCH] 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. --- Library/Homebrew/macos/xcode.rb | 111 +++++++++++++++++--------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/Library/Homebrew/macos/xcode.rb b/Library/Homebrew/macos/xcode.rb index 0c8139c623..844926ede2 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 + @version ||= uncached_version + end - # 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 + 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? + return "0" unless MACOS - 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" + # 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