Skip to content

Commit 8415d12

Browse files
committed
Pass Process around explicitly
1 parent 0208b6d commit 8415d12

32 files changed

+856
-611
lines changed

src/bin/rustup-init.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ fn main() {
4040
let process = Process::os();
4141
let mut builder = Builder::new_multi_thread();
4242
builder.enable_all();
43-
with_runtime(process, builder, {
44-
async {
45-
match maybe_trace_rustup().await {
43+
with_runtime(process.clone(), builder, {
44+
async move {
45+
match maybe_trace_rustup(&process).await {
4646
Err(e) => {
47-
common::report_error(&e);
47+
common::report_error(&e, &process);
4848
std::process::exit(1);
4949
}
5050
Ok(utils::ExitCode(c)) => std::process::exit(c),
@@ -53,10 +53,10 @@ fn main() {
5353
});
5454
}
5555

56-
async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
56+
async fn maybe_trace_rustup(process: &Process) -> Result<utils::ExitCode> {
5757
#[cfg(not(feature = "otel"))]
5858
{
59-
run_rustup().await
59+
run_rustup(process).await
6060
}
6161
#[cfg(feature = "otel")]
6262
{
@@ -89,61 +89,63 @@ async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
8989
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
9090
let subscriber = Registry::default().with(env_filter).with(telemetry);
9191
tracing::subscriber::set_global_default(subscriber)?;
92-
let result = run_rustup().await;
92+
let result = run_rustup(process).await;
9393
// We're tracing, so block until all spans are exported.
9494
opentelemetry::global::shutdown_tracer_provider();
9595
result
9696
}
9797
}
9898

9999
#[cfg_attr(feature = "otel", tracing::instrument)]
100-
async fn run_rustup() -> Result<utils::ExitCode> {
101-
if let Ok(dir) = process().var("RUSTUP_TRACE_DIR") {
100+
async fn run_rustup(process: &Process) -> Result<utils::ExitCode> {
101+
if let Ok(dir) = process.var("RUSTUP_TRACE_DIR") {
102102
open_trace_file!(dir)?;
103103
}
104-
let result = run_rustup_inner().await;
105-
if process().var("RUSTUP_TRACE_DIR").is_ok() {
104+
let result = run_rustup_inner(process).await;
105+
if process.var("RUSTUP_TRACE_DIR").is_ok() {
106106
close_trace_file!();
107107
}
108108
result
109109
}
110110

111111
#[cfg_attr(feature = "otel", tracing::instrument(err))]
112-
async fn run_rustup_inner() -> Result<utils::ExitCode> {
112+
async fn run_rustup_inner(process: &Process) -> Result<utils::ExitCode> {
113113
// Guard against infinite proxy recursion. This mostly happens due to
114114
// bugs in rustup.
115115
do_recursion_guard()?;
116116

117117
// Before we do anything else, ensure we know where we are and who we
118118
// are because otherwise we cannot proceed usefully.
119-
let current_dir = process()
119+
let current_dir = process
120120
.current_dir()
121121
.context(RustupError::LocatingWorkingDir)?;
122122
utils::current_exe()?;
123123

124-
match process().name().as_deref() {
125-
Some("rustup") => rustup_mode::main(current_dir).await,
124+
match process.name().as_deref() {
125+
Some("rustup") => rustup_mode::main(current_dir, process).await,
126126
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
127127
// NB: The above check is only for the prefix of the file
128128
// name. Browsers rename duplicates to
129129
// e.g. rustup-setup(2), and this allows all variations
130130
// to work.
131-
setup_mode::main(current_dir).await
131+
setup_mode::main(current_dir, process).await
132132
}
133133
Some(n) if n.starts_with("rustup-gc-") => {
134134
// This is the final uninstallation stage on windows where
135135
// rustup deletes its own exe
136136
cfg_if! {
137137
if #[cfg(windows)] {
138-
self_update::complete_windows_uninstall()
138+
self_update::complete_windows_uninstall(process)
139139
} else {
140140
unreachable!("Attempted to use Windows-specific code on a non-Windows platform. Aborting.")
141141
}
142142
}
143143
}
144144
Some(n) => {
145145
is_proxyable_tools(n)?;
146-
proxy_mode::main(n, current_dir).await.map(ExitCode::from)
146+
proxy_mode::main(n, current_dir, process)
147+
.await
148+
.map(ExitCode::from)
147149
}
148150
None => {
149151
// Weird case. No arg0, or it's unparsable.

0 commit comments

Comments
 (0)