Skip to content

Commit 7a46e17

Browse files
authored
Merge pull request #3368 from rbtcollins/currentprocess-revamp
2 parents 929385c + 4de14bd commit 7a46e17

33 files changed

+152
-117
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ derivative.workspace = true
5555
download = { path = "download", default-features = false }
5656
effective-limits = "0.5.5"
5757
enum-map = "2.5.0"
58+
enum_dispatch.workspace = true
5859
flate2 = "1"
5960
fs_at.workspace = true
6061
git-testament = "0.2"
@@ -174,6 +175,7 @@ members = ["download", "rustup-macros"]
174175
[workspace.dependencies]
175176
anyhow = "1.0.69"
176177
derivative = "2.2.0"
178+
enum_dispatch = "0.3.11"
177179
fs_at = "0.1.6"
178180
lazy_static = "1"
179181
once_cell = "1.17.1"

src/bin/rustup-init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ use rustup::cli::rustup_mode;
2323
#[cfg(windows)]
2424
use rustup::cli::self_update;
2525
use rustup::cli::setup_mode;
26-
use rustup::currentprocess::{process, with, OSProcess};
26+
use rustup::currentprocess::{process, varsource::VarSource, with, OSProcess};
2727
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
2828
use rustup::is_proxyable_tools;
2929
use rustup::utils::utils;
3030

3131
fn main() {
3232
let process = OSProcess::default();
33-
with(Box::new(process), || match maybe_trace_rustup() {
33+
with(process.into(), || match maybe_trace_rustup() {
3434
Err(e) => {
3535
common::report_error(&e);
3636
std::process::exit(1);

src/cli/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ use term2::Terminal;
1414

1515
use super::self_update;
1616
use super::term2;
17+
use crate::currentprocess::argsource::ArgSource;
18+
use crate::currentprocess::{
19+
filesource::{StdinSource, StdoutSource},
20+
varsource::VarSource,
21+
};
1722
use crate::utils::notifications as util_notifications;
1823
use crate::utils::notify::NotificationLevel;
1924
use crate::utils::utils;

src/cli/log.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io::Write;
33
use term2::Terminal;
44

55
use super::term2;
6+
use crate::currentprocess::varsource::VarSource;
67
use crate::process;
78

89
macro_rules! warn {

src/cli/proxy_mode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anyhow::Result;
55
use crate::{
66
cli::{common::set_globals, job, self_update},
77
command::run_command_for_dir,
8+
currentprocess::argsource::ArgSource,
89
toolchain::names::{LocalToolchainName, ResolvableLocalToolchainName},
910
utils::utils::{self, ExitCode},
1011
Cfg,

src/cli/rustup_mode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ use crate::{
2121
topical_doc,
2222
},
2323
command,
24+
currentprocess::{
25+
argsource::ArgSource,
26+
filesource::{StderrSource, StdoutSource},
27+
varsource::VarSource,
28+
},
2429
dist::{
2530
dist::{PartialToolchainDesc, Profile, TargetTriple},
2631
manifest::{Component, ComponentStatus},

src/cli/self_update.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use crate::{
6565
markdown::md,
6666
term2::{self, Terminal},
6767
},
68+
currentprocess::{filesource::StdoutSource, varsource::VarSource},
6869
dist::dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc},
6970
install::UpdateStatus,
7071
process,
@@ -1296,11 +1297,11 @@ mod tests {
12961297
with_rustup_home(|home| {
12971298
let mut vars = HashMap::new();
12981299
home.apply(&mut vars);
1299-
let tp = Box::new(currentprocess::TestProcess {
1300+
let tp = currentprocess::TestProcess {
13001301
vars,
13011302
..Default::default()
1302-
});
1303-
currentprocess::with(tp.clone(), || -> Result<()> {
1303+
};
1304+
currentprocess::with(tp.clone().into(), || -> Result<()> {
13041305
// TODO: we could pass in a custom cfg to get notification
13051306
// callbacks rather than output to the tp sink.
13061307
let mut cfg = common::set_globals(false, false).unwrap();
@@ -1343,11 +1344,11 @@ info: default host triple is {0}
13431344
let cargo_home = root_dir.path().join("cargo");
13441345
let mut vars = HashMap::new();
13451346
vars.env("CARGO_HOME", cargo_home.to_string_lossy().to_string());
1346-
let tp = Box::new(currentprocess::TestProcess {
1347+
let tp = currentprocess::TestProcess {
13471348
vars,
13481349
..Default::default()
1349-
});
1350-
currentprocess::with(tp, || -> Result<()> {
1350+
};
1351+
currentprocess::with(tp.into(), || -> Result<()> {
13511352
super::install_bins().unwrap();
13521353
Ok(())
13531354
})

src/cli/self_update/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::path::PathBuf;
2929
use anyhow::{bail, Result};
3030

3131
use super::utils;
32-
use crate::process;
32+
use crate::{currentprocess::varsource::VarSource, process};
3333

3434
pub(crate) type Shell = Box<dyn UnixShell>;
3535

src/cli/self_update/unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anyhow::{bail, Context, Result};
55

66
use super::install_bins;
77
use super::shell;
8+
use crate::currentprocess::varsource::VarSource;
89
use crate::process;
910
use crate::utils::utils;
1011
use crate::utils::Notification;

0 commit comments

Comments
 (0)