From c6d47218a4d960df1fa0be03e8005eabf1f2c4d3 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Fri, 29 Nov 2024 23:33:34 +0100 Subject: [PATCH] manifest: Skip non-directories when resolving workspace `members` If globs provided in the `members` array resolve to files, even if none of its results are (symlinks to) directories or if the path is a relative path to a file without any globbing directives, `cargo` skips it without error. Cargo only errors out if the glob (or again relative path) didn't resolve to any files at all (which is what `glob::glob()` should also be doing for us). It does however support symlinks, meaning we need to canonicalize every result to follow any symlinks before deducing if the entry is a directory that needs to be treated as a workspace member crate. --- src/lib.rs | 2 +- src/manifest.rs | 8 ++++++++ src/subcommand.rs | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b50f122..0e65fec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,6 @@ pub use args::Args; pub use artifact::{Artifact, ArtifactType}; pub use config::{EnvError, EnvOption, LocalizedConfig}; pub use error::Error; -pub use manifest::CrateType; +pub use manifest::{CrateType, Manifest}; pub use profile::Profile; pub use subcommand::Subcommand; diff --git a/src/manifest.rs b/src/manifest.rs index 5c15f5f..e3f1f8d 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -36,8 +36,16 @@ impl Manifest { let mut all_members = HashMap::new(); for member in &workspace.members { + // XXX: Cargo would fail if the glob yielded no file results. But it allows cases where + // the only results are non-directories, including non-glob *file* paths in `members`... for manifest_dir in glob::glob(workspace_root.join(member).to_str().unwrap())? { let manifest_dir = manifest_dir?; + if !dunce::canonicalize(&manifest_dir) + .map_err(|e| Error::Io(manifest_dir.clone(), e))? + .is_dir() + { + continue; + } let manifest_path = manifest_dir.join("Cargo.toml"); let manifest = Manifest::parse_from_toml(&manifest_path)?; diff --git a/src/subcommand.rs b/src/subcommand.rs index cb0ea07..2dd0f6e 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -30,7 +30,7 @@ impl Subcommand { args.package.len() < 2, "Multiple packages are not supported yet by `cargo-subcommand`" ); - let package = args.package.get(0).map(|s| s.as_str()); + let package = args.package.first().map(|s| s.as_str()); assert!( !args.workspace, "`--workspace` is not supported yet by `cargo-subcommand`"