diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 0d07dafa347..291b918f466 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1590,7 +1590,10 @@ impl WorkspaceRootConfig { let excluded = self .exclude .iter() - .any(|ex| manifest_path.starts_with(self.root_dir.join(ex))); + .filter_map(|ex| self.root_dir.join(ex).to_str().and_then(|p| glob(p).ok())) + .flatten() + .filter_map(|ex| ex.ok()) + .any(|ex| manifest_path.starts_with(ex)); let explicit_member = match self.members { Some(ref members) => members diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 58da0c0afce..5a2a6000212 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -1593,6 +1593,50 @@ fn excluded_simple() { assert!(p.root().join("foo/target").is_dir()); } +#[cargo_test] +fn excluded_glob() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "ws" + version = "0.1.0" + authors = [] + + [workspace] + exclude = ["repos/*"] + "#, + ) + .file("src/lib.rs", "") + .file( + "repos/workspace/Cargo.toml", + r#" + [workspace] + members = ["crates/*"] + "#, + ) + .file( + "repos/workspace/crates/xyz/Cargo.toml", + &basic_manifest("xyz", "0.1.0"), + ) + .file("repos/workspace/crates/xyz/src/lib.rs", "") + .file("repos/foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("repos/foo/src/lib.rs", "") + .file("repos/bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("repos/bar/src/lib.rs", ""); + let p = p.build(); + + p.cargo("build").run(); + assert!(p.root().join("target").is_dir()); + p.cargo("build").cwd("repos/workspace").run(); + assert!(p.root().join("repos/workspace/target").is_dir()); + p.cargo("build").cwd("repos/foo").run(); + assert!(p.root().join("repos/foo/target").is_dir()); + p.cargo("build").cwd("repos/bar").run(); + assert!(p.root().join("repos/bar/target").is_dir()); +} + #[cargo_test] fn exclude_members_preferred() { let p = project()