Skip to content

Commit e36ad49

Browse files
committed
Pass Process around explicitly
1 parent 6d5f0f6 commit e36ad49

31 files changed

+850
-609
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
{
@@ -72,61 +72,63 @@ async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
7272

7373
let subscriber = Registry::default().with(telemetry);
7474
tracing::subscriber::set_global_default(subscriber)?;
75-
let result = run_rustup().await;
75+
let result = run_rustup(process).await;
7676
// We're tracing, so block until all spans are exported.
7777
opentelemetry::global::shutdown_tracer_provider();
7878
result
7979
}
8080
}
8181

8282
#[cfg_attr(feature = "otel", tracing::instrument)]
83-
async fn run_rustup() -> Result<utils::ExitCode> {
84-
if let Ok(dir) = process().var("RUSTUP_TRACE_DIR") {
83+
async fn run_rustup(process: &Process) -> Result<utils::ExitCode> {
84+
if let Ok(dir) = process.var("RUSTUP_TRACE_DIR") {
8585
open_trace_file!(dir)?;
8686
}
87-
let result = run_rustup_inner().await;
88-
if process().var("RUSTUP_TRACE_DIR").is_ok() {
87+
let result = run_rustup_inner(process).await;
88+
if process.var("RUSTUP_TRACE_DIR").is_ok() {
8989
close_trace_file!();
9090
}
9191
result
9292
}
9393

9494
#[cfg_attr(feature = "otel", tracing::instrument(err))]
95-
async fn run_rustup_inner() -> Result<utils::ExitCode> {
95+
async fn run_rustup_inner(process: &Process) -> Result<utils::ExitCode> {
9696
// Guard against infinite proxy recursion. This mostly happens due to
9797
// bugs in rustup.
9898
do_recursion_guard()?;
9999

100100
// Before we do anything else, ensure we know where we are and who we
101101
// are because otherwise we cannot proceed usefully.
102-
let current_dir = process()
102+
let current_dir = process
103103
.current_dir()
104104
.context(RustupError::LocatingWorkingDir)?;
105105
utils::current_exe()?;
106106

107-
match process().name().as_deref() {
108-
Some("rustup") => rustup_mode::main(current_dir).await,
107+
match process.name().as_deref() {
108+
Some("rustup") => rustup_mode::main(current_dir, process).await,
109109
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
110110
// NB: The above check is only for the prefix of the file
111111
// name. Browsers rename duplicates to
112112
// e.g. rustup-setup(2), and this allows all variations
113113
// to work.
114-
setup_mode::main(current_dir).await
114+
setup_mode::main(current_dir, process).await
115115
}
116116
Some(n) if n.starts_with("rustup-gc-") => {
117117
// This is the final uninstallation stage on windows where
118118
// rustup deletes its own exe
119119
cfg_if! {
120120
if #[cfg(windows)] {
121-
self_update::complete_windows_uninstall()
121+
self_update::complete_windows_uninstall(process)
122122
} else {
123123
unreachable!("Attempted to use Windows-specific code on a non-Windows platform. Aborting.")
124124
}
125125
}
126126
}
127127
Some(n) => {
128128
is_proxyable_tools(n)?;
129-
proxy_mode::main(n, current_dir).await.map(ExitCode::from)
129+
proxy_mode::main(n, current_dir, process)
130+
.await
131+
.map(ExitCode::from)
130132
}
131133
None => {
132134
// Weird case. No arg0, or it's unparsable.

0 commit comments

Comments
 (0)