Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply workspace.exclude to workspace.default-members. #8485

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,26 @@ impl<'cfg> Workspace<'cfg> {
None
};

for path in members_paths {
for path in &members_paths {
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
}

if let Some(default) = default_members_paths {
for path in default {
let manifest_path = paths::normalize_path(&path.join("Cargo.toml"));
let normalized_path = paths::normalize_path(&path);
let manifest_path = normalized_path.join("Cargo.toml");
if !self.members.contains(&manifest_path) {
// default-members are allowed to be excluded, but they
// still must be referred to by the original (unfiltered)
// members list. Note that we aren't testing against the
// manifest path, both because `members_paths` doesn't
// include `/Cargo.toml`, and because excluded paths may not
// be crates.
let exclude = members_paths.contains(&normalized_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this condition is here as well? I may not be fully remembering what the members_paths set is either...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

members_paths is the glob-expanded paths of members (without Cargo.tomls). Without this check I believe the test (Which this patch adds) excluded_default_members_still_must_be_members failed -- e.g. you could have members = ["foo"], default-members = ["foo", "bar"] and exclude = ["bar"].

&& workspace_config.is_excluded(&normalized_path);
if exclude {
continue;
}
anyhow::bail!(
"package `{}` is listed in workspace’s default-members \
but is not a member.",
Expand Down
90 changes: 90 additions & 0 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,96 @@ fn exclude_but_also_depend() {
assert!(p.root().join("foo/bar/target").is_dir());
}

#[cargo_test]
fn excluded_default_members_still_must_be_members() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo"]
default-members = ["foo", "bar"]
exclude = ["bar"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "")
.file("bar/something.txt", "");
let p = p.build();
p.cargo("build")
.with_status(101)
.with_stderr(
"\
error: package `[..]bar` is listed in workspace’s default-members \
but is not a member.
",
)
.run();
}

#[cargo_test]
fn excluded_default_members_crate_glob() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar/*"]
default-members = ["bar/*"]
exclude = ["bar/quux"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/main.rs", "fn main() {}")
.file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("bar/baz/src/main.rs", "fn main() {}")
.file("bar/quux/Cargo.toml", &basic_manifest("quux", "0.1.0"))
.file("bar/quux/src/main.rs", "fn main() {}");

let p = p.build();
p.cargo("build").run();

assert!(p.root().join("target").is_dir());
assert!(!p.bin("foo").is_file());
assert!(p.bin("baz").is_file());
assert!(!p.bin("quux").exists());

thomcc marked this conversation as resolved.
Show resolved Hide resolved
p.cargo("build --workspace").run();
assert!(p.root().join("target").is_dir());
assert!(p.bin("foo").is_file());
assert!(!p.bin("quux").exists());

p.cargo("build").cwd("bar/quux").run();
assert!(p.root().join("bar/quux/target").is_dir());
}

#[cargo_test]
fn excluded_default_members_not_crate_glob() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["foo", "bar/*"]
default-members = ["bar/*"]
exclude = ["bar/docs"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/main.rs", "fn main() {}")
.file("bar/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("bar/baz/src/main.rs", "fn main() {}")
.file("bar/docs/readme.txt", "This folder is not a crate!");

let p = p.build();
p.cargo("build").run();

assert!(!p.bin("foo").is_file());
assert!(p.bin("baz").is_file());
p.cargo("build --workspace").run();
assert!(p.bin("foo").is_file());
}

#[cargo_test]
fn glob_syntax() {
let p = project()
Expand Down