Add mdfind method to MacOS module
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
60b518278b
commit
8f6ee31004
@ -1,4 +1,11 @@
|
|||||||
module MacOS extend self
|
module MacOS extend self
|
||||||
|
|
||||||
|
MDITEM_BUNDLE_ID_KEY = "kMDItemCFBundleIdentifier"
|
||||||
|
XCODE_4_BUNDLE_ID = "com.apple.dt.Xcode"
|
||||||
|
XCODE_3_BUNDLE_ID = "com.apple.Xcode"
|
||||||
|
CLT_STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo"
|
||||||
|
CLT_FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI"
|
||||||
|
|
||||||
def version
|
def version
|
||||||
MACOS_VERSION
|
MACOS_VERSION
|
||||||
end
|
end
|
||||||
@ -32,15 +39,14 @@ module MacOS extend self
|
|||||||
# Note, that different ways to install the CLTs lead to different
|
# Note, that different ways to install the CLTs lead to different
|
||||||
# version numbers.
|
# version numbers.
|
||||||
@clt_version ||= begin
|
@clt_version ||= begin
|
||||||
# CLT installed via stand-alone website download
|
standalone = pkgutil_info(CLT_STANDALONE_PKG_ID)
|
||||||
clt_pkginfo_stand_alone = `pkgutil --pkg-info com.apple.pkg.DeveloperToolsCLILeo 2>/dev/null`.strip
|
from_xcode = pkgutil_info(CLT_FROM_XCODE_PKG_ID)
|
||||||
# CLT installed via preferences from within Xcode
|
|
||||||
clt_pkginfo_from_xcode = `pkgutil --pkg-info com.apple.pkg.DeveloperToolsCLI 2>/dev/null`.strip
|
if not standalone.empty?
|
||||||
if not clt_pkginfo_stand_alone.empty?
|
standalone =~ /version: (.*)$/
|
||||||
clt_pkginfo_stand_alone =~ /version: (.*)$/
|
|
||||||
$1
|
$1
|
||||||
elsif not clt_pkginfo_from_xcode.empty?
|
elsif not from_xcode.empty?
|
||||||
clt_pkginfo_from_xcode =~ /version: (.*)$/
|
from_xcode =~ /version: (.*)$/
|
||||||
$1
|
$1
|
||||||
else
|
else
|
||||||
# We return "" instead of nil because we want clt_installed? to be true on older Macs.
|
# We return "" instead of nil because we want clt_installed? to be true on older Macs.
|
||||||
@ -191,16 +197,11 @@ module MacOS extend self
|
|||||||
# Ask Spotlight where Xcode is. If the user didn't install the
|
# Ask Spotlight where Xcode is. If the user didn't install the
|
||||||
# helper tools and installed Xcode in a non-conventional place, this
|
# helper tools and installed Xcode in a non-conventional place, this
|
||||||
# is our only option. See: http://superuser.com/questions/390757
|
# is our only option. See: http://superuser.com/questions/390757
|
||||||
path = `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"`.strip
|
path = app_with_bundle_id(XCODE_4_BUNDLE_ID) or app_with_bundle_id(XCODE_3_BUNDLE_ID)
|
||||||
if path.empty?
|
|
||||||
# Xcode 3 had a different identifier
|
unless path.nil?
|
||||||
path = `mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode'"`.strip
|
path += "Contents/Developer"
|
||||||
end
|
path if File.executable? "#{path}/usr/bin/make"
|
||||||
path = "#{path}/Contents/Developer"
|
|
||||||
if !path.empty? and File.executable? "#{path}/usr/bin/make"
|
|
||||||
Pathname.new path
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -208,24 +209,14 @@ module MacOS extend self
|
|||||||
|
|
||||||
def xcode_installed?
|
def xcode_installed?
|
||||||
# Telling us whether the Xcode.app is installed or not.
|
# Telling us whether the Xcode.app is installed or not.
|
||||||
@xcode_installed ||= begin
|
@xcode_installed ||= File.directory?('/Applications/Xcode.app') ||
|
||||||
if File.directory? '/Applications/Xcode.app'
|
File.directory?('/Developer/Applications/Xcode.app') ||
|
||||||
true
|
app_with_bundle_id(XCODE_4_BUNDLE_ID) ||
|
||||||
elsif File.directory? '/Developer/Applications/Xcode.app' # old style
|
app_with_bundle_id(XCODE_3_BUNDLE_ID) ||
|
||||||
true
|
false
|
||||||
elsif not `mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"`.strip.empty?
|
|
||||||
# Xcode 4
|
|
||||||
true
|
|
||||||
elsif not `mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode'"`.strip.empty?
|
|
||||||
# Xcode 3
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def xcode_version
|
def xcode_version
|
||||||
# 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.
|
||||||
@ -405,4 +396,19 @@ module MacOS extend self
|
|||||||
|
|
||||||
StandardCompilers[xcode].all? {|k,v| MacOS.send(k) == v}
|
StandardCompilers[xcode].all? {|k,v| MacOS.send(k) == v}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def app_with_bundle_id id
|
||||||
|
mdfind(MDITEM_BUNDLE_ID_KEY, id)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def mdfind attribute, id
|
||||||
|
path = `mdfind "#{attribute} == '#{id}'"`.strip
|
||||||
|
Pathname.new(path) unless path.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def pkgutil_info id
|
||||||
|
`pkgutil --pkg-info #{id} 2>/dev/null`.strip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user