Skip to content

Process cleanup #3877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ version = "0.52.0"
enum-map = "2.5.0"
platforms.workspace = true
proptest.workspace = true
rustup-macros.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
trycmd = "0.15.0"

Expand All @@ -130,7 +129,7 @@ platforms.workspace = true
regex = "1"

[workspace]
members = ["download", "rustup-macros"]
members = ["download"]

[workspace.dependencies]
anyhow = "1.0.69"
Expand All @@ -141,7 +140,6 @@ opentelemetry_sdk = { version = "0.23", features = ["rt-tokio"] }
opentelemetry-otlp = "0.16"
platforms = "3.4"
proptest = "1.1.0"
rustup-macros = { path = "rustup-macros" }
tempfile = "3.8"
termcolor = "1.2"
thiserror = "1.0"
Expand Down
13 changes: 0 additions & 13 deletions rustup-macros/Cargo.toml

This file was deleted.

124 changes: 0 additions & 124 deletions rustup-macros/src/lib.rs

This file was deleted.

41 changes: 17 additions & 24 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,51 @@

#![recursion_limit = "1024"]

use std::process::ExitCode;

use anyhow::{anyhow, Context, Result};
use cfg_if::cfg_if;
// Public macros require availability of the internal symbols
use rs_tracing::{
close_trace_file, close_trace_file_internal, open_trace_file, trace_to_file_internal,
};
use tokio::runtime::Builder;

use rustup::cli::common;
use rustup::cli::proxy_mode;
use rustup::cli::rustup_mode;
#[cfg(windows)]
use rustup::cli::self_update;
use rustup::cli::setup_mode;
use rustup::currentprocess::{with_runtime, Process};
use rustup::currentprocess::Process;
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use rustup::errors::RustupError;
use rustup::is_proxyable_tools;
use rustup::utils::utils::{self, ExitCode};
use rustup::utils::utils;

