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!
# 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.
(@locate ||= {}).fetch(tool.to_s) do
@locate[tool.to_s] = if File.executable?(path = "/usr/bin/#{tool}")
(@locate ||= {}).fetch(tool.to_s) do |key|
@locate[key] = if File.executable?(path = "/usr/bin/#{tool}")
Pathname.new path
# 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
@ -76,7 +76,7 @@ module MacOS extend self
end
def sdk_path(v = version)
(@sdk_path ||= {}).fetch(v.to_s) do
(@sdk_path ||= {}).fetch(v.to_s) do |key|
opts = []
# First query Xcode itself
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"
# Xcode < 4.3 style
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
@ -250,14 +250,14 @@ module MacOS extend self
def mdfind id
return [] unless MACOS
(@mdfind ||= {}).fetch(id.to_s) do
@mdfind[id.to_s] = `/usr/bin/mdfind "kMDItemCFBundleIdentifier == '#{id}'"`.split("\n")
(@mdfind ||= {}).fetch(id.to_s) do |key|
@mdfind[key] = `/usr/bin/mdfind "kMDItemCFBundleIdentifier == '#{key}'"`.split("\n")
end
end
def pkgutil_info id
(@pkginfo ||= {}).fetch(id.to_s) do
@pkginfo[id.to_s] = `/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip
(@pkginfo ||= {}).fetch(id.to_s) do |key|
@pkginfo[key] = `/usr/sbin/pkgutil --pkg-info "#{key}" 2>/dev/null`.strip
end
end
end