Skip to content

Commit

Permalink
xcode_emulation: work in the absence of xcodebuild
Browse files Browse the repository at this point in the history
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 [email protected]!

This was a manual cherry-pick from:

  https://code.google.com/p/gyp/source/detail?r=1819

Fixes nodejs#341.
  • Loading branch information
TooTallNate committed Dec 18, 2013
1 parent 90dbe71 commit 5785bae
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ def _GetStdout(self, cmdlist):
return out.rstrip('\n')

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

def _SdkRoot(self, configname):
if configname is None:
Expand Down Expand Up @@ -397,10 +404,11 @@ def GetCflags(self, configname, arch=None):

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

config = self.spec['configurations'][self.configname]
framework_dirs = config.get('mac_framework_dirs', [])
for directory in framework_dirs:
cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root))
if 'SDKROOT' in self._Settings():
config = self.spec['configurations'][self.configname]
framework_dirs = config.get('mac_framework_dirs', [])
for directory in framework_dirs:
cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root))

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

config = self.spec['configurations'][self.configname]
framework_dirs = config.get('mac_framework_dirs', [])
for directory in framework_dirs:
ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath()))
if 'SDKROOT' in self._Settings():
config = self.spec['configurations'][self.configname]
framework_dirs = config.get('mac_framework_dirs', [])
for directory in framework_dirs:
ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath()))

self.configname = None
return ldflags
Expand Down Expand Up @@ -826,7 +835,10 @@ def _AdjustLibrary(self, library, config_name=None):
l = '-l' + m.group(1)
else:
l = library
return l.replace('$(SDKROOT)', self._SdkPath(config_name))
if self._SdkPath():
return l.replace('$(SDKROOT)', self._SdkPath(config_name))
else:
return l

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

0 comments on commit 5785bae

Please sign in to comment.