@@ -14,6 +14,7 @@ from __future__ import print_function
14
14
import argparse
15
15
import multiprocessing
16
16
import os
17
+ import platform
17
18
import shutil
18
19
import sys
19
20
import textwrap
@@ -32,11 +33,15 @@ from SwiftBuildSupport import (
32
33
get_preset_options ,
33
34
print_with_argv0 ,
34
35
quote_shell_command ,
36
+ WorkingDirectory ,
35
37
)
36
38
37
39
sys .path .append (os .path .join (os .path .dirname (__file__ ), 'swift_build_support' ))
38
40
import swift_build_support .clang
39
41
import swift_build_support .cmake
42
+ import swift_build_support .debug
43
+ import swift_build_support .ninja
44
+ import swift_build_support .tar
40
45
import swift_build_support .targets
41
46
from swift_build_support .migration import migrate_impl_args
42
47
@@ -333,6 +338,10 @@ details of the setups of other systems or automated environments.""")
333
338
extra_actions_group .add_argument ("--export-compile-commands" ,
334
339
help = "generate compilation databases in addition to building" ,
335
340
action = "store_true" )
341
+ extra_actions_group .add_argument ("--symbols-package" ,
342
+ metavar = "PATH" ,
343
+ help = "if provided, an archive of the symbols directory will be "
344
+ "generated at this path" )
336
345
337
346
build_variant_group = parser .add_mutually_exclusive_group (required = False )
338
347
build_variant_group .add_argument ("-d" , "--debug" ,
@@ -530,6 +539,14 @@ also build for Apple watchos, but disallow tests that require an watchOS device"
530
539
name of the directory under $SWIFT_BUILD_ROOT where the build products will be
531
540
placed""" ,
532
541
metavar = "PATH" )
542
+ parser .add_argument ("--install-prefix" ,
543
+ help = "The installation prefix. This is where built Swift products "
544
+ "(like bin, lib, and include) will be installed." ,
545
+ metavar = "PATH" ,
546
+ default = swift_build_support .targets .install_prefix ())
547
+ parser .add_argument ("--install-symroot" ,
548
+ help = "the path to install debug symbols into" ,
549
+ metavar = "PATH" )
533
550
534
551
parser .add_argument ("-j" , "--jobs" ,
535
552
help = """
@@ -544,6 +561,9 @@ the number of parallel build jobs to use""",
544
561
parser .add_argument ("--cmake" ,
545
562
help = "the path to a CMake executable that will be "
546
563
"used to build Swift" )
564
+ parser .add_argument ("--show-sdks" ,
565
+ help = "print installed Xcode and SDK versions" ,
566
+ action = "store_true" )
547
567
548
568
parser .add_argument ("--extra-swift-args" , help = textwrap .dedent ("""
549
569
Pass through extra flags to swift in the form of a cmake list 'module_regexp;flag'. Can
@@ -559,12 +579,27 @@ the number of parallel build jobs to use""",
559
579
'--darwin-xcrun-toolchain' ,
560
580
'--cmake' ,
561
581
'--host-target' ,
582
+ '--skip-build' ,
583
+ '--show-sdks' ,
584
+ '--install-prefix' ,
585
+ '--install-symroot' ,
586
+ '--symbols-package' ,
562
587
]))
563
588
564
589
if args .host_target is None :
565
590
print_with_argv0 ("Unknown operating system." )
566
591
return 1
567
592
593
+ if args .symbols_package :
594
+ if not os .path .isabs (args .symbols_package ):
595
+ print ('--symbols-package must be an absolute path '
596
+ '(was \' {}\' )' .format (args .symbols_package ))
597
+ return 1
598
+ if not args .install_symroot :
599
+ print_with_argv0 ("--install-symroot is required when specifying "
600
+ "--symbols-package." )
601
+ return 1
602
+
568
603
# Build cmark if any cmark-related options were specified.
569
604
if (args .cmark_build_variant is not None ):
570
605
args .build_cmark = True
@@ -726,7 +761,32 @@ the number of parallel build jobs to use""",
726
761
727
762
if args .skip_build :
728
763
build_script_impl_inferred_args += [
729
- "--skip-build"
764
+ "--skip-build-cmark" ,
765
+ "--skip-build-llvm" ,
766
+ "--skip-build-swift" ,
767
+ "--skip-build-osx" ,
768
+ "--skip-build-ios" ,
769
+ "--skip-build-ios-device" ,
770
+ "--skip-build-ios-simulator" ,
771
+ "--skip-build-tvos" ,
772
+ "--skip-build-tvos_device" ,
773
+ "--skip-build-tvos-simulator" ,
774
+ "--skip-build-watchos" ,
775
+ "--skip-build-watchos-device" ,
776
+ "--skip-build-watchos-simulator" ,
777
+ "--skip-build-lldb" ,
778
+ "--skip-build-llbuild" ,
779
+ "--skip-build-swiftpm" ,
780
+ "--skip-build-xctest" ,
781
+ "--skip-build-foundation" ,
782
+ "--skip-build-libdispatch" ,
783
+ "--skip-build-benchmarks" ,
784
+ ]
785
+
786
+ if platform .system () == 'Darwin' :
787
+ build_script_impl_inferred_args += [
788
+ "--toolchain-prefix" ,
789
+ swift_build_support .targets .darwin_toolchain_prefix (args .install_prefix ),
730
790
]
731
791
732
792
if args .build_subdir is None :
@@ -804,6 +864,7 @@ the number of parallel build jobs to use""",
804
864
build_script_impl_args = [
805
865
os .path .join (SWIFT_SOURCE_ROOT , "swift" , "utils" , "build-script-impl" ),
806
866
"--build-dir" , build_dir ,
867
+ "--install-prefix" , os .path .abspath (args .install_prefix ),
807
868
"--host-target" , args .host_target ,
808
869
"--host-cc" , host_clang .cc ,
809
870
"--host-cxx" , host_clang .cxx ,
@@ -826,6 +887,9 @@ the number of parallel build jobs to use""",
826
887
build_script_impl_args += [
827
888
"--foundation-build-type" , args .foundation_build_variant
828
889
]
890
+ if args .cmake_generator == 'Ninja' and \
891
+ not swift_build_support .ninja .is_ninja_installed ():
892
+ build_script_impl_args += ["--build-ninja" ]
829
893
build_script_impl_args += build_script_impl_inferred_args
830
894
831
895
# If we have extra_swift_args, combine all of them together and then add
@@ -839,8 +903,33 @@ the number of parallel build jobs to use""",
839
903
for v in ['MAKEFLAGS' , 'SDKROOT' , 'MACOSX_DEPLOYMENT_TARGET' , 'IPHONEOS_DEPLOYMENT_TARGET' ]:
840
904
os .environ .pop (v , None )
841
905
906
+ if args .show_sdks :
907
+ swift_build_support .debug .print_xcodebuild_versions ([
908
+ 'iphonesimulator' ,
909
+ 'appletvsimulator' ,
910
+ 'watchsimulator' ,
911
+ ])
912
+
842
913
check_call (build_script_impl_args )
843
914
915
+ if args .symbols_package :
916
+ print ('--- Creating symbols package ---' )
917
+ print ('-- Package file: {} --' .format (args .symbols_package ))
918
+
919
+ if platform .system () == 'Darwin' :
920
+ prefix = swift_build_support .targets .darwin_toolchain_prefix (
921
+ args .install_prefix )
922
+ else :
923
+ prefix = args .install_prefix
924
+
925
+ # As a security measure, `tar` normally strips leading '/' from paths
926
+ # it is archiving. To stay safe, we change working directories, then
927
+ # run `tar` without the leading '/' (we remove it ourselves to keep
928
+ # `tar` from emitting a warning).
929
+ with WorkingDirectory (args .install_symroot ):
930
+ swift_build_support .tar .tar (source = prefix .lstrip ('/' ),
931
+ destination = args .symbols_package )
932
+
844
933
return 0
845
934
846
935
0 commit comments