From d6ed7fea4ae611c9418ef9c310b233d9434f1998 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 21 Jul 2013 20:09:55 -0500 Subject: [PATCH] Cache pkgutil results at the source --- Library/Homebrew/macos.rb | 4 +++- Library/Homebrew/os/mac/xcode.rb | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index 1359d2b484..b86bc8f42e 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -234,7 +234,9 @@ module MacOS extend self end def pkgutil_info id - `/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip + (@pkginfo ||= {}).fetch(id.to_s) do + @pkginfo[id.to_s] = `/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip + end end end diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index d8ac28a9eb..bfac9f9bd6 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -182,16 +182,17 @@ module MacOS::CLT extend self !latest_version? end + # Version string (a pretty damn long one) of the CLT package. + # Note, that different ways to install the CLTs lead to different + # version numbers. def version - # The pkgutils calls are slow, don't repeat if no CLT installed. - return @version if @version_determined + @version ||= detect_version + end - @version_determined = true - # Version string (a pretty damn long one) of the CLT package. - # Note, that different ways to install the CLTs lead to different - # version numbers. - @version ||= [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id| - MacOS.pkgutil_info(id) =~ /version: (.+)$/ - end && $1 + def detect_version + [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id| + version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1] + return version if version + end end end