Skip to content

Commit 6df98f6

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 4c6a3d5 commit 6df98f6

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/toolchain.rs

+19
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,25 @@ impl<'a> InstalledCommonToolchain<'a> {
453453
path_entries.push(cargo_home.join("bin"));
454454
}
455455

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

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();

tests/suite/cli_rustup.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,21 @@ fn recursive_cargo() {
585585
fs::create_dir_all(&cargo_bin_path).unwrap();
586586
fs::copy(&real_mock_cargo, &cargo_subcommand).unwrap();
587587

588-
config.expect_stdout_ok(&["cargo", "--recursive-cargo-subcommand"], "hash-nightly-2");
588+
// Verify the default behavior, which is currently broken on Windows.
589+
let args = &["cargo", "--recursive-cargo-subcommand"];
590+
if cfg!(windows) {
591+
config.expect_err(
592+
&["cargo", "--recursive-cargo-subcommand"],
593+
"bad mock proxy commandline",
594+
);
595+
}
596+
597+
// Try the opt-in, which should fix it.
598+
let out = config.run(args[0], &args[1..], &[("RUSTUP_WINDOWS_PATH_ADD_BIN", "0")]);
599+
if !out.ok || !out.stdout.contains("hash-nightly-2") {
600+
clitools::print_command(args, &out);
601+
panic!("expected hash-nightly-2 in output");
602+
}
589603
});
590604
});
591605
}

0 commit comments

Comments
 (0)