@@ -4,7 +4,10 @@ use anyhow::Result;
44use serde:: Deserialize ;
55use tracing:: { error, event, Level } ;
66
7+ use crate :: evergreen:: evg_config_utils:: is_bazel_suite;
8+
79use super :: { external_cmd:: run_command, resmoke_suite:: ResmokeSuiteConfig } ;
10+ use std:: collections:: HashMap ;
811
912/// Interface for discovering details about test suites.
1013pub trait TestDiscovery : Send + Sync {
@@ -45,6 +48,7 @@ pub struct ResmokeProxy {
4548 skip_covered_tests : bool ,
4649 /// True if test discovery should include tests that are tagged with fully disabled features.
4750 include_fully_disabled_feature_tests : bool ,
51+ bazel_suite_configs : BazelConfigs ,
4852}
4953
5054impl ResmokeProxy {
@@ -55,10 +59,12 @@ impl ResmokeProxy {
5559 /// * `resmoke_cmd` - Command to invoke resmoke.
5660 /// * `skip_covered_tests` - Whether the generator should skip tests run in more complex suites.
5761 /// * `include_fully_disabled_feature_tests` - If the generator should include tests that are tagged with fully disabled features.
62+ /// * `bazel_suite_configs` - Optional bazel suite configurations.
5863 pub fn new (
5964 resmoke_cmd : & str ,
6065 skip_covered_tests : bool ,
6166 include_fully_disabled_feature_tests : bool ,
67+ bazel_suite_configs : BazelConfigs ,
6268 ) -> Self {
6369 let cmd_parts: Vec < _ > = resmoke_cmd. split ( ' ' ) . collect ( ) ;
6470 let cmd = cmd_parts[ 0 ] ;
@@ -68,10 +74,46 @@ impl ResmokeProxy {
6874 resmoke_script : script,
6975 skip_covered_tests,
7076 include_fully_disabled_feature_tests,
77+ bazel_suite_configs,
7178 }
7279 }
7380}
7481
82+ #[ derive( Debug , Clone , Default ) ]
83+ pub struct BazelConfigs {
84+ /// Map of bazel resmoke config targets to their generated suite config YAMLs.
85+ configs : HashMap < String , String > ,
86+ }
87+
88+ impl BazelConfigs {
89+ pub fn from_yaml_file ( path : & Path ) -> Result < Self > {
90+ let contents = std:: fs:: read_to_string ( path) ?;
91+ let configs: Result < HashMap < String , String > , serde_yaml:: Error > =
92+ serde_yaml:: from_str ( & contents) ;
93+ if configs. is_err ( ) {
94+ error ! (
95+ file = path. display( ) . to_string( ) ,
96+ contents = & contents,
97+ "Failed to parse bazel configs from yaml file" ,
98+ ) ;
99+ }
100+ Ok ( Self { configs : configs? } )
101+ }
102+
103+ /// Get the generated suite config for a bazel resmoke target.
104+ ///
105+ /// # Arguments
106+ ///
107+ /// * `target` - Bazel resmoke test target, like "//buildscripts/resmoke:core".
108+ ///
109+ /// # Returns
110+ ///
111+ /// The path the the generated suite config YAML, like "bazel-out/buildscripts/resmoke/core_config.yml".
112+ pub fn get ( & self , target : & str ) -> & str {
113+ self . configs . get ( & format ! ( "{}_config" , target) ) . unwrap ( )
114+ }
115+ }
116+
75117/// Details about tests comprising a test suite.
76118#[ derive( Debug , Deserialize ) ]
77119#[ allow( dead_code) ]
@@ -94,9 +136,15 @@ impl TestDiscovery for ResmokeProxy {
94136 ///
95137 /// A list of tests belonging to given suite.
96138 fn discover_tests ( & self , suite_name : & str ) -> Result < Vec < String > > {
139+ let suite_config = if is_bazel_suite ( suite_name) {
140+ self . bazel_suite_configs . get ( suite_name)
141+ } else {
142+ suite_name
143+ } ;
144+
97145 let mut cmd = vec ! [ & * self . resmoke_cmd] ;
98146 cmd. append ( & mut self . resmoke_script . iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ) ;
99- cmd. append ( & mut vec ! [ "test-discovery" , "--suite" , suite_name ] ) ;
147+ cmd. append ( & mut vec ! [ "test-discovery" , "--suite" , suite_config ] ) ;
100148
101149 // When running in a patch build, we use the --skipTestsCoveredByMoreComplexSuites
102150 // flag to tell Resmoke to exclude any tests in the given suite that will
@@ -114,7 +162,7 @@ impl TestDiscovery for ResmokeProxy {
114162
115163 event ! (
116164 Level :: INFO ,
117- suite_name ,
165+ suite_config ,
118166 duration_ms = start. elapsed( ) . as_millis( ) as u64 ,
119167 "Resmoke test discovery finished"
120168 ) ;
@@ -146,9 +194,15 @@ impl TestDiscovery for ResmokeProxy {
146194 ///
147195 /// Resmoke configuration for the given suite.
148196 fn get_suite_config ( & self , suite_name : & str ) -> Result < ResmokeSuiteConfig > {
197+ let suite_config = if is_bazel_suite ( suite_name) {
198+ self . bazel_suite_configs . get ( suite_name)
199+ } else {
200+ suite_name
201+ } ;
202+
149203 let mut cmd = vec ! [ & * self . resmoke_cmd] ;
150204 cmd. append ( & mut self . resmoke_script . iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ) ;
151- cmd. append ( & mut vec ! [ "suiteconfig" , "--suite" , suite_name ] ) ;
205+ cmd. append ( & mut vec ! [ "suiteconfig" , "--suite" , suite_config ] ) ;
152206 let cmd_output = run_command ( & cmd) . unwrap ( ) ;
153207
154208 Ok ( ResmokeSuiteConfig :: from_str ( & cmd_output) ?)
0 commit comments