Skip to content

Commit 7ba68f5

Browse files
committed
Move set_env to InstalledCommonToolchain
1 parent a55ff4a commit 7ba68f5

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/toolchain.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,6 @@ impl<'a> Toolchain<'a> {
158158
== Some(true)
159159
}
160160

161-
// Custom and Distributable. Installed only.
162-
fn set_env(&self, cmd: &mut Command) {
163-
self.set_ldpath(cmd);
164-
165-
// Because rustup and cargo use slightly different
166-
// definitions of cargo home (rustup doesn't read HOME on
167-
// windows), we must set it here to ensure cargo and
168-
// rustup agree.
169-
if let Ok(cargo_home) = utils::cargo_home() {
170-
cmd.env("CARGO_HOME", &cargo_home);
171-
}
172-
173-
env_var::inc("RUST_RECURSION_COUNT", cmd);
174-
175-
cmd.env("RUSTUP_TOOLCHAIN", &self.name);
176-
cmd.env("RUSTUP_HOME", &self.cfg.rustup_dir);
177-
}
178-
179161
// Custom and Distributable. Installed only.
180162
pub fn set_ldpath(&self, cmd: &mut Command) {
181163
let mut new_path = vec![self.path.join("lib")];
@@ -358,9 +340,26 @@ impl<'a> InstalledCommonToolchain<'a> {
358340
Path::new(&binary)
359341
};
360342
let mut cmd = Command::new(&path);
361-
self.0.set_env(&mut cmd);
343+
self.set_env(&mut cmd);
362344
Ok(cmd)
363345
}
346+
347+
fn set_env(&self, cmd: &mut Command) {
348+
self.0.set_ldpath(cmd);
349+
350+
// Because rustup and cargo use slightly different
351+
// definitions of cargo home (rustup doesn't read HOME on
352+
// windows), we must set it here to ensure cargo and
353+
// rustup agree.
354+
if let Ok(cargo_home) = utils::cargo_home() {
355+
cmd.env("CARGO_HOME", &cargo_home);
356+
}
357+
358+
env_var::inc("RUST_RECURSION_COUNT", cmd);
359+
360+
cmd.env("RUSTUP_TOOLCHAIN", &self.0.name);
361+
cmd.env("RUSTUP_HOME", &self.0.cfg.rustup_dir);
362+
}
364363
}
365364

366365
/// Newtype to facilitate splitting out custom-toolchain specific code.
@@ -494,9 +493,7 @@ impl<'a> DistributableToolchain<'a> {
494493
if !self.0.exists() {
495494
return Err(ErrorKind::ToolchainNotInstalled(self.0.name.to_owned()).into());
496495
}
497-
if !primary_toolchain.exists() {
498-
return Err(ErrorKind::ToolchainNotInstalled(primary_toolchain.name.to_owned()).into());
499-
}
496+
let installed_primary = primary_toolchain.as_installed_common()?;
500497

501498
let src_file = self.0.path.join("bin").join(format!("cargo{}", EXE_SUFFIX));
502499

@@ -528,7 +525,7 @@ impl<'a> DistributableToolchain<'a> {
528525
src_file
529526
};
530527
let mut cmd = Command::new(exe_path);
531-
primary_toolchain.set_env(&mut cmd); // set up the environment to match rustc, not cargo
528+
installed_primary.set_env(&mut cmd); // set up the environment to match rustc, not cargo
532529
cmd.env("RUSTUP_TOOLCHAIN", &primary_toolchain.name);
533530
Ok(cmd)
534531
}

0 commit comments

Comments
 (0)