From 380be409222e162fedab7e722b8428d341f2ed61 Mon Sep 17 00:00:00 2001 From: Ted Kaminski Date: Thu, 23 Jun 2022 16:46:35 +0000 Subject: [PATCH 1/2] Allow '.' in workspace.default-members in non-virtual workspaces. --- src/cargo/core/workspace.rs | 4 +++- tests/testsuite/workspaces.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index ee74c31a4de..51e5b44d339 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -690,7 +690,9 @@ impl<'cfg> Workspace<'cfg> { for path in default { 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) + && (self.is_virtual() || manifest_path != root_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 diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index d58b0220a21..52f41b1183f 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -119,6 +119,35 @@ fn non_virtual_default_members_build_other_member() { .run(); } +#[cargo_test] +fn non_virtual_default_members_build_root_project() { + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + authors = [] + + [workspace] + members = ["bar"] + default-members = ["."] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .build(); + + p.cargo("build") + .with_stderr( + "[..] Compiling foo v0.1.0 ([..])\n\ + [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n", + ) + .run(); +} + #[cargo_test] fn inferred_root() { let p = project() From 917b87e56fe70e7c76acc7c562c7947a558e74a9 Mon Sep 17 00:00:00 2001 From: Ted Kaminski Date: Wed, 13 Jul 2022 21:14:47 +0000 Subject: [PATCH 2/2] Finish updating members via find_path_deps before setting up default_members --- src/cargo/core/workspace.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 51e5b44d339..2adf13a5b1a 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -686,13 +686,13 @@ impl<'cfg> Workspace<'cfg> { })?; } + self.find_path_deps(&root_manifest_path, &root_manifest_path, false)?; + if let Some(default) = default_members_paths { for path in default { let normalized_path = paths::normalize_path(&path); let manifest_path = normalized_path.join("Cargo.toml"); - if !self.members.contains(&manifest_path) - && (self.is_virtual() || manifest_path != root_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 @@ -718,7 +718,7 @@ impl<'cfg> Workspace<'cfg> { self.default_members.push(self.current_manifest.clone()) } - self.find_path_deps(&root_manifest_path, &root_manifest_path, false) + Ok(()) } fn find_path_deps(