@@ -152,6 +152,7 @@ def build(args):
152
152
"""
153
153
swiftc = os .path .abspath (args .swiftc )
154
154
build_dir = os .path .abspath (args .build_dir )
155
+ static_lib_build_dir = GenericUnixStrategy .static_lib_build_dir (build_dir )
155
156
foundation_build_dir = os .path .abspath (args .foundation_build_dir )
156
157
core_foundation_build_dir = GenericUnixStrategy .core_foundation_build_dir (
157
158
foundation_build_dir , args .foundation_install_prefix )
@@ -206,6 +207,12 @@ def build(args):
206
207
build_dir = build_dir ,
207
208
foundation_build_dir = foundation_build_dir ))
208
209
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
+
209
216
if args .test :
210
217
# Execute main() using the arguments necessary to run the tests.
211
218
main (args = ["test" ,
@@ -217,9 +224,13 @@ def build(args):
217
224
# we also install the built XCTest products.
218
225
if args .module_path is not None and args .lib_path is not None :
219
226
# Execute main() using the arguments necessary for installation.
220
- main ( args = ["install" , build_dir ,
227
+ install_args = ["install" , build_dir ,
221
228
"--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 )
223
234
224
235
note ('Done.' )
225
236
@@ -286,6 +297,7 @@ def install(args):
286
297
products into the given module and library paths.
287
298
"""
288
299
build_dir = os .path .abspath (args .build_dir )
300
+ static_lib_build_dir = GenericUnixStrategy .static_lib_build_dir (build_dir )
289
301
module_install_path = os .path .abspath (args .module_install_path )
290
302
library_install_path = os .path .abspath (args .library_install_path )
291
303
@@ -307,6 +319,14 @@ def install(args):
307
319
os .path .join (build_dir , xctest_swiftdoc ),
308
320
os .path .join (module_install_path , xctest_swiftdoc )))
309
321
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
+
310
330
@staticmethod
311
331
def core_foundation_build_dir (foundation_build_dir , foundation_install_prefix ):
312
332
"""
@@ -322,6 +342,16 @@ def core_foundation_build_dir(foundation_build_dir, foundation_install_prefix):
322
342
return os .path .join (foundation_build_dir ,
323
343
foundation_install_prefix .strip ("/" ), 'lib' , 'swift' )
324
344
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
+
325
355
326
356
def main (args = sys .argv [1 :]):
327
357
"""
@@ -352,6 +382,7 @@ def main(args=sys.argv[1:]):
352
382
--build-dir="/tmp/XCTest_build" \\
353
383
--foundation-build-dir "/swift/usr/lib/swift/linux" \\
354
384
--library-install-path="/swift/usr/lib/swift/linux" \\
385
+ --static-library-install-path="/swift/usr/lib/swift_static/linux" \\
355
386
--module-install-path="/swift/usr/lib/swift/linux/x86_64"
356
387
357
388
Note that installation is not supported on Darwin as this library
@@ -416,6 +447,11 @@ def main(args=sys.argv[1:]):
416
447
help = "Location at which to install XCTest.so. This directory will be "
417
448
"created if it doesn't already exist." ,
418
449
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" )
419
455
build_parser .add_argument (
420
456
"--release" ,
421
457
help = "builds for release" ,
@@ -508,6 +544,10 @@ def main(args=sys.argv[1:]):
508
544
"-l" , "--library-install-path" ,
509
545
help = "Location at which to install XCTest.so. This directory will be "
510
546
"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." )
511
551
512
552
# Many versions of Python require a subcommand must be specified.
513
553
# We handle this here: if no known subcommand (or none of the help options)
0 commit comments