@@ -150,6 +150,11 @@ impl BuildSystem {
150150 Err ( e) => return Some ( Err ( e) ) ,
151151 Ok ( path) => path,
152152 } ;
153+
154+ for path in & mut self . search_path_prefix {
155+ * path = config_root. join ( & path) ;
156+ }
157+
153158 let mut cache = BUILD_SYSTEM_CACHE . lock ( ) ;
154159 let key = ( repo_root. clone ( ) , self . args . clone ( ) ) ;
155160 if let Some ( maybe_result) = cache. get ( & key)
@@ -164,10 +169,6 @@ impl BuildSystem {
164169 & self . args
165170 ) ;
166171
167- for path in & mut self . search_path_prefix {
168- * path = config_root. join ( & path) ;
169- }
170-
171172 let querier: Arc < dyn SourceDbQuerier > = match & self . args {
172173 BuildSystemArgs :: Buck ( args) => Arc :: new ( BxlQuerier :: new ( args. clone ( ) ) ) ,
173174 BuildSystemArgs :: Custom ( args) => Arc :: new ( CustomQuerier :: new ( args. clone ( ) ) ) ,
@@ -179,3 +180,81 @@ impl BuildSystem {
179180 Some ( Ok ( source_db) )
180181 }
181182}
183+
184+ #[ cfg( test) ]
185+ mod tests {
186+ use vec1:: vec1;
187+
188+ use super :: * ;
189+
190+ #[ test]
191+ fn test_get_source_db_always_configures_paths ( ) {
192+ let mut bs = BuildSystem {
193+ args : BuildSystemArgs :: Custom ( CustomQueryArgs {
194+ command : vec1 ! [ "python3" . to_owned( ) ] ,
195+ repo_root : None ,
196+ } ) ,
197+ ignore_if_build_system_missing : false ,
198+ search_path_prefix : vec ! [
199+ PathBuf :: from( "path/to/project" ) ,
200+ PathBuf :: from( "/absolute/path/to/project" ) ,
201+ ] ,
202+ } ;
203+ let mut bs2 = bs. clone ( ) ;
204+
205+ let root = Path :: new ( "/root" ) ;
206+
207+ bs. get_source_db ( root. to_path_buf ( ) ) . unwrap ( ) . unwrap ( ) ;
208+ assert_eq ! (
209+ & bs. search_path_prefix,
210+ & [
211+ root. join( "path/to/project" ) ,
212+ PathBuf :: from( "/absolute/path/to/project" )
213+ ]
214+ ) ;
215+ bs2. get_source_db ( root. to_path_buf ( ) ) . unwrap ( ) . unwrap ( ) ;
216+ assert_eq ! (
217+ & bs2. search_path_prefix,
218+ & [
219+ root. join( "path/to/project" ) ,
220+ PathBuf :: from( "/absolute/path/to/project" )
221+ ]
222+ ) ;
223+
224+ // double check that configuring twice doesn't corrupt path, even though it should
225+ // never be called twice
226+ bs2. get_source_db ( root. to_path_buf ( ) ) . unwrap ( ) . unwrap ( ) ;
227+ assert_eq ! (
228+ & bs2. search_path_prefix,
229+ & [
230+ root. join( "path/to/project" ) ,
231+ PathBuf :: from( "/absolute/path/to/project" )
232+ ]
233+ ) ;
234+ }
235+
236+ #[ test]
237+ fn test_build_system_not_exist ( ) {
238+ let mut bs = BuildSystem {
239+ args : BuildSystemArgs :: Custom ( CustomQueryArgs {
240+ command : vec1 ! [ "this_command_should_not_exist_?/" . to_owned( ) ] ,
241+ repo_root : None ,
242+ } ) ,
243+ ignore_if_build_system_missing : false ,
244+ search_path_prefix : vec ! [ ] ,
245+ } ;
246+ let root = Path :: new ( "/root" ) ;
247+
248+ bs. get_source_db ( root. to_path_buf ( ) ) . unwrap ( ) . unwrap_err ( ) ;
249+
250+ let mut bs = BuildSystem {
251+ args : BuildSystemArgs :: Custom ( CustomQueryArgs {
252+ command : vec1 ! [ "this_command_should_not_exist_?/" . to_owned( ) ] ,
253+ repo_root : None ,
254+ } ) ,
255+ ignore_if_build_system_missing : true ,
256+ search_path_prefix : vec ! [ ] ,
257+ } ;
258+ assert ! ( bs. get_source_db( root. to_path_buf( ) ) . is_none( ) ) ;
259+ }
260+ }
0 commit comments