Skip to content

Commit

Permalink
manifest: Skip non-directories when resolving workspace members
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarijnS95 committed Nov 29, 2024
1 parent de0458c commit c6d4721
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
2 changes: 1 addition & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down

0 comments on commit c6d4721

Please sign in to comment.