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.
This commit is contained in:
Max Howell 2012-08-06 13:46:02 -04:00
parent a8a9388062
commit 97acbe8f66

View File

@ -56,65 +56,70 @@ module MacOS::Xcode extend self
# may return a version string # may return a version string
# that is guessed based on the compiler, so do not # that is guessed based on the compiler, so do not
# use it in order to check if Xcode is installed. # use it in order to check if Xcode is installed.
@version ||= begin @version ||= uncached_version
return "0" unless MACOS end
# this shortcut makes version work for people who don't realise you def uncached_version
# need to install the CLI tools # This is a separate function as you can't cache the value out of a block
xcode43build = V4_BUNDLE_PATH/'Contents/Developer/usr/bin/xcodebuild' # if return is used in the middle, which we do many times in here.
if xcode43build.file?
`#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
return $1 if $1
end
# Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus return "0" unless MACOS
raise if bad_xcode_select_path?
raise unless which "xcodebuild" # this shortcut makes version work for people who don't realise you
`xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ # need to install the CLI tools
raise if $1.nil? or not $?.success? xcode43build = V4_BUNDLE_PATH/'Contents/Developer/usr/bin/xcodebuild'
$1 if xcode43build.file?
rescue `#{xcode43build} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
# For people who's xcode-select is unset, or who have installed $1 if $1
# xcode-gcc-installer or whatever other combinations we can try and end
# supprt. See https://github.com/mxcl/homebrew/wiki/Xcode
case MacOS.llvm_build_version.to_i # Xcode 4.3 xc* tools hang indefinately if xcode-select path is set thus
when 1..2063 then "3.1.0" raise if bad_xcode_select_path?
when 2064..2065 then "3.1.4"
when 2366..2325 raise unless which "xcodebuild"
# we have no data for this range so we are guessing `xcodebuild -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/
"3.2.0" raise if $1.nil? or not $?.success?
when 2326 $1
# also applies to "3.2.3" 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" "3.2.4"
when 2327..2333 then "3.2.5" when 16
when 2335 "3.2.5"
# this build number applies to 3.2.6, 4.0 and 4.1 when 17..20
# https://github.com/mxcl/homebrew/wiki/Xcode
"4.0" "4.0"
when 21
"4.1"
when 22..30
"4.2"
when 31
"4.3"
when 40
"4.4"
else else
case (MacOS.clang_version.to_f * 10).to_i "4.4"
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
end end
end end
end end