Skip to content

Commit 4c6a3d5

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

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

src/toolchain.rs

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

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

tests/mock/mock_bin_src.rs

Lines changed: 13 additions & 1 deletion
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

tests/suite/cli_rustup.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,49 @@ fn fallback_cargo_calls_correct_rustc() {
547547
});
548548
}
549549

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

0 commit comments

Comments
 (0)