@@ -20,6 +20,7 @@ use buck2_build_api::analysis::calculation::RuleAnalysisCalculation;
20
20
use buck2_build_api:: artifact_groups:: calculation:: ArtifactGroupCalculation ;
21
21
use buck2_build_api:: artifact_groups:: ArtifactGroup ;
22
22
use buck2_build_api:: interpreter:: rule_defs:: cmd_args:: SimpleCommandLineArtifactVisitor ;
23
+ use buck2_build_api:: interpreter:: rule_defs:: provider:: builtin:: default_info:: FrozenDefaultInfo ;
23
24
use buck2_build_api:: interpreter:: rule_defs:: provider:: collection:: FrozenProviderCollection ;
24
25
use buck2_build_api:: interpreter:: rule_defs:: provider:: test_provider:: TestProvider ;
25
26
use buck2_cli_proto:: HasClientContext ;
@@ -354,6 +355,7 @@ async fn test(
354
355
. transpose ( )
355
356
. context ( "Invalid `duration`" ) ?;
356
357
358
+ let only_build_tests = !request. build ;
357
359
let test_outcome = test_targets (
358
360
ctx,
359
361
resolved_pattern,
@@ -373,6 +375,7 @@ async fn test(
373
375
MissingTargetBehavior :: from_skip ( build_opts. skip_missing_targets ) ,
374
376
timeout,
375
377
request. ignore_tests_attribute ,
378
+ only_build_tests,
376
379
)
377
380
. await ?;
378
381
@@ -448,6 +451,7 @@ async fn test_targets(
448
451
missing_target_behavior : MissingTargetBehavior ,
449
452
timeout : Option < Duration > ,
450
453
ignore_tests_attribute : bool ,
454
+ only_build_tests : bool ,
451
455
) -> anyhow:: Result < TestOutcome > {
452
456
let session = Arc :: new ( session) ;
453
457
@@ -531,6 +535,7 @@ async fn test_targets(
531
535
working_dir_cell,
532
536
missing_target_behavior,
533
537
ignore_tests_attribute,
538
+ only_build_tests,
534
539
} ) ;
535
540
536
541
driver. push_pattern (
@@ -657,6 +662,7 @@ pub(crate) struct TestDriverState<'a, 'e> {
657
662
working_dir_cell : CellName ,
658
663
missing_target_behavior : MissingTargetBehavior ,
659
664
ignore_tests_attribute : bool ,
665
+ only_build_tests : bool ,
660
666
}
661
667
662
668
/// Maintains the state of an ongoing test execution.
@@ -839,6 +845,7 @@ impl<'a, 'e> TestDriver<'a, 'e> {
839
845
state. label_filtering . dupe ( ) ,
840
846
state. cell_resolver ,
841
847
state. working_dir_cell ,
848
+ state. only_build_tests ,
842
849
)
843
850
. await ?;
844
851
anyhow:: Ok ( vec ! [ ] )
@@ -893,17 +900,18 @@ async fn test_target(
893
900
label_filtering : Arc < TestLabelFiltering > ,
894
901
cell_resolver : & CellResolver ,
895
902
working_dir_cell : CellName ,
903
+ only_build_tests : bool ,
896
904
) -> anyhow:: Result < Option < ConfiguredProvidersLabel > > {
897
905
// NOTE: We fail if we hit an incompatible target here. This can happen if we reach an
898
906
// incompatible target via `tests = [...]`. This should perhaps change, but that's how it works
899
907
// in v1: https://fb.workplace.com/groups/buckeng/posts/8520953297953210
900
908
let frozen_providers = ctx. get_providers ( & target) . await ?. require_compatible ( ) ?;
901
909
let providers = frozen_providers. provider_collection ( ) ;
902
- build_artifacts ( ctx, providers, & label_filtering) . await ?;
910
+ build_artifacts ( ctx, providers, & label_filtering, only_build_tests ) . await ?;
903
911
904
912
let fut = match <dyn TestProvider >:: from_collection ( providers) {
905
913
Some ( test_info) => {
906
- if skip_run_based_on_labels ( test_info, & label_filtering ) {
914
+ if label_filtering . is_excluded ( test_info. labels ( ) ) {
907
915
return Ok ( None ) ;
908
916
}
909
917
run_tests (
@@ -929,46 +937,46 @@ async fn test_target(
929
937
fut. await
930
938
}
931
939
932
- fn skip_run_based_on_labels (
933
- provider : & dyn TestProvider ,
940
+ fn skip_build_based_on_labels < ' a > (
941
+ labels_fn : & dyn Fn ( ) -> Vec < & ' a str > ,
934
942
label_filtering : & TestLabelFiltering ,
935
943
) -> bool {
936
- let target_labels = provider. labels ( ) ;
937
- label_filtering. is_excluded ( target_labels)
938
- }
939
-
940
- fn skip_build_based_on_labels (
941
- provider : & dyn TestProvider ,
942
- label_filtering : & TestLabelFiltering ,
943
- ) -> bool {
944
- !label_filtering. build_filtered_targets && skip_run_based_on_labels ( provider, label_filtering)
944
+ !label_filtering. build_filtered_targets && label_filtering. is_excluded ( labels_fn ( ) )
945
945
}
946
946
947
947
async fn build_artifacts (
948
948
ctx : & mut DiceComputations < ' _ > ,
949
949
providers : & FrozenProviderCollection ,
950
950
label_filtering : & TestLabelFiltering ,
951
+ only_build_tests : bool ,
951
952
) -> anyhow:: Result < ( ) > {
952
953
fn get_artifacts_to_build (
953
954
label_filtering : & TestLabelFiltering ,
954
955
providers : & FrozenProviderCollection ,
956
+ only_build_tests : bool ,
955
957
) -> anyhow:: Result < IndexSet < ArtifactGroup > > {
956
- Ok ( match <dyn TestProvider >:: from_collection ( providers) {
957
- Some ( provider) => {
958
- if skip_build_based_on_labels ( provider, label_filtering) {
959
- return Ok ( indexset ! [ ] ) ;
960
- }
961
- let mut artifact_visitor = SimpleCommandLineArtifactVisitor :: new ( ) ;
962
- provider. visit_artifacts ( & mut artifact_visitor) ?;
963
- artifact_visitor. inputs
958
+ let mut artifacts = IndexSet :: new ( ) ;
959
+
960
+ if let Some ( test_provider) = <dyn TestProvider >:: from_collection ( providers) {
961
+ if skip_build_based_on_labels ( & || test_provider. labels ( ) , label_filtering) {
962
+ return Ok ( indexset ! [ ] ) ;
964
963
}
965
- None => {
966
- // not a test
967
- indexset ! [ ]
964
+ let mut artifact_visitor = SimpleCommandLineArtifactVisitor :: new ( ) ;
965
+ test_provider. visit_artifacts ( & mut artifact_visitor) ?;
966
+ artifacts. extend ( artifact_visitor. inputs )
967
+ }
968
+
969
+ if !only_build_tests {
970
+ if let Some ( provider) = providers. builtin_provider :: < FrozenDefaultInfo > ( ) {
971
+ provider. for_each_output ( & mut |artifact| {
972
+ artifacts. insert ( artifact) ;
973
+ } ) ?;
968
974
}
969
- } )
975
+ }
976
+ Ok ( artifacts)
970
977
}
971
- let artifacts_to_build = get_artifacts_to_build ( label_filtering, providers) ?;
978
+
979
+ let artifacts_to_build = get_artifacts_to_build ( label_filtering, providers, only_build_tests) ?;
972
980
// build the test target first
973
981
ctx. try_compute_join ( artifacts_to_build. iter ( ) , |ctx, input| {
974
982
ctx. ensure_artifact_group ( input) . boxed ( )
0 commit comments