diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs
index c36f10d33c1..d11d00bbcb9 100644
--- a/src/cargo/core/workspace.rs
+++ b/src/cargo/core/workspace.rs
@@ -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: {}",
diff --git a/src/doc/man/generated/cargo-bench.html b/src/doc/man/generated/cargo-bench.html
index a2505612ab3..3117d547690 100644
--- a/src/doc/man/generated/cargo-bench.html
+++ b/src/doc/man/generated/cargo-bench.html
@@ -69,11 +69,16 @@
Benchmark Options
Package Selection
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.
diff --git a/src/doc/man/generated/cargo-build.html b/src/doc/man/generated/cargo-build.html
index da9bbf7e5de..6bb4d6f1dfe 100644
--- a/src/doc/man/generated/cargo-build.html
+++ b/src/doc/man/generated/cargo-build.html
@@ -25,11 +25,16 @@ OPTIONS
Package Selection
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.
diff --git a/src/doc/man/generated/cargo-check.html b/src/doc/man/generated/cargo-check.html
index 13107b51580..1360cc6cc42 100644
--- a/src/doc/man/generated/cargo-check.html
+++ b/src/doc/man/generated/cargo-check.html
@@ -29,11 +29,16 @@ OPTIONS
Package Selection
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.
diff --git a/src/doc/man/generated/cargo-doc.html b/src/doc/man/generated/cargo-doc.html
index 0550e50229b..c94c121bf63 100644
--- a/src/doc/man/generated/cargo-doc.html
+++ b/src/doc/man/generated/cargo-doc.html
@@ -45,11 +45,16 @@ Documentation Options
Package Selection
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.
diff --git a/src/doc/man/generated/cargo-fix.html b/src/doc/man/generated/cargo-fix.html
index bec13f66a99..190f31c47e5 100644
--- a/src/doc/man/generated/cargo-fix.html
+++ b/src/doc/man/generated/cargo-fix.html
@@ -100,11 +100,16 @@ Fix options
Package Selection
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.
diff --git a/src/doc/man/generated/cargo-test.html b/src/doc/man/generated/cargo-test.html
index 86d410df281..02ff2670fca 100644
--- a/src/doc/man/generated/cargo-test.html
+++ b/src/doc/man/generated/cargo-test.html
@@ -75,11 +75,16 @@ Test Options
Package Selection
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.
diff --git a/src/doc/man/options-packages.adoc b/src/doc/man/options-packages.adoc
index 51ab9f0c370..cd671059d6e 100644
--- a/src/doc/man/options-packages.adoc
+++ b/src/doc/man/options-packages.adoc
@@ -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_...::
diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1
index 82b30f1cf50..2d8d7541172 100644
--- a/src/etc/man/cargo-bench.1
+++ b/src/etc/man/cargo-bench.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-bench
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-BENCH" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-BENCH" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -77,11 +77,15 @@ the executable as a whole.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1
index 86b91a89551..7ccbc561256 100644
--- a/src/etc/man/cargo-build.1
+++ b/src/etc/man/cargo-build.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-build
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-BUILD" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-BUILD" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -39,11 +39,15 @@ Compile local packages and all of their dependencies.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1
index 43bf72a35cb..149c1382ef1 100644
--- a/src/etc/man/cargo-check.1
+++ b/src/etc/man/cargo-check.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-check
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-CHECK" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-CHECK" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -43,11 +43,15 @@ not been modified.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1
index 91f176e6949..d8d6b2fb9af 100644
--- a/src/etc/man/cargo-doc.1
+++ b/src/etc/man/cargo-doc.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-doc
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-DOC" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-DOC" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -56,11 +56,15 @@ Include non\-public items in the documentation.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1
index 48dbe6d5257..0cfb9d555d9 100644
--- a/src/etc/man/cargo-fix.1
+++ b/src/etc/man/cargo-fix.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-fix
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-FIX" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-FIX" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -113,11 +113,15 @@ Fix code even if the working directory has staged changes.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1
index 241101ab21f..e067c4b73a2 100644
--- a/src/etc/man/cargo-test.1
+++ b/src/etc/man/cargo-test.1
@@ -1,13 +1,13 @@
'\" t
.\" Title: cargo-test
.\" Author: [see the "AUTHOR(S)" section]
-.\" Generator: Asciidoctor 2.0.8
-.\" Date: 2019-06-07
+.\" Generator: Asciidoctor 2.0.10
+.\" Date: 2019-08-19
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "CARGO\-TEST" "1" "2019-06-07" "\ \&" "\ \&"
+.TH "CARGO\-TEST" "1" "2019-08-19" "\ \&" "\ \&"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
@@ -83,11 +83,15 @@ the executable as a whole.
.SS "Package Selection"
.sp
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 (\fB\-\-all\fP is implied). Otherwise, only the
-package in the current directory will be selected. The default packages may be
-overridden with the \fBworkspace.default\-members\fP key in the root \fBCargo.toml\fP
-manifest.
+depend on the selected manifest file (based on the current working directory if
+\fB\-\-manifest\-path\fP 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.
+.sp
+The default members of a workspace can be set explicitly with the
+\fBworkspace.default\-members\fP key in the root manifest. If this is not set, a
+virtual workspace will include all workspace members (equivalent to passing
+\fB\-\-all\fP), and a non\-virtual workspace will include only the root crate itself.
.sp
\fB\-p\fP \fISPEC\fP..., \fB\-\-package\fP \fISPEC\fP...
.RS 4
diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs
index 677e09829b4..e1dba6416b4 100644
--- a/tests/testsuite/workspaces.rs
+++ b/tests/testsuite/workspaces.rs
@@ -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(