mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Apply workspace.exclude to workspace.default-members.
This commit is contained in:
parent
43cf77395c
commit
b70a5962c3
@ -538,14 +538,26 @@ impl<'cfg> Workspace<'cfg> {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
for path in members_paths {
|
for path in &members_paths {
|
||||||
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
|
self.find_path_deps(&path.join("Cargo.toml"), &root_manifest_path, false)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(default) = default_members_paths {
|
if let Some(default) = default_members_paths {
|
||||||
for path in default {
|
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) {
|
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)
|
||||||
|
&& workspace_config.is_excluded(&normalized_path);
|
||||||
|
if exclude {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"package `{}` is listed in workspace’s default-members \
|
"package `{}` is listed in workspace’s default-members \
|
||||||
but is not a member.",
|
but is not a member.",
|
||||||
|
@ -1628,6 +1628,94 @@ fn exclude_but_also_depend() {
|
|||||||
assert!(p.root().join("foo/bar/target").is_dir());
|
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/lib.rs", "");
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
p.cargo("build --workspace").run();
|
||||||
|
assert!(p.root().join("target").is_dir());
|
||||||
|
assert!(p.bin("foo").is_file());
|
||||||
|
|
||||||
|
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]
|
#[cargo_test]
|
||||||
fn glob_syntax() {
|
fn glob_syntax() {
|
||||||
let p = project()
|
let p = project()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user