summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/parser/clang/config.rs38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/parser/clang/config.rs b/src/parser/clang/config.rs
index 05fe3ab..1d9c6ba 100644
--- a/src/parser/clang/config.rs
+++ b/src/parser/clang/config.rs
@@ -17,31 +17,39 @@ pub(crate) struct ProvidedConfig {
17 #[structopt(long = "clang-compile-commands-location")] 17 #[structopt(long = "clang-compile-commands-location")]
18 pub(super) compile_commands_location: Option<PathBuf>, 18 pub(super) compile_commands_location: Option<PathBuf>,
19 #[structopt(long = "clang-extra-args", number_of_values = 1)] 19 #[structopt(long = "clang-extra-args", number_of_values = 1)]
20 #[serde(default)] 20 pub(super) extra_args: Option<Vec<String>>,
21 pub(super) extra_args: Vec<String>,
22} 21}
23 22
24impl Default for Config { 23impl Default for Config {
25 fn default() -> Self { 24 fn default() -> Self {
26 Config::from_merge( 25 Config::from_merge(ProvidedConfig::default(), ProvidedConfig::default())
27 ProvidedConfig::default(), 26 // Currently errors out only on CLI parse fail with clang's extra args
28 ProvidedConfig::default(), 27 .unwrap()
29 )
30 // Currently errors out only on CLI parse fail with clang's extra args
31 .unwrap()
32 } 28 }
33} 29}
34 30
31fn default_extra_args() -> Vec<String> {
32 vec![
33 // We don't parse function bodies so libclang report every arguments/functions/etc. as unused.
34 String::from("-Wno-unused-const-variable"),
35 String::from("-Wno-unused-function"),
36 String::from("-Wno-unused-parameter"),
37 String::from("-Wno-unused-private-field"),
38 String::from("-Wno-unused-variable"),
39 // We don't "link" so every linker arguments from the compile_commands.json gets reported
40 String::from("-Qunused-arguments"),
41 ]
42}
43
35impl Config { 44impl Config {
36 pub(crate) fn from_merge( 45 pub(crate) fn from_merge(cli: ProvidedConfig, config: ProvidedConfig) -> Result<Self> {
37 cli: ProvidedConfig,
38 mut config: ProvidedConfig,
39 ) -> Result<Self> {
40 let mut extra_args = Vec::new(); 46 let mut extra_args = Vec::new();
41 for args in cli.extra_args { 47 if let Some(cli_extra_args) = cli.extra_args {
42 extra_args.append(&mut ::shell_words::split(&args)?); 48 for args in cli_extra_args {
49 extra_args.append(&mut ::shell_words::split(&args)?);
50 }
43 } 51 }
44 extra_args.append(&mut config.extra_args); 52 extra_args.append(&mut config.extra_args.unwrap_or_else(default_extra_args));
45 Ok(Self { 53 Ok(Self {
46 compile_commands_location: cli 54 compile_commands_location: cli
47 .compile_commands_location 55 .compile_commands_location