Skip to content
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
14 changes: 13 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,19 @@ fn find_workspace_root_with_loader(

for ances_manifest_path in find_root_iter(manifest_path, gctx) {
debug!("find_root - trying {}", ances_manifest_path.display());
if let Some(ws_root_path) = loader(&ances_manifest_path)? {
let ws_root_path = loader(&ances_manifest_path).with_context(|| {
format!(
"failed searching for potential workspace\n\
package manifest: `{}`\n\
invalid potential workspace manifest: `{}`\n\
\n\
help: to avoid searching for a non-existent workspace, add \
`[workspace]` to the package manifest",
manifest_path.display(),
ances_manifest_path.display(),
)
})?;
if let Some(ws_root_path) = ws_root_path {
return Ok(Some(ws_root_path));
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,11 @@ fn git_install_reads_workspace_manifest() {
|
6 | incremental = 3
| ^
[ERROR] failed searching for potential workspace
package manifest: `[ROOT]/home/.cargo/git/checkouts/foo-[HASH]/[..]/bin1/Cargo.toml`
invalid potential workspace manifest: `[ROOT]/home/.cargo/git/checkouts/foo-[HASH]/[..]/Cargo.toml`

[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest

"#]])
.run();
Expand Down
53 changes: 52 additions & 1 deletion tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use std::fs;
use crate::prelude::*;
use cargo_test_support::registry::Package;
use cargo_test_support::str;
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project, sleep_ms};
use cargo_test_support::{
ProjectBuilder, basic_lib_manifest, basic_manifest, git, paths, project, project_in_home,
sleep_ms,
};

#[cargo_test]
fn simple_explicit() {
Expand Down Expand Up @@ -1121,6 +1124,11 @@ fn new_warning_with_corrupt_ws() {
| ^
[WARNING] compiling this new package may not work due to invalid workspace configuration

failed searching for potential workspace
package manifest: `[ROOT]/foo/bar/Cargo.toml`
invalid potential workspace manifest: `[ROOT]/foo/Cargo.toml`

[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest
[NOTE] see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

"#]]).run();
Expand Down Expand Up @@ -1399,6 +1407,11 @@ fn error_if_parent_cargo_toml_is_invalid() {
|
1 | Totally not a TOML file
| ^
[ERROR] failed searching for potential workspace
package manifest: `[ROOT]/foo/bar/Cargo.toml`
invalid potential workspace manifest: `[ROOT]/foo/Cargo.toml`

[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest

"#]])
.run();
Expand Down Expand Up @@ -2198,6 +2211,44 @@ fn cargo_home_at_root_works() {
p.cargo("check --frozen").env("CARGO_HOME", p.root()).run();
}

#[cargo_test]
fn parent_manifest_error_mentions_workspace_search() {
ProjectBuilder::new(paths::home())
.file(
"Cargo.toml",
r#"
[package]
name = "home-manifest"
version = "0.1.0"
authors = []
"#,
)
.build();

let p = project_in_home("stuff")
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] failed searching for potential workspace
package manifest: `[ROOT]/home/stuff/Cargo.toml`
invalid potential workspace manifest: `[ROOT]/home/Cargo.toml`

[HELP] to avoid searching for a non-existent workspace, add `[workspace]` to the package manifest

Caused by:
failed to parse manifest at `[ROOT]/home/Cargo.toml`

Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

"#]])
.run();
}

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