Skip to content

Commit b70a596

Browse files
author
Thom Chiovoloni
committed
Apply workspace.exclude to workspace.default-members.
1 parent 43cf773 commit b70a596

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

src/cargo/core/workspace.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,26 @@ impl<'cfg> Workspace<'cfg> {
538538
None
539539
};
540540

541-
for path in members_paths {
541+
for path in &members_paths {
542542
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
543543
}
544544

545545
if let Some(default) = default_members_paths {
546546
for path in default {
547-
let manifest_path = paths::normalize_path(&path.join("Cargo.toml"));
547+
let normalized_path = paths::normalize_path(&path);
548+
let manifest_path = normalized_path.join("Cargo.toml");
548549
if !self.members.contains(&manifest_path) {
550+
// default-members are allowed to be excluded, but they
551+
// still must be referred to by the original (unfiltered)
552+
// members list. Note that we aren't testing against the
553+
// manifest path, both because `members_paths` doesn't
554+
// include `/Cargo.toml`, and because excluded paths may not
555+
// be crates.
556+
let exclude = members_paths.contains(&normalized_path)
557+
&& workspace_config.is_excluded(&normalized_path);
558+
if exclude {
559+
continue;
560+
}
549561
anyhow::bail!(
550562
"package `{}` is listed in workspace’s default-members \
551563
but is not a member.",

tests/testsuite/workspaces.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,94 @@ fn exclude_but_also_depend() {
16281628
assert!(p.root().join("foo/bar/target").is_dir());
16291629
}
16301630

1631+
#[cargo_test]
1632+
fn excluded_default_members_still_must_be_members() {
1633+
let p = project()
1634+
.file(
1635+
"Cargo.toml",
1636+
r#"
1637+
[workspace]
1638+
members = ["foo"]
1639+
default-members = ["foo", "bar"]
1640+
exclude = ["bar"]
1641+
"#,
1642+
)
1643+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1644+
.file("foo/src/lib.rs", "")
1645+
.file("bar/something.txt", "");
1646+
let p = p.build();
1647+
p.cargo("build")
1648+
.with_status(101)
1649+
.with_stderr(
1650+
"\
1651+
error: package `[..]bar` is listed in workspace’s default-members \
1652+
but is not a member.
1653+
",
1654+
)
1655+
.run();
1656+
}
1657+
1658+
#[cargo_test]
1659+
fn excluded_default_members_crate_glob() {
1660+
let p = project()
1661+
.file(
1662+
"Cargo.toml",
1663+
r#"
1664+
[workspace]
1665+
members = ["foo", "bar/*"]
1666+
default-members = ["bar/*"]
1667+
exclude = ["bar/quux"]
1668+
"#,
1669+
)
1670+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1671+
.file("foo/src/main.rs", "fn main() {}")
1672+
.file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
1673+
.file("bar/baz/src/main.rs", "fn main() {}")
1674+
.file("bar/quux/Cargo.toml", &basic_manifest("quux", "0.1.0"))
1675+
.file("bar/quux/src/lib.rs", "");
1676+
1677+
let p = p.build();
1678+
p.cargo("build").run();
1679+
1680+
assert!(p.root().join("target").is_dir());
1681+
assert!(!p.bin("foo").is_file());
1682+
assert!(p.bin("baz").is_file());
1683+
1684+
p.cargo("build --workspace").run();
1685+
assert!(p.root().join("target").is_dir());
1686+
assert!(p.bin("foo").is_file());
1687+
1688+
p.cargo("build").cwd("bar/quux").run();
1689+
assert!(p.root().join("bar/quux/target").is_dir());
1690+
}
1691+
1692+
#[cargo_test]
1693+
fn excluded_default_members_not_crate_glob() {
1694+
let p = project()
1695+
.file(
1696+
"Cargo.toml",
1697+
r#"
1698+
[workspace]
1699+
members = ["foo", "bar/*"]
1700+
default-members = ["bar/*"]
1701+
exclude = ["bar/docs"]
1702+
"#,
1703+
)
1704+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
1705+
.file("foo/src/main.rs", "fn main() {}")
1706+
.file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
1707+
.file("bar/baz/src/main.rs", "fn main() {}")
1708+
.file("bar/docs/readme.txt", "This folder is not a crate!");
1709+
1710+
let p = p.build();
1711+
p.cargo("build").run();
1712+
1713+
assert!(!p.bin("foo").is_file());
1714+
assert!(p.bin("baz").is_file());
1715+
p.cargo("build --workspace").run();
1716+
assert!(p.bin("foo").is_file());
1717+
}
1718+
16311719
#[cargo_test]
16321720
fn glob_syntax() {
16331721
let p = project()

0 commit comments

Comments
 (0)