Prevent CLT.version being ""
Also cache the response if N/A as it is slow to keep repeating that. And only do one pkgutil call if possible.
This commit is contained in:
parent
0509406069
commit
dc68752d3d
@ -163,22 +163,15 @@ module MacOS::CLT extend self
|
|||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
|
# The pkgutils calls are slow, don't repeat if no CLT installed.
|
||||||
|
@version if @version_determined
|
||||||
|
|
||||||
|
@version_determined = true
|
||||||
# Version string (a pretty damn long one) of the CLT package.
|
# Version string (a pretty damn long one) of the CLT package.
|
||||||
# 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.
|
||||||
@version ||= begin
|
@version ||= [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id|
|
||||||
standalone = MacOS.pkgutil_info(STANDALONE_PKG_ID)
|
MacOS.pkgutil_info(id) =~ /version: (.+)$/
|
||||||
from_xcode = MacOS.pkgutil_info(FROM_XCODE_PKG_ID)
|
end && $1
|
||||||
|
|
||||||
if not standalone.empty?
|
|
||||||
standalone =~ /version: (.*)$/
|
|
||||||
$1
|
|
||||||
elsif not from_xcode.empty?
|
|
||||||
from_xcode =~ /version: (.*)$/
|
|
||||||
$1
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user