XcodeVersion() returns wrong result '0100' on Xcode 10.0

17 views
Skip to first unread message

Pyry Jahkola

unread,
Oct 18, 2018, 6:34:42 AM10/18/18
to gyp-developer
Hi,

I bumped into debugging GYP while upgrading dependencies for a project I'm working on.

As it turns out, the code for gyp.xcode_emulation.XcodeVersion doesn't really support the latest Xcode release 10.0 (Sep 2018). On my macOS, I get the following output in shell:

$ xcodebuild -version
Xcode 10.0
Build version 10A255
$ /usr/sbin/pkgutil --pkg-info com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 10.0.0.0.1.1535735448
...

The way XcodeVersion() has been documented, I'd expect it to return the pair ('1000', '10A255'), however I get:

$ cd pylib
$ python2.7
>>> 
import gyp.xcode_emulation, re
>>> gyp.xcode_emulation.XcodeVersion()
('0100', '10A255')

This must not be right because elsewhere in that module, the result is compared to at least the strings '0500' (Xcode 5.0) and '0900' (9.0) which 10.0 definitely should compare greater than! (I'll refrain from commenting the design of representing a version string in this format, so…)

Further, in the unhappy code path where xcodebuild -version fails, XcodeVersion() attempts to match the result of CLTVersion() with the three-component version pattern of r'(\d\.\d\.?\d*)'. That approach is obviously wrong too, because CLTVersion() returns a rather longer version string:

>>> version = gyp.xcode_emulation.CLTVersion()
>>> version
'10.0.0.0.1.1535735448'
>>> re.match(r'(\d\.\d\.?\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'

Not sure how to file a patch to the repo, so I suggest the following changes in the attached patch:
  1. Parse the result of CLTVersion() like this:
    version = re.search(r'^(\d{1,2}\.\d(\.\d+)?)', version).groups()[0]
  2. Compile the 4-digit version string such that it works for versions up to 99.9.9, as long as the minor and patch numbers are less than ten or missing:
    version = format(''.join((version.split()[-1].split('.') + ['0', '0'])[:3]),
                     '>04s')
I think these two changes should resolve this issue while maintaining backwards compatibility.
gyp-xcode-version-1000.patch

Refael Ackermann

unread,
Oct 18, 2018, 10:08:15 AM10/18/18
to gyp-developer
Hello Pyry,

Since it seems like Google has significantly reduced their investment in GYP, I'm coordinating maintenance efforts in https://github.com/refack/gyp (probably will move to https://github.com/nodejs/gyp).
It you have the time or open a PR, that would be much appreciated.

Pyry Jahkola

unread,
Oct 18, 2018, 10:10:44 AM10/18/18
to gyp-developer
Thanks Refael,

I would… but I get a 404 when visiting that repo!
Reply all
Reply to author
Forward
0 new messages