Files
swift-mirror/utils/build_swift/migration.py
Ross Bayer 4edb8d9baa [build-script] Presets Module (#14422)
* Implemented a presets module which includes a more robust and easy to understand parser. Moved the swift-sdks migration code to a new migration module and added testing for both the presets and migration modules. Also converted build-script to use the new presets parser.

* Switched the expansion algorithm to resolve mixins in-place (little known feature) and also changed the parser to skip all non-preset sections. Tests are included for these two behaviors.

* Re-worked the presets error hierarchy to have more descriptive and information packed exception classes. Also re-worked the PresetParser to catch duplicate preset declarations and duplicate options in a single preset. There's some special shim-code to handle the disconnect between the Python 2 ConfigParser module and the Python 3 update which adds DuplicateOptionError.
2018-02-26 11:26:22 -08:00

85 lines
2.6 KiB
Python

# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
"""
Temporary module with functionaly used to migrate away from build-script-impl.
"""
from __future__ import absolute_import, unicode_literals
from swift_build_support.swift_build_support.targets import \
StdlibDeploymentTarget
__all__ = [
'UnknownSDKError',
'migrate_swift_sdks',
]
_SDK_TARGETS = {
'OSX': StdlibDeploymentTarget.OSX.targets,
'IOS': StdlibDeploymentTarget.iOS.targets,
'IOS_SIMULATOR': StdlibDeploymentTarget.iOSSimulator.targets,
'TVOS': StdlibDeploymentTarget.AppleTV.targets,
'TVOS_SIMULATOR': StdlibDeploymentTarget.AppleTVSimulator.targets,
'WATCHOS': StdlibDeploymentTarget.AppleWatch.targets,
'WATCHOS_SIMULATOR': StdlibDeploymentTarget.AppleWatchSimulator.targets,
}
# -----------------------------------------------------------------------------
class UnknownSDKError(Exception):
"""Error indicating an unknown SDK was encountered when migrating to target
triples.
"""
pass
def _swift_sdks_to_stdlib_targets(swift_sdks):
stdlib_targets = []
for sdk in swift_sdks:
sdk_targets = _SDK_TARGETS.get(sdk, None)
if sdk_targets is None:
raise UnknownSDKError(sdk)
stdlib_targets += sdk_targets
return stdlib_targets
def migrate_swift_sdks(args):
"""Migrate usages of the now deprecated `--swift-sdks` option to the new
`--stdlib-deployment-targets` option, converting Swift SDKs to the
corresponding targets. Since argument parsing is a last-wins scenario, only
the last `--swift-sdks` option is migrated, all others are removed.
This function is a stop-gap to replacing all instances of `--swift-sdks`.
"""
swift_sdks_args = [arg for arg in args if arg.startswith('--swift-sdks')]
if len(swift_sdks_args) < 1:
return args
# Only get the last --swift-sdks arg since last-wins
swift_sdks_arg = swift_sdks_args[-1]
sdk_list = swift_sdks_arg.split('=')[1].split(';')
stdlib_targets = _swift_sdks_to_stdlib_targets(sdk_list)
target_names = ' '.join([target.name for target in stdlib_targets])
stdlib_targets_arg = '--stdlib-deployment-targets=' + target_names
args = [arg for arg in args if not arg.startswith('--swift-sdks')]
args.append(stdlib_targets_arg)
return args