From 41a7eee6e1895335335f10626a7ccdb6087c5622 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Mon, 18 Nov 2024 16:31:22 +0100 Subject: [PATCH] Add ability to override targets on cmd line --- src/cargo-about/generate.rs | 13 ++++++++++--- src/lib.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cargo-about/generate.rs b/src/cargo-about/generate.rs index cceb9bc..3ce7303 100644 --- a/src/cargo-about/generate.rs +++ b/src/cargo-about/generate.rs @@ -52,6 +52,12 @@ pub struct Args { /// Do not activate the `default` feature #[clap(long)] no_default_features: bool, + /// The target triples to use for dependency graph filtering. + /// + /// Overrides the `targets` configuration value, and note that unlike cargo + /// itself this can take multiple targets instead of just one. + #[clap(long)] + target: Vec, /// Run without accessing the network. /// /// In addition to cargo not fetching crates, this will mean that only @@ -63,13 +69,13 @@ pub struct Args { /// copyright information in the license that would be retrieved from /// the original git repo for the crate in question #[arg(long)] - pub(crate) offline: bool, + offline: bool, /// Assert that `Cargo.lock` will remain unchanged #[arg(long)] - pub(crate) locked: bool, + locked: bool, /// Equivalent to specifying both `--locked` and `--offline` #[arg(long)] - pub(crate) frozen: bool, + frozen: bool, /// The path of the Cargo.toml for the root crate. /// /// Defaults to the current crate or workspace in the current working directory @@ -194,6 +200,7 @@ pub fn cmd(args: Args, color: crate::Color) -> anyhow::Result<()> { offline: args.offline, }, &cfg, + &args.target, )); }); s.spawn(|_| { diff --git a/src/lib.rs b/src/lib.rs index 29b0f69..a01cca4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,6 +102,7 @@ pub fn get_all_crates( workspace: bool, lock_opts: krates::LockOptions, cfg: &licenses::config::Config, + target_overrdes: &[String], ) -> anyhow::Result { let mut mdc = krates::Cmd::new(); mdc.manifest_path(cargo_toml); @@ -139,7 +140,15 @@ pub fn get_all_crates( builder.ignore_kind(krates::DepKind::Build, krates::Scope::NonWorkspace); } - builder.include_targets(cfg.targets.iter().map(|triple| (triple.as_str(), vec![]))); + if target_overrdes.is_empty() { + builder.include_targets(cfg.targets.iter().map(|triple| (triple.as_str(), vec![]))); + } else { + builder.include_targets( + target_overrdes + .iter() + .map(|triple| (triple.as_str(), vec![])), + ); + } let graph = builder.build(mdc, |filtered: cm::Package| { if let Some(src) = filtered.source {