Skip to content

Commit

Permalink
Add ability to override targets on cmd line
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Nov 18, 2024
1 parent c64807d commit 41a7eee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/cargo-about/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Run without accessing the network.
///
/// In addition to cargo not fetching crates, this will mean that only
Expand All @@ -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
Expand Down Expand Up @@ -194,6 +200,7 @@ pub fn cmd(args: Args, color: crate::Color) -> anyhow::Result<()> {
offline: args.offline,
},
&cfg,
&args.target,
));
});
s.spawn(|_| {
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub fn get_all_crates(
workspace: bool,
lock_opts: krates::LockOptions,
cfg: &licenses::config::Config,
target_overrdes: &[String],
) -> anyhow::Result<Krates> {
let mut mdc = krates::Cmd::new();
mdc.manifest_path(cargo_toml);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 41a7eee

Please sign in to comment.