def build()

in build_script.py [0:0]


    def build(args):
        """
        Build XCTest and place the built products in the given 'build_dir'.
        If 'test' is specified, also executes the 'test' subcommand.
        """
        swiftc = os.path.abspath(args.swiftc)
        build_dir = os.path.abspath(args.build_dir)
        static_lib_build_dir = GenericUnixStrategy.static_lib_build_dir(build_dir)
        foundation_build_dir = os.path.abspath(args.foundation_build_dir)
        swift_build_dir = os.path.abspath(args.swift_build_dir)
        arch = platform.machine()
        core_foundation_build_dir = GenericUnixStrategy.core_foundation_build_dir(
            foundation_build_dir, args.foundation_install_prefix)
        if args.libdispatch_build_dir:
            libdispatch_build_dir = os.path.abspath(args.libdispatch_build_dir)
        if args.libdispatch_src_dir:
            libdispatch_src_dir = os.path.abspath(args.libdispatch_src_dir)

        _mkdirp(build_dir)

        sourcePaths = _find_files_with_extension(
                os.path.join(SOURCE_DIR, 'Sources', 'XCTest'),
                'swift')

        if args.build_style == "debug":
            style_options = "-g"
        else:
            style_options = "-O"

        # Not incremental..
        # Build library
        if args.libdispatch_build_dir and args.libdispatch_src_dir:
            libdispatch_args = "-I {libdispatch_build_dir}/src -I {libdispatch_src_dir} ".format(
                libdispatch_build_dir=libdispatch_build_dir,
                libdispatch_src_dir=libdispatch_src_dir)
        else:
            libdispatch_args = ""

        # NOTE: Force -swift-version 5 to build XCTest sources.
        run("{swiftc} -Xcc -fblocks -c {style_options} -emit-object -emit-module "
            "-module-name XCTest -module-link-name XCTest -parse-as-library "
            "-emit-module-path {build_dir}/XCTest.swiftmodule "
            "-force-single-frontend-invocation "
            "-swift-version 5 "
            "-I {foundation_build_dir} -I {core_foundation_build_dir} "
            "{libdispatch_args} "
            "{source_paths} -o {build_dir}/XCTest.o".format(
                swiftc=swiftc,
                style_options=style_options,
                build_dir=build_dir,
                foundation_build_dir=foundation_build_dir,
                core_foundation_build_dir=core_foundation_build_dir,
                libdispatch_args=libdispatch_args,
                source_paths=" ".join(sourcePaths)))
        run("{swiftc} -emit-library {build_dir}/XCTest.o "
            "-L {dispatch_build_dir} -L {foundation_build_dir} -L {swift_build_dir} "
            "-lswiftGlibc -lswiftCore -lFoundation -lm "
            # We embed an rpath of `$ORIGIN` to ensure other referenced
            # libraries (like `Foundation`) can be found solely via XCTest.
            "-Xlinker -rpath=\\$ORIGIN "
            "-o {build_dir}/libXCTest.so".format(
                swiftc=swiftc,
                build_dir=build_dir,
                dispatch_build_dir=os.path.join(args.libdispatch_build_dir, 'src', '.libs'),
                foundation_build_dir=foundation_build_dir,
                swift_build_dir=os.path.join(args.swift_build_dir, 'lib', 'swift', 'linux', arch)))

        # Build the static library.
        run("mkdir -p {static_lib_build_dir}".format(static_lib_build_dir=static_lib_build_dir))
        run("ar rcs {static_lib_build_dir}/libXCTest.a {build_dir}/XCTest.o".format(
            static_lib_build_dir=static_lib_build_dir,
            build_dir=build_dir))

        if args.test:
            # Execute main() using the arguments necessary to run the tests.
            main(args=["test",
                       "--swiftc", swiftc,
                       "--foundation-build-dir", foundation_build_dir,
                       build_dir])

        # If --module-install-path and --library-install-path were specified,
        # we also install the built XCTest products.
        if args.module_path is not None and args.lib_path is not None:
            # Execute main() using the arguments necessary for installation.
            install_args = ["install", build_dir,
                       "--module-install-path", args.module_path,
                       "--library-install-path", args.lib_path]
            if args.static_lib_path:
                       install_args += ["--static-library-install-path",
                           args.static_lib_path]
            main(args=install_args)

        note('Done.')