Skip to content

Commit 09faa3e

Browse files
committed
Change config paths to only check CARGO_HOME for cargo-script
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
1 parent edd36eb commit 09faa3e

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/bin/cargo/commands/run.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,8 @@ pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsStri
171171

172172
let manifest_path = root_manifest(Some(manifest_path), gctx)?;
173173

174-
// Treat `cargo foo.rs` like `cargo install --path foo` and re-evaluate the config based on the
175-
// location where the script resides, rather than the environment from where it's being run.
176-
let parent_path = manifest_path
177-
.parent()
178-
.expect("a file should always have a parent");
179-
gctx.reload_rooted_at(parent_path)?;
174+
// Reload to cargo home.
175+
gctx.reload_rooted_at(gctx.home().clone().into_path_unlocked())?;
180176

181177
let mut ws = Workspace::new(&manifest_path, gctx)?;
182178
if gctx.cli_unstable().avoid_dev_deps {

tests/testsuite/script.rs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use std::fs;
2+
13
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::paths::cargo_home;
25
use cargo_test_support::prelude::*;
36
use cargo_test_support::registry::Package;
47
use cargo_test_support::str;
@@ -318,26 +321,47 @@ rustc = "non-existent-rustc"
318321
.file("script.rs", script)
319322
.build();
320323

321-
// Verify the config is bad
324+
// Verify that the config from current directory is used
322325
p.cargo("-Zscript script.rs -NotAnArg")
323326
.masquerade_as_nightly_cargo(&["script"])
324-
.with_status(101)
325-
.with_stderr_data(str![[r#"
326-
[ERROR] could not execute process `non-existent-rustc -vV` (never executed)
327-
328-
Caused by:
329-
[NOT_FOUND]
327+
.with_stdout_data(str![[r#"
328+
bin: [ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]
329+
args: ["-NotAnArg"]
330330
331331
"#]])
332332
.run();
333333

334-
// Verify that the config isn't used
334+
// Verify that the config from parent directory is not used
335335
p.cargo("-Zscript ../script/script.rs -NotAnArg")
336336
.masquerade_as_nightly_cargo(&["script"])
337337
.with_stdout_data(str![[r#"
338338
bin: [ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]
339339
args: ["-NotAnArg"]
340340
341+
"#]])
342+
.run();
343+
344+
// Write a global config.toml in the cargo home directory
345+
let cargo_home = cargo_home();
346+
fs::write(
347+
&cargo_home.join("config.toml"),
348+
r#"
349+
[build]
350+
rustc = "non-existent-rustc"
351+
"#,
352+
)
353+
.unwrap();
354+
355+
// Verify the global config is used
356+
p.cargo("-Zscript script.rs -NotAnArg")
357+
.masquerade_as_nightly_cargo(&["script"])
358+
.with_status(101)
359+
.with_stderr_data(str![[r#"
360+
[ERROR] could not execute process `non-existent-rustc -vV` (never executed)
361+
362+
Caused by:
363+
[NOT_FOUND]
364+
341365
"#]])
342366
.run();
343367
}

0 commit comments

Comments
 (0)