From 073a32b61ff43e87ec520efdd6408e4f3cb937ee Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Sun, 4 Jun 2023 18:31:06 +0200 Subject: [PATCH] Add message on reusing previous temporary path on failed cargo installs --- src/cargo/ops/cargo_install.rs | 4 +++- tests/testsuite/directory.rs | 4 +++- tests/testsuite/install.rs | 9 ++++++--- tests/testsuite/required_features.rs | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 5f843e8c731..8833cd81f58 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -320,7 +320,9 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> { format!( "failed to compile `{}`, intermediate artifacts can be \ - found at `{}`", + found at `{}`, to reuse those artifacts with a future \ + compilation, set the environment variable \ + `CARGO_TARGET_DIR` to that path.", self.pkg, self.ws.target_dir().display() ) diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 0e28de03942..07a04475ea4 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -188,7 +188,9 @@ fn simple_install_fail() { .with_status(101) .with_stderr( " Installing bar v0.1.0 -error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]` +error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]`, \ +to reuse those artifacts with a future compilation, set the environment variable \ +`CARGO_TARGET_DIR` to that path. Caused by: no matching package found diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 2609d804819..62de6d061f3 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -978,7 +978,8 @@ fn compile_failure() { "\ [ERROR] could not compile `foo` (bin \"foo\") due to previous error [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be \ - found at `[..]target` + found at `[..]target`, to reuse those artifacts with a future compilation, \ + set the environment variable `CARGO_TARGET_DIR` to that path. ", ) .run(); @@ -2264,7 +2265,9 @@ fn failed_install_retains_temp_directory() { ) .unwrap(); compare::match_contains( - "error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at `[..]`", + "error: failed to compile `foo v0.0.1`, intermediate artifacts can be found at \ + `[..]`, to reuse those artifacts with a future compilation, set the environment \ + variable `CARGO_TARGET_DIR` to that path.", &stderr, None, ) @@ -2272,7 +2275,7 @@ fn failed_install_retains_temp_directory() { // Find the path in the output. let start = stderr.find("found at `").unwrap() + 10; - let end = stderr[start..].find('\n').unwrap() - 1; + let end = stderr[start..].find(',').unwrap() - 1; let path = Path::new(&stderr[start..(end + start)]); assert!(path.exists()); assert!(path.join("release/deps").exists()); diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index ac6c9d23335..e427e20a45d 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -658,7 +658,8 @@ Consider enabling some of the needed features by passing, e.g., `--features=\"a\ "\ [INSTALLING] foo v0.0.1 ([..]) [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ - `[..]target` + `[..]target`, to reuse those artifacts with a future compilation, set the environment \ + variable `CARGO_TARGET_DIR` to that path. Caused by: target `foo` in package `foo` requires the features: `a` @@ -678,7 +679,8 @@ Caused by: "\ [INSTALLING] foo v0.0.1 ([..]) [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ - `[..]target` + `[..]target`, to reuse those artifacts with a future compilation, set the environment \ + variable `CARGO_TARGET_DIR` to that path. Caused by: target `foo` in package `foo` requires the features: `a`