Only apply default-members when building root manifest

This commit is contained in:
Wim Looman 2019-03-16 15:30:41 +01:00 committed by Eric Huss
parent 93660b02ee
commit 53e84c571d
3 changed files with 79 additions and 8 deletions

View File

@ -452,11 +452,15 @@ impl<'cfg> Workspace<'cfg> {
WorkspaceConfig::Root(ref root_config) => {
members_paths = root_config
.members_paths(root_config.members.as_ref().unwrap_or(&vec![]))?;
default_members_paths = if let Some(ref default) = root_config.default_members {
Some(root_config.members_paths(default)?)
default_members_paths = if root_manifest_path == self.current_manifest {
if let Some(ref default) = root_config.default_members {
Some(root_config.members_paths(default)?)
} else {
None
}
} else {
None
}
};
}
_ => failure::bail!(
"root of a workspace inferred but wasn't a root: {}",

View File

@ -1,9 +1,13 @@
By default, when no package selection options are given, the packages selected
depend on the current working directory. In the root of a virtual workspace,
all workspace members are selected (`--all` is implied). Otherwise, only the
package in the current directory will be selected. The default packages may be
overridden with the `workspace.default-members` key in the root `Cargo.toml`
manifest.
depend on the selected manifest file (based on the current working directory if
`--manifest-path` is not given). If the manifest is the root of a workspace then
the workspaces default members are selected, otherwise only the package defined
by the manifest will be selected.
The default members of a workspace can be set explicitly with the
`workspace.default-members` key in the root manifest. If this is not set, a
virtual workspace will include all workspace members (equivalent to passing
`--all`), and a non-virtual workspace will include only the root crate itself.
*-p* _SPEC_...::
*--package* _SPEC_...::

View File

@ -82,6 +82,44 @@ fn simple_explicit_default_members() {
assert!(!p.bin("foo").is_file());
}
#[cargo_test]
fn non_virtual_default_members_build_other_member() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
authors = []
[workspace]
members = [".", "bar", "baz"]
default-members = ["baz"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("baz/src/lib.rs", "pub fn baz() {}")
.build();
p.cargo("build")
.with_stderr(
"[..] Compiling baz v0.1.0 ([..])\n\
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
)
.run();
p.cargo("build --manifest-path bar/Cargo.toml")
.with_stderr(
"[..] Compiling bar v0.1.0 ([..])\n\
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
)
.run();
}
#[cargo_test]
fn inferred_root() {
let p = project()
@ -848,6 +886,31 @@ but is not a member.
.run();
}
#[cargo_test]
fn virtual_default_members_build_other_member() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bar", "baz"]
default-members = ["baz"]
"#,
)
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("bar/src/lib.rs", "pub fn bar() {}")
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("baz/src/lib.rs", "pub fn baz() {}")
.build();
p.cargo("build --manifest-path bar/Cargo.toml")
.with_stderr(
"[..] Compiling bar v0.1.0 ([..])\n\
[..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n",
)
.run();
}
#[cargo_test]
fn virtual_build_no_members() {
let p = project().file(