OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 This module contains classes that help to emulate xcodebuild behavior on top of | 6 This module contains classes that help to emulate xcodebuild behavior on top of |
7 other build systems, such as make and ninja. | 7 other build systems, such as make and ninja. |
8 """ | 8 """ |
9 | 9 |
10 import copy | 10 import copy |
(...skipping 262 matching lines...) Loading... |
273 | 273 |
274 def _GetStdout(self, cmdlist): | 274 def _GetStdout(self, cmdlist): |
275 job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) | 275 job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE) |
276 out = job.communicate()[0] | 276 out = job.communicate()[0] |
277 if job.returncode != 0: | 277 if job.returncode != 0: |
278 sys.stderr.write(out + '\n') | 278 sys.stderr.write(out + '\n') |
279 raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) | 279 raise GypError('Error %d running %s' % (job.returncode, cmdlist[0])) |
280 return out.rstrip('\n') | 280 return out.rstrip('\n') |
281 | 281 |
282 def _GetSdkVersionInfoItem(self, sdk, infoitem): | 282 def _GetSdkVersionInfoItem(self, sdk, infoitem): |
283 return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) | 283 # xcodebuild requires Xcode and can't run on Command Line Tools-only |
| 284 # systems from 10.7 onward. |
| 285 # Since the CLT has no SDK paths anyway, returning None is the |
| 286 # most sensible route and should still do the right thing. |
| 287 try: |
| 288 return self._GetStdout(['xcodebuild', '-version', '-sdk', sdk, infoitem]) |
| 289 except: |
| 290 pass |
284 | 291 |
285 def _SdkRoot(self, configname): | 292 def _SdkRoot(self, configname): |
286 if configname is None: | 293 if configname is None: |
287 configname = self.configname | 294 configname = self.configname |
288 return self.GetPerConfigSetting('SDKROOT', configname, default='') | 295 return self.GetPerConfigSetting('SDKROOT', configname, default='') |
289 | 296 |
290 def _SdkPath(self, configname=None): | 297 def _SdkPath(self, configname=None): |
291 sdk_root = self._SdkRoot(configname) | 298 sdk_root = self._SdkRoot(configname) |
292 if sdk_root.startswith('/'): | 299 if sdk_root.startswith('/'): |
293 return sdk_root | 300 return sdk_root |
(...skipping 108 matching lines...) Loading... |
402 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', | 409 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', |
403 default='NO'): | 410 default='NO'): |
404 cflags.append('-mssse3') # Note 3rd 's'. | 411 cflags.append('-mssse3') # Note 3rd 's'. |
405 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): | 412 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): |
406 cflags.append('-msse4.1') | 413 cflags.append('-msse4.1') |
407 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): | 414 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): |
408 cflags.append('-msse4.2') | 415 cflags.append('-msse4.2') |
409 | 416 |
410 cflags += self._Settings().get('WARNING_CFLAGS', []) | 417 cflags += self._Settings().get('WARNING_CFLAGS', []) |
411 | 418 |
412 config = self.spec['configurations'][self.configname] | 419 if 'SDKROOT' in self._Settings(): |
413 framework_dirs = config.get('mac_framework_dirs', []) | 420 config = self.spec['configurations'][self.configname] |
414 for directory in framework_dirs: | 421 framework_dirs = config.get('mac_framework_dirs', []) |
415 cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) | 422 for directory in framework_dirs: |
| 423 cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) |
416 | 424 |
417 self.configname = None | 425 self.configname = None |
418 return cflags | 426 return cflags |
419 | 427 |
420 def GetCflagsC(self, configname): | 428 def GetCflagsC(self, configname): |
421 """Returns flags that need to be added to .c, and .m compilations.""" | 429 """Returns flags that need to be added to .c, and .m compilations.""" |
422 self.configname = configname | 430 self.configname = configname |
423 cflags_c = [] | 431 cflags_c = [] |
424 if self._Settings().get('GCC_C_LANGUAGE_STANDARD', '') == 'ansi': | 432 if self._Settings().get('GCC_C_LANGUAGE_STANDARD', '') == 'ansi': |
425 cflags_c.append('-ansi') | 433 cflags_c.append('-ansi') |
(...skipping 226 matching lines...) Loading... |
652 # Xcode adds the product directory by default. | 660 # Xcode adds the product directory by default. |
653 ldflags.append('-L' + product_dir) | 661 ldflags.append('-L' + product_dir) |
654 | 662 |
655 install_name = self.GetInstallName() | 663 install_name = self.GetInstallName() |
656 if install_name and self.spec['type'] != 'loadable_module': | 664 if install_name and self.spec['type'] != 'loadable_module': |
657 ldflags.append('-install_name ' + install_name.replace(' ', r'\ ')) | 665 ldflags.append('-install_name ' + install_name.replace(' ', r'\ ')) |
658 | 666 |
659 for rpath in self._Settings().get('LD_RUNPATH_SEARCH_PATHS', []): | 667 for rpath in self._Settings().get('LD_RUNPATH_SEARCH_PATHS', []): |
660 ldflags.append('-Wl,-rpath,' + rpath) | 668 ldflags.append('-Wl,-rpath,' + rpath) |
661 | 669 |
662 config = self.spec['configurations'][self.configname] | 670 if 'SDKROOT' in self._Settings(): |
663 framework_dirs = config.get('mac_framework_dirs', []) | 671 config = self.spec['configurations'][self.configname] |
664 for directory in framework_dirs: | 672 framework_dirs = config.get('mac_framework_dirs', []) |
665 ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath())) | 673 for directory in framework_dirs: |
| 674 ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath())) |
666 | 675 |
667 self.configname = None | 676 self.configname = None |
668 return ldflags | 677 return ldflags |
669 | 678 |
670 def GetLibtoolflags(self, configname): | 679 def GetLibtoolflags(self, configname): |
671 """Returns flags that need to be passed to the static linker. | 680 """Returns flags that need to be passed to the static linker. |
672 | 681 |
673 Args: | 682 Args: |
674 configname: The name of the configuration to get ld flags for. | 683 configname: The name of the configuration to get ld flags for. |
675 """ | 684 """ |
(...skipping 160 matching lines...) Loading... |
836 | 845 |
837 def _AdjustLibrary(self, library, config_name=None): | 846 def _AdjustLibrary(self, library, config_name=None): |
838 if library.endswith('.framework'): | 847 if library.endswith('.framework'): |
839 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] | 848 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] |
840 else: | 849 else: |
841 m = self.library_re.match(library) | 850 m = self.library_re.match(library) |
842 if m: | 851 if m: |
843 l = '-l' + m.group(1) | 852 l = '-l' + m.group(1) |
844 else: | 853 else: |
845 l = library | 854 l = library |
846 return l.replace('$(SDKROOT)', self._SdkPath(config_name)) | 855 if self._SdkPath(): |
| 856 return l.replace('$(SDKROOT)', self._SdkPath(config_name)) |
| 857 else: |
| 858 return l |
847 | 859 |
848 def AdjustLibraries(self, libraries, config_name=None): | 860 def AdjustLibraries(self, libraries, config_name=None): |
849 """Transforms entries like 'Cocoa.framework' in libraries into entries like | 861 """Transforms entries like 'Cocoa.framework' in libraries into entries like |
850 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. | 862 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. |
851 """ | 863 """ |
852 libraries = [self._AdjustLibrary(library, config_name) | 864 libraries = [self._AdjustLibrary(library, config_name) |
853 for library in libraries] | 865 for library in libraries] |
854 return libraries | 866 return libraries |
855 | 867 |
856 def _BuildMachineOSBuild(self): | 868 def _BuildMachineOSBuild(self): |
(...skipping 512 matching lines...) Loading... |
1369 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' | 1381 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' |
1370 target_dict['configurations'][new_config_name] = new_config_dict | 1382 target_dict['configurations'][new_config_name] = new_config_dict |
1371 return targets | 1383 return targets |
1372 | 1384 |
1373 def CloneConfigurationForDeviceAndEmulator(target_dicts): | 1385 def CloneConfigurationForDeviceAndEmulator(target_dicts): |
1374 """If |target_dicts| contains any iOS targets, automatically create -iphoneos | 1386 """If |target_dicts| contains any iOS targets, automatically create -iphoneos |
1375 targets for iOS device builds.""" | 1387 targets for iOS device builds.""" |
1376 if _HasIOSTarget(target_dicts): | 1388 if _HasIOSTarget(target_dicts): |
1377 return _AddIOSDeviceConfigurations(target_dicts) | 1389 return _AddIOSDeviceConfigurations(target_dicts) |
1378 return target_dicts | 1390 return target_dicts |
OLD | NEW |