fn main() {
#[tokio::main]
async fn main() -> Result<ExitCode> {
#[cfg(windows)]
pre_rustup_main_init();

let process = Process::os();
let mut builder = Builder::new_multi_thread();
builder.enable_all();
with_runtime(process.clone(), builder, {
async move {
match maybe_trace_rustup(&process).await {
Err(e) => {
common::report_error(&e, &process);
std::process::exit(1);
}
Ok(utils::ExitCode(c)) => std::process::exit(c),
}
}
});
}

async fn maybe_trace_rustup(process: &Process) -> Result<utils::ExitCode> {
#[cfg(feature = "otel")]
opentelemetry::global::set_text_map_propagator(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
let subscriber = rustup::cli::log::tracing_subscriber(process);
let subscriber = rustup::cli::log::tracing_subscriber(&process);
tracing::subscriber::set_global_default(subscriber)?;
let result = run_rustup(process).await;
let result = run_rustup(&process).await;
// We're tracing, so block until all spans are exported.
#[cfg(feature = "otel")]
opentelemetry::global::shutdown_tracer_provider();
result

match result {
Err(e) => {
common::report_error(&e, &process);
std::process::exit(1)
}
Ok(utils::ExitCode(c)) => std::process::exit(c),
}
}

#[cfg_attr(feature = "otel", tracing::instrument)]
Expand Down Expand Up @@ -116,7 +109,7 @@ async fn run_rustup_inner(process: &Process) -> Result<utils::ExitCode> {
is_proxyable_tools(n)?;
proxy_mode::main(n, current_dir, process)
.await
.map(ExitCode::from)
.map(utils::ExitCode::from)
}
None => {
// Weird case. No arg0, or it's unparsable.
Expand Down
2 changes: 0 additions & 2 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ fn format_dhms(sec: u64) -> (u64, u8, u8, u8) {

#[cfg(test)]
mod tests {
use rustup_macros::unit_test as test;

use super::format_dhms;

#[test]
Expand Down
24 changes: 12 additions & 12 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,10 @@ fn update_root(process: &Process) -> String {
/// `CARGO_HOME` suitable for display, possibly with $HOME
/// substituted for the directory prefix
fn canonical_cargo_home(process: &Process) -> Result<Cow<'static, str>> {
let path = utils::cargo_home(process)?;
let path = process.cargo_home()?;

let default_cargo_home = utils::home_dir(process)
let default_cargo_home = process
.home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(".cargo");
Ok(if default_cargo_home == path {
Expand Down Expand Up @@ -727,7 +728,7 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool, process: &Process)
fn do_pre_install_sanity_checks(no_prompt: bool, process: &Process) -> Result<()> {
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
let rustup_sh_path = utils::home_dir(process).unwrap().join(".rustup");
let rustup_sh_path = process.home_dir().unwrap().join(".rustup");
let rustup_sh_version_path = rustup_sh_path.join("rustup-version");

let rustc_exists = rustc_manifest_path.exists() && uninstaller_path.exists();
Expand Down Expand Up @@ -761,7 +762,7 @@ fn do_pre_install_sanity_checks(no_prompt: bool, process: &Process) -> Result<()
}

fn pre_install_msg(no_modify_path: bool, process: &Process) -> Result<String> {
let cargo_home = utils::cargo_home(process)?;
let cargo_home = process.cargo_home()?;
let cargo_home_bin = cargo_home.join("bin");
let rustup_home = home::rustup_home()?;

Expand Down Expand Up @@ -824,7 +825,7 @@ fn current_install_opts(opts: &InstallOpts<'_>, process: &Process) -> String {
}

fn install_bins(process: &Process) -> Result<()> {
let bin_path = utils::cargo_home(process)?.join("bin");
let bin_path = process.cargo_home()?.join("bin");
let this_exe_path = utils::current_exe()?;
let rustup_path = bin_path.join(format!("rustup{EXE_SUFFIX}"));

Expand All @@ -840,7 +841,7 @@ fn install_bins(process: &Process) -> Result<()> {
}

pub(crate) fn install_proxies(process: &Process) -> Result<()> {
let bin_path = utils::cargo_home(process)?.join("bin");
let bin_path = process.cargo_home()?.join("bin");
let rustup_path = bin_path.join(format!("rustup{EXE_SUFFIX}"));

let rustup = Handle::from_path(&rustup_path)?;
Expand Down Expand Up @@ -938,7 +939,8 @@ async fn maybe_install_rust(

// If RUSTUP_HOME is not set, make sure it exists
if process.var_os("RUSTUP_HOME").is_none() {
let home = utils::home_dir(process)
let home = process
.home_dir()
.map(|p| p.join(".rustup"))
.ok_or_else(|| anyhow::anyhow!("could not find home dir to put .rustup in"))?;

Expand Down Expand Up @@ -988,7 +990,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
return Ok(utils::ExitCode(1));
}

let cargo_home = utils::cargo_home(process)?;
let cargo_home = process.cargo_home()?;

if !cargo_home.join(format!("bin/rustup{EXE_SUFFIX}")).exists() {
return Err(CLIError::NotSelfInstalled { p: cargo_home }.into());
Expand Down Expand Up @@ -1178,7 +1180,7 @@ fn parse_new_rustup_version(version: String) -> String {
}

pub(crate) async fn prepare_update(process: &Process) -> Result<Option<PathBuf>> {
let cargo_home = utils::cargo_home(process)?;
let cargo_home = process.cargo_home()?;
let rustup_path = cargo_home.join(format!("bin{MAIN_SEPARATOR}rustup{EXE_SUFFIX}"));
let setup_path = cargo_home.join(format!("bin{MAIN_SEPARATOR}rustup-init{EXE_SUFFIX}"));

Expand Down Expand Up @@ -1319,7 +1321,7 @@ pub(crate) async fn check_rustup_update(process: &Process) -> Result<()> {

#[cfg_attr(feature = "otel", tracing::instrument)]
pub(crate) fn cleanup_self_updater(process: &Process) -> Result<()> {
let cargo_home = utils::cargo_home(process)?;
let cargo_home = process.cargo_home()?;
let setup = cargo_home.join(format!("bin/rustup-init{EXE_SUFFIX}"));

if setup.exists() {
Expand All @@ -1333,8 +1335,6 @@ pub(crate) fn cleanup_self_updater(process: &Process) -> Result<()> {
mod tests {
use std::collections::HashMap;

use rustup_macros::unit_test as test;

use crate::cli::common;
use crate::cli::self_update::InstallOpts;
use crate::dist::dist::{PartialToolchainDesc, Profile};
Expand Down
Loading
Loading