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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 """Transforms entries like 'Cocoa.framework' in libraries into entries like | 869 """Transforms entries like 'Cocoa.framework' in libraries into entries like |
870 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. | 870 '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc. |
871 """ | 871 """ |
872 libraries = [self._AdjustLibrary(library, config_name) | 872 libraries = [self._AdjustLibrary(library, config_name) |
873 for library in libraries] | 873 for library in libraries] |
874 return libraries | 874 return libraries |
875 | 875 |
876 def _BuildMachineOSBuild(self): | 876 def _BuildMachineOSBuild(self): |
877 return self._GetStdout(['sw_vers', '-buildVersion']) | 877 return self._GetStdout(['sw_vers', '-buildVersion']) |
878 | 878 |
| 879 # This method ported from the logic in Homebrew's CLT version check |
| 880 def _CLTVersion(self): |
| 881 # pkgutil output looks like |
| 882 # package-id: com.apple.pkg.CLTools_Executables |
| 883 # version: 5.0.1.0.1.1382131676 |
| 884 # volume: / |
| 885 # location: / |
| 886 # install-time: 1382544035 |
| 887 # groups: com.apple.FindSystemFiles.pkg-group com.apple.DevToolsBoth.pkg-g
roup com.apple.DevToolsNonRelocatableShared.pkg-group |
| 888 STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo" |
| 889 FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI" |
| 890 MAVERICKS_PKG_ID = "com.apple.pkg.CLTools_Executables" |
| 891 |
| 892 regex = re.compile('version: (?P<version>.+)') |
| 893 for key in [MAVERICKS_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID]: |
| 894 try: |
| 895 output = self._GetStdout(['/usr/sbin/pkgutil', '--pkg-info', key]) |
| 896 return re.search(regex, output).groupdict()['version'] |
| 897 except: |
| 898 continue |
| 899 |
879 def _XcodeVersion(self): | 900 def _XcodeVersion(self): |
880 # `xcodebuild -version` output looks like | 901 # `xcodebuild -version` output looks like |
881 # Xcode 4.6.3 | 902 # Xcode 4.6.3 |
882 # Build version 4H1503 | 903 # Build version 4H1503 |
883 # or like | 904 # or like |
884 # Xcode 3.2.6 | 905 # Xcode 3.2.6 |
885 # Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 | 906 # Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0 |
886 # BuildVersion: 10M2518 | 907 # BuildVersion: 10M2518 |
887 # Convert that to '0463', '4H1503'. | 908 # Convert that to '0463', '4H1503'. |
888 if len(XcodeSettings._xcode_version_cache) == 0: | 909 if len(XcodeSettings._xcode_version_cache) == 0: |
889 version_list = self._GetStdout(['xcodebuild', '-version']).splitlines() | 910 try: |
| 911 version_list = self._GetStdout(['xcodebuild', '-version']).splitlines() |
| 912 # In some circumstances xcodebuild exits 0 but doesn't return |
| 913 # the right results; for example, a user on 10.7 or 10.8 with |
| 914 # a bogus path set via xcode-select |
| 915 # In that case this may be a CLT-only install so fall back to |
| 916 # checking that version. |
| 917 if len(version_list) < 2: |
| 918 raise GypError, "xcodebuild returned unexpected results" |
| 919 except: |
| 920 version = self._CLTVersion() |
| 921 if version: |
| 922 version = re.match('(\d\.\d\.?\d*)', version).groups()[0] |
| 923 else: |
| 924 raise GypError, "No Xcode or CLT version detected!" |
| 925 # The CLT has no build information, so we return an empty string. |
| 926 version_list = [version, ''] |
890 version = version_list[0] | 927 version = version_list[0] |
891 build = version_list[-1] | 928 build = version_list[-1] |
892 # Be careful to convert "4.2" to "0420": | 929 # Be careful to convert "4.2" to "0420": |
893 version = version.split()[-1].replace('.', '') | 930 version = version.split()[-1].replace('.', '') |
894 version = (version + '0' * (3 - len(version))).zfill(4) | 931 version = (version + '0' * (3 - len(version))).zfill(4) |
895 build = build.split()[-1] | 932 if build: |
| 933 build = build.split()[-1] |
896 XcodeSettings._xcode_version_cache = (version, build) | 934 XcodeSettings._xcode_version_cache = (version, build) |
897 return XcodeSettings._xcode_version_cache | 935 return XcodeSettings._xcode_version_cache |
898 | 936 |
899 def _XcodeIOSDeviceFamily(self, configname): | 937 def _XcodeIOSDeviceFamily(self, configname): |
900 family = self.xcode_settings[configname].get('TARGETED_DEVICE_FAMILY', '1') | 938 family = self.xcode_settings[configname].get('TARGETED_DEVICE_FAMILY', '1') |
901 return [int(x) for x in family.split(',')] | 939 return [int(x) for x in family.split(',')] |
902 | 940 |
903 def GetExtraPlistItems(self, configname=None): | 941 def GetExtraPlistItems(self, configname=None): |
904 """Returns a dictionary with extra items to insert into Info.plist.""" | 942 """Returns a dictionary with extra items to insert into Info.plist.""" |
905 if configname not in XcodeSettings._plist_cache: | 943 if configname not in XcodeSettings._plist_cache: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 Prior to version 5.0.0, if SDKROOT was not explicitly set in the Xcode | 981 Prior to version 5.0.0, if SDKROOT was not explicitly set in the Xcode |
944 project, then the environment variable was empty. Starting with this | 982 project, then the environment variable was empty. Starting with this |
945 version, Xcode uses the name of the newest SDK installed. | 983 version, Xcode uses the name of the newest SDK installed. |
946 """ | 984 """ |
947 if self._XcodeVersion() < '0500': | 985 if self._XcodeVersion() < '0500': |
948 return '' | 986 return '' |
949 default_sdk_path = self._XcodeSdkPath('') | 987 default_sdk_path = self._XcodeSdkPath('') |
950 default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path) | 988 default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path) |
951 if default_sdk_root: | 989 if default_sdk_root: |
952 return default_sdk_root | 990 return default_sdk_root |
953 all_sdks = self._GetStdout(['xcodebuild', '-showsdks']) | 991 try: |
| 992 all_sdks = self._GetStdout(['xcodebuild', '-showsdks']) |
| 993 except: |
| 994 # If xcodebuild fails, there will be no valid SDKs |
| 995 return '' |
954 for line in all_sdks.splitlines(): | 996 for line in all_sdks.splitlines(): |
955 items = line.split() | 997 items = line.split() |
956 if len(items) >= 3 and items[-2] == '-sdk': | 998 if len(items) >= 3 and items[-2] == '-sdk': |
957 sdk_root = items[-1] | 999 sdk_root = items[-1] |
958 sdk_path = self._XcodeSdkPath(sdk_root) | 1000 sdk_path = self._XcodeSdkPath(sdk_root) |
959 if sdk_path == default_sdk_path: | 1001 if sdk_path == default_sdk_path: |
960 return sdk_root | 1002 return sdk_root |
961 return '' | 1003 return '' |
962 | 1004 |
963 def _DefaultArch(self): | 1005 def _DefaultArch(self): |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' | 1431 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' |
1390 target_dict['configurations'][new_config_name] = new_config_dict | 1432 target_dict['configurations'][new_config_name] = new_config_dict |
1391 return targets | 1433 return targets |
1392 | 1434 |
1393 def CloneConfigurationForDeviceAndEmulator(target_dicts): | 1435 def CloneConfigurationForDeviceAndEmulator(target_dicts): |
1394 """If |target_dicts| contains any iOS targets, automatically create -iphoneos | 1436 """If |target_dicts| contains any iOS targets, automatically create -iphoneos |
1395 targets for iOS device builds.""" | 1437 targets for iOS device builds.""" |
1396 if _HasIOSTarget(target_dicts): | 1438 if _HasIOSTarget(target_dicts): |
1397 return _AddIOSDeviceConfigurations(target_dicts) | 1439 return _AddIOSDeviceConfigurations(target_dicts) |
1398 return target_dicts | 1440 return target_dicts |
OLD | NEW |