From 66afef888a009f96f5153a649a0db7b3764f2967 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sat, 18 Jan 2020 18:09:45 +0100 Subject: clang-parser: better extra_args defaults --- src/parser/clang/config.rs | 38 +++++++++++++++++++++++--------------- 1 file 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 { #[structopt(long = "clang-compile-commands-location")] pub(super) compile_commands_location: Option, #[structopt(long = "clang-extra-args", number_of_values = 1)] - #[serde(default)] - pub(super) extra_args: Vec, + pub(super) extra_args: Option>, } impl Default for Config { fn default() -> Self { - Config::from_merge( - ProvidedConfig::default(), - ProvidedConfig::default(), - ) - // Currently errors out only on CLI parse fail with clang's extra args - .unwrap() + Config::from_merge(ProvidedConfig::default(), ProvidedConfig::default()) + // Currently errors out only on CLI parse fail with clang's extra args + .unwrap() } } +fn default_extra_args() -> Vec { + vec![ + // We don't parse function bodies so libclang report every arguments/functions/etc. as unused. + String::from("-Wno-unused-const-variable"), + String::from("-Wno-unused-function"), + String::from("-Wno-unused-parameter"), + String::from("-Wno-unused-private-field"), + String::from("-Wno-unused-variable"), + // We don't "link" so every linker arguments from the compile_commands.json gets reported + String::from("-Qunused-arguments"), + ] +} + impl Config { - pub(crate) fn from_merge( - cli: ProvidedConfig, - mut config: ProvidedConfig, - ) -> Result { + pub(crate) fn from_merge(cli: ProvidedConfig, config: ProvidedConfig) -> Result { let mut extra_args = Vec::new(); - for args in cli.extra_args { - extra_args.append(&mut ::shell_words::split(&args)?); + if let Some(cli_extra_args) = cli.extra_args { + for args in cli_extra_args { + extra_args.append(&mut ::shell_words::split(&args)?); + } } - extra_args.append(&mut config.extra_args); + extra_args.append(&mut config.extra_args.unwrap_or_else(default_extra_args)); Ok(Self { compile_commands_location: cli .compile_commands_location -- cgit v1.2.3