Skip to content

Commit 5785bae

Browse files
committed
xcode_emulation: work in the absence of xcodebuild
OS X systems running only the Command Line Tools for Xcode package, without the full Xcode, don't have a functioning xcodebuild, but this isn't mandatory for building many gyp projects (e.g. node.js, v8). This commit handles xcodebuild failures and avoids populating Xcode-specific CFLAGS/LDFLAGS when xcodebuild can't be run. This has been tested on both Xcode and CLT-only systems by successfully building node.js. The behaviour can be simulated on systems with Xcode by setting the xcode-select path to something nonsensical, e.g. xcode-select -switch /usr/bin BUG=https://code.google.com/p/gyp/issues/detail?id=292 Review URL: https://codereview.chromium.org/102733012/ Patch from mistydemeo@gmail.com! This was a manual cherry-pick from: https://code.google.com/p/gyp/source/detail?r=1819 Fixes #341.
1 parent 90dbe71 commit 5785bae

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

gyp/pylib/gyp/xcode_emulation.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ def _GetStdout(self, cmdlist):
273273
return out.rstrip('\n')
274274

275275
def _GetSdkVersionInfoItem(self, sdk, infoitem):
276-
return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem])
276+
# xcodebuild requires Xcode and can't run on Command Line Tools-only
277+
# systems from 10.7 onward.
278+
# Since the CLT has no SDK paths anyway, returning None is the
279+
# most sensible route and should still do the right thing.
280+
try:
281+
return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem])
282+
except:
283+
pass
277284

278285
def _SdkRoot(self, configname):
279286
if configname is None:
@@ -397,10 +404,11 @@ def GetCflags(self, configname, arch=None):
397404

398405
cflags += self._Settings().get('WARNING_CFLAGS', [])
399406

400-
config = self.spec['configurations'][self.configname]
401-
framework_dirs = config.get('mac_framework_dirs', [])
402-
for directory in framework_dirs:
403-
cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root))
407+
if 'SDKROOT' in self._Settings():
408+
config = self.spec['configurations'][self.configname]
409+
framework_dirs = config.get('mac_framework_dirs', [])
410+
for directory in framework_dirs:
411+
cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root))
404412

405413
self.configname = None
406414
return cflags
@@ -647,10 +655,11 @@ def GetLdflags(self, configname, product_dir, gyp_to_build_path, arch=None):
647655
for rpath in self._Settings().get('LD_RUNPATH_SEARCH_PATHS', []):
648656
ldflags.append('-Wl,-rpath,' + rpath)
649657

650-
config = self.spec['configurations'][self.configname]
651-
framework_dirs = config.get('mac_framework_dirs', [])
652-
for directory in framework_dirs:
653-
ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath()))
658+
if 'SDKROOT' in self._Settings():
659+
config = self.spec['configurations'][self.configname]
660+
framework_dirs = config.get('mac_framework_dirs', [])
661+
for directory in framework_dirs:
662+
ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath()))
654663

655664
self.configname = None
656665
return ldflags
@@ -826,7 +835,10 @@ def _AdjustLibrary(self, library, config_name=None):
826835
l = '-l' + m.group(1)
827836
else:
828837
l = library
829-
return l.replace('$(SDKROOT)', self._SdkPath(config_name))
838+
if self._SdkPath():
839+
return l.replace('$(SDKROOT)', self._SdkPath(config_name))
840+
else:
841+
return l
830842

831843
def AdjustLibraries(self, libraries, config_name=None):
832844
"""Transforms entries like 'Cocoa.framework' in libraries into entries like

0 commit comments

Comments
 (0)