From 192a7eca6d1fc69c4f5c129ecdc4b1c820698d22 Mon Sep 17 00:00:00 2001 From: Simon Evans Date: Tue, 25 Apr 2017 09:10:00 +0100 Subject: [PATCH] Build a static library version of xctest libXCTest.a can optionally be installed with --static-library-install-path - Put the static libXCTest.a into a static/ subdir when building - This simplifies linking in static libraries over shared libraries when using -static-stdlib during build testing. --- build_script.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/build_script.py b/build_script.py index 8681155fe..e2b950466 100755 --- a/build_script.py +++ b/build_script.py @@ -152,6 +152,7 @@ def build(args): """ 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) core_foundation_build_dir = GenericUnixStrategy.core_foundation_build_dir( foundation_build_dir, args.foundation_install_prefix) @@ -206,6 +207,12 @@ def build(args): build_dir=build_dir, foundation_build_dir=foundation_build_dir)) + # 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", @@ -217,9 +224,13 @@ def build(args): # 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. - main(args=["install", build_dir, + install_args = ["install", build_dir, "--module-install-path", args.module_path, - "--library-install-path", args.lib_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.') @@ -286,6 +297,7 @@ def install(args): products into the given module and library paths. """ build_dir = os.path.abspath(args.build_dir) + static_lib_build_dir = GenericUnixStrategy.static_lib_build_dir(build_dir) module_install_path = os.path.abspath(args.module_install_path) library_install_path = os.path.abspath(args.library_install_path) @@ -307,6 +319,14 @@ def install(args): os.path.join(build_dir, xctest_swiftdoc), os.path.join(module_install_path, xctest_swiftdoc))) + if args.static_library_install_path: + static_library_install_path = os.path.abspath(args.static_library_install_path) + _mkdirp(static_library_install_path) + xctest_a = "libXCTest.a" + run("cp {} {}".format( + os.path.join(static_lib_build_dir, xctest_a), + os.path.join(static_library_install_path, xctest_a))) + @staticmethod def core_foundation_build_dir(foundation_build_dir, foundation_install_prefix): """ @@ -322,6 +342,16 @@ def core_foundation_build_dir(foundation_build_dir, foundation_install_prefix): return os.path.join(foundation_build_dir, foundation_install_prefix.strip("/"), 'lib', 'swift') + @staticmethod + def static_lib_build_dir(build_dir): + """ + Given the path to the build directory, return the path to be used for + the static library libXCTest.a. Putting it in a separate directory to + libXCTest.so simplifies static linking when building a static test + foundation. + """ + return os.path.join(build_dir, "static") + def main(args=sys.argv[1:]): """ @@ -352,6 +382,7 @@ def main(args=sys.argv[1:]): --build-dir="/tmp/XCTest_build" \\ --foundation-build-dir "/swift/usr/lib/swift/linux" \\ --library-install-path="/swift/usr/lib/swift/linux" \\ + --static-library-install-path="/swift/usr/lib/swift_static/linux" \\ --module-install-path="/swift/usr/lib/swift/linux/x86_64" Note that installation is not supported on Darwin as this library @@ -416,6 +447,11 @@ def main(args=sys.argv[1:]): help="Location at which to install XCTest.so. This directory will be " "created if it doesn't already exist.", dest="lib_path") + build_parser.add_argument( + "--static-library-install-path", + help="Location at which to install XCTest.a. This directory will be " + "created if it doesn't already exist.", + dest="static_lib_path") build_parser.add_argument( "--release", help="builds for release", @@ -508,6 +544,10 @@ def main(args=sys.argv[1:]): "-l", "--library-install-path", help="Location at which to install XCTest.so. This directory will be " "created if it doesn't already exist.") + install_parser.add_argument( + "-s", "--static-library-install-path", + help="Location at which to install XCTest.a. This directory will be " + "created if it doesn't already exist.") # Many versions of Python require a subcommand must be specified. # We handle this here: if no known subcommand (or none of the help options)