From 073a32b61ff43e87ec520efdd6408e4f3cb937ee Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Sun, 4 Jun 2023 18:31:06 +0200 Subject: [PATCH 1/2] 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` From 03675ef6a4f8f2edad803063dfef41dd844dbb22 Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Mon, 5 Jun 2023 11:27:31 +0200 Subject: [PATCH 2/2] Add additional info on a new line --- src/cargo/ops/cargo_install.rs | 2 +- tests/testsuite/directory.rs | 8 +++++--- tests/testsuite/install.rs | 6 +++--- tests/testsuite/required_features.rs | 7 ++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 8833cd81f58..8ddfa4fab3d 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -320,7 +320,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> { format!( "failed to compile `{}`, intermediate artifacts can be \ - found at `{}`, to reuse those artifacts with a future \ + found at `{}`.\nTo reuse those artifacts with a future \ compilation, set the environment variable \ `CARGO_TARGET_DIR` to that path.", self.pkg, diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 07a04475ea4..e72f1f07d13 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -188,8 +188,8 @@ 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 `[..]`, \ -to reuse those artifacts with a future compilation, set the environment variable \ +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: @@ -761,7 +761,9 @@ fn version_missing() { .with_stderr( "\ [INSTALLING] bar v0.1.0 -error: failed to compile [..] +error: failed to compile [..], 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: failed to select a version for the requirement `foo = \"^2\"` diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 62de6d061f3..0f6d9909a42 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -978,7 +978,7 @@ 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`, to reuse those artifacts with a future compilation, \ + found at `[..]target`.\nTo reuse those artifacts with a future compilation, \ set the environment variable `CARGO_TARGET_DIR` to that path. ", ) @@ -2266,7 +2266,7 @@ fn failed_install_retains_temp_directory() { .unwrap(); compare::match_contains( "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 \ + `[..]`.\nTo reuse those artifacts with a future compilation, set the environment \ variable `CARGO_TARGET_DIR` to that path.", &stderr, None, @@ -2275,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(',').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 e427e20a45d..88be89fd4d0 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -658,8 +658,9 @@ 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`, to reuse those artifacts with a future compilation, set the environment \ - variable `CARGO_TARGET_DIR` to that path. + `[..]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` @@ -679,7 +680,7 @@ Caused by: "\ [INSTALLING] foo v0.0.1 ([..]) [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be found at \ - `[..]target`, to reuse those artifacts with a future compilation, set the environment \ + `[..]target`.\nTo reuse those artifacts with a future compilation, set the environment \ variable `CARGO_TARGET_DIR` to that path. Caused by: