Skip to content

Commit 78315d4

Browse files
committed
Unconditionally set RUSTUP_TOOLCHAIN_SOURCE in proxy
1 parent a8956a3 commit 78315d4

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

src/cli/proxy_mode.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{path::PathBuf, process::ExitStatus};
1+
use std::{
2+
path::PathBuf,
3+
process::{Command, ExitStatus},
4+
};
25

36
use anyhow::Result;
47

@@ -7,7 +10,7 @@ use crate::{
710
command::run_command_for_dir,
811
config::ActiveReason,
912
process::Process,
10-
toolchain::{ResolvableLocalToolchainName, maybe_set_env_source},
13+
toolchain::ResolvableLocalToolchainName,
1114
};
1215

1316
#[tracing::instrument(level = "trace", skip(process))]
@@ -36,8 +39,23 @@ pub async fn main(arg0: &str, current_dir: PathBuf, process: &Process) -> Result
3639
let cfg = set_globals(current_dir, true, process)?;
3740
let toolchain = cfg.resolve_local_toolchain(toolchain).await?;
3841
let mut cmd = toolchain.command(arg0)?;
39-
if toolchain_specified {
40-
maybe_set_env_source(&mut cmd, || Some(ActiveReason::CommandLine));
41-
}
42+
set_env_source(
43+
&mut cmd,
44+
if toolchain_specified {
45+
Some(ActiveReason::CommandLine)
46+
} else if let Ok(Some((_, reason))) = cfg.active_toolchain() {
47+
Some(reason)
48+
} else {
49+
None
50+
},
51+
);
4252
run_command_for_dir(cmd, arg0, &cmd_args)
4353
}
54+
55+
/// Set the `RUSTUP_TOOLCHAIN_SOURCE` environment variable to indicate how the toolchain was
56+
/// determined.
57+
fn set_env_source(cmd: &mut Command, reason: Option<ActiveReason>) {
58+
if let Some(reason) = reason {
59+
cmd.env("RUSTUP_TOOLCHAIN_SOURCE", reason.to_source());
60+
}
61+
}

src/toolchain.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,6 @@ impl<'a> Toolchain<'a> {
181181

182182
env_var::inc("RUST_RECURSION_COUNT", cmd, self.cfg.process);
183183

184-
maybe_set_env_source(cmd, || {
185-
if let Ok(Some((_, reason))) = self.cfg.active_toolchain() {
186-
Some(reason)
187-
} else {
188-
None
189-
}
190-
});
191-
192184
cmd.env("RUSTUP_TOOLCHAIN", format!("{}", self.name));
193185
cmd.env("RUSTUP_HOME", &self.cfg.rustup_dir);
194186
}
@@ -613,16 +605,3 @@ impl<'a> Toolchain<'a> {
613605
.collect())
614606
}
615607
}
616-
617-
/// Set the `RUSTUP_TOOLCHAIN_SOURCE` environment variable if not already set.
618-
///
619-
/// `RUSTUP_TOOLCHAIN_SOURCE` indicates how the toolchain was determined. The environment
620-
/// variable could have been set in proxy_mode.rs, in which case it should not be changed.
621-
pub(crate) fn maybe_set_env_source(cmd: &mut Command, f: impl FnOnce() -> Option<ActiveReason>) {
622-
if env::var_os("RUSTUP_TOOLCHAIN_SOURCE").is_some() {
623-
return;
624-
}
625-
if let Some(reason) = f() {
626-
cmd.env("RUSTUP_TOOLCHAIN_SOURCE", reason.to_source());
627-
}
628-
}

0 commit comments

Comments
 (0)