@@ -2,12 +2,15 @@ use anyhow::Context;
22use clap:: Parser ;
33use codeql_extractor:: trap;
44use figment:: {
5- providers:: { Env , Serialized } ,
5+ providers:: { Env , Format , Serialized , Yaml } ,
6+ value:: Value ,
67 Figment ,
78} ;
9+ use itertools:: Itertools ;
810use num_traits:: Zero ;
911use rust_extractor_macros:: extractor_cli_config;
1012use serde:: { Deserialize , Serialize } ;
13+ use std:: fmt:: Debug ;
1114use std:: ops:: Not ;
1215use std:: path:: PathBuf ;
1316
@@ -38,19 +41,34 @@ pub struct Config {
3841 pub verbose : u8 ,
3942 pub compression : Compression ,
4043 pub inputs : Vec < PathBuf > ,
44+ pub qltest : bool ,
45+ pub qltest_cargo_check : bool ,
4146}
4247
4348impl Config {
4449 pub fn extract ( ) -> anyhow:: Result < Config > {
4550 let args = argfile:: expand_args ( argfile:: parse_fromfile, argfile:: PREFIX )
4651 . context ( "expanding parameter files" ) ?;
4752 let cli_args = CliConfig :: parse_from ( args) ;
48- Figment :: new ( )
53+ let mut figment = Figment :: new ( )
4954 . merge ( Env :: prefixed ( "CODEQL_" ) )
5055 . merge ( Env :: prefixed ( "CODEQL_EXTRACTOR_RUST_" ) )
5156 . merge ( Env :: prefixed ( "CODEQL_EXTRACTOR_RUST_OPTION_" ) )
52- . merge ( Serialized :: defaults ( cli_args) )
53- . extract ( )
54- . context ( "loading configuration" )
57+ . merge ( Serialized :: defaults ( cli_args) ) ;
58+ if let Ok ( Value :: Bool ( _, true ) ) = figment. find_value ( "qltest" ) {
59+ let cwd = std:: env:: current_dir ( ) ?;
60+ let mut option_files = cwd
61+ . ancestors ( )
62+ // only travel up while we're within the test pack
63+ . take_while_inclusive ( |p| !p. join ( "qlpack.yml" ) . exists ( ) )
64+ . map ( |p| p. join ( "options" ) )
65+ . filter ( |p| p. exists ( ) )
66+ . collect_vec ( ) ;
67+ option_files. reverse ( ) ;
68+ for path in option_files {
69+ figment = figment. merge ( Yaml :: file_exact ( path) ) ;
70+ }
71+ }
72+ figment. extract ( ) . context ( "loading configuration" )
5573 }
5674}
0 commit comments