Skip to content

Commit aa753bb

Browse files
authored
Merge pull request #29 from fornwall/avoid-cargo-target-dir-env
Avoid exporting CARGO_TARGET_DIR (fixes #27)
2 parents 278d383 + 8ae9856 commit aa753bb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ fn cargo(
11771177
}
11781178

11791179
let cargo_target_dir = format!("{}", platform::binary_cache_path()?.display(),);
1180-
cmd.env("CARGO_TARGET_DIR", cargo_target_dir);
1180+
cmd.arg("--target-dir");
1181+
cmd.arg(cargo_target_dir);
11811182

11821183
// Block `--release` on `bench`.
11831184
if !meta.debug && cmd_name != "bench" {

tests/data/cargo-target-dir-env.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::env;
2+
3+
pub fn main() {
4+
// Test that CARGO_TARGET_DIR is not set by rust-script to avoid
5+
// interfering with cargo calls done by the script.
6+
// See https://github.com/fornwall/rust-script/issues/27
7+
let env_variable = env::var("CARGO_TARGET_DIR");
8+
println!("--output--");
9+
println!(
10+
"{:?}",
11+
matches!(env_variable, Err(env::VarError::NotPresent))
12+
);
13+
}

tests/tests/script.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,22 @@ fn test_pub_fn_main() {
171171
.unwrap()
172172
}
173173

174+
#[test]
175+
fn test_cargo_target_dir_env() {
176+
let out = rust_script!("tests/data/cargo-target-dir-env.rs").unwrap();
177+
scan!(out.stdout_output();
178+
("true") => ()
179+
)
180+
.unwrap()
181+
}
182+
174183
#[test]
175184
fn test_outer_line_doc() {
176185
let out = rust_script!("tests/data/outer-line-doc.rs").unwrap();
177186
scan!(out.stdout_output();
178187
("Some(1)") => ()
179188
)
180-
.unwrap()
189+
.unwrap()
181190
}
182191

183192
#[test]

0 commit comments

Comments
 (0)