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 14, 2024
1 parent 6d5f0f6 commit e36ad49
Show file tree
Hide file tree
Showing 31 changed files with 850 additions and 609 deletions.
38 changes: 20 additions & 18 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 All @@ -72,61 +72,63 @@ async fn maybe_trace_rustup() -> Result<utils::ExitCode> {

let subscriber = Registry::default().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
// rustup deletes its own exe
cfg_if! {
if #[cfg(windows)] {
self_update::complete_windows_uninstall()
self_update::complete_windows_uninstall(process)
} else {
unreachable!("Attempted to use Windows-specific code on a non-Windows platform. Aborting.")
}
}
}
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 e36ad49

Please sign in to comment.