def create_argument_parser(): """Return a configured argument parser.""" # NOTE: USAGE, DESCRIPTION and EPILOG are defined at the bottom of the file parser = _ApplyDefaultsArgumentParser( apply_defaults=_apply_default_arguments, formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE, description=DESCRIPTION, epilog=EPILOG) builder = parser.to_builder() # Prepare DSL functions option = builder.add_option set_defaults = builder.set_defaults in_group = builder.in_group mutually_exclusive_group = builder.mutually_exclusive_group # Prepare DSL actions append = builder.actions.append store = builder.actions.store store_true = builder.actions.store_true store_false = builder.actions.store_false store_int = builder.actions.store_int store_path = builder.actions.store_path toggle_true = builder.actions.toggle_true toggle_false = builder.actions.toggle_false unsupported = builder.actions.unsupported # ------------------------------------------------------------------------- # Top-level options option(['-n', '--dry-run'], store_true, help='print the commands that would be executed, but do not ' 'execute them') option('--legacy-impl', store_true('legacy_impl'), help='use legacy implementation') option('--build-runtime-with-host-compiler', toggle_true, help='Use the host compiler, not the self-built one to compile the ' 'Swift runtime') option(['-i', '--ios'], store_true, help='also build for iOS, but disallow tests that require an iOS ' 'device') option(['-I', '--ios-all'], store_true('ios_all'), help='also build for iOS, and allow all iOS tests') option('--skip-ios', store_false('ios'), help='set to skip everything iOS-related') option('--tvos', toggle_true, help='also build for tvOS, but disallow tests that require a tvos ' 'device') option('--tvos-all', toggle_true('tvos_all'), help='also build for tvOS, and allow all tvOS tests') option('--skip-tvos', store_false('tvos'), help='set to skip everything tvOS-related') option('--watchos', toggle_true, help='also build for watchOS, but disallow tests that require an ' 'watchOS device') option('--watchos-all', toggle_true('watchos_all'), help='also build for Apple watchOS, and allow all Apple watchOS ' 'tests') option('--skip-watchos', store_false('watchos'), help='set to skip everything watchOS-related') option('--android', toggle_true, help='also build for Android') option('--swift-analyze-code-coverage', store, choices=['false', 'not-merged', 'merged'], # so CMake can see the inert mode as a false value default=defaults.SWIFT_ANALYZE_CODE_COVERAGE, help='enable code coverage analysis in Swift (false, not-merged, ' 'merged).') option('--build-subdir', store, metavar='PATH', help='name of the directory under $SWIFT_BUILD_ROOT where the ' 'build products will be placed') option('--install-prefix', store_path, default=targets.install_prefix(), help='The installation prefix. This is where built Swift products ' '(like bin, lib, and include) will be installed.') option('--install-symroot', store_path, help='the path to install debug symbols into') option('--install-destdir', store_path, help='the path to use as the filesystem root for the installation') option(['-j', '--jobs'], store_int('build_jobs'), default=multiprocessing.cpu_count(), help='the number of parallel build jobs to use') option('--darwin-xcrun-toolchain', store, help='the name of the toolchain to use on Darwin') option('--cmake', store_path(executable=True), help='the path to a CMake executable that will be used to build ' 'Swift') option('--show-sdks', toggle_true, help='print installed Xcode and SDK versions') option('--extra-swift-args', append, help='Pass through extra flags to swift in the form of a CMake ' 'list "module_regexp;flag". Can be called multiple times to ' 'add multiple such module_regexp flag pairs. All semicolons ' 'in flags must be escaped with a "\\"') option('--host-cc', store_path(executable=True), help='the absolute path to CC, the "clang" compiler for the host ' 'platform. Default is auto detected.') option('--host-cxx', store_path(executable=True), help='the absolute path to CXX, the "clang++" compiler for the ' 'host platform. Default is auto detected.') option('--cmake-c-launcher', store_path(executable=True), help='the absolute path to set CMAKE_C_COMPILER_LAUNCHER') option('--cmake-cxx-launcher', store_path(executable=True), help='the absolute path to set CMAKE_CXX_COMPILER_LAUNCHER') option('--host-lipo', store_path(executable=True), help='the absolute path to lipo. Default is auto detected.') option('--host-libtool', store_path(executable=True), help='the absolute path to libtool. Default is auto detected.') option('--distcc', toggle_true, help='use distcc in pump mode') option('--enable-asan', toggle_true, help='enable Address Sanitizer') option('--enable-ubsan', toggle_true, help='enable Undefined Behavior Sanitizer') option('--enable-tsan', toggle_true, help='enable Thread Sanitizer for swift tools') option('--enable-tsan-runtime', toggle_true, help='enable Thread Sanitizer on the swift runtime') option('--enable-lsan', toggle_true, help='enable Leak Sanitizer for swift tools') option('--enable-sanitize-coverage', toggle_true, help='enable sanitizer coverage for swift tools. Necessary for ' 'fuzzing swiftc') option('--compiler-vendor', store, choices=['none', 'apple'], default=defaults.COMPILER_VENDOR, help='Compiler vendor name') option('--clang-compiler-version', store, type=argparse.ClangVersionType(), metavar='MAJOR.MINOR.PATCH', help='string that indicates a compiler version for Clang') option('--clang-user-visible-version', store, type=argparse.ClangVersionType(), default=defaults.CLANG_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR.PATCH', help='User-visible version of the embedded Clang and LLVM ' 'compilers') option('--swift-compiler-version', store, type=argparse.SwiftVersionType(), metavar='MAJOR.MINOR', help='string that indicates a compiler version for Swift') option('--swift-user-visible-version', store, type=argparse.SwiftVersionType(), default=defaults.SWIFT_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR', help='User-visible version of the embedded Swift compiler') option('--darwin-deployment-version-osx', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_OSX, metavar='MAJOR.MINOR', help='minimum deployment target version for OS X') option('--darwin-deployment-version-ios', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_IOS, metavar='MAJOR.MINOR', help='minimum deployment target version for iOS') option('--darwin-deployment-version-tvos', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_TVOS, metavar='MAJOR.MINOR', help='minimum deployment target version for tvOS') option('--darwin-deployment-version-watchos', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS, metavar='MAJOR.MINOR', help='minimum deployment target version for watchOS') option('--extra-cmake-options', append, type=argparse.ShellSplitType(), help='Pass through extra options to CMake in the form of comma ' 'separated options "-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp". Can ' 'be called multiple times to add multiple such options.') option('--build-args', store, type=argparse.ShellSplitType(), default=[], help='arguments to the build tool. This would be prepended to the ' 'default argument that is "-j8" when CMake generator is ' '"Ninja".') option('--verbose-build', toggle_true, help='print the commands executed during the build') option('--lto', store('lto_type'), choices=['thin', 'full'], const='full', default=None, metavar='LTO_TYPE', help='use lto optimization on llvm/swift tools. This does not ' 'imply using lto on the swift standard library or runtime. ' 'Options: thin, full. If no optional arg is provided, full is ' 'chosen by default') option('--clang-profile-instr-use', store_path, help='profile file to use for clang PGO') default_max_lto_link_job_counts = host.max_lto_link_job_counts() option('--llvm-max-parallel-lto-link-jobs', store_int, default=default_max_lto_link_job_counts['llvm'], metavar='COUNT', help='the maximum number of parallel link jobs to use when ' 'compiling llvm') option('--swift-tools-max-parallel-lto-link-jobs', store_int, default=default_max_lto_link_job_counts['swift'], metavar='COUNT', help='the maximum number of parallel link jobs to use when ' 'compiling swift tools.') option('--disable-guaranteed-normal-arguments', store_true, help='Disable guaranteed normal arguments') option('--enable-stdlibcore-exclusivity-checking', store_true, help='Enable exclusivity checking in stdlibCore') option('--force-optimized-typechecker', store_true, help='Force the type checker to be built with ' 'optimization') option('--lit-args', store, default='-sv', metavar='LITARGS', help='lit args to use when testing') option('--coverage-db', store_path, help='coverage database to use when prioritizing testing') # ------------------------------------------------------------------------- in_group('Host and cross-compilation targets') option('--host-target', store, default=StdlibDeploymentTarget.host_target().name, help='The host target. LLVM, Clang, and Swift will be built for ' 'this target. The built LLVM and Clang will be used to ' 'compile Swift for the cross-compilation targets.') option('--cross-compile-hosts', append, type=argparse.ShellSplitType(), default=[], help='A space separated list of targets to cross-compile host ' 'Swift tools for. Can be used multiple times.') option('--stdlib-deployment-targets', append, type=argparse.ShellSplitType(), default=None, help='list of targets to compile or cross-compile the Swift ' 'standard library for. %(default)s by default.') option('--build-stdlib-deployment-targets', store, type=argparse.ShellSplitType(), default=['all'], help='A space-separated list that filters which of the configured ' 'targets to build the Swift standard library for, or "all".') # ------------------------------------------------------------------------- in_group('Options to select projects') option(['-l', '--lldb'], store_true('build_lldb'), help='build LLDB') option(['-b', '--llbuild'], store_true('build_llbuild'), help='build llbuild') option(['--libcxx'], store_true('build_libcxx'), help='build libcxx') option(['-p', '--swiftpm'], store_true('build_swiftpm'), help='build swiftpm') option(['--swiftsyntax'], store_true('build_swiftsyntax'), help='build swiftSyntax') option(['--skstresstester'], store_true('build_skstresstester'), help='build the SourceKit stress tester') option(['--swiftevolve'], store_true('build_swiftevolve'), help='build the swift-evolve tool') option(['--indexstore-db'], toggle_true('build_indexstoredb'), help='build IndexStoreDB') option(['--sourcekit-lsp'], toggle_true('build_sourcekitlsp'), help='build SourceKitLSP') option('--xctest', toggle_true('build_xctest'), help='build xctest') option('--foundation', toggle_true('build_foundation'), help='build foundation') option('--libdispatch', toggle_true('build_libdispatch'), help='build libdispatch') option('--libicu', toggle_true('build_libicu'), help='build libicu') option('--playgroundsupport', store_true('build_playgroundsupport'), help='build PlaygroundSupport') option('--build-ninja', toggle_true, help='build the Ninja tool') option(['--build-libparser-only'], store_true('build_libparser_only'), help='build only libParser for SwiftSyntax') # ------------------------------------------------------------------------- in_group('Extra actions to perform before or in addition to building') option(['-c', '--clean'], store_true, help='do a clean build') option('--export-compile-commands', toggle_true, help='generate compilation databases in addition to building') option('--symbols-package', store_path, help='if provided, an archive of the symbols directory will be ' 'generated at this path') # ------------------------------------------------------------------------- in_group('Build variant') with mutually_exclusive_group(): set_defaults(build_variant='Debug') option(['-d', '--debug'], store('build_variant'), const='Debug', help='build the Debug variant of everything (LLVM, Clang, ' 'Swift host tools, target Swift standard libraries, LLDB) ' '(default is %(default)s)') option(['-r', '--release-debuginfo'], store('build_variant'), const='RelWithDebInfo', help='build the RelWithDebInfo variant of everything (default ' 'is %(default)s)') option(['-R', '--release'], store('build_variant'), const='Release', help='build the Release variant of everything (default is ' '%(default)s)') # ------------------------------------------------------------------------- in_group('Override build variant for a specific project') option('--debug-llvm', store('llvm_build_variant'), const='Debug', help='build the Debug variant of LLVM') option('--debug-swift', store('swift_build_variant'), const='Debug', help='build the Debug variant of Swift host tools') option('--debug-swift-stdlib', store('swift_stdlib_build_variant'), const='Debug', help='build the Debug variant of the Swift standard library and ' ' SDK overlay') option('--debug-lldb', store('lldb_build_variant'), const='Debug', help='build the Debug variant of LLDB') option('--lldb-build-with-xcode', store('lldb_build_with_xcode'), const='1', help='build LLDB using xcodebuild, if possible') option('--lldb-build-with-cmake', store('lldb_build_with_xcode'), const='0', help='build LLDB using CMake') option('--debug-cmark', store('cmark_build_variant'), const='Debug', help='build the Debug variant of CommonMark') option('--debug-foundation', store('foundation_build_variant'), const='Debug', help='build the Debug variant of Foundation') option('--debug-libdispatch', store('libdispatch_build_variant'), const='Debug', help='build the Debug variant of libdispatch') option('--debug-libicu', store('libicu_build_variant'), const='Debug', help='build the Debug variant of libicu') # ------------------------------------------------------------------------- # Assertions group with mutually_exclusive_group(): set_defaults(assertions=True) # TODO: Convert to store_true option('--assertions', store, const=True, help='enable assertions in all projects') # TODO: Convert to store_false option('--no-assertions', store('assertions'), const=False, help='disable assertions in all projects') # ------------------------------------------------------------------------- in_group('Control assertions in a specific project') option('--cmark-assertions', store, const=True, help='enable assertions in CommonMark') option('--llvm-assertions', store, const=True, help='enable assertions in LLVM') option('--no-llvm-assertions', store('llvm_assertions'), const=False, help='disable assertions in LLVM') option('--swift-assertions', store, const=True, help='enable assertions in Swift') option('--no-swift-assertions', store('swift_assertions'), const=False, help='disable assertions in Swift') option('--swift-stdlib-assertions', store, const=True, help='enable assertions in the Swift standard library') option('--no-swift-stdlib-assertions', store('swift_stdlib_assertions'), const=False, help='disable assertions in the Swift standard library') option('--lldb-assertions', store, const=True, help='enable assertions in LLDB') option('--no-lldb-assertions', store('lldb_assertions'), const=False, help='disable assertions in LLDB') option('--llbuild-assertions', store, const=True, help='enable assertions in llbuild') option('--no-llbuild-assertions', store('llbuild_assertions'), const=False, help='disable assertions in llbuild') # ------------------------------------------------------------------------- in_group('Select the CMake generator') set_defaults(cmake_generator=defaults.CMAKE_GENERATOR) option(['-e', '--eclipse'], store('cmake_generator'), const='Eclipse CDT4 - Ninja', help="use CMake's Eclipse generator (%(default)s by default)") option(['-m', '--make'], store('cmake_generator'), const='Unix Makefiles', help="use CMake's Makefile generator (%(default)s by default)") option(['-x', '--xcode'], store('cmake_generator'), const='Xcode', help="use CMake's Xcode generator (%(default)s by default)") # ------------------------------------------------------------------------- in_group('Run tests') # NOTE: We can't merge -t and --test, because nargs='?' makes # `-ti` to be treated as `-t=i`. # FIXME: Convert to store_true action option('-t', store('test', const=True), help='test Swift after building') option('--test', toggle_true, help='test Swift after building') option('-T', store('validation_test', const=True), help='run the validation test suite (implies --test)') option('--validation-test', toggle_true, help='run the validation test suite (implies --test)') # FIXME: Convert to store_true action option('-o', store('test_optimized', const=True), help='run the test suite in optimized mode too (implies --test)') option('--test-optimized', toggle_true, help='run the test suite in optimized mode too (implies --test)') # FIXME: Convert to store_true action option('-s', store('test_optimize_for_size', const=True), help='run the test suite in optimize for size mode too ' '(implies --test)') option('--test-optimize-for-size', toggle_true, help='run the test suite in optimize for size mode too ' '(implies --test)') # FIXME: Convert to store_true action option('-y', store('test_optimize_none_implicit_dynamic', const=True), help='run the test suite in optimize none with implicit dynamic' ' mode too (implies --test)') option('--test-optimize-none-implicit-dynamic', toggle_true, help='run the test suite in optimize none with implicit dynamic' 'mode too (implies --test)') option('--long-test', toggle_true, help='run the long test suite') option('--stress-test', toggle_true, help='run the stress test suite') option('--host-test', toggle_true, help='run executable tests on host devices (such as iOS or tvOS)') option('--test-paths', append, type=argparse.ShellSplitType(), help='run tests located in specific directories and/or files ' '(implies --test and/or --validation-test)') option(['-B', '--benchmark'], store_true, help='run the Swift Benchmark Suite after building') option('--benchmark-num-o-iterations', store_int, default=3, help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -O') option('--benchmark-num-onone-iterations', store_int, default=3, help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -Onone') option('--skip-test-osx', toggle_false('test_osx'), help='skip testing Swift stdlibs for Mac OS X') option('--skip-test-linux', toggle_false('test_linux'), help='skip testing Swift stdlibs for Linux') option('--skip-test-freebsd', toggle_false('test_freebsd'), help='skip testing Swift stdlibs for FreeBSD') option('--skip-test-cygwin', toggle_false('test_cygwin'), help='skip testing Swift stdlibs for Cygwin') # ------------------------------------------------------------------------- in_group('Run build') option('--build-swift-dynamic-stdlib', toggle_true, default=True, help='build dynamic variants of the Swift standard library') option('--build-swift-static-stdlib', toggle_true, help='build static variants of the Swift standard library') option('--build-swift-dynamic-sdk-overlay', toggle_true, default=True, help='build dynamic variants of the Swift SDK overlay') option('--build-swift-static-sdk-overlay', toggle_true, help='build static variants of the Swift SDK overlay') option('--build-swift-stdlib-unittest-extra', toggle_true, help='Build optional StdlibUnittest components') option(['-S', '--skip-build'], store_true, help='generate build directory only without building') option('--skip-build-linux', toggle_false('build_linux'), help='skip building Swift stdlibs for Linux') option('--skip-build-freebsd', toggle_false('build_freebsd'), help='skip building Swift stdlibs for FreeBSD') option('--skip-build-cygwin', toggle_false('build_cygwin'), help='skip building Swift stdlibs for Cygwin') option('--skip-build-osx', toggle_false('build_osx'), help='skip building Swift stdlibs for MacOSX') option('--skip-build-ios', toggle_false('build_ios'), help='skip building Swift stdlibs for iOS') option('--skip-build-ios-device', toggle_false('build_ios_device'), help='skip building Swift stdlibs for iOS devices ' '(i.e. build simulators only)') option('--skip-build-ios-simulator', toggle_false('build_ios_simulator'), help='skip building Swift stdlibs for iOS simulator ' '(i.e. build devices only)') option('--skip-build-tvos', toggle_false('build_tvos'), help='skip building Swift stdlibs for tvOS') option('--skip-build-tvos-device', toggle_false('build_tvos_device'), help='skip building Swift stdlibs for tvOS devices ' '(i.e. build simulators only)') option('--skip-build-tvos-simulator', toggle_false('build_tvos_simulator'), help='skip building Swift stdlibs for tvOS simulator ' '(i.e. build devices only)') option('--skip-build-watchos', toggle_false('build_watchos'), help='skip building Swift stdlibs for watchOS') option('--skip-build-watchos-device', toggle_false('build_watchos_device'), help='skip building Swift stdlibs for watchOS devices ' '(i.e. build simulators only)') option('--skip-build-watchos-simulator', toggle_false('build_watchos_simulator'), help='skip building Swift stdlibs for watchOS simulator ' '(i.e. build devices only)') option('--skip-build-android', toggle_false('build_android'), help='skip building Swift stdlibs for Android') option('--skip-build-benchmarks', toggle_false('build_benchmarks'), help='skip building Swift Benchmark Suite') option('--build-external-benchmarks', toggle_true, help='skip building Swift Benchmark Suite') # ------------------------------------------------------------------------- in_group('Skip testing specified targets') option('--skip-test-ios', toggle_false('test_ios'), help='skip testing all iOS targets. Equivalent to specifying both ' '--skip-test-ios-simulator and --skip-test-ios-host') option('--skip-test-ios-simulator', toggle_false('test_ios_simulator'), help='skip testing iOS simulator targets') option('--skip-test-ios-32bit-simulator', toggle_false('test_ios_32bit_simulator'), help='skip testing iOS 32 bit simulator targets') option('--skip-test-ios-host', toggle_false('test_ios_host'), help='skip testing iOS device targets on the host machine (the ' 'phone itself)') option('--skip-test-tvos', toggle_false('test_tvos'), help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-tvos-simulator and --skip-test-tvos-host') option('--skip-test-tvos-simulator', toggle_false('test_tvos_simulator'), help='skip testing tvOS simulator targets') option('--skip-test-tvos-host', toggle_false('test_tvos_host'), help='skip testing tvOS device targets on the host machine (the ' 'TV itself)') option('--skip-test-watchos', toggle_false('test_watchos'), help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-watchos-simulator and --skip-test-watchos-host') option('--skip-test-watchos-simulator', toggle_false('test_watchos_simulator'), help='skip testing watchOS simulator targets') option('--skip-test-watchos-host', toggle_false('test_watchos_host'), help='skip testing watchOS device targets on the host machine (the ' 'watch itself)') option('--skip-test-android', toggle_false('test_android'), help='skip testing all Android targets.') option('--skip-test-android-host', toggle_false('test_android_host'), help='skip testing Android device targets on the host machine (the ' 'phone itself)') option('--skip-test-indexstore-db', toggle_false('test_indexstoredb'), help='skip testing indexstore-db') option('--skip-test-sourcekit-lsp', toggle_false('test_sourcekitlsp'), help='skip testing sourcekit-lsp') # ------------------------------------------------------------------------- in_group('Build settings specific for LLVM') option('--llvm-targets-to-build', store, default='X86;ARM;AArch64;PowerPC;SystemZ;Mips', help='LLVM target generators to build') # ------------------------------------------------------------------------- in_group('Build settings for Android') option('--android-ndk', store_path, help='An absolute path to the NDK that will be used as a libc ' 'implementation for Android builds') option('--android-api-level', store, default='21', help='The Android API level to target when building for Android. ' 'Currently only 21 or above is supported') option('--android-ndk-gcc-version', store, choices=['4.8', '4.9'], default='4.9', help='The GCC version to use when building for Android. Currently ' 'only 4.9 is supported. %(default)s is also the default ' 'value. This option may be used when experimenting with ' 'versions of the Android NDK not officially supported by ' 'Swift') option('--android-icu-uc', store_path, help='Path to libicuuc.so') option('--android-icu-uc-include', store_path, help='Path to a directory containing headers for libicuuc') option('--android-icu-i18n', store_path, help='Path to libicui18n.so') option('--android-icu-i18n-include', store_path, help='Path to a directory containing headers libicui18n') option('--android-icu-data', store_path, help='Path to libicudata.so') option('--android-deploy-device-path', store_path, default=android.adb.commands.DEVICE_TEMP_DIR, help='Path on an Android device to which built Swift stdlib ' 'products will be deployed. If running host tests, specify ' 'the "{}" directory.'.format( android.adb.commands.DEVICE_TEMP_DIR)) option('--android-arch', store, choices=['armv7', 'aarch64'], default='armv7', help='The Android target architecture when building for Android. ' 'Currently only armv7 and aarch64 are supported. ' '%(default)s is the default.') # ------------------------------------------------------------------------- in_group('Unsupported options') option('--build-jobs', unsupported) option('--common-cmake-options', unsupported) option('--only-execute', unsupported) option('--skip-test-optimize-for-size', unsupported) option('--skip-test-optimize-none-implicit-dynamic', unsupported) option('--skip-test-optimized', unsupported) # ------------------------------------------------------------------------- return builder.build()
def convert_to_impl_arguments(self): """convert_to_impl_arguments() -> (env, args) Convert the invocation to an environment and list of arguments suitable for invoking `build-script-impl`. """ # Create local shadows, for convenience. args = self.args toolchain = self.toolchain cmake = CMake(args=args, toolchain=self.toolchain) impl_args = [ "--workspace", self.workspace.source_root, "--build-dir", self.workspace.build_root, "--install-prefix", args.install_prefix, "--host-target", args.host_target, "--stdlib-deployment-targets={}".format(" ".join( args.stdlib_deployment_targets)), "--host-cc", toolchain.cc, "--host-cxx", toolchain.cxx, "--darwin-xcrun-toolchain", args.darwin_xcrun_toolchain, "--darwin-deployment-version-osx=%s" % (args.darwin_deployment_version_osx), "--darwin-deployment-version-ios=%s" % (args.darwin_deployment_version_ios), "--darwin-deployment-version-tvos=%s" % (args.darwin_deployment_version_tvos), "--darwin-deployment-version-watchos=%s" % (args.darwin_deployment_version_watchos), "--cmake", toolchain.cmake, "--cmark-build-type", args.cmark_build_variant, "--llvm-build-type", args.llvm_build_variant, "--swift-build-type", args.swift_build_variant, "--swift-stdlib-build-type", args.swift_stdlib_build_variant, "--lldb-build-type", args.lldb_build_variant, "--foundation-build-type", args.foundation_build_variant, "--libdispatch-build-type", args.libdispatch_build_variant, "--libicu-build-type", args.libicu_build_variant, "--xctest-build-type", args.build_variant, "--llbuild-build-type", args.build_variant, "--swift-enable-assertions", str(args.swift_assertions).lower(), "--swift-stdlib-enable-assertions", str(args.swift_stdlib_assertions).lower(), "--swift-analyze-code-coverage", str(args.swift_analyze_code_coverage).lower(), "--llbuild-enable-assertions", str(args.llbuild_assertions).lower(), "--lldb-assertions", str(args.lldb_assertions).lower(), "--cmake-generator", args.cmake_generator, "--build-jobs", str(args.build_jobs), "--common-cmake-options=%s" % ' '.join(pipes.quote(opt) for opt in cmake.common_options()), "--build-args=%s" % ' '.join(pipes.quote(arg) for arg in cmake.build_args()), "--dsymutil-jobs", str(args.dsymutil_jobs), ] # Compute any product specific cmake arguments. # # NOTE: The sum(list(...)) is b/c compute_product_pipelines returns a # tuple of lists of which the first is the build-script-impl products # and the second is the non-build-script-impl-products. It guarantees # that when we concatenate these two lists together we get a valid # dependency graph. for product_class in sum(list(self.compute_product_pipelines()[0]), []): if not product_class.is_build_script_impl_product(): continue product_name = product_class.product_name() product_source_name = product_class.product_source_name() source_dir = self.workspace.source_dir(product_source_name) if not os.path.exists(source_dir): fatal_error("can't find source directory for %s " "(tried %s)" % (product_name, source_dir)) product = product_class( args=args, toolchain=self.toolchain, source_dir=source_dir, # FIXME: This is incorrect since it always assumes the host # target I think? build_dir=self.workspace.build_dir(args.host_target, product_name)) cmake_opts = product.cmake_options # FIXME: We should be using pipes.quote here but we run into issues # with build-script-impl/cmake not being happy with all of the # extra "'" in the strings. To fix this easily, we really need to # just invoke cmake from build-script directly rather than futzing # with build-script-impl. This makes even more sense since there # really isn't a security issue here. if cmake_opts: impl_args += [ "--{}-cmake-options={}".format(product_name, ' '.join(cmake_opts)) ] if args.build_stdlib_deployment_targets: impl_args += [ "--build-stdlib-deployment-targets", " ".join(args.build_stdlib_deployment_targets) ] if args.cross_compile_hosts: impl_args += [ "--cross-compile-hosts", " ".join(args.cross_compile_hosts) ] if args.test_paths: impl_args += ["--test-paths", " ".join(args.test_paths)] if toolchain.ninja: impl_args += ["--ninja-bin=%s" % toolchain.ninja] if args.distcc: impl_args += [ "--distcc", "--distcc-pump=%s" % toolchain.distcc_pump ] if args.sccache: args.cmake_c_launcher = toolchain.sccache args.cmake_cxx_launcher = toolchain.sccache # *NOTE* We use normal cmake to pass through tsan/ubsan options. We do # NOT pass them to build-script-impl. if args.enable_asan: impl_args += ["--enable-asan"] # If we are on linux, disable leak detection when running ASAN. We # have a separate bot that checks for leaks. if platform.system() == 'Linux': os.environ['ASAN_OPTIONS'] = 'detect_leaks=0' if args.enable_ubsan: impl_args += ["--enable-ubsan"] # If we have lsan, we need to export our suppression list. The actual # passing in of the LSAN flag is done via the normal cmake method. We # do not pass the flag to build-script-impl. if args.enable_lsan: supp_file = os.path.join(SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME, "utils", "lsan_leaks_suppression_list.txt") os.environ['LSAN_OPTIONS'] = 'suppressions={}'.format(supp_file) if args.verbose_build: impl_args += ["--verbose-build"] if args.install_symroot: impl_args += [ "--install-symroot", os.path.abspath(args.install_symroot) ] if args.install_destdir: impl_args += [ "--install-destdir", os.path.abspath(args.install_destdir) ] if args.skip_build: impl_args += ["--skip-build"] if not args.build_benchmarks: impl_args += ["--skip-build-benchmarks"] if args.swift_disable_dead_stripping: args.extra_cmake_options.append( '-DSWIFT_DISABLE_DEAD_STRIPPING:BOOL=TRUE') if args.build_backdeployconcurrency: args.extra_cmake_options.append( '-DSWIFT_BACK_DEPLOY_CONCURRENCY:BOOL=TRUE') # Then add subproject install flags that either skip building them /or/ # if we are going to build them and install_all is set, we also install # them. conditional_subproject_configs = [ (args.build_cmark, "cmark"), (args.build_llvm, "llvm"), (args.build_swift, "swift"), (args.build_foundation, "foundation"), (args.build_xctest, "xctest"), (args.build_lldb, "lldb"), (args.build_llbuild, "llbuild"), (args.build_libcxx, "libcxx"), (args.build_libdispatch, "libdispatch"), (args.build_libicu, "libicu") ] for (should_build, string_name) in conditional_subproject_configs: if not should_build and not self.args.infer_dependencies: impl_args += ["--skip-build-{}".format(string_name)] elif self.install_all: impl_args += ["--install-{}".format(string_name)] if args.build_swift_dynamic_stdlib: impl_args += ["--build-swift-dynamic-stdlib"] if args.build_swift_static_stdlib: impl_args += ["--build-swift-static-stdlib"] if args.build_swift_stdlib_unittest_extra: impl_args += ["--build-swift-stdlib-unittest-extra"] if args.build_swift_dynamic_sdk_overlay: impl_args += ["--build-swift-dynamic-sdk-overlay"] if args.build_swift_static_sdk_overlay: impl_args += ["--build-swift-static-sdk-overlay"] if not args.build_android: impl_args += ["--skip-build-android"] if not args.build_clang_tools_extra: impl_args += ["--skip-build-clang-tools-extra"] if not args.test and not args.long_test and not args.stress_test: impl_args += ["--skip-test-swift"] if not args.test: impl_args += [ "--skip-test-cmark", "--skip-test-lldb", "--skip-test-llbuild", "--skip-test-xctest", "--skip-test-foundation", "--skip-test-libdispatch", "--skip-test-libicu", ] if args.build_runtime_with_host_compiler: impl_args += ["--build-runtime-with-host-compiler"] if args.validation_test: impl_args += ["--validation-test"] if args.long_test: impl_args += ["--long-test"] if args.stress_test: impl_args += ["--stress-test"] if args.skip_local_build: impl_args += ["--skip-local-build"] if args.only_executable_test: impl_args += ["--only-executable-test"] if not args.benchmark: impl_args += ["--skip-test-benchmarks"] if args.build_libparser_only: impl_args += ["--build-libparser-only"] if args.android: impl_args += [ "--android-arch", args.android_arch, "--android-ndk", args.android_ndk, "--android-api-level", args.android_api_level, "--android-ndk-gcc-version", args.android_ndk_gcc_version, "--android-icu-uc", args.android_icu_uc, "--android-icu-uc-include", args.android_icu_uc_include, "--android-icu-i18n", args.android_icu_i18n, "--android-icu-i18n-include", args.android_icu_i18n_include, "--android-icu-data", args.android_icu_data, ] # If building natively on an Android host, only pass the API level. if StdlibDeploymentTarget.Android.contains( StdlibDeploymentTarget.host_target().name): impl_args += ["--android-api-level", args.android_api_level] if args.android_deploy_device_path: impl_args += [ "--android-deploy-device-path", args.android_deploy_device_path, ] if platform.system() == 'Darwin': impl_args += [ "--toolchain-prefix", targets.darwin_toolchain_prefix(args.install_prefix), "--host-lipo", toolchain.lipo, ] # Isolate build from the system; Darwin toolchains build against SDKs. # For additional isolation, disable pkg-config. Homebrew's pkg-config # prioritizes CommandLineTools paths, resulting in compile errors. args.extra_cmake_options += [ '-DCMAKE_IGNORE_PATH=/usr/lib;/usr/local/lib;/lib', '-DPKG_CONFIG_EXECUTABLE=/usr/bin/false', ] if toolchain.libtool is not None: impl_args += [ "--host-libtool", toolchain.libtool, ] if args.native_clang_tools_path is not None: impl_args += [ "--native-clang-tools-path=%s" % args.native_clang_tools_path ] if args.native_llvm_tools_path is not None: impl_args += [ "--native-llvm-tools-path=%s" % args.native_llvm_tools_path ] if args.native_swift_tools_path is not None: impl_args += [ "--native-swift-tools-path=%s" % args.native_swift_tools_path ] # If we have extra_swift_args, combine all of them together and then # add them as one command. if args.extra_swift_args: impl_args += [ "--extra-swift-args=%s" % ';'.join(args.extra_swift_args) ] # Enable macCatalyst if args.maccatalyst: (args.extra_cmake_options.append( '-DSWIFT_ENABLE_MACCATALYST:BOOL=TRUE')) if args.maccatalyst_ios_tests: impl_args += ["--darwin-test-maccatalyst-ios-like=1"] # If we have extra_cmake_options, combine all of them together and then # add them as one command. if args.extra_cmake_options: impl_args += [ "--extra-cmake-options=%s" % ' '.join(pipes.quote(opt) for opt in args.extra_cmake_options) ] if args.lto_type is not None: impl_args += [ "--llvm-enable-lto=%s" % args.lto_type, "--swift-tools-enable-lto=%s" % args.lto_type ] if args.llvm_max_parallel_lto_link_jobs is not None: impl_args += [ "--llvm-num-parallel-lto-link-jobs=%s" % min(args.llvm_max_parallel_lto_link_jobs, args.build_jobs) ] if args.swift_tools_max_parallel_lto_link_jobs is not None: impl_args += [ "--swift-tools-num-parallel-lto-link-jobs=%s" % min(args.swift_tools_max_parallel_lto_link_jobs, args.build_jobs) ] if args.libswift_mode is not None: impl_args += [ "--libswift=%s" % args.libswift_mode, ] impl_args += args.build_script_impl_args if args.dry_run: impl_args += ["--dry-run"] if args.reconfigure: impl_args += ["--reconfigure"] if args.clang_profile_instr_use: impl_args += [ "--clang-profile-instr-use=%s" % os.path.abspath(args.clang_profile_instr_use) ] if args.lit_args: impl_args += ["--llvm-lit-args=%s" % args.lit_args] if args.coverage_db: impl_args += [ "--coverage-db=%s" % os.path.abspath(args.coverage_db) ] if args.llvm_install_components: impl_args += [ "--llvm-install-components=%s" % args.llvm_install_components ] if not args.clean_libdispatch: impl_args += ["--skip-clean-libdispatch"] if not args.clean_foundation: impl_args += ["--skip-clean-foundation"] if not args.clean_xctest: impl_args += ["--skip-clean-xctest"] if not args.clean_llbuild: impl_args += ["--skip-clean-llbuild"] if args.llvm_ninja_targets: impl_args += [ "--llvm-ninja-targets=%s" % ' '.join(args.llvm_ninja_targets) ] if args.llvm_ninja_targets_for_cross_compile_hosts: impl_args += [ "--llvm-ninja-targets-for-cross-compile-hosts=%s" % ' '.join(args.llvm_ninja_targets_for_cross_compile_hosts) ] if args.darwin_symroot_path_filters: impl_args += [ "--darwin_symroot_path_filters=%s" % ' '.join(args.darwin_symroot_path_filters) ] # Compute the set of host-specific variables, which we pass through to # the build script via environment variables. host_specific_variables = self.compute_host_specific_variables() impl_env = {} for (host_target, options) in host_specific_variables.items(): for (name, value) in options.items(): # We mangle into an environment variable we can easily evaluate # from the `build-script-impl`. impl_env["HOST_VARIABLE_{}__{}".format( host_target.replace("-", "_"), name)] = value return (impl_env, impl_args)
def create_argument_parser(): """Return a configured argument parser.""" # NOTE: USAGE, DESCRIPTION and EPILOG are defined at the bottom of the file parser = _ApplyDefaultsArgumentParser( apply_defaults=_apply_default_arguments, formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE, description=DESCRIPTION, epilog=EPILOG) builder = parser.to_builder() # Prepare DSL functions option = builder.add_option set_defaults = builder.set_defaults in_group = builder.in_group mutually_exclusive_group = builder.mutually_exclusive_group # Prepare DSL actions append = builder.actions.append store = builder.actions.store store_true = builder.actions.store_true store_false = builder.actions.store_false store_int = builder.actions.store_int store_path = builder.actions.store_path toggle_true = builder.actions.toggle_true toggle_false = builder.actions.toggle_false unsupported = builder.actions.unsupported # ------------------------------------------------------------------------- # Top-level options option(['-n', '--dry-run'], store_true, help='print the commands that would be executed, but do not ' 'execute them') option('--dump-config', toggle_true, help='instead of building, write JSON to stdout containing ' 'various values used to build in this configuration') option('--legacy-impl', store_true('legacy_impl'), help='use legacy implementation') option('--build-runtime-with-host-compiler', toggle_true, help='Use the host compiler, not the self-built one to compile the ' 'Swift runtime') option(['-i', '--ios'], store_true, help='also build for iOS, but disallow tests that require an iOS ' 'device') option(['-I', '--ios-all'], store_true('ios_all'), help='also build for iOS, and allow all iOS tests') option('--skip-ios', store_false('ios'), help='set to skip everything iOS-related') option('--tvos', toggle_true, help='also build for tvOS, but disallow tests that require a tvos ' 'device') option('--tvos-all', toggle_true('tvos_all'), help='also build for tvOS, and allow all tvOS tests') option('--skip-tvos', store_false('tvos'), help='set to skip everything tvOS-related') option('--watchos', toggle_true, help='also build for watchOS, but disallow tests that require an ' 'watchOS device') option('--watchos-all', toggle_true('watchos_all'), help='also build for Apple watchOS, and allow all Apple watchOS ' 'tests') option('--skip-watchos', store_false('watchos'), help='set to skip everything watchOS-related') option('--android', toggle_true, help='also build for Android') option( '--swift-analyze-code-coverage', store, choices=['false', 'not-merged', 'merged'], # so CMake can see the inert mode as a false value default=defaults.SWIFT_ANALYZE_CODE_COVERAGE, help='enable code coverage analysis in Swift (false, not-merged, ' 'merged).') option('--build-subdir', store, metavar='PATH', help='name of the directory under $SWIFT_BUILD_ROOT where the ' 'build products will be placed') option('--install-prefix', store_path, default=targets.install_prefix(), help='The installation prefix. This is where built Swift products ' '(like bin, lib, and include) will be installed.') option('--install-symroot', store_path, help='the path to install debug symbols into') option('--install-destdir', store_path, help='the path to use as the filesystem root for the installation') option(['-j', '--jobs'], store_int('build_jobs'), default=multiprocessing.cpu_count(), help='the number of parallel build jobs to use') option('--darwin-xcrun-toolchain', store, help='the name of the toolchain to use on Darwin') option('--cmake', store_path(executable=True), help='the path to a CMake executable that will be used to build ' 'Swift') option('--show-sdks', toggle_true, help='print installed Xcode and SDK versions') option('--extra-swift-args', append, help='Pass through extra flags to swift in the form of a CMake ' 'list "module_regexp;flag". Can be called multiple times to ' 'add multiple such module_regexp flag pairs. All semicolons ' 'in flags must be escaped with a "\\"') option('--host-cc', store_path(executable=True), help='the absolute path to CC, the "clang" compiler for the host ' 'platform. Default is auto detected.') option('--host-cxx', store_path(executable=True), help='the absolute path to CXX, the "clang++" compiler for the ' 'host platform. Default is auto detected.') option('--cmake-c-launcher', store_path(executable=True), help='the absolute path to set CMAKE_C_COMPILER_LAUNCHER') option('--cmake-cxx-launcher', store_path(executable=True), help='the absolute path to set CMAKE_CXX_COMPILER_LAUNCHER') option('--host-lipo', store_path(executable=True), help='the absolute path to lipo. Default is auto detected.') option('--host-libtool', store_path(executable=True), help='the absolute path to libtool. Default is auto detected.') option('--distcc', toggle_true, help='use distcc in pump mode') option('--enable-asan', toggle_true, help='enable Address Sanitizer') option('--enable-ubsan', toggle_true, help='enable Undefined Behavior Sanitizer') option('--enable-tsan', toggle_true, help='enable Thread Sanitizer for swift tools') option('--enable-tsan-runtime', toggle_true, help='enable Thread Sanitizer on the swift runtime') option('--enable-lsan', toggle_true, help='enable Leak Sanitizer for swift tools') option('--enable-sanitize-coverage', toggle_true, help='enable sanitizer coverage for swift tools. Necessary for ' 'fuzzing swiftc') option('--compiler-vendor', store, choices=['none', 'apple'], default=defaults.COMPILER_VENDOR, help='Compiler vendor name') option('--clang-compiler-version', store, type=argparse.ClangVersionType(), metavar='MAJOR.MINOR.PATCH', help='string that indicates a compiler version for Clang') option('--clang-user-visible-version', store, type=argparse.ClangVersionType(), default=defaults.CLANG_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR.PATCH', help='User-visible version of the embedded Clang and LLVM ' 'compilers') option('--swift-compiler-version', store, type=argparse.SwiftVersionType(), metavar='MAJOR.MINOR', help='string that indicates a compiler version for Swift') option('--swift-user-visible-version', store, type=argparse.SwiftVersionType(), default=defaults.SWIFT_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR', help='User-visible version of the embedded Swift compiler') option('--darwin-deployment-version-osx', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_OSX, metavar='MAJOR.MINOR', help='minimum deployment target version for OS X') option('--darwin-deployment-version-ios', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_IOS, metavar='MAJOR.MINOR', help='minimum deployment target version for iOS') option('--darwin-deployment-version-tvos', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_TVOS, metavar='MAJOR.MINOR', help='minimum deployment target version for tvOS') option('--darwin-deployment-version-watchos', store, default=defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS, metavar='MAJOR.MINOR', help='minimum deployment target version for watchOS') option('--extra-cmake-options', append, type=argparse.ShellSplitType(), help='Pass through extra options to CMake in the form of comma ' 'separated options "-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp". Can ' 'be called multiple times to add multiple such options.') option('--build-args', store, type=argparse.ShellSplitType(), default=[], help='arguments to the build tool. This would be prepended to the ' 'default argument that is "-j8" when CMake generator is ' '"Ninja".') option('--verbose-build', toggle_true, help='print the commands executed during the build') option('--lto', store('lto_type'), choices=['thin', 'full'], const='full', default=None, metavar='LTO_TYPE', help='use lto optimization on llvm/swift tools. This does not ' 'imply using lto on the swift standard library or runtime. ' 'Options: thin, full. If no optional arg is provided, full is ' 'chosen by default') option('--clang-profile-instr-use', store_path, help='profile file to use for clang PGO') default_max_lto_link_job_counts = host.max_lto_link_job_counts() option('--llvm-max-parallel-lto-link-jobs', store_int, default=default_max_lto_link_job_counts['llvm'], metavar='COUNT', help='the maximum number of parallel link jobs to use when ' 'compiling llvm') option('--swift-tools-max-parallel-lto-link-jobs', store_int, default=default_max_lto_link_job_counts['swift'], metavar='COUNT', help='the maximum number of parallel link jobs to use when ' 'compiling swift tools.') option('--disable-guaranteed-normal-arguments', store_true, help='Disable guaranteed normal arguments') option('--enable-stdlibcore-exclusivity-checking', store_true, help='Enable exclusivity checking in stdlibCore') option('--force-optimized-typechecker', store_true, help='Force the type checker to be built with ' 'optimization') option('--lit-args', store, default='-sv', metavar='LITARGS', help='lit args to use when testing') option('--coverage-db', store_path, help='coverage database to use when prioritizing testing') # ------------------------------------------------------------------------- in_group('Host and cross-compilation targets') option('--host-target', store, default=StdlibDeploymentTarget.host_target().name, help='The host target. LLVM, Clang, and Swift will be built for ' 'this target. The built LLVM and Clang will be used to ' 'compile Swift for the cross-compilation targets.') option('--cross-compile-hosts', append, type=argparse.ShellSplitType(), default=[], help='A space separated list of targets to cross-compile host ' 'Swift tools for. Can be used multiple times.') option('--stdlib-deployment-targets', append, type=argparse.ShellSplitType(), default=None, help='list of targets to compile or cross-compile the Swift ' 'standard library for. %(default)s by default.') option('--build-stdlib-deployment-targets', store, type=argparse.ShellSplitType(), default=['all'], help='A space-separated list that filters which of the configured ' 'targets to build the Swift standard library for, or "all".') # ------------------------------------------------------------------------- in_group('Options to select projects') option(['-l', '--lldb'], store_true('build_lldb'), help='build LLDB') option(['-b', '--llbuild'], store_true('build_llbuild'), help='build llbuild') option(['--libcxx'], store_true('build_libcxx'), help='build libcxx') option(['-p', '--swiftpm'], store_true('build_swiftpm'), help='build swiftpm') option(['--swiftsyntax'], store_true('build_swiftsyntax'), help='build swiftSyntax') option(['--skstresstester'], store_true('build_skstresstester'), help='build the SourceKit stress tester') option(['--swiftevolve'], store_true('build_swiftevolve'), help='build the swift-evolve tool') option(['--indexstore-db'], toggle_true('build_indexstoredb'), help='build IndexStoreDB') option(['--sourcekit-lsp'], toggle_true('build_sourcekitlsp'), help='build SourceKitLSP') option(['--toolchain-benchmarks'], toggle_true('build_toolchainbenchmarks'), help='build Swift Benchmarks using swiftpm against the just built ' 'toolchain') option('--xctest', toggle_true('build_xctest'), help='build xctest') option('--foundation', toggle_true('build_foundation'), help='build foundation') option('--libdispatch', toggle_true('build_libdispatch'), help='build libdispatch') option('--libicu', toggle_true('build_libicu'), help='build libicu') option('--playgroundsupport', store_true('build_playgroundsupport'), help='build PlaygroundSupport') option('--build-ninja', toggle_true, help='build the Ninja tool') option(['--build-libparser-only'], store_true('build_libparser_only'), help='build only libParser for SwiftSyntax') # ------------------------------------------------------------------------- in_group('Extra actions to perform before or in addition to building') option(['-c', '--clean'], store_true, help='do a clean build') option('--export-compile-commands', toggle_true, help='generate compilation databases in addition to building') option('--symbols-package', store_path, help='if provided, an archive of the symbols directory will be ' 'generated at this path') # ------------------------------------------------------------------------- in_group('Build variant') with mutually_exclusive_group(): set_defaults(build_variant='Debug') option(['-d', '--debug'], store('build_variant'), const='Debug', help='build the Debug variant of everything (LLVM, Clang, ' 'Swift host tools, target Swift standard libraries, LLDB) ' '(default is %(default)s)') option(['-r', '--release-debuginfo'], store('build_variant'), const='RelWithDebInfo', help='build the RelWithDebInfo variant of everything (default ' 'is %(default)s)') option(['-R', '--release'], store('build_variant'), const='Release', help='build the Release variant of everything (default is ' '%(default)s)') # ------------------------------------------------------------------------- in_group('Override build variant for a specific project') option('--debug-llvm', store('llvm_build_variant'), const='Debug', help='build the Debug variant of LLVM') option('--debug-swift', store('swift_build_variant'), const='Debug', help='build the Debug variant of Swift host tools') option('--debug-swift-stdlib', store('swift_stdlib_build_variant'), const='Debug', help='build the Debug variant of the Swift standard library and ' ' SDK overlay') option('--debug-lldb', store('lldb_build_variant'), const='Debug', help='build the Debug variant of LLDB') option('--lldb-build-with-xcode', store('lldb_build_with_xcode'), const='1', help='build LLDB using xcodebuild, if possible') option('--lldb-build-with-cmake', store('lldb_build_with_xcode'), const='0', help='build LLDB using CMake') option('--debug-cmark', store('cmark_build_variant'), const='Debug', help='build the Debug variant of CommonMark') option('--debug-foundation', store('foundation_build_variant'), const='Debug', help='build the Debug variant of Foundation') option('--debug-libdispatch', store('libdispatch_build_variant'), const='Debug', help='build the Debug variant of libdispatch') option('--debug-libicu', store('libicu_build_variant'), const='Debug', help='build the Debug variant of libicu') # ------------------------------------------------------------------------- # Assertions group with mutually_exclusive_group(): set_defaults(assertions=True) # TODO: Convert to store_true option(['-a', '--assertions'], store, const=True, help='enable assertions in all projects') # TODO: Convert to store_false option(['-A', '--no-assertions'], store('assertions'), const=False, help='disable assertions in all projects') # ------------------------------------------------------------------------- in_group('Control assertions in a specific project') option('--cmark-assertions', store, const=True, help='enable assertions in CommonMark') option('--llvm-assertions', store, const=True, help='enable assertions in LLVM') option('--no-llvm-assertions', store('llvm_assertions'), const=False, help='disable assertions in LLVM') option('--swift-assertions', store, const=True, help='enable assertions in Swift') option('--no-swift-assertions', store('swift_assertions'), const=False, help='disable assertions in Swift') option('--swift-stdlib-assertions', store, const=True, help='enable assertions in the Swift standard library') option('--no-swift-stdlib-assertions', store('swift_stdlib_assertions'), const=False, help='disable assertions in the Swift standard library') option('--lldb-assertions', store, const=True, help='enable assertions in LLDB') option('--no-lldb-assertions', store('lldb_assertions'), const=False, help='disable assertions in LLDB') option('--llbuild-assertions', store, const=True, help='enable assertions in llbuild') option('--no-llbuild-assertions', store('llbuild_assertions'), const=False, help='disable assertions in llbuild') # ------------------------------------------------------------------------- in_group('Select the CMake generator') set_defaults(cmake_generator=defaults.CMAKE_GENERATOR) option(['-e', '--eclipse'], store('cmake_generator'), const='Eclipse CDT4 - Ninja', help="use CMake's Eclipse generator (%(default)s by default)") option(['-m', '--make'], store('cmake_generator'), const='Unix Makefiles', help="use CMake's Makefile generator (%(default)s by default)") option(['-x', '--xcode'], store('cmake_generator'), const='Xcode', help="use CMake's Xcode generator (%(default)s by default)") # ------------------------------------------------------------------------- in_group('Run tests') # NOTE: We can't merge -t and --test, because nargs='?' makes # `-ti` to be treated as `-t=i`. # FIXME: Convert to store_true action option('-t', store('test', const=True), help='test Swift after building') option('--test', toggle_true, help='test Swift after building') option('-T', store('validation_test', const=True), help='run the validation test suite (implies --test)') option('--validation-test', toggle_true, help='run the validation test suite (implies --test)') # FIXME: Convert to store_true action option('-o', store('test_optimized', const=True), help='run the test suite in optimized mode too (implies --test)') option('--test-optimized', toggle_true, help='run the test suite in optimized mode too (implies --test)') # FIXME: Convert to store_true action option('-s', store('test_optimize_for_size', const=True), help='run the test suite in optimize for size mode too ' '(implies --test)') option('--test-optimize-for-size', toggle_true, help='run the test suite in optimize for size mode too ' '(implies --test)') # FIXME: Convert to store_true action option('-y', store('test_optimize_none_implicit_dynamic', const=True), help='run the test suite in optimize none with implicit dynamic' ' mode too (implies --test)') option('--test-optimize-none-implicit-dynamic', toggle_true, help='run the test suite in optimize none with implicit dynamic' 'mode too (implies --test)') option('--long-test', toggle_true, help='run the long test suite') option('--stress-test', toggle_true, help='run the stress test suite') option('--host-test', toggle_true, help='run executable tests on host devices (such as iOS or tvOS)') option('--only-executable-test', toggle_true, help='Only run executable tests. Does nothing if host-test is not ' 'allowed') option('--test-paths', append, type=argparse.ShellSplitType(), help='run tests located in specific directories and/or files ' '(implies --test and/or --validation-test)') option(['-B', '--benchmark'], store_true, help='run the Swift Benchmark Suite after building') option('--benchmark-num-o-iterations', store_int, default=3, help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -O') option('--benchmark-num-onone-iterations', store_int, default=3, help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -Onone') # We want to run the TSan (compiler-rt) libdispatch tests on Linux, where # libdispatch is just another library and not available by default. To do # so we build Clang/LLVM/libdispatch and use it to compile/run the TSan # libdispatch tests. option('--tsan-libdispatch-test', toggle_true, help='Builds a new toolchain including the libdispatch C library. ' 'Then re-builds the TSan runtime (compiler-rt) using this ' 'freshly-built Clang and runs the TSan libdispatch tests.') option('--skip-test-osx', toggle_false('test_osx'), help='skip testing Swift stdlibs for Mac OS X') option('--skip-test-linux', toggle_false('test_linux'), help='skip testing Swift stdlibs for Linux') option('--skip-test-freebsd', toggle_false('test_freebsd'), help='skip testing Swift stdlibs for FreeBSD') option('--skip-test-cygwin', toggle_false('test_cygwin'), help='skip testing Swift stdlibs for Cygwin') # ------------------------------------------------------------------------- in_group('Run build') option('--build-swift-dynamic-stdlib', toggle_true, default=True, help='build dynamic variants of the Swift standard library') option('--build-swift-static-stdlib', toggle_true, help='build static variants of the Swift standard library') option('--build-swift-dynamic-sdk-overlay', toggle_true, default=True, help='build dynamic variants of the Swift SDK overlay') option('--build-swift-static-sdk-overlay', toggle_true, help='build static variants of the Swift SDK overlay') option('--build-swift-stdlib-unittest-extra', toggle_true, help='Build optional StdlibUnittest components') option(['-S', '--skip-build'], store_true, help='generate build directory only without building') option('--skip-build-linux', toggle_false('build_linux'), help='skip building Swift stdlibs for Linux') option('--skip-build-freebsd', toggle_false('build_freebsd'), help='skip building Swift stdlibs for FreeBSD') option('--skip-build-cygwin', toggle_false('build_cygwin'), help='skip building Swift stdlibs for Cygwin') option('--skip-build-osx', toggle_false('build_osx'), help='skip building Swift stdlibs for MacOSX') option('--skip-build-ios', toggle_false('build_ios'), help='skip building Swift stdlibs for iOS') option('--skip-build-ios-device', toggle_false('build_ios_device'), help='skip building Swift stdlibs for iOS devices ' '(i.e. build simulators only)') option('--skip-build-ios-simulator', toggle_false('build_ios_simulator'), help='skip building Swift stdlibs for iOS simulator ' '(i.e. build devices only)') option('--skip-build-tvos', toggle_false('build_tvos'), help='skip building Swift stdlibs for tvOS') option('--skip-build-tvos-device', toggle_false('build_tvos_device'), help='skip building Swift stdlibs for tvOS devices ' '(i.e. build simulators only)') option('--skip-build-tvos-simulator', toggle_false('build_tvos_simulator'), help='skip building Swift stdlibs for tvOS simulator ' '(i.e. build devices only)') option('--skip-build-watchos', toggle_false('build_watchos'), help='skip building Swift stdlibs for watchOS') option('--skip-build-watchos-device', toggle_false('build_watchos_device'), help='skip building Swift stdlibs for watchOS devices ' '(i.e. build simulators only)') option('--skip-build-watchos-simulator', toggle_false('build_watchos_simulator'), help='skip building Swift stdlibs for watchOS simulator ' '(i.e. build devices only)') option('--skip-build-android', toggle_false('build_android'), help='skip building Swift stdlibs for Android') option('--skip-build-benchmarks', toggle_false('build_benchmarks'), help='skip building Swift Benchmark Suite') option('--build-external-benchmarks', toggle_true, help='skip building Swift Benchmark Suite') # ------------------------------------------------------------------------- in_group('Skip testing specified targets') option('--skip-test-ios', toggle_false('test_ios'), help='skip testing all iOS targets. Equivalent to specifying both ' '--skip-test-ios-simulator and --skip-test-ios-host') option('--skip-test-ios-simulator', toggle_false('test_ios_simulator'), help='skip testing iOS simulator targets') option('--skip-test-ios-32bit-simulator', toggle_false('test_ios_32bit_simulator'), help='skip testing iOS 32 bit simulator targets') option('--skip-test-ios-host', toggle_false('test_ios_host'), help='skip testing iOS device targets on the host machine (the ' 'phone itself)') option('--skip-test-tvos', toggle_false('test_tvos'), help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-tvos-simulator and --skip-test-tvos-host') option('--skip-test-tvos-simulator', toggle_false('test_tvos_simulator'), help='skip testing tvOS simulator targets') option('--skip-test-tvos-host', toggle_false('test_tvos_host'), help='skip testing tvOS device targets on the host machine (the ' 'TV itself)') option('--skip-test-watchos', toggle_false('test_watchos'), help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-watchos-simulator and --skip-test-watchos-host') option('--skip-test-watchos-simulator', toggle_false('test_watchos_simulator'), help='skip testing watchOS simulator targets') option('--skip-test-watchos-host', toggle_false('test_watchos_host'), help='skip testing watchOS device targets on the host machine (the ' 'watch itself)') option('--skip-test-android', toggle_false('test_android'), help='skip testing all Android targets.') option('--skip-test-android-host', toggle_false('test_android_host'), help='skip testing Android device targets on the host machine (the ' 'phone itself)') option('--skip-test-indexstore-db', toggle_false('test_indexstoredb'), help='skip testing indexstore-db') option('--skip-test-sourcekit-lsp', toggle_false('test_sourcekitlsp'), help='skip testing sourcekit-lsp') # ------------------------------------------------------------------------- in_group('Build settings specific for LLVM') option('--llvm-targets-to-build', store, default='X86;ARM;AArch64;PowerPC;SystemZ;Mips', help='LLVM target generators to build') # ------------------------------------------------------------------------- in_group('Build settings for Android') option('--android-ndk', store_path, help='An absolute path to the NDK that will be used as a libc ' 'implementation for Android builds') option('--android-api-level', store, default='21', help='The Android API level to target when building for Android. ' 'Currently only 21 or above is supported') option('--android-ndk-gcc-version', store, choices=['4.8', '4.9'], default='4.9', help='The GCC version to use when building for Android. Currently ' 'only 4.9 is supported. %(default)s is also the default ' 'value. This option may be used when experimenting with ' 'versions of the Android NDK not officially supported by ' 'Swift') option('--android-icu-uc', store_path, help='Path to libicuuc.so') option('--android-icu-uc-include', store_path, help='Path to a directory containing headers for libicuuc') option('--android-icu-i18n', store_path, help='Path to libicui18n.so') option('--android-icu-i18n-include', store_path, help='Path to a directory containing headers libicui18n') option('--android-icu-data', store_path, help='Path to libicudata.so') option('--android-deploy-device-path', store_path, default=android.adb.commands.DEVICE_TEMP_DIR, help='Path on an Android device to which built Swift stdlib ' 'products will be deployed. If running host tests, specify ' 'the "{}" directory.'.format(android.adb.commands.DEVICE_TEMP_DIR)) option('--android-arch', store, choices=['armv7', 'aarch64'], default='armv7', help='The Android target architecture when building for Android. ' 'Currently only armv7 and aarch64 are supported. ' '%(default)s is the default.') # ------------------------------------------------------------------------- in_group('Unsupported options') option('--build-jobs', unsupported) option('--common-cmake-options', unsupported) option('--only-execute', unsupported) option('--skip-test-optimize-for-size', unsupported) option('--skip-test-optimize-none-implicit-dynamic', unsupported) option('--skip-test-optimized', unsupported) # ------------------------------------------------------------------------- return builder.build()
def create_argument_parser(): """Return a configured argument parser.""" parser = _ApplyDefaultsArgumentParser( apply_defaults=_apply_default_arguments, formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE, description=DESCRIPTION, epilog=EPILOG) parser.add_argument( "-n", "--dry-run", help="print the commands that would be executed, but do not execute " "them", action="store_true", default=False) parser.add_argument( "--no-legacy-impl", dest="legacy_impl", help="avoid legacy implementation", action="store_false", default=True) targets_group = parser.add_argument_group( title="Host and cross-compilation targets") targets_group.add_argument( "--host-target", help="The host target. LLVM, Clang, and Swift will be built for this " "target. The built LLVM and Clang will be used to compile Swift " "for the cross-compilation targets.", default=StdlibDeploymentTarget.host_target().name) targets_group.add_argument( "--cross-compile-hosts", help="A space separated list of targets to cross-compile host Swift " "tools for. Can be used multiple times.", action=arguments.action.concat, type=arguments.type.shell_split, default=[]) targets_group.add_argument( "--stdlib-deployment-targets", help="list of targets to compile or cross-compile the Swift standard " "library for. %(default)s by default.", action=arguments.action.concat, type=arguments.type.shell_split, default=None) targets_group.add_argument( "--build-stdlib-deployment-targets", help="A space-separated list that filters which of the configured " "targets to build the Swift standard library for, or 'all'.", type=arguments.type.shell_split, default=["all"]) projects_group = parser.add_argument_group( title="Options to select projects") projects_group.add_argument( "-l", "--lldb", help="build LLDB", action="store_true", dest="build_lldb") projects_group.add_argument( "-b", "--llbuild", help="build llbuild", action="store_true", dest="build_llbuild") projects_group.add_argument( "-p", "--swiftpm", help="build swiftpm", action="store_true", dest="build_swiftpm") projects_group.add_argument( "--xctest", help="build xctest", action=arguments.action.enable, dest="build_xctest") projects_group.add_argument( "--foundation", help="build foundation", action=arguments.action.enable, dest="build_foundation") projects_group.add_argument( "--libdispatch", help="build libdispatch", action=arguments.action.enable, dest="build_libdispatch") projects_group.add_argument( "--libicu", help="build libicu", action=arguments.action.enable, dest="build_libicu") projects_group.add_argument( "--playgroundlogger", help="build playgroundlogger", action="store_true", dest="build_playgroundlogger") projects_group.add_argument( "--playgroundsupport", help="build PlaygroundSupport", action="store_true", dest="build_playgroundsupport") projects_group.add_argument( "--build-ninja", help="build the Ninja tool", action=arguments.action.enable) extra_actions_group = parser.add_argument_group( title="Extra actions to perform before or in addition to building") extra_actions_group.add_argument( "-c", "--clean", help="do a clean build", action="store_true") extra_actions_group.add_argument( "--export-compile-commands", help="generate compilation databases in addition to building", action=arguments.action.enable) extra_actions_group.add_argument( "--symbols-package", metavar="PATH", help="if provided, an archive of the symbols directory will be " "generated at this path") build_variant_group = parser.add_mutually_exclusive_group(required=False) build_variant_group.add_argument( "-d", "--debug", help="build the Debug variant of everything (LLVM, Clang, Swift host " "tools, target Swift standard libraries, LLDB (if enabled) " "(default)", action="store_const", const="Debug", dest="build_variant") build_variant_group.add_argument( "-r", "--release-debuginfo", help="build the RelWithDebInfo variant of everything (default is " "Debug)", action="store_const", const="RelWithDebInfo", dest="build_variant") build_variant_group.add_argument( "-R", "--release", help="build the Release variant of everything (default is Debug)", action="store_const", const="Release", dest="build_variant") build_variant_override_group = parser.add_argument_group( title="Override build variant for a specific project") build_variant_override_group.add_argument( "--debug-llvm", help="build the Debug variant of LLVM", action="store_const", const="Debug", dest="llvm_build_variant") build_variant_override_group.add_argument( "--debug-swift", help="build the Debug variant of Swift host tools", action="store_const", const="Debug", dest="swift_build_variant") build_variant_override_group.add_argument( "--debug-swift-stdlib", help="build the Debug variant of the Swift standard library and SDK " "overlay", action="store_const", const="Debug", dest="swift_stdlib_build_variant") build_variant_override_group.add_argument( "--debug-lldb", help="build the Debug variant of LLDB", action="store_const", const="Debug", dest="lldb_build_variant") build_variant_override_group.add_argument( "--debug-cmark", help="build the Debug variant of CommonMark", action="store_const", const="Debug", dest="cmark_build_variant") build_variant_override_group.add_argument( "--debug-foundation", help="build the Debug variant of Foundation", action="store_const", const="Debug", dest="foundation_build_variant") build_variant_override_group.add_argument( "--debug-libdispatch", help="build the Debug variant of libdispatch", action="store_const", const="Debug", dest="libdispatch_build_variant") build_variant_override_group.add_argument( "--debug-libicu", help="build the Debug variant of libicu", action="store_const", const="Debug", dest="libicu_build_variant") assertions_group = parser.add_mutually_exclusive_group(required=False) assertions_group.add_argument( "--assertions", help="enable assertions in all projects", action="store_const", const=True, dest="assertions") assertions_group.add_argument( "--no-assertions", help="disable assertions in all projects", action="store_const", const=False, dest="assertions") assertions_override_group = parser.add_argument_group( title="Control assertions in a specific project") assertions_override_group.add_argument( "--cmark-assertions", help="enable assertions in CommonMark", action="store_const", const=True, dest="cmark_assertions") assertions_override_group.add_argument( "--llvm-assertions", help="enable assertions in LLVM", action="store_const", const=True, dest="llvm_assertions") assertions_override_group.add_argument( "--no-llvm-assertions", help="disable assertions in LLVM", action="store_const", const=False, dest="llvm_assertions") assertions_override_group.add_argument( "--swift-assertions", help="enable assertions in Swift", action="store_const", const=True, dest="swift_assertions") assertions_override_group.add_argument( "--no-swift-assertions", help="disable assertions in Swift", action="store_const", const=False, dest="swift_assertions") assertions_override_group.add_argument( "--swift-stdlib-assertions", help="enable assertions in the Swift standard library", action="store_const", const=True, dest="swift_stdlib_assertions") assertions_override_group.add_argument( "--no-swift-stdlib-assertions", help="disable assertions in the Swift standard library", action="store_const", const=False, dest="swift_stdlib_assertions") assertions_override_group.add_argument( "--lldb-assertions", help="enable assertions in LLDB", action="store_const", const=True, dest="lldb_assertions") assertions_override_group.add_argument( "--no-lldb-assertions", help="disable assertions in LLDB", action="store_const", const=False, dest="lldb_assertions") # FIXME: This should be one option using choices=[...] cmake_generator_group = parser.add_argument_group( title="Select the CMake generator") cmake_generator_group.add_argument( "-x", "--xcode", help="use CMake's Xcode generator (default is Ninja)", action="store_const", const="Xcode", dest="cmake_generator") cmake_generator_group.add_argument( "-m", "--make", help="use CMake's Makefile generator (default is Ninja)", action="store_const", const="Unix Makefiles", dest="cmake_generator") cmake_generator_group.add_argument( "-e", "--eclipse", help="use CMake's Eclipse generator (default is Ninja)", action="store_const", const="Eclipse CDT4 - Ninja", dest="cmake_generator") run_tests_group = parser.add_argument_group( title="Run tests") # NOTE: We can't merge -t and --test, because nargs='?' makes # `-ti` to be treated as `-t=i`. run_tests_group.add_argument( "-t", help="test Swift after building", action="store_const", const=True, dest="test") run_tests_group.add_argument( "--test", help="test Swift after building", action=arguments.action.enable) run_tests_group.add_argument( "-T", help="run the validation test suite (implies --test)", action="store_const", const=True, dest="validation_test") run_tests_group.add_argument( "--validation-test", help="run the validation test suite (implies --test)", action=arguments.action.enable) run_tests_group.add_argument( "--test-paths", help="run tests located in specific directories and/or files \ (implies --test and/or --validation-test)", action=arguments.action.concat, type=arguments.type.shell_split, default=[]) run_tests_group.add_argument( "-o", help="run the test suite in optimized mode too (implies --test)", action="store_const", const=True, dest="test_optimized") run_tests_group.add_argument( "--test-optimized", help="run the test suite in optimized mode too (implies --test)", action=arguments.action.enable) run_tests_group.add_argument( "-s", help="run the test suite in optimize for size mode too \ (implies --test)", action="store_const", const=True, dest="test_optimize_for_size") run_tests_group.add_argument( "--test-optimize-for-size", help="run the test suite in optimize for size mode too \ (implies --test)", action=arguments.action.enable) run_tests_group.add_argument( "--long-test", help="run the long test suite", action=arguments.action.enable) run_tests_group.add_argument( "--host-test", help="run executable tests on host devices (such as iOS or tvOS)", action=arguments.action.enable) run_tests_group.add_argument( "-B", "--benchmark", help="run the Swift Benchmark Suite after building", action="store_true") run_tests_group.add_argument( "--benchmark-num-o-iterations", help="if the Swift Benchmark Suite is run after building, run N \ iterations with -O", metavar='N', type=int, default=3) run_tests_group.add_argument( "--benchmark-num-onone-iterations", help="if the Swift Benchmark Suite is run after building, run N \ iterations with -Onone", metavar='N', type=int, default=3) run_tests_group.add_argument( "--skip-test-osx", dest='test_osx', action=arguments.action.disable, help="skip testing Swift stdlibs for Mac OS X") run_tests_group.add_argument( "--skip-test-linux", dest='test_linux', action=arguments.action.disable, help="skip testing Swift stdlibs for Linux") run_tests_group.add_argument( "--skip-test-freebsd", dest='test_freebsd', action=arguments.action.disable, help="skip testing Swift stdlibs for FreeBSD") run_tests_group.add_argument( "--skip-test-cygwin", dest='test_cygwin', action=arguments.action.disable, help="skip testing Swift stdlibs for Cygwin") parser.add_argument( "--build-runtime-with-host-compiler", help="Use the host compiler, not the self-built one to compile the " "Swift runtime", action=arguments.action.enable) run_build_group = parser.add_argument_group( title="Run build") run_build_group.add_argument( "--build-swift-dynamic-stdlib", help="build dynamic variants of the Swift standard library", action=arguments.action.enable, default=True) run_build_group.add_argument( "--build-swift-static-stdlib", help="build static variants of the Swift standard library", action=arguments.action.enable) run_build_group.add_argument( "--build-swift-dynamic-sdk-overlay", help="build dynamic variants of the Swift SDK overlay", action=arguments.action.enable, default=True) run_build_group.add_argument( "--build-swift-static-sdk-overlay", help="build static variants of the Swift SDK overlay", action=arguments.action.enable) run_build_group.add_argument( "--build-swift-stdlib-unittest-extra", help="Build optional StdlibUnittest components", action=arguments.action.enable) run_build_group.add_argument( "-S", "--skip-build", help="generate build directory only without building", action="store_true") run_build_group.add_argument( "--skip-build-linux", dest='build_linux', action=arguments.action.disable, help="skip building Swift stdlibs for Linux") run_build_group.add_argument( "--skip-build-freebsd", dest='build_freebsd', action=arguments.action.disable, help="skip building Swift stdlibs for FreeBSD") run_build_group.add_argument( "--skip-build-cygwin", dest='build_cygwin', action=arguments.action.disable, help="skip building Swift stdlibs for Cygwin") run_build_group.add_argument( "--skip-build-osx", dest='build_osx', action=arguments.action.disable, help="skip building Swift stdlibs for MacOSX") run_build_group.add_argument( "--skip-build-ios", dest='build_ios', action=arguments.action.disable, help="skip building Swift stdlibs for iOS") run_build_group.add_argument( "--skip-build-ios-device", dest='build_ios_device', action=arguments.action.disable, help="skip building Swift stdlibs for iOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-ios-simulator", dest='build_ios_simulator', action=arguments.action.disable, help="skip building Swift stdlibs for iOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-tvos", dest='build_tvos', action=arguments.action.disable, help="skip building Swift stdlibs for tvOS") run_build_group.add_argument( "--skip-build-tvos-device", dest='build_tvos_device', action=arguments.action.disable, help="skip building Swift stdlibs for tvOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-tvos-simulator", dest='build_tvos_simulator', action=arguments.action.disable, help="skip building Swift stdlibs for tvOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-watchos", dest='build_watchos', action=arguments.action.disable, help="skip building Swift stdlibs for watchOS") run_build_group.add_argument( "--skip-build-watchos-device", dest='build_watchos_device', action=arguments.action.disable, help="skip building Swift stdlibs for watchOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-watchos-simulator", dest='build_watchos_simulator', action=arguments.action.disable, help="skip building Swift stdlibs for watchOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-android", dest='build_android', action=arguments.action.disable, help="skip building Swift stdlibs for Android") run_build_group.add_argument( "--skip-build-benchmarks", dest='build_benchmarks', action=arguments.action.disable, help="skip building Swift Benchmark Suite") run_build_group.add_argument( "--build-external-benchmarks", dest='build_external_benchmarks', action=arguments.action.enable, help="skip building Swift Benchmark Suite") skip_test_group = parser.add_argument_group( title="Skip testing specified targets") skip_test_group.add_argument( "--skip-test-ios", dest='test_ios', action=arguments.action.disable, help="skip testing all iOS targets. Equivalent to specifying both " "--skip-test-ios-simulator and --skip-test-ios-host") skip_test_group.add_argument( "--skip-test-ios-simulator", dest='test_ios_simulator', action=arguments.action.disable, help="skip testing iOS simulator targets") skip_test_group.add_argument( "--skip-test-ios-32bit-simulator", dest='test_ios_32bit_simulator', action=arguments.action.disable, help="skip testing iOS 32 bit simulator targets") skip_test_group.add_argument( "--skip-test-ios-host", dest='test_ios_host', action=arguments.action.disable, help="skip testing iOS device targets on the host machine (the phone " "itself)") skip_test_group.add_argument( "--skip-test-tvos", dest='test_tvos', action=arguments.action.disable, help="skip testing all tvOS targets. Equivalent to specifying both " "--skip-test-tvos-simulator and --skip-test-tvos-host") skip_test_group.add_argument( "--skip-test-tvos-simulator", dest='test_tvos_simulator', action=arguments.action.disable, help="skip testing tvOS simulator targets") skip_test_group.add_argument( "--skip-test-tvos-host", dest='test_tvos_host', action=arguments.action.disable, help="skip testing tvOS device targets on the host machine (the TV " "itself)") skip_test_group.add_argument( "--skip-test-watchos", dest='test_watchos', action=arguments.action.disable, help="skip testing all tvOS targets. Equivalent to specifying both " "--skip-test-watchos-simulator and --skip-test-watchos-host") skip_test_group.add_argument( "--skip-test-watchos-simulator", dest='test_watchos_simulator', action=arguments.action.disable, help="skip testing watchOS simulator targets") skip_test_group.add_argument( "--skip-test-watchos-host", dest='test_watchos_host', action=arguments.action.disable, help="skip testing watchOS device targets on the host machine (the " "watch itself)") skip_test_group.add_argument( "--skip-test-android-host", dest='test_android_host', action=arguments.action.disable, help="skip testing Android device targets on the host machine (the " "phone itself)") parser.add_argument( "-i", "--ios", help="also build for iOS, but disallow tests that require an iOS " "device", action="store_true") parser.add_argument( "-I", "--ios-all", help="also build for iOS, and allow all iOS tests", action="store_true", dest="ios_all") parser.add_argument( "--skip-ios", help="set to skip everything iOS-related", dest="ios", action="store_false") parser.add_argument( "--tvos", help="also build for tvOS, but disallow tests that require a tvos " "device", action=arguments.action.enable) parser.add_argument( "--tvos-all", help="also build for tvOS, and allow all tvOS tests", action=arguments.action.enable, dest="tvos_all") parser.add_argument( "--skip-tvos", help="set to skip everything tvOS-related", dest="tvos", action="store_false") parser.add_argument( "--watchos", help="also build for watchOS, but disallow tests that require an " "watchOS device", action=arguments.action.enable) parser.add_argument( "--watchos-all", help="also build for Apple watchOS, and allow all Apple watchOS tests", action=arguments.action.enable, dest="watchos_all") parser.add_argument( "--skip-watchos", help="set to skip everything watchOS-related", dest="watchos", action="store_false") parser.add_argument( "--android", help="also build for Android", action=arguments.action.enable) parser.add_argument( "--swift-analyze-code-coverage", help="enable code coverage analysis in Swift (false, not-merged, " "merged).", choices=["false", "not-merged", "merged"], # so CMake can see the inert mode as a false value default=defaults.SWIFT_ANALYZE_CODE_COVERAGE, dest="swift_analyze_code_coverage") parser.add_argument( "--build-subdir", help="name of the directory under $SWIFT_BUILD_ROOT where the build " "products will be placed", metavar="PATH") parser.add_argument( "--install-prefix", help="The installation prefix. This is where built Swift products " "(like bin, lib, and include) will be installed.", metavar="PATH", default=targets.install_prefix()) parser.add_argument( "--install-symroot", help="the path to install debug symbols into", metavar="PATH") parser.add_argument( "-j", "--jobs", help="the number of parallel build jobs to use", type=int, dest="build_jobs", default=multiprocessing.cpu_count()) parser.add_argument( "--darwin-xcrun-toolchain", help="the name of the toolchain to use on Darwin", default=defaults.DARWIN_XCRUN_TOOLCHAIN) parser.add_argument( "--cmake", help="the path to a CMake executable that will be used to build " "Swift", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--show-sdks", help="print installed Xcode and SDK versions", action=arguments.action.enable) parser.add_argument( "--extra-swift-args", help="Pass through extra flags to swift in the form of a cmake list " "'module_regexp;flag'. Can be called multiple times to add " "multiple such module_regexp flag pairs. All semicolons in flags " "must be escaped with a '\\'", action="append", dest="extra_swift_args", default=[]) llvm_group = parser.add_argument_group( title="Build settings specific for LLVM") llvm_group.add_argument( '--llvm-targets-to-build', help='LLVM target generators to build', default="X86;ARM;AArch64;PowerPC;SystemZ;Mips") android_group = parser.add_argument_group( title="Build settings for Android") android_group.add_argument( "--android-ndk", help="An absolute path to the NDK that will be used as a libc " "implementation for Android builds", metavar="PATH") android_group.add_argument( "--android-api-level", help="The Android API level to target when building for Android. " "Currently only 21 or above is supported", default="21") android_group.add_argument( "--android-ndk-gcc-version", help="The GCC version to use when building for Android. Currently " "only 4.9 is supported. %(default)s is also the default value. " "This option may be used when experimenting with versions " "of the Android NDK not officially supported by Swift", choices=["4.8", "4.9"], default="4.9") android_group.add_argument( "--android-icu-uc", help="Path to a directory containing libicuuc.so", metavar="PATH") android_group.add_argument( "--android-icu-uc-include", help="Path to a directory containing headers for libicuuc", metavar="PATH") android_group.add_argument( "--android-icu-i18n", help="Path to a directory containing libicui18n.so", metavar="PATH") android_group.add_argument( "--android-icu-i18n-include", help="Path to a directory containing headers libicui18n", metavar="PATH") android_group.add_argument( "--android-deploy-device-path", help="Path on an Android device to which built Swift stdlib products " "will be deployed. If running host tests, specify the '{}' " "directory.".format(android.adb.commands.DEVICE_TEMP_DIR), default=android.adb.commands.DEVICE_TEMP_DIR, metavar="PATH") parser.add_argument( "--host-cc", help="the absolute path to CC, the 'clang' compiler for the host " "platform. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-cxx", help="the absolute path to CXX, the 'clang++' compiler for the host " "platform. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-lipo", help="the absolute path to lipo. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-libtool", help="the absolute path to libtool. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--distcc", help="use distcc in pump mode", action=arguments.action.enable) parser.add_argument( "--enable-asan", help="enable Address Sanitizer", action=arguments.action.enable) parser.add_argument( "--enable-ubsan", help="enable Undefined Behavior Sanitizer", action=arguments.action.enable) parser.add_argument( "--enable-tsan", help="enable Thread Sanitizer for swift tools", action=arguments.action.enable) parser.add_argument( "--enable-tsan-runtime", help="enable Thread Sanitizer on the swift runtime") parser.add_argument( "--enable-lsan", help="enable Leak Sanitizer for swift tools", action=arguments.action.enable) parser.add_argument( "--compiler-vendor", choices=["none", "apple"], default=defaults.COMPILER_VENDOR, help="Compiler vendor name") parser.add_argument( "--clang-compiler-version", help="string that indicates a compiler version for Clang", type=arguments.type.clang_compiler_version, metavar="MAJOR.MINOR.PATCH") parser.add_argument( "--clang-user-visible-version", help="User-visible version of the embedded Clang and LLVM compilers", type=arguments.type.clang_compiler_version, default=defaults.CLANG_USER_VISIBLE_VERSION, metavar="MAJOR.MINOR.PATCH") parser.add_argument( "--swift-compiler-version", help="string that indicates a compiler version for Swift", type=arguments.type.swift_compiler_version, metavar="MAJOR.MINOR") parser.add_argument( "--swift-user-visible-version", help="User-visible version of the embedded Swift compiler", type=arguments.type.swift_compiler_version, default=defaults.SWIFT_USER_VISIBLE_VERSION, metavar="MAJOR.MINOR") parser.add_argument( "--darwin-deployment-version-osx", help="minimum deployment target version for OS X", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_OSX) parser.add_argument( "--darwin-deployment-version-ios", help="minimum deployment target version for iOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_IOS) parser.add_argument( "--darwin-deployment-version-tvos", help="minimum deployment target version for tvOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_TVOS) parser.add_argument( "--darwin-deployment-version-watchos", help="minimum deployment target version for watchOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS) parser.add_argument( "--extra-cmake-options", help="Pass through extra options to CMake in the form of comma " "separated options '-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp'. Can be " "called multiple times to add multiple such options.", action=arguments.action.concat, type=arguments.type.shell_split, default=[]) parser.add_argument( "--build-args", help="arguments to the build tool. This would be prepended to the " "default argument that is '-j8' when CMake generator is " "\"Ninja\".", type=arguments.type.shell_split, default=[]) parser.add_argument( "--verbose-build", help="print the commands executed during the build", action=arguments.action.enable) parser.add_argument( "--lto", help="use lto optimization on llvm/swift tools. This does not " "imply using lto on the swift standard library or runtime. " "Options: thin, full. If no optional arg is provided, full is " "chosen by default", metavar="LTO_TYPE", nargs='?', choices=['thin', 'full'], default=None, const='full', dest='lto_type') parser.add_argument( "--clang-profile-instr-use", help="profile file to use for clang PGO", metavar="PATH") default_max_lto_link_job_counts = host.max_lto_link_job_counts() parser.add_argument( "--llvm-max-parallel-lto-link-jobs", help="the maximum number of parallel link jobs to use when compiling " "llvm", metavar="COUNT", default=default_max_lto_link_job_counts['llvm']) parser.add_argument( "--swift-tools-max-parallel-lto-link-jobs", help="the maximum number of parallel link jobs to use when compiling " "swift tools.", metavar="COUNT", default=default_max_lto_link_job_counts['swift']) parser.add_argument("--enable-sil-ownership", help="Enable the SIL ownership model", action='store_true') parser.add_argument("--force-optimized-typechecker", help="Force the type checker to be built with " "optimization", action='store_true') parser.add_argument( # Explicitly unavailable options here. "--build-jobs", "--common-cmake-options", "--only-execute", "--skip-test-optimize-for-size", "--skip-test-optimized", action=arguments.action.unavailable) parser.add_argument( "--lit-args", help="lit args to use when testing", metavar="LITARGS", default="-sv") parser.add_argument( "--coverage-db", help="coverage database to use when prioritizing testing", metavar="PATH") return parser
def create_argument_parser(): """Return a configured argument parser.""" parser = _ApplyDefaultsArgumentParser( apply_defaults=_apply_default_arguments, formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE, description=DESCRIPTION, epilog=EPILOG) parser.add_argument( "-n", "--dry-run", help="print the commands that would be executed, but do not execute " "them", action="store_true", default=False) parser.add_argument( "--no-legacy-impl", dest="legacy_impl", help="avoid legacy implementation", action="store_false", default=True) targets_group = parser.add_argument_group( title="Host and cross-compilation targets") targets_group.add_argument( "--host-target", help="The host target. LLVM, Clang, and Swift will be built for this " "target. The built LLVM and Clang will be used to compile Swift " "for the cross-compilation targets.", default=StdlibDeploymentTarget.host_target().name) targets_group.add_argument( "--cross-compile-hosts", help="A space separated list of targets to cross-compile host Swift " "tools for. Can be used multiple times.", action=arguments.action.concat, type=arguments.type.shell_split, default=[]) targets_group.add_argument( "--stdlib-deployment-targets", help="list of targets to compile or cross-compile the Swift standard " "library for. %(default)s by default.", action=arguments.action.concat, type=arguments.type.shell_split, default=None) targets_group.add_argument( "--build-stdlib-deployment-targets", help="A space-separated list that filters which of the configured " "targets to build the Swift standard library for, or 'all'.", type=arguments.type.shell_split, default=["all"]) projects_group = parser.add_argument_group( title="Options to select projects") projects_group.add_argument( "-l", "--lldb", help="build LLDB", action="store_true", dest="build_lldb") projects_group.add_argument( "-b", "--llbuild", help="build llbuild", action="store_true", dest="build_llbuild") projects_group.add_argument( "-p", "--swiftpm", help="build swiftpm", action="store_true", dest="build_swiftpm") projects_group.add_argument( "--xctest", help="build xctest", action=arguments.action.optional_bool, dest="build_xctest") projects_group.add_argument( "--foundation", help="build foundation", action=arguments.action.optional_bool, dest="build_foundation") projects_group.add_argument( "--libdispatch", help="build libdispatch", action=arguments.action.optional_bool, dest="build_libdispatch") projects_group.add_argument( "--libicu", help="build libicu", action=arguments.action.optional_bool, dest="build_libicu") projects_group.add_argument( "--playgroundlogger", help="build playgroundlogger", action="store_true", dest="build_playgroundlogger") projects_group.add_argument( "--playgroundsupport", help="build PlaygroundSupport", action="store_true", dest="build_playgroundsupport") projects_group.add_argument( "--build-ninja", help="build the Ninja tool", action=arguments.action.optional_bool) extra_actions_group = parser.add_argument_group( title="Extra actions to perform before or in addition to building") extra_actions_group.add_argument( "-c", "--clean", help="do a clean build", action="store_true") extra_actions_group.add_argument( "--export-compile-commands", help="generate compilation databases in addition to building", action=arguments.action.optional_bool) extra_actions_group.add_argument( "--symbols-package", metavar="PATH", help="if provided, an archive of the symbols directory will be " "generated at this path") build_variant_group = parser.add_mutually_exclusive_group(required=False) build_variant_group.add_argument( "-d", "--debug", help="build the Debug variant of everything (LLVM, Clang, Swift host " "tools, target Swift standard libraries, LLDB (if enabled) " "(default)", action="store_const", const="Debug", dest="build_variant") build_variant_group.add_argument( "-r", "--release-debuginfo", help="build the RelWithDebInfo variant of everything (default is " "Debug)", action="store_const", const="RelWithDebInfo", dest="build_variant") build_variant_group.add_argument( "-R", "--release", help="build the Release variant of everything (default is Debug)", action="store_const", const="Release", dest="build_variant") build_variant_override_group = parser.add_argument_group( title="Override build variant for a specific project") build_variant_override_group.add_argument( "--debug-llvm", help="build the Debug variant of LLVM", action="store_const", const="Debug", dest="llvm_build_variant") build_variant_override_group.add_argument( "--debug-swift", help="build the Debug variant of Swift host tools", action="store_const", const="Debug", dest="swift_build_variant") build_variant_override_group.add_argument( "--debug-swift-stdlib", help="build the Debug variant of the Swift standard library and SDK " "overlay", action="store_const", const="Debug", dest="swift_stdlib_build_variant") build_variant_override_group.add_argument( "--debug-lldb", help="build the Debug variant of LLDB", action="store_const", const="Debug", dest="lldb_build_variant") build_variant_override_group.add_argument( "--debug-cmark", help="build the Debug variant of CommonMark", action="store_const", const="Debug", dest="cmark_build_variant") build_variant_override_group.add_argument( "--debug-foundation", help="build the Debug variant of Foundation", action="store_const", const="Debug", dest="foundation_build_variant") build_variant_override_group.add_argument( "--debug-libdispatch", help="build the Debug variant of libdispatch", action="store_const", const="Debug", dest="libdispatch_build_variant") build_variant_override_group.add_argument( "--debug-libicu", help="build the Debug variant of libicu", action="store_const", const="Debug", dest="libicu_build_variant") assertions_group = parser.add_mutually_exclusive_group(required=False) assertions_group.add_argument( "--assertions", help="enable assertions in all projects", action="store_const", const=True, dest="assertions") assertions_group.add_argument( "--no-assertions", help="disable assertions in all projects", action="store_const", const=False, dest="assertions") assertions_override_group = parser.add_argument_group( title="Control assertions in a specific project") assertions_override_group.add_argument( "--cmark-assertions", help="enable assertions in CommonMark", action="store_const", const=True, dest="cmark_assertions") assertions_override_group.add_argument( "--llvm-assertions", help="enable assertions in LLVM", action="store_const", const=True, dest="llvm_assertions") assertions_override_group.add_argument( "--no-llvm-assertions", help="disable assertions in LLVM", action="store_const", const=False, dest="llvm_assertions") assertions_override_group.add_argument( "--swift-assertions", help="enable assertions in Swift", action="store_const", const=True, dest="swift_assertions") assertions_override_group.add_argument( "--no-swift-assertions", help="disable assertions in Swift", action="store_const", const=False, dest="swift_assertions") assertions_override_group.add_argument( "--swift-stdlib-assertions", help="enable assertions in the Swift standard library", action="store_const", const=True, dest="swift_stdlib_assertions") assertions_override_group.add_argument( "--no-swift-stdlib-assertions", help="disable assertions in the Swift standard library", action="store_const", const=False, dest="swift_stdlib_assertions") assertions_override_group.add_argument( "--lldb-assertions", help="enable assertions in LLDB", action="store_const", const=True, dest="lldb_assertions") assertions_override_group.add_argument( "--no-lldb-assertions", help="disable assertions in LLDB", action="store_const", const=False, dest="lldb_assertions") # FIXME: This should be one option using choices=[...] cmake_generator_group = parser.add_argument_group( title="Select the CMake generator") cmake_generator_group.add_argument( "-x", "--xcode", help="use CMake's Xcode generator (default is Ninja)", action="store_const", const="Xcode", dest="cmake_generator") cmake_generator_group.add_argument( "-m", "--make", help="use CMake's Makefile generator (default is Ninja)", action="store_const", const="Unix Makefiles", dest="cmake_generator") cmake_generator_group.add_argument( "-e", "--eclipse", help="use CMake's Eclipse generator (default is Ninja)", action="store_const", const="Eclipse CDT4 - Ninja", dest="cmake_generator") run_tests_group = parser.add_argument_group( title="Run tests") # NOTE: We can't merge -t and --test, because nargs='?' makes # `-ti` to be treated as `-t=i`. run_tests_group.add_argument( "-t", help="test Swift after building", action="store_const", const=True, dest="test") run_tests_group.add_argument( "--test", help="test Swift after building", action=arguments.action.optional_bool) run_tests_group.add_argument( "-T", help="run the validation test suite (implies --test)", action="store_const", const=True, dest="validation_test") run_tests_group.add_argument( "--validation-test", help="run the validation test suite (implies --test)", action=arguments.action.optional_bool) run_tests_group.add_argument( "-o", help="run the test suite in optimized mode too (implies --test)", action="store_const", const=True, dest="test_optimized") run_tests_group.add_argument( "--test-optimized", help="run the test suite in optimized mode too (implies --test)", action=arguments.action.optional_bool) run_tests_group.add_argument( "-s", help="run the test suite in optimize for size mode too \ (implies --test)", action="store_const", const=True, dest="test_optimize_for_size") run_tests_group.add_argument( "--test-optimize-for-size", help="run the test suite in optimize for size mode too \ (implies --test)", action=arguments.action.optional_bool) run_tests_group.add_argument( "--long-test", help="run the long test suite", action=arguments.action.optional_bool) run_tests_group.add_argument( "--host-test", help="run executable tests on host devices (such as iOS or tvOS)", action=arguments.action.optional_bool) run_tests_group.add_argument( "-B", "--benchmark", help="run the Swift Benchmark Suite after building", action="store_true") run_tests_group.add_argument( "--benchmark-num-o-iterations", help="if the Swift Benchmark Suite is run after building, run N \ iterations with -O", metavar='N', type=int, default=3) run_tests_group.add_argument( "--benchmark-num-onone-iterations", help="if the Swift Benchmark Suite is run after building, run N \ iterations with -Onone", metavar='N', type=int, default=3) run_tests_group.add_argument( "--skip-test-osx", dest='test_osx', action=arguments.action.optional_false, help="skip testing Swift stdlibs for Mac OS X") run_tests_group.add_argument( "--skip-test-linux", dest='test_linux', action=arguments.action.optional_false, help="skip testing Swift stdlibs for Linux") run_tests_group.add_argument( "--skip-test-freebsd", dest='test_freebsd', action=arguments.action.optional_false, help="skip testing Swift stdlibs for FreeBSD") run_tests_group.add_argument( "--skip-test-cygwin", dest='test_cygwin', action=arguments.action.optional_false, help="skip testing Swift stdlibs for Cygwin") parser.add_argument( "--build-runtime-with-host-compiler", help="Use the host compiler, not the self-built one to compile the " "Swift runtime", action=arguments.action.optional_bool) run_build_group = parser.add_argument_group( title="Run build") run_build_group.add_argument( "--build-swift-dynamic-stdlib", help="build dynamic variants of the Swift standard library", action=arguments.action.optional_bool, default=True) run_build_group.add_argument( "--build-swift-static-stdlib", help="build static variants of the Swift standard library", action=arguments.action.optional_bool) run_build_group.add_argument( "--build-swift-dynamic-sdk-overlay", help="build dynamic variants of the Swift SDK overlay", action=arguments.action.optional_bool, default=True) run_build_group.add_argument( "--build-swift-static-sdk-overlay", help="build static variants of the Swift SDK overlay", action=arguments.action.optional_bool) run_build_group.add_argument( "--build-swift-stdlib-unittest-extra", help="Build optional StdlibUnittest components", action=arguments.action.optional_bool) run_build_group.add_argument( "-S", "--skip-build", help="generate build directory only without building", action="store_true") run_build_group.add_argument( "--skip-build-linux", dest='build_linux', action=arguments.action.optional_false, help="skip building Swift stdlibs for Linux") run_build_group.add_argument( "--skip-build-freebsd", dest='build_freebsd', action=arguments.action.optional_false, help="skip building Swift stdlibs for FreeBSD") run_build_group.add_argument( "--skip-build-cygwin", dest='build_cygwin', action=arguments.action.optional_false, help="skip building Swift stdlibs for Cygwin") run_build_group.add_argument( "--skip-build-osx", dest='build_osx', action=arguments.action.optional_false, help="skip building Swift stdlibs for MacOSX") run_build_group.add_argument( "--skip-build-ios", dest='build_ios', action=arguments.action.optional_false, help="skip building Swift stdlibs for iOS") run_build_group.add_argument( "--skip-build-ios-device", dest='build_ios_device', action=arguments.action.optional_false, help="skip building Swift stdlibs for iOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-ios-simulator", dest='build_ios_simulator', action=arguments.action.optional_false, help="skip building Swift stdlibs for iOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-tvos", dest='build_tvos', action=arguments.action.optional_false, help="skip building Swift stdlibs for tvOS") run_build_group.add_argument( "--skip-build-tvos-device", dest='build_tvos_device', action=arguments.action.optional_false, help="skip building Swift stdlibs for tvOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-tvos-simulator", dest='build_tvos_simulator', action=arguments.action.optional_false, help="skip building Swift stdlibs for tvOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-watchos", dest='build_watchos', action=arguments.action.optional_false, help="skip building Swift stdlibs for watchOS") run_build_group.add_argument( "--skip-build-watchos-device", dest='build_watchos_device', action=arguments.action.optional_false, help="skip building Swift stdlibs for watchOS devices " "(i.e. build simulators only)") run_build_group.add_argument( "--skip-build-watchos-simulator", dest='build_watchos_simulator', action=arguments.action.optional_false, help="skip building Swift stdlibs for watchOS simulator " "(i.e. build devices only)") run_build_group.add_argument( "--skip-build-android", dest='build_android', action=arguments.action.optional_false, help="skip building Swift stdlibs for Android") run_build_group.add_argument( "--skip-build-benchmarks", dest='build_benchmarks', action=arguments.action.optional_false, help="skip building Swift Benchmark Suite") skip_test_group = parser.add_argument_group( title="Skip testing specified targets") skip_test_group.add_argument( "--skip-test-ios", dest='test_ios', action=arguments.action.optional_false, help="skip testing all iOS targets. Equivalent to specifying both " "--skip-test-ios-simulator and --skip-test-ios-host") skip_test_group.add_argument( "--skip-test-ios-simulator", dest='test_ios_simulator', action=arguments.action.optional_false, help="skip testing iOS simulator targets") skip_test_group.add_argument( "--skip-test-ios-32bit-simulator", dest='test_ios_32bit_simulator', action=arguments.action.optional_false, help="skip testing iOS 32 bit simulator targets") skip_test_group.add_argument( "--skip-test-ios-host", dest='test_ios_device', action=arguments.action.optional_false, help="skip testing iOS device targets on the host machine (the phone " "itself)") skip_test_group.add_argument( "--skip-test-tvos", dest='test_tvos', action=arguments.action.optional_false, help="skip testing all tvOS targets. Equivalent to specifying both " "--skip-test-tvos-simulator and --skip-test-tvos-host") skip_test_group.add_argument( "--skip-test-tvos-simulator", dest='test_tvos_simulator', action=arguments.action.optional_false, help="skip testing tvOS simulator targets") skip_test_group.add_argument( "--skip-test-tvos-host", dest='test_tvos_device', action=arguments.action.optional_false, help="skip testing tvOS device targets on the host machine (the TV " "itself)") skip_test_group.add_argument( "--skip-test-watchos", dest='test_watchos', action=arguments.action.optional_false, help="skip testing all tvOS targets. Equivalent to specifying both " "--skip-test-watchos-simulator and --skip-test-watchos-host") skip_test_group.add_argument( "--skip-test-watchos-simulator", dest='test_watchos_simulator', action=arguments.action.optional_false, help="skip testing watchOS simulator targets") skip_test_group.add_argument( "--skip-test-watchos-host", dest='test_watchos_device', action=arguments.action.optional_false, help="skip testing watchOS device targets on the host machine (the " "watch itself)") skip_test_group.add_argument( "--skip-test-android-host", dest='test_android_device', action=arguments.action.optional_false, help="skip testing Android device targets on the host machine (the " "phone itself)") parser.add_argument( "-i", "--ios", help="also build for iOS, but disallow tests that require an iOS " "device", action="store_true") parser.add_argument( "-I", "--ios-all", help="also build for iOS, and allow all iOS tests", action="store_true", dest="ios_all") parser.add_argument( "--skip-ios", help="set to skip everything iOS-related", dest="ios", action="store_false") parser.add_argument( "--tvos", help="also build for tvOS, but disallow tests that require a tvos " "device", action=arguments.action.optional_bool) parser.add_argument( "--tvos-all", help="also build for tvOS, and allow all tvOS tests", action=arguments.action.optional_bool, dest="tvos_all") parser.add_argument( "--skip-tvos", help="set to skip everything tvOS-related", dest="tvos", action="store_false") parser.add_argument( "--watchos", help="also build for watchOS, but disallow tests that require an " "watchOS device", action=arguments.action.optional_bool) parser.add_argument( "--watchos-all", help="also build for Apple watchOS, and allow all Apple watchOS tests", action=arguments.action.optional_bool, dest="watchos_all") parser.add_argument( "--skip-watchos", help="set to skip everything watchOS-related", dest="watchos", action="store_false") parser.add_argument( "--android", help="also build for Android", action=arguments.action.optional_bool) parser.add_argument( "--swift-analyze-code-coverage", help="enable code coverage analysis in Swift (false, not-merged, " "merged).", choices=["false", "not-merged", "merged"], # so CMake can see the inert mode as a false value default=defaults.SWIFT_ANALYZE_CODE_COVERAGE, dest="swift_analyze_code_coverage") parser.add_argument( "--build-subdir", help="name of the directory under $SWIFT_BUILD_ROOT where the build " "products will be placed", metavar="PATH") parser.add_argument( "--install-prefix", help="The installation prefix. This is where built Swift products " "(like bin, lib, and include) will be installed.", metavar="PATH", default=targets.install_prefix()) parser.add_argument( "--install-symroot", help="the path to install debug symbols into", metavar="PATH") parser.add_argument( "-j", "--jobs", help="the number of parallel build jobs to use", type=int, dest="build_jobs", default=multiprocessing.cpu_count()) parser.add_argument( "--darwin-xcrun-toolchain", help="the name of the toolchain to use on Darwin", default=defaults.DARWIN_XCRUN_TOOLCHAIN) parser.add_argument( "--cmake", help="the path to a CMake executable that will be used to build " "Swift", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--show-sdks", help="print installed Xcode and SDK versions", action=arguments.action.optional_bool) parser.add_argument( "--extra-swift-args", help="Pass through extra flags to swift in the form of a cmake list " "'module_regexp;flag'. Can be called multiple times to add " "multiple such module_regexp flag pairs. All semicolons in flags " "must be escaped with a '\\'", action="append", dest="extra_swift_args", default=[]) llvm_group = parser.add_argument_group( title="Build settings specific for LLVM") llvm_group.add_argument( '--llvm-targets-to-build', help='LLVM target generators to build', default="X86;ARM;AArch64;PowerPC;SystemZ;Mips") android_group = parser.add_argument_group( title="Build settings for Android") android_group.add_argument( "--android-ndk", help="An absolute path to the NDK that will be used as a libc " "implementation for Android builds", metavar="PATH") android_group.add_argument( "--android-api-level", help="The Android API level to target when building for Android. " "Currently only 21 or above is supported", default="21") android_group.add_argument( "--android-ndk-gcc-version", help="The GCC version to use when building for Android. Currently " "only 4.9 is supported. %(default)s is also the default value. " "This option may be used when experimenting with versions " "of the Android NDK not officially supported by Swift", choices=["4.8", "4.9"], default="4.9") android_group.add_argument( "--android-icu-uc", help="Path to a directory containing libicuuc.so", metavar="PATH") android_group.add_argument( "--android-icu-uc-include", help="Path to a directory containing headers for libicuuc", metavar="PATH") android_group.add_argument( "--android-icu-i18n", help="Path to a directory containing libicui18n.so", metavar="PATH") android_group.add_argument( "--android-icu-i18n-include", help="Path to a directory containing headers libicui18n", metavar="PATH") android_group.add_argument( "--android-deploy-device-path", help="Path on an Android device to which built Swift stdlib products " "will be deployed. If running host tests, specify the '{}' " "directory.".format(android.adb.commands.DEVICE_TEMP_DIR), default=android.adb.commands.DEVICE_TEMP_DIR, metavar="PATH") parser.add_argument( "--host-cc", help="the absolute path to CC, the 'clang' compiler for the host " "platform. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-cxx", help="the absolute path to CXX, the 'clang++' compiler for the host " "platform. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-lipo", help="the absolute path to lipo. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--host-libtool", help="the absolute path to libtool. Default is auto detected.", type=arguments.type.executable, metavar="PATH") parser.add_argument( "--distcc", help="use distcc in pump mode", action=arguments.action.optional_bool) parser.add_argument( "--enable-asan", help="enable Address Sanitizer", action=arguments.action.optional_bool) parser.add_argument( "--enable-ubsan", help="enable Undefined Behavior Sanitizer", action=arguments.action.optional_bool) parser.add_argument( "--enable-tsan", help="enable Thread Sanitizer for swift tools", action=arguments.action.optional_bool) parser.add_argument( "--enable-tsan-runtime", help="enable Thread Sanitizer on the swift runtime") parser.add_argument( "--enable-lsan", help="enable Leak Sanitizer for swift tools", action=arguments.action.optional_bool) parser.add_argument( "--compiler-vendor", choices=["none", "apple"], default=defaults.COMPILER_VENDOR, help="Compiler vendor name") parser.add_argument( "--clang-compiler-version", help="string that indicates a compiler version for Clang", type=arguments.type.clang_compiler_version, metavar="MAJOR.MINOR.PATCH") parser.add_argument( "--clang-user-visible-version", help="User-visible version of the embedded Clang and LLVM compilers", type=arguments.type.clang_compiler_version, default=defaults.CLANG_USER_VISIBLE_VERSION, metavar="MAJOR.MINOR.PATCH") parser.add_argument( "--swift-compiler-version", help="string that indicates a compiler version for Swift", type=arguments.type.swift_compiler_version, metavar="MAJOR.MINOR") parser.add_argument( "--swift-user-visible-version", help="User-visible version of the embedded Swift compiler", type=arguments.type.swift_compiler_version, default=defaults.SWIFT_USER_VISIBLE_VERSION, metavar="MAJOR.MINOR") parser.add_argument( "--darwin-deployment-version-osx", help="minimum deployment target version for OS X", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_OSX) parser.add_argument( "--darwin-deployment-version-ios", help="minimum deployment target version for iOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_IOS) parser.add_argument( "--darwin-deployment-version-tvos", help="minimum deployment target version for tvOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_TVOS) parser.add_argument( "--darwin-deployment-version-watchos", help="minimum deployment target version for watchOS", metavar="MAJOR.MINOR", default=defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS) parser.add_argument( "--extra-cmake-options", help="Pass through extra options to CMake in the form of comma " "separated options '-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp'. Can be " "called multiple times to add multiple such options.", action=arguments.action.concat, type=arguments.type.shell_split, default=[]) parser.add_argument( "--build-args", help="arguments to the build tool. This would be prepended to the " "default argument that is '-j8' when CMake generator is " "\"Ninja\".", type=arguments.type.shell_split, default=[]) parser.add_argument( "--verbose-build", help="print the commands executed during the build", action=arguments.action.optional_bool) parser.add_argument( "--lto", help="use lto optimization on llvm/swift tools. This does not " "imply using lto on the swift standard library or runtime. " "Options: thin, full. If no optional arg is provided, full is " "chosen by default", metavar="LTO_TYPE", nargs='?', choices=['thin', 'full'], default=None, const='full', dest='lto_type') parser.add_argument( "--clang-profile-instr-use", help="profile file to use for clang PGO", metavar="PATH") default_max_lto_link_job_counts = host.max_lto_link_job_counts() parser.add_argument( "--llvm-max-parallel-lto-link-jobs", help="the maximum number of parallel link jobs to use when compiling " "llvm", metavar="COUNT", default=default_max_lto_link_job_counts['llvm']) parser.add_argument( "--swift-tools-max-parallel-lto-link-jobs", help="the maximum number of parallel link jobs to use when compiling " "swift tools.", metavar="COUNT", default=default_max_lto_link_job_counts['swift']) parser.add_argument("--enable-sil-ownership", help="Enable the SIL ownership model", action='store_true') parser.add_argument("--force-optimized-typechecker", help="Force the type checker to be built with " "optimization", action='store_true') parser.add_argument( # Explicitly unavailable options here. "--build-jobs", "--common-cmake-options", "--only-execute", "--skip-test-optimize-for-size", "--skip-test-optimized", action=arguments.action.unavailable) parser.add_argument( "--lit-args", help="lit args to use when testing", metavar="LITARGS", default="-sv") parser.add_argument( "--coverage-db", help="coverage database to use when prioritizing testing", metavar="PATH") return parser
def create_argument_parser(): """Return a configured argument parser.""" parser = _ApplyDefaultsArgumentParser( apply_defaults=_apply_default_arguments, formatter_class=argparse.RawDescriptionHelpFormatter, usage=USAGE, description=DESCRIPTION, epilog=EPILOG) parser.add_argument( '-n', '--dry-run', action='store_true', default=False, help='print the commands that would be executed, but do not execute ' 'them') parser.add_argument( '--no-legacy-impl', dest='legacy_impl', action='store_false', default=True, help='avoid legacy implementation') parser.add_argument( '--build-runtime-with-host-compiler', action=arguments.action.enable, help='Use the host compiler, not the self-built one to compile the ' 'Swift runtime') parser.add_argument( '-i', '--ios', action='store_true', help='also build for iOS, but disallow tests that require an iOS ' 'device') parser.add_argument( '-I', '--ios-all', action='store_true', dest='ios_all', help='also build for iOS, and allow all iOS tests') parser.add_argument( '--skip-ios', action='store_false', dest='ios', help='set to skip everything iOS-related') parser.add_argument( '--tvos', action=arguments.action.enable, help='also build for tvOS, but disallow tests that require a tvos ' 'device') parser.add_argument( '--tvos-all', action=arguments.action.enable, dest='tvos_all', help='also build for tvOS, and allow all tvOS tests') parser.add_argument( '--skip-tvos', action='store_false', dest='tvos', help='set to skip everything tvOS-related') parser.add_argument( '--watchos', action=arguments.action.enable, help='also build for watchOS, but disallow tests that require an ' 'watchOS device') parser.add_argument( '--watchos-all', action=arguments.action.enable, dest='watchos_all', help='also build for Apple watchOS, and allow all Apple watchOS tests') parser.add_argument( '--skip-watchos', action='store_false', dest='watchos', help='set to skip everything watchOS-related') parser.add_argument( '--android', action=arguments.action.enable, help='also build for Android') parser.add_argument( '--swift-analyze-code-coverage', dest='swift_analyze_code_coverage', choices=['false', 'not-merged', 'merged'], # so CMake can see the inert mode as a false value default=defaults.SWIFT_ANALYZE_CODE_COVERAGE, help='enable code coverage analysis in Swift (false, not-merged, ' 'merged).') parser.add_argument( '--build-subdir', metavar='PATH', help='name of the directory under $SWIFT_BUILD_ROOT where the build ' 'products will be placed') parser.add_argument( '--install-prefix', default=targets.install_prefix(), metavar='PATH', help='The installation prefix. This is where built Swift products ' '(like bin, lib, and include) will be installed.') parser.add_argument( '--install-symroot', metavar='PATH', help='the path to install debug symbols into') parser.add_argument( '-j', '--jobs', type=int, dest='build_jobs', default=multiprocessing.cpu_count(), help='the number of parallel build jobs to use') parser.add_argument( '--darwin-xcrun-toolchain', default=defaults.DARWIN_XCRUN_TOOLCHAIN, help='the name of the toolchain to use on Darwin') parser.add_argument( '--cmake', type=arguments.type.executable, metavar='PATH', help='the path to a CMake executable that will be used to build ' 'Swift') parser.add_argument( '--show-sdks', action=arguments.action.enable, help='print installed Xcode and SDK versions') parser.add_argument( '--extra-swift-args', action='append', dest='extra_swift_args', default=[], help='Pass through extra flags to swift in the form of a cmake list ' '"module_regexp;flag". Can be called multiple times to add ' 'multiple such module_regexp flag pairs. All semicolons in flags ' 'must be escaped with a "\\"') parser.add_argument( '--host-cc', type=arguments.type.executable, metavar='PATH', help='the absolute path to CC, the "clang" compiler for the host ' 'platform. Default is auto detected.') parser.add_argument( '--host-cxx', type=arguments.type.executable, metavar='PATH', help='the absolute path to CXX, the "clang++" compiler for the host ' 'platform. Default is auto detected.') parser.add_argument( '--host-lipo', type=arguments.type.executable, metavar='PATH', help='the absolute path to lipo. Default is auto detected.') parser.add_argument( '--host-libtool', type=arguments.type.executable, metavar='PATH', help='the absolute path to libtool. Default is auto detected.') parser.add_argument( '--distcc', action=arguments.action.enable, help='use distcc in pump mode') parser.add_argument( '--enable-asan', action=arguments.action.enable, help='enable Address Sanitizer') parser.add_argument( '--enable-ubsan', action=arguments.action.enable, help='enable Undefined Behavior Sanitizer') parser.add_argument( '--enable-tsan', action=arguments.action.enable, help='enable Thread Sanitizer for swift tools') parser.add_argument( '--enable-tsan-runtime', action=arguments.action.enable, help='enable Thread Sanitizer on the swift runtime') parser.add_argument( '--enable-lsan', action=arguments.action.enable, help='enable Leak Sanitizer for swift tools') parser.add_argument( '--compiler-vendor', choices=['none', 'apple'], default=defaults.COMPILER_VENDOR, help='Compiler vendor name') parser.add_argument( '--clang-compiler-version', type=arguments.type.clang_compiler_version, metavar='MAJOR.MINOR.PATCH', help='string that indicates a compiler version for Clang') parser.add_argument( '--clang-user-visible-version', type=arguments.type.clang_compiler_version, default=defaults.CLANG_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR.PATCH', help='User-visible version of the embedded Clang and LLVM compilers') parser.add_argument( '--swift-compiler-version', type=arguments.type.swift_compiler_version, metavar='MAJOR.MINOR', help='string that indicates a compiler version for Swift') parser.add_argument( '--swift-user-visible-version', type=arguments.type.swift_compiler_version, default=defaults.SWIFT_USER_VISIBLE_VERSION, metavar='MAJOR.MINOR', help='User-visible version of the embedded Swift compiler') parser.add_argument( '--darwin-deployment-version-osx', default=defaults.DARWIN_DEPLOYMENT_VERSION_OSX, metavar='MAJOR.MINOR', help='minimum deployment target version for OS X') parser.add_argument( '--darwin-deployment-version-ios', default=defaults.DARWIN_DEPLOYMENT_VERSION_IOS, metavar='MAJOR.MINOR', help='minimum deployment target version for iOS') parser.add_argument( '--darwin-deployment-version-tvos', default=defaults.DARWIN_DEPLOYMENT_VERSION_TVOS, metavar='MAJOR.MINOR', help='minimum deployment target version for tvOS') parser.add_argument( '--darwin-deployment-version-watchos', default=defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS, metavar='MAJOR.MINOR', help='minimum deployment target version for watchOS') parser.add_argument( '--extra-cmake-options', action=arguments.action.concat, type=arguments.type.shell_split, default=[], help='Pass through extra options to CMake in the form of comma ' 'separated options "-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp". Can be ' 'called multiple times to add multiple such options.') parser.add_argument( '--build-args', type=arguments.type.shell_split, default=[], help='arguments to the build tool. This would be prepended to the ' 'default argument that is "-j8" when CMake generator is ' '"Ninja".') parser.add_argument( '--verbose-build', action=arguments.action.enable, help='print the commands executed during the build') parser.add_argument( '--lto', dest='lto_type', nargs='?', choices=['thin', 'full'], const='full', default=None, metavar='LTO_TYPE', help='use lto optimization on llvm/swift tools. This does not ' 'imply using lto on the swift standard library or runtime. ' 'Options: thin, full. If no optional arg is provided, full is ' 'chosen by default') parser.add_argument( '--clang-profile-instr-use', metavar='PATH', help='profile file to use for clang PGO') default_max_lto_link_job_counts = host.max_lto_link_job_counts() parser.add_argument( '--llvm-max-parallel-lto-link-jobs', default=default_max_lto_link_job_counts['llvm'], metavar='COUNT', help='the maximum number of parallel link jobs to use when compiling ' 'llvm') parser.add_argument( '--swift-tools-max-parallel-lto-link-jobs', default=default_max_lto_link_job_counts['swift'], metavar='COUNT', help='the maximum number of parallel link jobs to use when compiling ' 'swift tools.') parser.add_argument( '--enable-sil-ownership', action='store_true', help='Enable the SIL ownership model') parser.add_argument( '--force-optimized-typechecker', action='store_true', help='Force the type checker to be built with ' 'optimization') parser.add_argument( '--lit-args', default='-sv', metavar='LITARGS', help='lit args to use when testing') parser.add_argument( '--coverage-db', metavar='PATH', help='coverage database to use when prioritizing testing') parser.add_argument( # Explicitly unavailable options here. '--build-jobs', '--common-cmake-options', '--only-execute', '--skip-test-optimize-for-size', '--skip-test-optimized', action=arguments.action.unavailable) targets_group = parser.add_argument_group( title='Host and cross-compilation targets') targets_group.add_argument( '--host-target', default=StdlibDeploymentTarget.host_target().name, help='The host target. LLVM, Clang, and Swift will be built for this ' 'target. The built LLVM and Clang will be used to compile Swift ' 'for the cross-compilation targets.') targets_group.add_argument( '--cross-compile-hosts', action=arguments.action.concat, type=arguments.type.shell_split, default=[], help='A space separated list of targets to cross-compile host Swift ' 'tools for. Can be used multiple times.') targets_group.add_argument( '--stdlib-deployment-targets', action=arguments.action.concat, type=arguments.type.shell_split, default=None, help='list of targets to compile or cross-compile the Swift standard ' 'library for. %(default)s by default.') targets_group.add_argument( '--build-stdlib-deployment-targets', type=arguments.type.shell_split, default=['all'], help='A space-separated list that filters which of the configured ' 'targets to build the Swift standard library for, or "all".') projects_group = parser.add_argument_group( title='Options to select projects') projects_group.add_argument( '-l', '--lldb', action='store_true', dest='build_lldb', help='build LLDB') projects_group.add_argument( '-b', '--llbuild', action='store_true', dest='build_llbuild', help='build llbuild') projects_group.add_argument( '-p', '--swiftpm', action='store_true', dest='build_swiftpm', help='build swiftpm') projects_group.add_argument( '--xctest', action=arguments.action.enable, dest='build_xctest', help='build xctest') projects_group.add_argument( '--foundation', action=arguments.action.enable, dest='build_foundation', help='build foundation') projects_group.add_argument( '--libdispatch', action=arguments.action.enable, dest='build_libdispatch', help='build libdispatch') projects_group.add_argument( '--libicu', action=arguments.action.enable, dest='build_libicu', help='build libicu') projects_group.add_argument( '--playgroundlogger', action='store_true', dest='build_playgroundlogger', help='build playgroundlogger') projects_group.add_argument( '--playgroundsupport', action='store_true', dest='build_playgroundsupport', help='build PlaygroundSupport') projects_group.add_argument( '--build-ninja', action=arguments.action.enable, help='build the Ninja tool') extra_actions_group = parser.add_argument_group( title='Extra actions to perform before or in addition to building') extra_actions_group.add_argument( '-c', '--clean', action='store_true', help='do a clean build') extra_actions_group.add_argument( '--export-compile-commands', action=arguments.action.enable, help='generate compilation databases in addition to building') extra_actions_group.add_argument( '--symbols-package', metavar='PATH', help='if provided, an archive of the symbols directory will be ' 'generated at this path') build_variant_group = parser.add_mutually_exclusive_group(required=False) build_variant_group.add_argument( '-d', '--debug', action='store_const', const='Debug', dest='build_variant', help='build the Debug variant of everything (LLVM, Clang, Swift host ' 'tools, target Swift standard libraries, LLDB (if enabled) ' '(default)') build_variant_group.add_argument( '-r', '--release-debuginfo', action='store_const', const='RelWithDebInfo', dest='build_variant', help='build the RelWithDebInfo variant of everything (default is ' 'Debug)') build_variant_group.add_argument( '-R', '--release', action='store_const', const='Release', dest='build_variant', help='build the Release variant of everything (default is Debug)') build_variant_override_group = parser.add_argument_group( title='Override build variant for a specific project') build_variant_override_group.add_argument( '--debug-llvm', action='store_const', const='Debug', dest='llvm_build_variant', help='build the Debug variant of LLVM') build_variant_override_group.add_argument( '--debug-swift', action='store_const', const='Debug', dest='swift_build_variant', help='build the Debug variant of Swift host tools') build_variant_override_group.add_argument( '--debug-swift-stdlib', action='store_const', const='Debug', dest='swift_stdlib_build_variant', help='build the Debug variant of the Swift standard library and SDK ' 'overlay') build_variant_override_group.add_argument( '--debug-lldb', action='store_const', const='Debug', dest='lldb_build_variant', help='build the Debug variant of LLDB') build_variant_override_group.add_argument( '--debug-cmark', action='store_const', const='Debug', dest='cmark_build_variant', help='build the Debug variant of CommonMark') build_variant_override_group.add_argument( '--debug-foundation', action='store_const', const='Debug', dest='foundation_build_variant', help='build the Debug variant of Foundation') build_variant_override_group.add_argument( '--debug-libdispatch', action='store_const', const='Debug', dest='libdispatch_build_variant', help='build the Debug variant of libdispatch') build_variant_override_group.add_argument( '--debug-libicu', action='store_const', const='Debug', dest='libicu_build_variant', help='build the Debug variant of libicu') assertions_group = parser.add_mutually_exclusive_group(required=False) assertions_group.add_argument( '--assertions', action='store_const', const=True, dest='assertions', help='enable assertions in all projects') assertions_group.add_argument( '--no-assertions', action='store_const', const=False, dest='assertions', help='disable assertions in all projects') assertions_override_group = parser.add_argument_group( title='Control assertions in a specific project') assertions_override_group.add_argument( '--cmark-assertions', action='store_const', const=True, dest='cmark_assertions', help='enable assertions in CommonMark') assertions_override_group.add_argument( '--llvm-assertions', action='store_const', const=True, dest='llvm_assertions', help='enable assertions in LLVM') assertions_override_group.add_argument( '--no-llvm-assertions', action='store_const', const=False, dest='llvm_assertions', help='disable assertions in LLVM') assertions_override_group.add_argument( '--swift-assertions', action='store_const', const=True, dest='swift_assertions', help='enable assertions in Swift') assertions_override_group.add_argument( '--no-swift-assertions', action='store_const', const=False, dest='swift_assertions', help='disable assertions in Swift') assertions_override_group.add_argument( '--swift-stdlib-assertions', action='store_const', const=True, dest='swift_stdlib_assertions', help='enable assertions in the Swift standard library') assertions_override_group.add_argument( '--no-swift-stdlib-assertions', action='store_const', const=False, dest='swift_stdlib_assertions', help='disable assertions in the Swift standard library') assertions_override_group.add_argument( '--lldb-assertions', action='store_const', const=True, dest='lldb_assertions', help='enable assertions in LLDB') assertions_override_group.add_argument( '--no-lldb-assertions', action='store_const', const=False, dest='lldb_assertions', help='disable assertions in LLDB') # FIXME: This should be one option using choices=[...] cmake_generator_group = parser.add_argument_group( title='Select the CMake generator') cmake_generator_group.add_argument( '-x', '--xcode', action='store_const', const='Xcode', dest='cmake_generator', help="use CMake's Xcode generator (default is Ninja)") cmake_generator_group.add_argument( '-m', '--make', action='store_const', const='Unix Makefiles', dest='cmake_generator', help="use CMake's Makefile generator (default is Ninja)") cmake_generator_group.add_argument( '-e', '--eclipse', action='store_const', const='Eclipse CDT4 - Ninja', dest='cmake_generator', help="use CMake's Eclipse generator (default is Ninja)") run_tests_group = parser.add_argument_group( title='Run tests') # NOTE: We can't merge -t and --test, because nargs='?' makes # `-ti` to be treated as `-t=i`. run_tests_group.add_argument( '-t', action='store_const', const=True, dest='test', help='test Swift after building') run_tests_group.add_argument( '--test', action=arguments.action.enable, help='test Swift after building') run_tests_group.add_argument( '-T', action='store_const', const=True, dest='validation_test', help='run the validation test suite (implies --test)') run_tests_group.add_argument( '--validation-test', action=arguments.action.enable, help='run the validation test suite (implies --test)') run_tests_group.add_argument( '--test-paths', action=arguments.action.concat, type=arguments.type.shell_split, default=[], help='run tests located in specific directories and/or files ' '(implies --test and/or --validation-test)') run_tests_group.add_argument( '-o', action='store_const', const=True, dest='test_optimized', help='run the test suite in optimized mode too (implies --test)') run_tests_group.add_argument( '--test-optimized', action=arguments.action.enable, help='run the test suite in optimized mode too (implies --test)') run_tests_group.add_argument( '-s', action='store_const', const=True, dest='test_optimize_for_size', help='run the test suite in optimize for size mode too ' '(implies --test)') run_tests_group.add_argument( '--test-optimize-for-size', action=arguments.action.enable, help='run the test suite in optimize for size mode too ' '(implies --test)') run_tests_group.add_argument( '--long-test', action=arguments.action.enable, help='run the long test suite') run_tests_group.add_argument( '--host-test', action=arguments.action.enable, help='run executable tests on host devices (such as iOS or tvOS)') run_tests_group.add_argument( '-B', '--benchmark', action='store_true', help='run the Swift Benchmark Suite after building') run_tests_group.add_argument( '--benchmark-num-o-iterations', type=int, default=3, metavar='N', help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -O') run_tests_group.add_argument( '--benchmark-num-onone-iterations', type=int, default=3, metavar='N', help='if the Swift Benchmark Suite is run after building, run N ' 'iterations with -Onone') run_tests_group.add_argument( '--skip-test-osx', action=arguments.action.disable, dest='test_osx', help='skip testing Swift stdlibs for Mac OS X') run_tests_group.add_argument( '--skip-test-linux', action=arguments.action.disable, dest='test_linux', help='skip testing Swift stdlibs for Linux') run_tests_group.add_argument( '--skip-test-freebsd', action=arguments.action.disable, dest='test_freebsd', help='skip testing Swift stdlibs for FreeBSD') run_tests_group.add_argument( '--skip-test-cygwin', action=arguments.action.disable, dest='test_cygwin', help='skip testing Swift stdlibs for Cygwin') run_build_group = parser.add_argument_group( title='Run build') run_build_group.add_argument( '--build-swift-dynamic-stdlib', action=arguments.action.enable, default=True, help='build dynamic variants of the Swift standard library') run_build_group.add_argument( '--build-swift-static-stdlib', action=arguments.action.enable, help='build static variants of the Swift standard library') run_build_group.add_argument( '--build-swift-dynamic-sdk-overlay', action=arguments.action.enable, default=True, help='build dynamic variants of the Swift SDK overlay') run_build_group.add_argument( '--build-swift-static-sdk-overlay', action=arguments.action.enable, help='build static variants of the Swift SDK overlay') run_build_group.add_argument( '--build-swift-stdlib-unittest-extra', action=arguments.action.enable, help='Build optional StdlibUnittest components') run_build_group.add_argument( '-S', '--skip-build', action='store_true', help='generate build directory only without building') run_build_group.add_argument( '--skip-build-linux', action=arguments.action.disable, dest='build_linux', help='skip building Swift stdlibs for Linux') run_build_group.add_argument( '--skip-build-freebsd', action=arguments.action.disable, dest='build_freebsd', help='skip building Swift stdlibs for FreeBSD') run_build_group.add_argument( '--skip-build-cygwin', action=arguments.action.disable, dest='build_cygwin', help='skip building Swift stdlibs for Cygwin') run_build_group.add_argument( '--skip-build-osx', action=arguments.action.disable, dest='build_osx', help='skip building Swift stdlibs for MacOSX') run_build_group.add_argument( '--skip-build-ios', action=arguments.action.disable, dest='build_ios', help='skip building Swift stdlibs for iOS') run_build_group.add_argument( '--skip-build-ios-device', action=arguments.action.disable, dest='build_ios_device', help='skip building Swift stdlibs for iOS devices ' '(i.e. build simulators only)') run_build_group.add_argument( '--skip-build-ios-simulator', action=arguments.action.disable, dest='build_ios_simulator', help='skip building Swift stdlibs for iOS simulator ' '(i.e. build devices only)') run_build_group.add_argument( '--skip-build-tvos', action=arguments.action.disable, dest='build_tvos', help='skip building Swift stdlibs for tvOS') run_build_group.add_argument( '--skip-build-tvos-device', action=arguments.action.disable, dest='build_tvos_device', help='skip building Swift stdlibs for tvOS devices ' '(i.e. build simulators only)') run_build_group.add_argument( '--skip-build-tvos-simulator', action=arguments.action.disable, dest='build_tvos_simulator', help='skip building Swift stdlibs for tvOS simulator ' '(i.e. build devices only)') run_build_group.add_argument( '--skip-build-watchos', action=arguments.action.disable, dest='build_watchos', help='skip building Swift stdlibs for watchOS') run_build_group.add_argument( '--skip-build-watchos-device', action=arguments.action.disable, dest='build_watchos_device', help='skip building Swift stdlibs for watchOS devices ' '(i.e. build simulators only)') run_build_group.add_argument( '--skip-build-watchos-simulator', action=arguments.action.disable, dest='build_watchos_simulator', help='skip building Swift stdlibs for watchOS simulator ' '(i.e. build devices only)') run_build_group.add_argument( '--skip-build-android', action=arguments.action.disable, dest='build_android', help='skip building Swift stdlibs for Android') run_build_group.add_argument( '--skip-build-benchmarks', action=arguments.action.disable, dest='build_benchmarks', help='skip building Swift Benchmark Suite') run_build_group.add_argument( '--build-external-benchmarks', action=arguments.action.enable, dest='build_external_benchmarks', help='skip building Swift Benchmark Suite') skip_test_group = parser.add_argument_group( title='Skip testing specified targets') skip_test_group.add_argument( '--skip-test-ios', action=arguments.action.disable, dest='test_ios', help='skip testing all iOS targets. Equivalent to specifying both ' '--skip-test-ios-simulator and --skip-test-ios-host') skip_test_group.add_argument( '--skip-test-ios-simulator', action=arguments.action.disable, dest='test_ios_simulator', help='skip testing iOS simulator targets') skip_test_group.add_argument( '--skip-test-ios-32bit-simulator', action=arguments.action.disable, dest='test_ios_32bit_simulator', help='skip testing iOS 32 bit simulator targets') skip_test_group.add_argument( '--skip-test-ios-host', action=arguments.action.disable, dest='test_ios_host', help='skip testing iOS device targets on the host machine (the phone ' 'itself)') skip_test_group.add_argument( '--skip-test-tvos', action=arguments.action.disable, dest='test_tvos', help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-tvos-simulator and --skip-test-tvos-host') skip_test_group.add_argument( '--skip-test-tvos-simulator', action=arguments.action.disable, dest='test_tvos_simulator', help='skip testing tvOS simulator targets') skip_test_group.add_argument( '--skip-test-tvos-host', action=arguments.action.disable, dest='test_tvos_host', help='skip testing tvOS device targets on the host machine (the TV ' 'itself)') skip_test_group.add_argument( '--skip-test-watchos', action=arguments.action.disable, dest='test_watchos', help='skip testing all tvOS targets. Equivalent to specifying both ' '--skip-test-watchos-simulator and --skip-test-watchos-host') skip_test_group.add_argument( '--skip-test-watchos-simulator', action=arguments.action.disable, dest='test_watchos_simulator', help='skip testing watchOS simulator targets') skip_test_group.add_argument( '--skip-test-watchos-host', action=arguments.action.disable, dest='test_watchos_host', help='skip testing watchOS device targets on the host machine (the ' 'watch itself)') skip_test_group.add_argument( '--skip-test-android-host', action=arguments.action.disable, dest='test_android_host', help='skip testing Android device targets on the host machine (the ' 'phone itself)') llvm_group = parser.add_argument_group( title='Build settings specific for LLVM') llvm_group.add_argument( '--llvm-targets-to-build', default='X86;ARM;AArch64;PowerPC;SystemZ;Mips', help='LLVM target generators to build') android_group = parser.add_argument_group( title='Build settings for Android') android_group.add_argument( '--android-ndk', metavar='PATH', help='An absolute path to the NDK that will be used as a libc ' 'implementation for Android builds') android_group.add_argument( '--android-api-level', default='21', help='The Android API level to target when building for Android. ' 'Currently only 21 or above is supported') android_group.add_argument( '--android-ndk-gcc-version', choices=['4.8', '4.9'], default='4.9', help='The GCC version to use when building for Android. Currently ' 'only 4.9 is supported. %(default)s is also the default value. ' 'This option may be used when experimenting with versions ' 'of the Android NDK not officially supported by Swift') android_group.add_argument( '--android-icu-uc', metavar='PATH', help='Path to a directory containing libicuuc.so') android_group.add_argument( '--android-icu-uc-include', metavar='PATH', help='Path to a directory containing headers for libicuuc') android_group.add_argument( '--android-icu-i18n', metavar='PATH', help='Path to a directory containing libicui18n.so') android_group.add_argument( '--android-icu-i18n-include', metavar='PATH', help='Path to a directory containing headers libicui18n') android_group.add_argument( '--android-deploy-device-path', default=android.adb.commands.DEVICE_TEMP_DIR, metavar='PATH', help='Path on an Android device to which built Swift stdlib products ' 'will be deployed. If running host tests, specify the "{}" ' 'directory.'.format(android.adb.commands.DEVICE_TEMP_DIR)) return parser