Skip to content

Commit c6d4721

Browse files
committed
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.
1 parent de0458c commit c6d4721

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ pub use args::Args;
1111
pub use artifact::{Artifact, ArtifactType};
1212
pub use config::{EnvError, EnvOption, LocalizedConfig};
1313
pub use error::Error;
14-
pub use manifest::CrateType;
14+
pub use manifest::{CrateType, Manifest};
1515
pub use profile::Profile;
1616
pub use subcommand::Subcommand;

src/manifest.rs

+8
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ impl Manifest {
3636
let mut all_members = HashMap::new();
3737

3838
for member in &workspace.members {
39+
// XXX: Cargo would fail if the glob yielded no file results. But it allows cases where
40+
// the only results are non-directories, including non-glob *file* paths in `members`...
3941
for manifest_dir in glob::glob(workspace_root.join(member).to_str().unwrap())? {
4042
let manifest_dir = manifest_dir?;
43+
if !dunce::canonicalize(&manifest_dir)
44+
.map_err(|e| Error::Io(manifest_dir.clone(), e))?
45+
.is_dir()
46+
{
47+
continue;
48+
}
4149
let manifest_path = manifest_dir.join("Cargo.toml");
4250
let manifest = Manifest::parse_from_toml(&manifest_path)?;
4351

src/subcommand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Subcommand {
3030
args.package.len() < 2,
3131
"Multiple packages are not supported yet by `cargo-subcommand`"
3232
);
33-
let package = args.package.get(0).map(|s| s.as_str());
33+
let package = args.package.first().map(|s| s.as_str());
3434
assert!(
3535
!args.workspace,
3636
"`--workspace` is not supported yet by `cargo-subcommand`"

0 commit comments

Comments
 (0)