Skip to content

Commit c3c5167

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 c3c5167

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/toolchain.rs

+19
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

+17-3
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,25 @@ 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+
if cfg!(windows) {
591+
expect_err(
592+
config,
593+
&["cargo", "--recursive-cargo-subcommand"],
594+
"bad mock proxy commandline",
595+
);
596+
}
597+
598+
let out = run(
590599
config,
591-
&["cargo", "--recursive-cargo-subcommand"],
592-
"hash-nightly-2",
600+
args[0],
601+
&args[1..],
602+
&[("RUSTUP_WINDOWS_PATH_ADD_BIN", "0")],
593603
);
604+
if !out.ok || !out.stdout.contains("hash-nightly-2") {
605+
clitools::print_command(args, &out);
606+
panic!("expected hash-nightly-2 in output");
607+
}
594608
});
595609
}
596610

tests/mock/mock_bin_src.rs

+4-2
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)