Skip to content

Commit

Permalink
Pass Process around explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jun 13, 2024
1 parent dfc9205 commit 1a33baa
Show file tree
Hide file tree
Showing 28 changed files with 658 additions and 504 deletions.
36 changes: 19 additions & 17 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ fn main() {
let process = Process::os();
let mut builder = Builder::new_multi_thread();
builder.enable_all();
with_runtime(process, builder, {
async {
match maybe_trace_rustup().await {
with_runtime(process.clone(), builder, {
async move {
match maybe_trace_rustup(&process).await {
Err(e) => {
common::report_error(&e);
common::report_error(&e, &process);
std::process::exit(1);
}
Ok(utils::ExitCode(c)) => std::process::exit(c),
Expand All @@ -53,10 +53,10 @@ fn main() {
});
}

async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
async fn maybe_trace_rustup(process: &Process) -> Result<utils::ExitCode> {
#[cfg(not(feature = "otel"))]
{
run_rustup().await
run_rustup(process).await
}
#[cfg(feature = "otel")]
{
Expand Down Expand Up @@ -89,46 +89,46 @@ async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let subscriber = Registry::default().with(env_filter).with(telemetry);
tracing::subscriber::set_global_default(subscriber)?;
let result = run_rustup().await;
let result = run_rustup(process).await;
// We're tracing, so block until all spans are exported.
opentelemetry::global::shutdown_tracer_provider();
result
}
}

#[cfg_attr(feature = "otel", tracing::instrument)]
async fn run_rustup() -> Result<utils::ExitCode> {
if let Ok(dir) = process().var("RUSTUP_TRACE_DIR") {
async fn run_rustup(process: &Process) -> Result<utils::ExitCode> {
if let Ok(dir) = process.var("RUSTUP_TRACE_DIR") {
open_trace_file!(dir)?;
}
let result = run_rustup_inner().await;
if process().var("RUSTUP_TRACE_DIR").is_ok() {
let result = run_rustup_inner(process).await;
if process.var("RUSTUP_TRACE_DIR").is_ok() {
close_trace_file!();
}
result
}

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

// Before we do anything else, ensure we know where we are and who we
// are because otherwise we cannot proceed usefully.
let current_dir = process()
let current_dir = process
.current_dir()
.context(RustupError::LocatingWorkingDir)?;
utils::current_exe()?;

match process().name().as_deref() {
Some("rustup") => rustup_mode::main(current_dir).await,
match process.name().as_deref() {
Some("rustup") => rustup_mode::main(current_dir, process).await,
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
// NB: The above check is only for the prefix of the file
// name. Browsers rename duplicates to
// e.g. rustup-setup(2), and this allows all variations
// to work.
setup_mode::main(current_dir).await
setup_mode::main(current_dir, process).await
}
Some(n) if n.starts_with("rustup-gc-") => {
// This is the final uninstallation stage on windows where
Expand All @@ -143,7 +143,9 @@ async fn run_rustup_inner() -> Result<utils::ExitCode> {
}
Some(n) => {
is_proxyable_tools(n)?;
proxy_mode::main(n, current_dir).await.map(ExitCode::from)
proxy_mode::main(n, current_dir, process)
.await
.map(ExitCode::from)
}
None => {
// Weird case. No arg0, or it's unparsable.
Expand Down
Loading

0 comments on commit 1a33baa

Please sign in to comment.