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 gyp.common | 10 import gyp.common |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 if job.returncode != 0: | 229 if job.returncode != 0: |
230 sys.stderr.write(out + '\n') | 230 sys.stderr.write(out + '\n') |
231 raise GypError('Error %d running xcodebuild' % job.returncode) | 231 raise GypError('Error %d running xcodebuild' % job.returncode) |
232 return out.rstrip('\n') | 232 return out.rstrip('\n') |
233 | 233 |
234 def _SdkPath(self): | 234 def _SdkPath(self): |
235 sdk_root = self.GetPerTargetSetting('SDKROOT', default='macosx') | 235 sdk_root = self.GetPerTargetSetting('SDKROOT', default='macosx') |
236 if sdk_root.startswith('/'): | 236 if sdk_root.startswith('/'): |
237 return sdk_root | 237 return sdk_root |
238 if sdk_root not in XcodeSettings._sdk_path_cache: | 238 if sdk_root not in XcodeSettings._sdk_path_cache: |
239 XcodeSettings._sdk_path_cache[sdk_root] = self._GetSdkVersionInfoItem( | 239 try: |
240 sdk_root, 'Path') | 240 XcodeSettings._sdk_path_cache[sdk_root] = self._GetSdkVersionInfoItem( |
| 241 sdk_root, 'Path') |
| 242 except: |
| 243 # if this fails it's because xcodebuild failed, which means |
| 244 # the user is probably on a CLT-only system, where there |
| 245 # is no valid SDK root |
| 246 XcodeSettings._sdk_path_cache[sdk_root] = None |
241 return XcodeSettings._sdk_path_cache[sdk_root] | 247 return XcodeSettings._sdk_path_cache[sdk_root] |
242 | 248 |
243 def _AppendPlatformVersionMinFlags(self, lst): | 249 def _AppendPlatformVersionMinFlags(self, lst): |
244 self._Appendf(lst, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s') | 250 self._Appendf(lst, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s') |
245 if 'IPHONEOS_DEPLOYMENT_TARGET' in self._Settings(): | 251 if 'IPHONEOS_DEPLOYMENT_TARGET' in self._Settings(): |
246 # TODO: Implement this better? | 252 # TODO: Implement this better? |
247 sdk_path_basename = os.path.basename(self._SdkPath()) | 253 sdk_path_basename = os.path.basename(self._SdkPath()) |
248 if sdk_path_basename.lower().startswith('iphonesimulator'): | 254 if sdk_path_basename.lower().startswith('iphonesimulator'): |
249 self._Appendf(lst, 'IPHONEOS_DEPLOYMENT_TARGET', | 255 self._Appendf(lst, 'IPHONEOS_DEPLOYMENT_TARGET', |
250 '-mios-simulator-version-min=%s') | 256 '-mios-simulator-version-min=%s') |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', | 339 if self._Test('GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS', 'YES', |
334 default='NO'): | 340 default='NO'): |
335 cflags.append('-mssse3') # Note 3rd 's'. | 341 cflags.append('-mssse3') # Note 3rd 's'. |
336 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): | 342 if self._Test('GCC_ENABLE_SSE41_EXTENSIONS', 'YES', default='NO'): |
337 cflags.append('-msse4.1') | 343 cflags.append('-msse4.1') |
338 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): | 344 if self._Test('GCC_ENABLE_SSE42_EXTENSIONS', 'YES', default='NO'): |
339 cflags.append('-msse4.2') | 345 cflags.append('-msse4.2') |
340 | 346 |
341 cflags += self._Settings().get('WARNING_CFLAGS', []) | 347 cflags += self._Settings().get('WARNING_CFLAGS', []) |
342 | 348 |
343 config = self.spec['configurations'][self.configname] | 349 if sdk_root: |
344 framework_dirs = config.get('mac_framework_dirs', []) | 350 config = self.spec['configurations'][self.configname] |
345 for directory in framework_dirs: | 351 framework_dirs = config.get('mac_framework_dirs', []) |
346 cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) | 352 for directory in framework_dirs: |
| 353 cflags.append('-F' + directory.replace('$(SDKROOT)', sdk_root)) |
347 | 354 |
348 self.configname = None | 355 self.configname = None |
349 return cflags | 356 return cflags |
350 | 357 |
351 def GetCflagsC(self, configname): | 358 def GetCflagsC(self, configname): |
352 """Returns flags that need to be added to .c, and .m compilations.""" | 359 """Returns flags that need to be added to .c, and .m compilations.""" |
353 self.configname = configname | 360 self.configname = configname |
354 cflags_c = [] | 361 cflags_c = [] |
355 self._Appendf(cflags_c, 'GCC_C_LANGUAGE_STANDARD', '-std=%s') | 362 self._Appendf(cflags_c, 'GCC_C_LANGUAGE_STANDARD', '-std=%s') |
356 cflags_c += self._Settings().get('OTHER_CFLAGS', []) | 363 cflags_c += self._Settings().get('OTHER_CFLAGS', []) |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 # Xcode adds the product directory by default. | 573 # Xcode adds the product directory by default. |
567 ldflags.append('-L' + product_dir) | 574 ldflags.append('-L' + product_dir) |
568 | 575 |
569 install_name = self.GetInstallName() | 576 install_name = self.GetInstallName() |
570 if install_name: | 577 if install_name: |
571 ldflags.append('-install_name ' + install_name.replace(' ', r'\ ')) | 578 ldflags.append('-install_name ' + install_name.replace(' ', r'\ ')) |
572 | 579 |
573 for rpath in self._Settings().get('LD_RUNPATH_SEARCH_PATHS', []): | 580 for rpath in self._Settings().get('LD_RUNPATH_SEARCH_PATHS', []): |
574 ldflags.append('-Wl,-rpath,' + rpath) | 581 ldflags.append('-Wl,-rpath,' + rpath) |
575 | 582 |
576 config = self.spec['configurations'][self.configname] | 583 if self._SdkPath(): |
577 framework_dirs = config.get('mac_framework_dirs', []) | 584 config = self.spec['configurations'][self.configname] |
578 for directory in framework_dirs: | 585 framework_dirs = config.get('mac_framework_dirs', []) |
579 ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath())) | 586 for directory in framework_dirs: |
| 587 ldflags.append('-F' + directory.replace('$(SDKROOT)', self._SdkPath())) |
580 | 588 |
581 self.configname = None | 589 self.configname = None |
582 return ldflags | 590 return ldflags |
583 | 591 |
584 def GetLibtoolflags(self, configname): | 592 def GetLibtoolflags(self, configname): |
585 """Returns flags that need to be passed to the static linker. | 593 """Returns flags that need to be passed to the static linker. |
586 | 594 |
587 Args: | 595 Args: |
588 configname: The name of the configuration to get ld flags for. | 596 configname: The name of the configuration to get ld flags for. |
589 """ | 597 """ |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 702 |
695 def _AdjustLibrary(self, library): | 703 def _AdjustLibrary(self, library): |
696 if library.endswith('.framework'): | 704 if library.endswith('.framework'): |
697 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] | 705 l = '-framework ' + os.path.splitext(os.path.basename(library))[0] |
698 else: | 706 else: |
699 m = self.library_re.match(library) | 707 m = self.library_re.match(library) |
700 if m: | 708 if m: |
701 l = '-l' + m.group(1) | 709 l = '-l' + m.group(1) |
702 else: | 710 else: |
703 l = library | 711 l = library |
704 return l.replace('$(SDKROOT)', self._SdkPath()) | 712 if self._SdkPath(): |
| 713 return l.replace('$(SDKROOT)', self._SdkPath()) |
| 714 else: |
| 715 return l |
705 | 716 |
706 def AdjustLibraries(self, libraries): | 717 def AdjustLibraries(self, libraries): |
707 """Transforms entries like 'Cocoa.framework' in libraries into entries like | 718 """Transforms entries like 'Cocoa.framework' in libraries into entries like |
708 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. | 719 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. |
709 """ | 720 """ |
710 libraries = [ self._AdjustLibrary(library) for library in libraries] | 721 libraries = [ self._AdjustLibrary(library) for library in libraries] |
711 return libraries | 722 return libraries |
712 | 723 |
713 | 724 |
714 class MacPrefixHeader(object): | 725 class MacPrefixHeader(object): |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 def GetSpecPostbuildCommands(spec, quiet=False): | 1086 def GetSpecPostbuildCommands(spec, quiet=False): |
1076 """Returns the list of postbuilds explicitly defined on |spec|, in a form | 1087 """Returns the list of postbuilds explicitly defined on |spec|, in a form |
1077 executable by a shell.""" | 1088 executable by a shell.""" |
1078 postbuilds = [] | 1089 postbuilds = [] |
1079 for postbuild in spec.get('postbuilds', []): | 1090 for postbuild in spec.get('postbuilds', []): |
1080 if not quiet: | 1091 if not quiet: |
1081 postbuilds.append('echo POSTBUILD\\(%s\\) %s' % ( | 1092 postbuilds.append('echo POSTBUILD\\(%s\\) %s' % ( |
1082 spec['target_name'], postbuild['postbuild_name'])) | 1093 spec['target_name'], postbuild['postbuild_name'])) |
1083 postbuilds.append(gyp.common.EncodePOSIXShellList(postbuild['action'])) | 1094 postbuilds.append(gyp.common.EncodePOSIXShellList(postbuild['action'])) |
1084 return postbuilds | 1095 return postbuilds |
OLD | NEW |