From de896baff7e97fac4dde79078c9a2fa1c652576b Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 18 Dec 2019 20:56:53 +0100 Subject: Big refactoring - entities should be more coherent when parsing multiple files - well defined, language agnostic entity tree - each module has its own configuration - less dead code --- src/parsing/clang/config.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/parsing/clang/config.rs (limited to 'src/parsing/clang/config.rs') diff --git a/src/parsing/clang/config.rs b/src/parsing/clang/config.rs new file mode 100644 index 0000000..cb05876 --- /dev/null +++ b/src/parsing/clang/config.rs @@ -0,0 +1,53 @@ +use anyhow::Result; +use serde_derive::{Deserialize, Serialize}; +use structopt::StructOpt; + +use std::path::PathBuf; + +#[derive(Debug, Clone, StructOpt, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub(crate) struct Config { + pub(crate) compile_commands_location: PathBuf, + pub(crate) extra_args: Vec, +} + +#[derive(Debug, Clone, Default, StructOpt, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub(crate) struct ProvidedConfig { + #[structopt(long = "clang-compile-commands-location")] + pub(crate) compile_commands_location: Option, + #[structopt(long = "clang-extra-args", number_of_values = 1)] + #[serde(default)] + pub(crate) extra_args: Vec, +} + +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() + } +} + +impl Config { + pub(crate) fn from_merge( + cli: ProvidedConfig, + mut config: ProvidedConfig, + ) -> Result { + let mut extra_args = Vec::new(); + for args in cli.extra_args { + extra_args.append(&mut ::shell_words::split(&args)?); + } + extra_args.append(&mut config.extra_args); + Ok(Self { + compile_commands_location: cli + .compile_commands_location + .or(config.compile_commands_location) + .unwrap_or_else(|| PathBuf::from(r".")), + extra_args, + }) + } +} -- cgit v1.2.3