Skip to content

Commit a61d845

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 a61d845

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
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: 25 additions & 11 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,7 +321,28 @@ rustc = "non-existent-rustc"
318321
.file("script.rs", script)
319322
.build();
320323

321-
// Verify the config is bad
324+
// Verify that the local config is not used
325+
p.cargo("-Zscript ../script/script.rs -NotAnArg")
326+
.masquerade_as_nightly_cargo(&["script"])
327+
.with_stdout_data(str![[r#"
328+
bin: [ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]
329+
args: ["-NotAnArg"]
330+
331+
"#]])
332+
.run();
333+
334+
// Write a global config.toml in the cargo home directory
335+
let cargo_home = cargo_home();
336+
fs::write(
337+
&cargo_home.join("config.toml"),
338+
r#"
339+
[build]
340+
rustc = "non-existent-rustc"
341+
"#,
342+
)
343+
.unwrap();
344+
345+
// Verify the global config is used
322346
p.cargo("-Zscript script.rs -NotAnArg")
323347
.masquerade_as_nightly_cargo(&["script"])
324348
.with_status(101)
@@ -328,16 +352,6 @@ rustc = "non-existent-rustc"
328352
Caused by:
329353
[NOT_FOUND]
330354
331-
"#]])
332-
.run();
333-
334-
// Verify that the config isn't used
335-
p.cargo("-Zscript ../script/script.rs -NotAnArg")
336-
.masquerade_as_nightly_cargo(&["script"])
337-
.with_stdout_data(str![[r#"
338-
bin: [ROOT]/home/.cargo/target/[HASH]/debug/script[EXE]
339-
args: ["-NotAnArg"]
340-
341355
"#]])
342356
.run();
343357
}

0 commit comments

Comments
 (0)