in Utilities/build-script-helper.py [0:0]
def main():
parser = argparse.ArgumentParser(description='Build along with the Swift build-script.')
def add_common_args(parser):
parser.add_argument('--package-path', metavar='PATH', help='directory of the package to build', default='.')
parser.add_argument('--toolchain', required=True, metavar='PATH', help='build using the toolchain at PATH')
parser.add_argument(
'--prefix',
dest='install_prefixes',
nargs='*',
help='paths (relative to the project root) where to install build products [%(default)s]',
metavar='PATHS')
parser.add_argument(
'--cross-compile-hosts',
dest='cross_compile_hosts',
nargs='*',
help='List of cross compile hosts targets.',
default=[])
parser.add_argument(
'--cross-compile-config',
metavar='PATH',
help="A JSON SPM config file with Swift flags for cross-compilation")
parser.add_argument('--ninja-bin', metavar='PATH', help='ninja binary to use for testing')
parser.add_argument('--cmake-bin', metavar='PATH', help='cmake binary to use for building')
parser.add_argument('--build-path', metavar='PATH', default='.build', help='build in the given path')
parser.add_argument('--foundation-build-dir', metavar='PATH', help='Path to the Foundation build directory')
parser.add_argument('--dispatch-build-dir', metavar='PATH', help='Path to the Dispatch build directory')
parser.add_argument('--lit-test-dir', metavar='PATH', help='the test dir in the Swift build directory')
parser.add_argument('--configuration', '-c', default='debug', help='build using configuration (release|debug)')
parser.add_argument('--no-local-deps', action='store_true', help='use normal remote dependencies when building')
parser.add_argument('--verbose', '-v', action='store_true', help='enable verbose output')
parser.add_argument('--local_compiler_build', action='store_true', help='driver is being built for use with a local compiler build')
subparsers = parser.add_subparsers(title='subcommands', dest='action', metavar='action')
clean_parser = subparsers.add_parser('clean', help='clean the package')
add_common_args(clean_parser)
build_parser = subparsers.add_parser('build', help='build the package')
add_common_args(build_parser)
test_parser = subparsers.add_parser('test', help='test the package')
add_common_args(test_parser)
install_parser = subparsers.add_parser('install', help='build the package')
add_common_args(install_parser)
args = parser.parse_args(sys.argv[1:])
# Canonicalize paths
args.package_path = os.path.abspath(args.package_path)
args.build_path = os.path.abspath(args.build_path)
args.toolchain = os.path.abspath(args.toolchain)
if platform.system() == 'Darwin':
args.sysroot = call_output(["xcrun", "--sdk", "macosx", "--show-sdk-path"], verbose=args.verbose)
else:
args.sysroot = None
swift_exec = os.path.join(os.path.join(args.toolchain, 'bin'), 'swiftc')
build_target = get_build_target(swift_exec, args)
if (build_target == 'x86_64-apple-macosx' and 'macosx-arm64' in args.cross_compile_hosts):
args.cross_compile_hosts = [build_target + macos_deployment_target, 'arm64-apple-macosx%s' % macos_deployment_target]
elif (build_target == 'arm64-apple-macosx' and 'macosx-x86_64' in args.cross_compile_hosts):
args.cross_compile_hosts = [build_target + macos_deployment_target, 'x86_64-apple-macosx%s' % macos_deployment_target]
elif args.cross_compile_hosts and re.match('android-', args.cross_compile_hosts[0]):
print('Cross-compiling for %s' % args.cross_compile_hosts[0])
elif args.cross_compile_hosts:
error("cannot cross-compile for %s" % cross_compile_hosts)
if args.cross_compile_hosts and args.local_compiler_build:
error('Cross-compilation is currently not supported for the local compiler installation')
if args.dispatch_build_dir:
args.dispatch_build_dir = os.path.abspath(args.dispatch_build_dir)
if args.foundation_build_dir:
args.foundation_build_dir = os.path.abspath(args.foundation_build_dir)
if args.lit_test_dir:
args.lit_test_dir = os.path.abspath(args.lit_test_dir)
# If a separate prefix has not been specified, installed into the specified toolchain
if not args.install_prefixes:
args.install_prefixes = [args.toolchain]
handle_invocation(args)