@@ -152,6 +152,7 @@ def build(args):
152152 """
153153 swiftc = os .path .abspath (args .swiftc )
154154 build_dir = os .path .abspath (args .build_dir )
155+ static_lib_build_dir = GenericUnixStrategy .static_lib_build_dir (build_dir )
155156 foundation_build_dir = os .path .abspath (args .foundation_build_dir )
156157 core_foundation_build_dir = GenericUnixStrategy .core_foundation_build_dir (
157158 foundation_build_dir , args .foundation_install_prefix )
@@ -206,6 +207,12 @@ def build(args):
206207 build_dir = build_dir ,
207208 foundation_build_dir = foundation_build_dir ))
208209
210+ # Build the static library.
211+ run ("mkdir -p {static_lib_build_dir}" .format (static_lib_build_dir = static_lib_build_dir ))
212+ run ("ar rcs {static_lib_build_dir}/libXCTest.a {build_dir}/XCTest.o" .format (
213+ static_lib_build_dir = static_lib_build_dir ,
214+ build_dir = build_dir ))
215+
209216 if args .test :
210217 # Execute main() using the arguments necessary to run the tests.
211218 main (args = ["test" ,
@@ -217,9 +224,13 @@ def build(args):
217224 # we also install the built XCTest products.
218225 if args .module_path is not None and args .lib_path is not None :
219226 # Execute main() using the arguments necessary for installation.
220- main ( args = ["install" , build_dir ,
227+ install_args = ["install" , build_dir ,
221228 "--module-install-path" , args .module_path ,
222- "--library-install-path" , args .lib_path ])
229+ "--library-install-path" , args .lib_path ]
230+ if args .static_lib_path :
231+ install_args += ["--static-library-install-path" ,
232+ args .static_lib_path ]
233+ main (args = install_args )
223234
224235 note ('Done.' )
225236
@@ -286,6 +297,7 @@ def install(args):
286297 products into the given module and library paths.
287298 """
288299 build_dir = os .path .abspath (args .build_dir )
300+ static_lib_build_dir = GenericUnixStrategy .static_lib_build_dir (build_dir )
289301 module_install_path = os .path .abspath (args .module_install_path )
290302 library_install_path = os .path .abspath (args .library_install_path )
291303
@@ -307,6 +319,14 @@ def install(args):
307319 os .path .join (build_dir , xctest_swiftdoc ),
308320 os .path .join (module_install_path , xctest_swiftdoc )))
309321
322+ if args .static_library_install_path :
323+ static_library_install_path = os .path .abspath (args .static_library_install_path )
324+ _mkdirp (static_library_install_path )
325+ xctest_a = "libXCTest.a"
326+ run ("cp {} {}" .format (
327+ os .path .join (static_lib_build_dir , xctest_a ),
328+ os .path .join (static_library_install_path , xctest_a )))
329+
310330 @staticmethod
311331 def core_foundation_build_dir (foundation_build_dir , foundation_install_prefix ):
312332 """
@@ -322,6 +342,16 @@ def core_foundation_build_dir(foundation_build_dir, foundation_install_prefix):
322342 return os .path .join (foundation_build_dir ,
323343 foundation_install_prefix .strip ("/" ), 'lib' , 'swift' )
324344
345+ @staticmethod
346+ def static_lib_build_dir (build_dir ):
347+ """
348+ Given the path to the build directory, return the path to be used for
349+ the static library libXCTest.a. Putting it in a separate directory to
350+ libXCTest.so simplifies static linking when building a static test
351+ foundation.
352+ """
353+ return os .path .join (build_dir , "static" )
354+
325355
326356def main (args = sys .argv [1 :]):
327357 """
@@ -352,6 +382,7 @@ def main(args=sys.argv[1:]):
352382 --build-dir="/tmp/XCTest_build" \\
353383 --foundation-build-dir "/swift/usr/lib/swift/linux" \\
354384 --library-install-path="/swift/usr/lib/swift/linux" \\
385+ --static-library-install-path="/swift/usr/lib/swift_static/linux" \\
355386 --module-install-path="/swift/usr/lib/swift/linux/x86_64"
356387
357388 Note that installation is not supported on Darwin as this library
@@ -416,6 +447,11 @@ def main(args=sys.argv[1:]):
416447 help = "Location at which to install XCTest.so. This directory will be "
417448 "created if it doesn't already exist." ,
418449 dest = "lib_path" )
450+ build_parser .add_argument (
451+ "--static-library-install-path" ,
452+ help = "Location at which to install XCTest.a. This directory will be "
453+ "created if it doesn't already exist." ,
454+ dest = "static_lib_path" )
419455 build_parser .add_argument (
420456 "--release" ,
421457 help = "builds for release" ,
@@ -508,6 +544,10 @@ def main(args=sys.argv[1:]):
508544 "-l" , "--library-install-path" ,
509545 help = "Location at which to install XCTest.so. This directory will be "
510546 "created if it doesn't already exist." )
547+ install_parser .add_argument (
548+ "-s" , "--static-library-install-path" ,
549+ help = "Location at which to install XCTest.a. This directory will be "
550+ "created if it doesn't already exist." )
511551
512552 # Many versions of Python require a subcommand must be specified.
513553 # We handle this here: if no known subcommand (or none of the help options)
0 commit comments