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 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 def _HasIOSTarget(targets): | 1422 def _HasIOSTarget(targets): |
1423 """Returns true if any target contains the iOS specific key | 1423 """Returns true if any target contains the iOS specific key |
1424 IPHONEOS_DEPLOYMENT_TARGET.""" | 1424 IPHONEOS_DEPLOYMENT_TARGET.""" |
1425 for target_dict in targets.values(): | 1425 for target_dict in targets.values(): |
1426 for config in target_dict['configurations'].values(): | 1426 for config in target_dict['configurations'].values(): |
1427 if config.get('xcode_settings', {}).get('IPHONEOS_DEPLOYMENT_TARGET'): | 1427 if config.get('xcode_settings', {}).get('IPHONEOS_DEPLOYMENT_TARGET'): |
1428 return True | 1428 return True |
1429 return False | 1429 return False |
1430 | 1430 |
1431 | 1431 |
| 1432 def _IOSIsDeviceSDKROOT(sdkroot): |
| 1433 """Tests if |sdkroot| is a SDK for building for device.""" |
| 1434 return 'iphoneos' in sdkroot.lower() |
| 1435 |
| 1436 |
| 1437 def _IOSDefaultArchForSDKRoot(sdkroot): |
| 1438 """Returns the expansion of standard ARCHS macro depending on the version |
| 1439 of Xcode installed and configured, and which |sdkroot| to use (iphoneos or |
| 1440 simulator).""" |
| 1441 xcode_version, xcode_build = XcodeVersion() |
| 1442 if xcode_version < '0500': |
| 1443 if _IOSIsDeviceSDKROOT(sdkroot): |
| 1444 return {'$(ARCHS_STANDARD)': ['armv7']} |
| 1445 else: |
| 1446 return {'$(ARCHS_STANDARD)': ['i386']} |
| 1447 else: |
| 1448 if _IOSIsDeviceSDKROOT(sdkroot): |
| 1449 return { |
| 1450 '$(ARCHS_STANDARD)': ['armv7', 'armv7s'], |
| 1451 '$(ARCHS_STANDARD_INCLUDING_64_BIT)': ['armv7', 'armv7s', 'arm64'], |
| 1452 } |
| 1453 else: |
| 1454 return { |
| 1455 '$(ARCHS_STANDARD)': ['i386'], |
| 1456 '$(ARCHS_STANDARD_INCLUDING_64_BIT)': ['i386', 'x86_64'], |
| 1457 } |
| 1458 |
| 1459 |
| 1460 def _FilterIOSArchitectureForSDKROOT(xcode_settings): |
| 1461 """Filter the ARCHS value from the |xcode_settings| dictionary to only |
| 1462 contains architectures valid for the sdk configured in SDKROOT value.""" |
| 1463 defaults_archs = _IOSDefaultArchForSDKRoot(xcode_settings.get('SDKROOT', '')) |
| 1464 allowed_archs = set() |
| 1465 for archs in defaults_archs.itervalues(): |
| 1466 allowed_archs.update(archs) |
| 1467 selected_archs = set() |
| 1468 for arch in (xcode_settings.get('ARCHS', []) or ['$(ARCHS_STANDARD)']): |
| 1469 if arch in defaults_archs: |
| 1470 selected_archs.update(defaults_archs[arch]) |
| 1471 elif arch in allowed_archs: |
| 1472 selected_archs.add(arch) |
| 1473 valid_archs = set(xcode_settings.get('VALID_ARCHS', [])) |
| 1474 if valid_archs: |
| 1475 selected_archs = selected_archs & valid_archs |
| 1476 xcode_settings['ARCHS'] = list(selected_archs) |
| 1477 |
| 1478 |
1432 def _AddIOSDeviceConfigurations(targets): | 1479 def _AddIOSDeviceConfigurations(targets): |
1433 """Clone all targets and append -iphoneos to the name. Configure these targets | 1480 """Clone all targets and append -iphoneos to the name. Configure these targets |
1434 to build for iOS devices.""" | 1481 to build for iOS devices and use correct architectures for those builds.""" |
1435 for target_dict in targets.values(): | 1482 for target_dict in targets.itervalues(): |
1436 for config_name in target_dict['configurations'].keys(): | 1483 toolset = target_dict['toolset'] |
1437 config = target_dict['configurations'][config_name] | 1484 configs = target_dict['configurations'] |
1438 new_config_name = config_name + '-iphoneos' | 1485 for config_name, config_dict in dict(configs).iteritems(): |
1439 new_config_dict = copy.deepcopy(config) | 1486 iphoneos_config_dict = copy.deepcopy(config_dict) |
1440 if target_dict['toolset'] == 'target': | 1487 configs[config_name + '-iphoneos'] = iphoneos_config_dict |
1441 new_config_dict['xcode_settings']['ARCHS'] = ['armv7'] | 1488 if toolset == 'target': |
1442 new_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' | 1489 iphoneos_config_dict['xcode_settings']['SDKROOT'] = 'iphoneos' |
1443 target_dict['configurations'][new_config_name] = new_config_dict | 1490 _FilterIOSArchitectureForSDKROOT(iphoneos_config_dict['xcode_settings']) |
| 1491 _FilterIOSArchitectureForSDKROOT(config_dict['xcode_settings']) |
1444 return targets | 1492 return targets |
1445 | 1493 |
1446 def CloneConfigurationForDeviceAndEmulator(target_dicts): | 1494 def CloneConfigurationForDeviceAndEmulator(target_dicts): |
1447 """If |target_dicts| contains any iOS targets, automatically create -iphoneos | 1495 """If |target_dicts| contains any iOS targets, automatically create -iphoneos |
1448 targets for iOS device builds.""" | 1496 targets for iOS device builds.""" |
1449 if _HasIOSTarget(target_dicts): | 1497 if _HasIOSTarget(target_dicts): |
1450 return _AddIOSDeviceConfigurations(target_dicts) | 1498 return _AddIOSDeviceConfigurations(target_dicts) |
1451 return target_dicts | 1499 return target_dicts |
OLD | NEW |