Skip to content

Commit 4d7311f

Browse files
committed
Don't add toolchain bin to PATH on Windows
1 parent a942c34 commit 4d7311f

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

src/toolchain.rs

-4
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ impl<'a> InstalledCommonToolchain<'a> {
452452
path_entries.push(cargo_home.join("bin"));
453453
}
454454

455-
if cfg!(target_os = "windows") {
456-
path_entries.push(self.0.path.join("bin"));
457-
}
458-
459455
env_var::prepend_path("PATH", path_entries, cmd);
460456
}
461457
}

tests/cli-rustup.rs

+45
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,51 @@ fn fallback_cargo_calls_correct_rustc() {
549549
});
550550
}
551551

552+
// Checks that cargo can recursively invoke itself with rustup shorthand (via
553+
// the proxy).
554+
//
555+
// This involves a series of chained commands:
556+
//
557+
// 1. Calls `cargo --recursive-cargo-subcommand`
558+
// 2. The rustup `cargo` proxy launches, and launches the "mock" nightly cargo exe.
559+
// 3. The nightly "mock" cargo sees --recursive-cargo-subcommand, and launches
560+
// `cargo-foo --recursive-cargo`
561+
// 4. `cargo-foo` sees `--recursive-cargo` and launches `cargo +nightly --version`
562+
// 5. The rustup `cargo` proxy launches, and launches the "mock" nightly cargo exe.
563+
// 6. The nightly "mock" cargo sees `--version` and prints the version.
564+
//
565+
// Previously, rustup would place the toolchain's `bin` directory in PATH for
566+
// Windows due to some DLL issues. However, those aren't necessary anymore.
567+
// If the toolchain `bin` directory is in PATH, then this test would fail in
568+
// step 5 because the `cargo` executable would be the "mock" nightly cargo,
569+
// and the first argument would be `+nightly` which would be an error.
570+
#[test]
571+
fn recursive_cargo() {
572+
setup(&|config| {
573+
expect_ok(config, &["rustup", "default", "nightly"]);
574+
575+
// We need an intermediary to run cargo itself.
576+
// The "mock" cargo can't do that because on Windows it will check
577+
// for a `cargo.exe` in the current directory before checking PATH.
578+
//
579+
// The solution here is to copy from the "mock" `cargo.exe` into
580+
// `~/.cargo/bin/cargo-foo`. This is just for convenience to avoid
581+
// needing to build another executable just for this test.
582+
let output = clitools::run(config, "rustup", &["which", "cargo"], &[]);
583+
let real_mock_cargo = output.stdout.trim();
584+
let cargo_bin_path = config.cargodir.join("bin");
585+
let cargo_subcommand = cargo_bin_path.join(format!("cargo-foo{}", EXE_SUFFIX));
586+
fs::create_dir_all(&cargo_bin_path).unwrap();
587+
fs::copy(&real_mock_cargo, &cargo_subcommand).unwrap();
588+
589+
expect_stdout_ok(
590+
config,
591+
&["cargo", "--recursive-cargo-subcommand"],
592+
"hash-nightly-2",
593+
);
594+
});
595+
}
596+
552597
#[test]
553598
fn show_home() {
554599
setup(&|config| {

tests/mock/mock_bin_src.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ fn main() {
6161
let rustc = &format!("rustc{}", EXE_SUFFIX);
6262
Command::new(rustc).arg("--version").status().unwrap();
6363
}
64+
Some("--recursive-cargo-subcommand") => {
65+
Command::new("cargo-foo")
66+
.arg("--recursive-cargo")
67+
.status()
68+
.unwrap();
69+
}
70+
Some("--recursive-cargo") => {
71+
Command::new("cargo")
72+
.args(&["+nightly", "--version"])
73+
.status()
74+
.unwrap();
75+
}
6476
Some("--echo-args") => {
6577
let mut out = io::stderr();
6678
for arg in args {
@@ -71,7 +83,7 @@ fn main() {
7183
let mut out = io::stderr();
7284
writeln!(out, "{}", std::env::var("PATH").unwrap()).unwrap();
7385
}
74-
_ => panic!("bad mock proxy commandline"),
86+
arg => panic!("bad mock proxy commandline: {:?}", arg),
7587
}
7688
}
7789

0 commit comments

Comments
 (0)