From adfd89f6093e03a754762038c154ac10d5280b60 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 13 Apr 2026 15:42:19 +0200 Subject: [PATCH] cli-test: Respect `CARGO_TARGET_DIR` `radicle-cli-test` initiates `cargo` builds under the assumption that the target directory is always within the source directory. However, the user may have a different idea, specified with the environment variable `CARGO_TARGET_DIR` (supported by `cargo`, see https://doc.rust-lang.org/cargo/reference/environment-variables.html). Add support for `CARGO_TARGET_DIR`, with a fallback to 'target' at the top of the source tree if `CARGO_TARGET_DIR` is undefined. --- crates/radicle-cli-test/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/radicle-cli-test/src/lib.rs b/crates/radicle-cli-test/src/lib.rs index 549de7d6..9e66a67d 100644 --- a/crates/radicle-cli-test/src/lib.rs +++ b/crates/radicle-cli-test/src/lib.rs @@ -199,13 +199,11 @@ impl TestFormula { for (package, binary) in binaries { log::debug!(target: "test", "Building binaries for package `{package}`.."); - let cargo_manifest_dir = cargo_manifest_dir(); - let results = escargot::CargoBuild::new() .package(package) .bin(binary) - .manifest_path(cargo_manifest_dir.clone().join("Cargo.toml")) - .target_dir(cargo_manifest_dir.join(CARGO_TARGET_DIR_DIRNAME)) + .manifest_path(cargo_manifest_dir().join("Cargo.toml")) + .target_dir(cargo_target_dir()) .exec() .unwrap(); @@ -531,6 +529,12 @@ fn cargo_manifest_dir() -> PathBuf { env::var("CARGO_MANIFEST_DIR").map(PathBuf::from).unwrap() } +fn cargo_target_dir() -> PathBuf { + env::var("CARGO_TARGET_DIR") + .map(PathBuf::from) + .unwrap_or(cargo_manifest_dir().join(CARGO_TARGET_DIR_DIRNAME)) +} + /// Get the list of binary paths to use as `$PATH` for the tests, /// starting with the current working directory. fn bins(cwd: PathBuf) -> Vec { @@ -540,11 +544,7 @@ fn bins(cwd: PathBuf) -> Vec { // this makes it more convenient to execute scripts during testing. bins.push(cwd); - bins.push( - cargo_manifest_dir() - .join(CARGO_TARGET_DIR_DIRNAME) - .join(CARGO_PROFILE), - ); + bins.push(cargo_target_dir().join(CARGO_PROFILE)); // Add the "real" `$PATH`. if let Ok(path) = env::var("PATH") {