Fetch yields the key, use it

This commit is contained in:
Jack Nagel 2013-10-04 12:43:30 -05:00
parent e887232b7e
commit 7bb90c992a

View File

@ -17,8 +17,8 @@ module MacOS extend self
# Don't call tools (cc, make, strip, etc.) directly! # Don't call tools (cc, make, strip, etc.) directly!
# Give the name of the binary you look for as a string to this method # Give the name of the binary you look for as a string to this method
# in order to get the full path back as a Pathname. # in order to get the full path back as a Pathname.
(@locate ||= {}).fetch(tool.to_s) do (@locate ||= {}).fetch(tool.to_s) do |key|
@locate[tool.to_s] = if File.executable?(path = "/usr/bin/#{tool}") @locate[key] = if File.executable?(path = "/usr/bin/#{tool}")
Pathname.new path Pathname.new path
# Homebrew GCCs most frequently; much faster to check this before xcrun # Homebrew GCCs most frequently; much faster to check this before xcrun
# This also needs to be queried if xcrun won't work, e.g. CLT-only # This also needs to be queried if xcrun won't work, e.g. CLT-only
@ -76,7 +76,7 @@ module MacOS extend self
end end
def sdk_path(v = version) def sdk_path(v = version)
(@sdk_path ||= {}).fetch(v.to_s) do (@sdk_path ||= {}).fetch(v.to_s) do |key|
opts = [] opts = []
# First query Xcode itself # First query Xcode itself
opts << `#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.chomp unless Xcode.bad_xcode_select_path? opts << `#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.chomp unless Xcode.bad_xcode_select_path?
@ -84,7 +84,7 @@ module MacOS extend self
opts << "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk" opts << "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk"
# Xcode < 4.3 style # Xcode < 4.3 style
opts << "/Developer/SDKs/MacOSX#{v}.sdk" opts << "/Developer/SDKs/MacOSX#{v}.sdk"
@sdk_path[v.to_s] = opts.map { |a| Pathname.new(a) }.detect(&:directory?) @sdk_path[key] = opts.map { |a| Pathname.new(a) }.detect(&:directory?)
end end
end end
@ -250,14 +250,14 @@ module MacOS extend self
def mdfind id def mdfind id
return [] unless MACOS return [] unless MACOS
(@mdfind ||= {}).fetch(id.to_s) do (@mdfind ||= {}).fetch(id.to_s) do |key|
@mdfind[id.to_s] = `/usr/bin/mdfind "kMDItemCFBundleIdentifier == '#{id}'"`.split("\n") @mdfind[key] = `/usr/bin/mdfind "kMDItemCFBundleIdentifier == '#{key}'"`.split("\n")
end end
end end
def pkgutil_info id def pkgutil_info id
(@pkginfo ||= {}).fetch(id.to_s) do (@pkginfo ||= {}).fetch(id.to_s) do |key|
@pkginfo[id.to_s] = `/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip @pkginfo[key] = `/usr/sbin/pkgutil --pkg-info "#{key}" 2>/dev/null`.strip
end end
end end
end end