Skip to content

Commit 9c56601

Browse files
committed
Add RUSTUP_WINDOWS_PATH_ADD_BIN
Due to the uncertainty around whether or not this change will cause problems, this introduces an opt-in for removing the PATH change on Windows.
1 parent 4d7311f commit 9c56601

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/toolchain.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,25 @@ impl<'a> InstalledCommonToolchain<'a> {
452452
path_entries.push(cargo_home.join("bin"));
453453
}
454454

455+
if cfg!(target_os = "windows") {
456+
// Historically rustup has included the bin directory in PATH to
457+
// work around some bugs (see
458+
// https://github.com/rust-lang/rustup/pull/3178 for more
459+
// information). This shouldn't be needed anymore, and it causes
460+
// problems because calling tools recursively (like `cargo
461+
// +nightly metadata` from within a cargo subcommand). The
462+
// recursive call won't work because it is not executing the
463+
// proxy, so the `+` toolchain override doesn't work.
464+
//
465+
// This is opt-in to allow us to get more real-world testing.
466+
if process()
467+
.var_os("RUSTUP_WINDOWS_PATH_ADD_BIN")
468+
.map_or(true, |s| s == "1")
469+
{
470+
path_entries.push(self.0.path.join("bin"));
471+
}
472+
}
473+
455474
env_var::prepend_path("PATH", path_entries, cmd);
456475
}
457476
}

tests/cli-rustup.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,23 @@ fn recursive_cargo() {
586586
fs::create_dir_all(&cargo_bin_path).unwrap();
587587
fs::copy(&real_mock_cargo, &cargo_subcommand).unwrap();
588588

589-
expect_stdout_ok(
589+
let args = &["cargo", "--recursive-cargo-subcommand"];
590+
expect_err(
590591
config,
591592
&["cargo", "--recursive-cargo-subcommand"],
592-
"hash-nightly-2",
593+
"bad mock proxy commandline",
594+
);
595+
596+
let out = run(
597+
config,
598+
args[0],
599+
&args[1..],
600+
&[("RUSTUP_WINDOWS_PATH_ADD_BIN", "0")],
593601
);
602+
if !out.ok || !out.stdout.contains("hash-nightly-2") {
603+
clitools::print_command(args, &out);
604+
panic!("expected hash-nightly-2 in output");
605+
}
594606
});
595607
}
596608

tests/mock/mock_bin_src.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ fn main() {
6262
Command::new(rustc).arg("--version").status().unwrap();
6363
}
6464
Some("--recursive-cargo-subcommand") => {
65-
Command::new("cargo-foo")
65+
let status = Command::new("cargo-foo")
6666
.arg("--recursive-cargo")
6767
.status()
6868
.unwrap();
69+
assert!(status.success());
6970
}
7071
Some("--recursive-cargo") => {
71-
Command::new("cargo")
72+
let status = Command::new("cargo")
7273
.args(&["+nightly", "--version"])
7374
.status()
7475
.unwrap();
76+
assert!(status.success());
7577
}
7678
Some("--echo-args") => {
7779
let mut out = io::stderr();

0 commit comments

Comments
 (0)