Skip to content

Build a static library version of xctest #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions build_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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.')

Expand Down Expand Up @@ -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)

Expand All @@ -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):
"""
Expand All @@ -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:]):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down