@@ -35,6 +35,7 @@ from build_swift.build_swift.constants import SWIFT_SOURCE_ROOT
3535
3636import six
3737
38+ from swift_build_support .swift_build_support import build_graph
3839from swift_build_support .swift_build_support import products
3940from swift_build_support .swift_build_support import shell
4041from swift_build_support .swift_build_support import targets
@@ -375,6 +376,10 @@ class BuildScriptInvocation(object):
375376
376377 self .build_libparser_only = args .build_libparser_only
377378
379+ @property
380+ def install_all (self ):
381+ return self .args .install_all or self .args .infer_dependencies
382+
378383 def build_ninja (self ):
379384 if not os .path .exists (self .workspace .source_dir ("ninja" )):
380385 fatal_error (
@@ -548,20 +553,28 @@ class BuildScriptInvocation(object):
548553 # Currently we do not build external benchmarks by default.
549554 if args .build_external_benchmarks :
550555 impl_args += ["--skip-build-external-benchmarks=0" ]
551- if not args .build_foundation :
552- impl_args += ["--skip-build-foundation" ]
553- if not args .build_xctest :
554- impl_args += ["--skip-build-xctest" ]
555- if not args .build_lldb :
556- impl_args += ["--skip-build-lldb" ]
557- if not args .build_llbuild :
558- impl_args += ["--skip-build-llbuild" ]
559- if not args .build_libcxx :
560- impl_args += ["--skip-build-libcxx" ]
561- if not args .build_libdispatch :
562- impl_args += ["--skip-build-libdispatch" ]
563- if not args .build_libicu :
564- impl_args += ["--skip-build-libicu" ]
556+
557+ # Then add subproject install flags that either skip building them /or/
558+ # if we are going to build them and install_all is set, we also install
559+ # them.
560+ conditional_subproject_configs = [
561+ (args .build_cmark , "cmark" ),
562+ (args .build_llvm , "llvm" ),
563+ (args .build_swift , "swift" ),
564+ (args .build_foundation , "foundation" ),
565+ (args .build_xctest , "xctest" ),
566+ (args .build_lldb , "lldb" ),
567+ (args .build_llbuild , "llbuild" ),
568+ (args .build_libcxx , "libcxx" ),
569+ (args .build_libdispatch , "libdispatch" ),
570+ (args .build_libicu , "libicu" )
571+ ]
572+ for (should_build , string_name ) in conditional_subproject_configs :
573+ if not should_build and not self .args .infer_dependencies :
574+ impl_args += ["--skip-build-{}" .format (string_name )]
575+ elif self .install_all :
576+ impl_args += ["--install-{}" .format (string_name )]
577+
565578 if args .build_swift_dynamic_stdlib :
566579 impl_args += ["--build-swift-dynamic-stdlib" ]
567580 if args .build_swift_static_stdlib :
@@ -816,13 +829,16 @@ class BuildScriptInvocation(object):
816829 # FIXME: This is a weird division (returning a list of class objects),
817830 # but it matches the existing structure of the `build-script-impl`.
818831 impl_product_classes = []
819- impl_product_classes .append (products .CMark )
820- impl_product_classes .append (products .LLVM )
832+ if self .args .build_cmark :
833+ impl_product_classes .append (products .CMark )
834+ if self .args .build_llvm :
835+ impl_product_classes .append (products .LLVM )
821836 if self .args .build_libcxx :
822837 impl_product_classes .append (products .LibCXX )
823838 if self .args .build_libicu :
824839 impl_product_classes .append (products .LibICU )
825- impl_product_classes .append (products .Swift )
840+ if self .args .build_swift :
841+ impl_product_classes .append (products .Swift )
826842 if self .args .build_lldb :
827843 impl_product_classes .append (products .LLDB )
828844 if self .args .build_libdispatch :
@@ -868,6 +884,30 @@ class BuildScriptInvocation(object):
868884 for prod in product_classes :
869885 assert (not prod .is_build_script_impl_product ())
870886
887+ # Now that we have our two lists of product_classes, if we are asked to
888+ # infer dependencies, infer the dependencies now and then re-split the
889+ # list.
890+ if self .args .infer_dependencies :
891+ combined = impl_product_classes + product_classes
892+
893+ # Now that we have produced the schedule, resplit. We require our
894+ # dependencies to respect our build-script-impl property. This means
895+ # that no build-script-impl products can have dependencies on
896+ # non-build-script-impl products. Otherwise, it would be unsafe to
897+ # re-order build-script-impl products in front of non
898+ # build-script-impl products.
899+ impl_product_classes = []
900+ product_classes = []
901+ is_darwin = platform .system () == 'Darwin'
902+ final_schedule = build_graph .produce_scheduled_build (combined )[0 ]
903+ for p in final_schedule :
904+ if is_darwin and p .is_nondarwin_only_build_product ():
905+ continue
906+
907+ if p .is_build_script_impl_product ():
908+ impl_product_classes .append (p )
909+ else :
910+ product_classes .append (p )
871911 return (impl_product_classes , product_classes )
872912
873913 def execute (self ):
@@ -956,7 +996,8 @@ class BuildScriptInvocation(object):
956996 print ("--- Running tests for %s ---" % product_name )
957997 product .test (host_target )
958998 print ("--- Finished tests for %s ---" % product_name )
959- if product .should_install (host_target ):
999+ if product .should_install (host_target ) or \
1000+ (self .install_all and product .should_build (host_target )):
9601001 print ("--- Installing %s ---" % product_name )
9611002 product .install (host_target )
9621003
0 commit comments