@@ -50,7 +50,11 @@ from swift_build_support.cmake import CMake # noqa (E402)
50
50
import swift_build_support .workspace # noqa (E402)
51
51
52
52
53
- def call_without_sleeping (command , env = None , dry_run = False ):
53
+ build_script_impl = os .path .join (
54
+ SWIFT_SOURCE_ROOT , "swift" , "utils" , "build-script-impl" )
55
+
56
+
57
+ def call_without_sleeping (command , env = None , dry_run = False , echo = False ):
54
58
"""
55
59
Execute a command during which system sleep is disabled.
56
60
@@ -62,7 +66,7 @@ def call_without_sleeping(command, env=None, dry_run=False):
62
66
# Don't mutate the caller's copy of the arguments.
63
67
command = ["caffeinate" ] + list (command )
64
68
65
- shell .call (command , env = env , dry_run = dry_run )
69
+ shell .call (command , env = env , dry_run = dry_run , echo = echo )
66
70
67
71
68
72
class HostSpecificConfiguration (object ):
@@ -774,6 +778,115 @@ class BuildScriptInvocation(object):
774
778
775
779
return options
776
780
781
+ def compute_product_classes (self ):
782
+ """compute_product_classes() -> list
783
+
784
+ Compute the list of all Product classes used in this build. This list
785
+ is constructed in dependency order.
786
+ """
787
+
788
+ # FIXME: This is a weird division (returning a list of class objects),
789
+ # but it matches the existing structure of the `build-script-impl`.
790
+
791
+ product_classes = []
792
+ product_classes .append (products .CMark )
793
+ product_classes .append (products .LLVM )
794
+ product_classes .append (products .Swift )
795
+ if self .args .build_lldb :
796
+ product_classes .append (products .LLDB )
797
+ if self .args .build_llbuild :
798
+ product_classes .append (products .LLBuild )
799
+ if self .args .build_libdispatch :
800
+ product_classes .append (products .LibDispatch )
801
+ if self .args .build_foundation :
802
+ product_classes .append (products .Foundation )
803
+ if self .args .build_xctest :
804
+ product_classes .append (products .XCTest )
805
+ if self .args .build_swiftpm :
806
+ product_classes .append (products .SwiftPM )
807
+ return product_classes
808
+
809
+ def execute (self ):
810
+ """Execute the invocation with the configured arguments."""
811
+
812
+ # Convert to a build-script-impl invocation.
813
+ (impl_env , impl_args ) = self .convert_to_impl_arguments ()
814
+
815
+ # If using the legacy implementation, delegate all behavior to
816
+ # `build-script-impl`.
817
+ if self .args .legacy_impl :
818
+ # Execute the underlying build script implementation.
819
+ call_without_sleeping ([build_script_impl ] + impl_args ,
820
+ env = impl_env , echo = True )
821
+ return
822
+
823
+ # Otherwise, we compute and execute the individual actions ourselves.
824
+
825
+ def execute_one_impl_action (host = None , product_class = None , name = None ):
826
+ if host is None :
827
+ assert (product_class is None and
828
+ name == "merged-hosts-lipo" ), "invalid action"
829
+ action_name = name
830
+ elif product_class is None :
831
+ assert name == "package" , "invalid action"
832
+ action_name = "{}-{}" .format (host .name , name )
833
+ else :
834
+ assert name is not None , "invalid action"
835
+ action_name = "{}-{}-{}" .format (
836
+ host .name , product_class .product_name (), name )
837
+ call_without_sleeping (
838
+ [build_script_impl ] + impl_args + [
839
+ "--only-execute" , action_name ],
840
+ env = impl_env , echo = self .args .verbose_build )
841
+
842
+ # Compute the list of hosts to operate on.
843
+ all_host_names = [
844
+ self .args .host_target ] + self .args .cross_compile_hosts
845
+ all_hosts = [StdlibDeploymentTarget .get_target_for_name (name )
846
+ for name in all_host_names ]
847
+
848
+ # Compute the list of product classes to operate on.
849
+ #
850
+ # FIXME: This should really be per-host, but the current structure
851
+ # matches that of `build-script-impl`.
852
+ product_classes = self .compute_product_classes ()
853
+
854
+ # Execute each "pass".
855
+
856
+ # Build...
857
+ for host_target in all_hosts :
858
+ # FIXME: We should only compute these once.
859
+ config = HostSpecificConfiguration (host_target .name , self )
860
+ print ("Building the standard library for: {}" .format (
861
+ " " .join (config .swift_stdlib_build_targets )))
862
+ if config .swift_test_run_targets and (
863
+ self .args .test or self .args .long_test ):
864
+ print ("Running Swift tests for: {}" .format (
865
+ " " .join (config .swift_test_run_targets )))
866
+ if config .swift_benchmark_run_targets and self .args .benchmark :
867
+ print ("Running Swift benchmarks for: {}" .format (
868
+ " " .join (config .swift_benchmark_run_targets )))
869
+
870
+ for product_class in product_classes :
871
+ execute_one_impl_action (host_target , product_class , "build" )
872
+
873
+ # Test...
874
+ for host_target in all_hosts :
875
+ for product_class in product_classes :
876
+ execute_one_impl_action (host_target , product_class , "test" )
877
+
878
+ # Install...
879
+ for host_target in all_hosts :
880
+ for product_class in product_classes :
881
+ execute_one_impl_action (host_target , product_class , "install" )
882
+
883
+ # Package...
884
+ for host_target in all_hosts :
885
+ execute_one_impl_action (host_target , name = "package" )
886
+
887
+ # Lipo...
888
+ execute_one_impl_action (name = "merged-hosts-lipo" )
889
+
777
890
778
891
# Main entry point for the preset mode.
779
892
def main_preset ():
@@ -1042,6 +1155,11 @@ details of the setups of other systems or automated environments.""")
1042
1155
"them" ,
1043
1156
action = "store_true" ,
1044
1157
default = False )
1158
+ parser .add_argument (
1159
+ "--no-legacy-impl" , dest = "legacy_impl" ,
1160
+ help = "avoid legacy implementation" ,
1161
+ action = "store_false" ,
1162
+ default = True )
1045
1163
1046
1164
targets_group = parser .add_argument_group (
1047
1165
title = "Host and cross-compilation targets" )
@@ -1739,9 +1857,6 @@ details of the setups of other systems or automated environments.""")
1739
1857
1740
1858
args = migration .parse_args (parser , sys .argv [1 :])
1741
1859
1742
- build_script_impl = os .path .join (
1743
- SWIFT_SOURCE_ROOT , "swift" , "utils" , "build-script-impl" )
1744
-
1745
1860
if args .build_script_impl_args :
1746
1861
# If we received any impl args, check if `build-script-impl` would
1747
1862
# accept them or not before any further processing.
@@ -1795,13 +1910,8 @@ details of the setups of other systems or automated environments.""")
1795
1910
if args .build_ninja :
1796
1911
invocation .build_ninja ()
1797
1912
1798
- # Convert to a build-script-impl invocation.
1799
- (build_script_impl_env , build_script_impl_args ) = \
1800
- invocation .convert_to_impl_arguments ()
1801
-
1802
1913
# Execute the underlying build script implementation.
1803
- call_without_sleeping ([build_script_impl ] + build_script_impl_args ,
1804
- env = build_script_impl_env )
1914
+ invocation .execute ()
1805
1915
1806
1916
if args .symbols_package :
1807
1917
print ('--- Creating symbols package ---' )
0 commit comments