diff --git a/Cargo.lock b/Cargo.lock index 2bf1e0db7d..9d533669d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1967,7 +1967,6 @@ dependencies = [ "remove_dir_all", "retry", "rs_tracing", - "rustup-macros", "same-file", "scopeguard", "semver", @@ -1997,15 +1996,6 @@ dependencies = [ "zstd", ] -[[package]] -name = "rustup-macros" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "rustversion" version = "1.0.17" diff --git a/Cargo.toml b/Cargo.toml index 59fde87f47..54f13a0a72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -130,7 +129,7 @@ platforms.workspace = true regex = "1" [workspace] -members = ["download", "rustup-macros"] +members = ["download"] [workspace.dependencies] anyhow = "1.0.69" @@ -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" diff --git a/rustup-macros/Cargo.toml b/rustup-macros/Cargo.toml deleted file mode 100644 index 886819a511..0000000000 --- a/rustup-macros/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "rustup-macros" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -proc-macro = true - -[dependencies] -proc-macro2 = "1.0.63" -quote = "1.0.23" -syn = { version = "2.0.13", features = ["full"] } diff --git a/rustup-macros/src/lib.rs b/rustup-macros/src/lib.rs deleted file mode 100644 index 1dfe6800c8..0000000000 --- a/rustup-macros/src/lib.rs +++ /dev/null @@ -1,124 +0,0 @@ -//! Procedural macros for `rustup`. - -use ::quote::quote; -use proc_macro2::TokenStream; -use syn::{parse_macro_input, parse_quote, Block, Expr, ItemFn, LitStr}; - -/// Custom wrapper macro around `#[test]` and `#[tokio::test]`. -/// -/// Calls `rustup::test::before_test()` before the test body, and -/// `rustup::test::after_test()` after, even in the event of an unwinding panic. -/// For async functions calls the async variants of these functions. -#[proc_macro_attribute] -pub fn integration_test( - args: proc_macro::TokenStream, - input: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let mut path: Option = None; - if !args.is_empty() { - let test_parser = syn::meta::parser(|meta| { - if meta.path.is_ident("mod_path") { - path = Some(meta.value()?.parse()?); - Ok(()) - } else { - Err(meta.error("unsupported test property")) - } - }); - - parse_macro_input!(args with test_parser); - } - let input = parse_macro_input!(input); - test_inner( - path.map(|s| s.value()).unwrap_or("::rustup::test".into()), - Clone::clone(&input), - ) - .unwrap_or_else(|err| { - let err = err.to_compile_error(); - quote! { #err #input } - }) - .into() -} - -/// Custom wrapper macro around `#[tokio::test]` for unit tests. -/// -/// Calls `rustup::test::before_test()` before the test body, and -/// `rustup::test::after_test()` after, even in the event of an unwinding panic. -/// -/// This wrapper makes the underlying test function async even if it's sync in nature. -/// This ensures that a [`tokio`] runtime is always present during tests, -/// making it easier to setup [`tracing`] subscribers -/// (e.g. [`opentelemetry_otlp::OtlpTracePipeline`] always requires a [`tokio`] runtime to be -/// installed). -#[proc_macro_attribute] -pub fn unit_test( - args: proc_macro::TokenStream, - input: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let mut path: Option = None; - - if !args.is_empty() { - let test_parser = syn::meta::parser(|meta| { - if meta.path.is_ident("mod_path") { - path = Some(meta.value()?.parse()?); - Ok(()) - } else { - Err(meta.error("unsupported test property")) - } - }); - - parse_macro_input!(args with test_parser); - } - - let input = parse_macro_input!(input); - - test_inner( - path.map(|s| s.value()).unwrap_or("crate::test".into()), - Clone::clone(&input), - ) - .unwrap_or_else(|err| { - let err = err.to_compile_error(); - quote! { #err #input } - }) - .into() -} - -fn test_inner(mod_path: String, mut input: ItemFn) -> syn::Result { - // Make the test function async even if it's sync. - input.sig.asyncness.get_or_insert_with(Default::default); - - let before_ident = format!("{}::before_test_async", mod_path); - let before_ident = syn::parse_str::(&before_ident)?; - let after_ident = format!("{}::after_test_async", mod_path); - let after_ident = syn::parse_str::(&after_ident)?; - - let inner = input.block; - let name = input.sig.ident.clone(); - let new_block: Block = parse_quote! { - { - #before_ident().await; - // Define a function with same name we can instrument inside the - // tracing enablement logic. - #[cfg_attr(feature = "otel", tracing::instrument(skip_all))] - async fn #name() { #inner } - // Thunk through a new thread to permit catching the panic - // without grabbing the entire state machine defined by the - // outer test function. - let result = ::std::panic::catch_unwind(||{ - let handle = tokio::runtime::Handle::current().clone(); - ::std::thread::spawn(move || handle.block_on(#name())).join().unwrap() - }); - #after_ident().await; - match result { - Ok(result) => result, - Err(err) => ::std::panic::resume_unwind(err) - } - } - }; - - input.block = Box::new(new_block); - - Ok(quote! { - #[::tokio::test(flavor = "multi_thread", worker_threads = 1)] - #input - }) -} diff --git a/src/bin/rustup-init.rs b/src/bin/rustup-init.rs index 42e1d88d95..f60c5221d3 100644 --- a/src/bin/rustup-init.rs +++ b/src/bin/rustup-init.rs @@ -13,13 +13,14 @@ #![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; @@ -27,44 +28,36 @@ 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 { #[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 { #[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)] @@ -116,7 +109,7 @@ async fn run_rustup_inner(process: &Process) -> Result { 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. diff --git a/src/cli/download_tracker.rs b/src/cli/download_tracker.rs index 6c66b95d91..25c53a49d7 100644 --- a/src/cli/download_tracker.rs +++ b/src/cli/download_tracker.rs @@ -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] diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index f91cdd36c6..973799f787 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -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> { - 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 { @@ -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(); @@ -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 { - 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()?; @@ -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}")); @@ -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)?; @@ -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"))?; @@ -988,7 +990,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result String { } pub(crate) async fn prepare_update(process: &Process) -> Result> { - 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}")); @@ -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() { @@ -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}; diff --git a/src/cli/self_update/shell.rs b/src/cli/self_update/shell.rs index b59325257b..af2c8601de 100644 --- a/src/cli/self_update/shell.rs +++ b/src/cli/self_update/shell.rs @@ -41,7 +41,7 @@ pub(crate) struct ShellScript { impl ShellScript { pub(crate) fn write(&self, process: &Process) -> Result<()> { - let home = utils::cargo_home(process)?; + let home = process.cargo_home()?; let cargo_bin = format!("{}/bin", cargo_home_str(process)?); let env_name = home.join(self.name); let env_file = self.content.replace("{cargo_bin}", &cargo_bin); @@ -52,9 +52,10 @@ impl ShellScript { // TODO: Update into a bytestring. pub(crate) fn cargo_home_str(process: &Process) -> Result> { - 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 { @@ -117,7 +118,7 @@ impl UnixShell for Posix { } fn rcfiles(&self, process: &Process) -> Vec { - match utils::home_dir(process) { + match process.home_dir() { Some(dir) => vec![dir.join(".profile")], _ => vec![], } @@ -142,7 +143,7 @@ impl UnixShell for Bash { // .profile as part of POSIX and always does setup for POSIX shells. [".bash_profile", ".bash_login", ".bashrc"] .iter() - .filter_map(|rc| utils::home_dir(process).map(|dir| dir.join(rc))) + .filter_map(|rc| process.home_dir().map(|dir| dir.join(rc))) .collect() } @@ -186,7 +187,7 @@ impl UnixShell for Zsh { } fn rcfiles(&self, process: &Process) -> Vec { - [Zsh::zdotdir(process).ok(), utils::home_dir(process)] + [Zsh::zdotdir(process).ok(), process.home_dir()] .iter() .filter_map(|dir| dir.as_ref().map(|p| p.join(".zshenv"))) .collect() @@ -226,7 +227,7 @@ impl UnixShell for Fish { path }); - let p1 = utils::home_dir(process).map(|mut path| { + let p1 = process.home_dir().map(|mut path| { path.push(".config/fish/conf.d/rustup.fish"); path }); @@ -257,11 +258,11 @@ impl UnixShell for Fish { pub(crate) fn legacy_paths(process: &Process) -> impl Iterator + '_ { let zprofiles = Zsh::zdotdir(process) .into_iter() - .chain(utils::home_dir(process)) + .chain(process.home_dir()) .map(|d| d.join(".zprofile")); let profiles = [".bash_profile", ".profile"] .iter() - .filter_map(|rc| utils::home_dir(process).map(|d| d.join(rc))); + .filter_map(|rc| process.home_dir().map(|d| d.join(rc))); profiles.chain(zprofiles) } diff --git a/src/cli/self_update/unix.rs b/src/cli/self_update/unix.rs index d58593978a..e91785eedf 100644 --- a/src/cli/self_update/unix.rs +++ b/src/cli/self_update/unix.rs @@ -48,7 +48,7 @@ pub(crate) fn do_anti_sudo_check(no_prompt: bool, process: &Process) -> Result Result<()> { - let cargo_home = utils::cargo_home(process)?; + let cargo_home = process.cargo_home()?; utils::remove_dir("cargo_home", &cargo_home, &|_: Notification<'_>| ()) } diff --git a/src/cli/self_update/windows.rs b/src/cli/self_update/windows.rs index c0dacb200b..355c45a012 100644 --- a/src/cli/self_update/windows.rs +++ b/src/cli/self_update/windows.rs @@ -279,7 +279,7 @@ pub fn complete_windows_uninstall(process: &Process) -> Result wait_for_parent()?; // Now that the parent has exited there are hopefully no more files open in CARGO_HOME - let cargo_home = utils::cargo_home(process)?; + let cargo_home = process.cargo_home()?; utils::remove_dir("cargo_home", &cargo_home, &|_: Notification<'_>| ())?; // Now, run a *system* binary to inherit the DELETE_ON_CLOSE @@ -492,7 +492,7 @@ where F: FnOnce(Vec, Vec) -> Option>, { let windows_path = get_windows_path_var()?; - let mut path_str = utils::cargo_home(process)?; + let mut path_str = process.cargo_home()?; path_str.push("bin"); Ok(windows_path .and_then(|old_path| f(old_path, OsString::from(path_str).encode_wide().collect()))) @@ -535,7 +535,7 @@ pub(crate) fn do_add_to_programs(process: &Process) -> Result<()> { } } - let mut path = utils::cargo_home(process)?; + let mut path = process.cargo_home()?; path.push("bin\\rustup.exe"); let mut uninstall_cmd = OsString::from("\""); uninstall_cmd.push(path); @@ -657,7 +657,7 @@ pub(crate) fn delete_rustup_and_cargo_home(process: &Process) -> Result<()> { }; // CARGO_HOME, hopefully empty except for bin/rustup.exe - let cargo_home = utils::cargo_home(process)?; + let cargo_home = process.cargo_home()?; // The rustup.exe bin let rustup_path = cargo_home.join(format!("bin/rustup{EXE_SUFFIX}")); @@ -728,8 +728,6 @@ mod tests { use winreg::enums::{RegType, HKEY_CURRENT_USER, KEY_READ, KEY_WRITE}; use winreg::{RegKey, RegValue}; - use rustup_macros::unit_test as test; - use crate::currentprocess::TestProcess; use crate::test::with_saved_path; diff --git a/src/config.rs b/src/config.rs index a8b54a190e..62406d3f50 100644 --- a/src/config.rs +++ b/src/config.rs @@ -258,7 +258,7 @@ impl<'a> Cfg<'a> { process: &'a Process, ) -> Result { // Set up the rustup home directory - let rustup_dir = utils::rustup_home(process)?; + let rustup_dir = process.rustup_home()?; utils::ensure_dir_exists("home", &rustup_dir, notify_handler.as_ref())?; @@ -968,8 +968,6 @@ enum ParseMode { #[cfg(test)] mod tests { - use rustup_macros::unit_test as test; - use super::*; #[test] diff --git a/src/currentprocess.rs b/src/currentprocess.rs index 7307d89345..115c678871 100644 --- a/src/currentprocess.rs +++ b/src/currentprocess.rs @@ -1,12 +1,9 @@ use std::env; use std::ffi::OsString; use std::fmt::Debug; -use std::future::Future; use std::io; -use std::panic; +use std::io::IsTerminal; use std::path::PathBuf; -use std::sync::Once; -use std::{cell::RefCell, io::IsTerminal}; #[cfg(feature = "test")] use std::{ collections::HashMap, @@ -15,6 +12,7 @@ use std::{ sync::{Arc, Mutex}, }; +use anyhow::{Context, Result}; #[cfg(feature = "test")] use tracing::subscriber::DefaultGuard; use tracing_subscriber::util::SubscriberInitExt; @@ -48,6 +46,18 @@ impl Process { .map(String::from) } + pub(crate) fn home_dir(&self) -> Option { + home::env::home_dir_with_env(self) + } + + pub(crate) fn cargo_home(&self) -> Result { + home::env::cargo_home_with_env(self).context("failed to determine cargo home") + } + + pub(crate) fn rustup_home(&self) -> Result { + home::env::rustup_home_with_env(self).context("failed to determine rustup home dir") + } + pub fn var(&self, key: &str) -> Result { match self { Process::OSProcess(_) => env::var(key), @@ -142,92 +152,6 @@ impl home::env::Env for Process { } } -static HOOK_INSTALLED: Once = Once::new(); - -fn ensure_hook() { - HOOK_INSTALLED.call_once(|| { - let orig_hook = panic::take_hook(); - panic::set_hook(Box::new(move |info| { - clear_process(); - orig_hook(info); - })); - }); -} - -/// Run a function in the context of a process definition and a tokio runtime. -/// -/// The process state is injected into a thread-local in every work thread of -/// the runtime, but this requires access to the runtime builder, so this -/// function must be the one to create the runtime. -pub fn with_runtime<'a, R>( - process: Process, - mut runtime_builder: tokio::runtime::Builder, - fut: impl Future + 'a, -) -> R { - ensure_hook(); - - let start_process = process.clone(); - let unpark_process = process.clone(); - let runtime = runtime_builder - // propagate to blocking threads - .on_thread_start(move || { - // assign the process persistently to the thread local. - PROCESS.with(|p| { - if let Some(old_p) = &*p.borrow() { - panic!("current process already set {old_p:?}"); - } - *p.borrow_mut() = Some(start_process.clone()); - // Thread exits will clear the process. - }); - }) - .on_thread_stop(move || { - PROCESS.with(|p| { - *p.borrow_mut() = None; - }); - }) - // propagate to async worker threads - .on_thread_unpark(move || { - // assign the process persistently to the thread local. - PROCESS.with(|p| { - if let Some(old_p) = &*p.borrow() { - panic!("current process already set {old_p:?}"); - } - *p.borrow_mut() = Some(unpark_process.clone()); - // Thread exits will clear the process. - }); - }) - .on_thread_park(move || { - PROCESS.with(|p| { - *p.borrow_mut() = None; - }); - }) - .build() - .unwrap(); - - // The current thread doesn't get hooks run on it. - PROCESS.with(move |p| { - if let Some(old_p) = &*p.borrow() { - panic!("current process already set {old_p:?}"); - } - *p.borrow_mut() = Some(process.clone()); - let result = runtime.block_on(async { - let _guard = crate::cli::log::tracing_subscriber(&process).set_default(); - fut.await - }); - *p.borrow_mut() = None; - result - }) -} - -/// Internal - for the panic hook only -fn clear_process() { - PROCESS.with(|p| p.replace(None)); -} - -thread_local! { - pub(crate) static PROCESS: RefCell> = const { RefCell::new(None) }; -} - // ----------- real process ----------------- #[derive(Clone, Debug)] diff --git a/src/currentprocess/terminalsource.rs b/src/currentprocess/terminalsource.rs index a6d81d03bc..fa8a3b5c85 100644 --- a/src/currentprocess/terminalsource.rs +++ b/src/currentprocess/terminalsource.rs @@ -238,8 +238,6 @@ impl io::Write for ColorableTerminalLocked { mod tests { use std::collections::HashMap; - use rustup_macros::unit_test as test; - use super::*; use crate::currentprocess::TestProcess; use crate::test::Env; diff --git a/src/diskio/test.rs b/src/diskio/test.rs index 4425975513..0a9aa46010 100644 --- a/src/diskio/test.rs +++ b/src/diskio/test.rs @@ -2,12 +2,9 @@ use std::collections::HashMap; use anyhow::Result; -use rustup_macros::unit_test as test; - -use crate::test::test_dir; - use super::{get_executor, Executor, Item, Kind}; use crate::currentprocess::TestProcess; +use crate::test::test_dir; impl Item { /// The length of the file, for files (for stats) diff --git a/src/dist/component/tests.rs b/src/dist/component/tests.rs index 42d394d4ea..aec40e266b 100644 --- a/src/dist/component/tests.rs +++ b/src/dist/component/tests.rs @@ -2,8 +2,6 @@ use std::fs; use std::io::Write; use std::path::PathBuf; -use rustup_macros::unit_test as test; - use crate::currentprocess::TestProcess; use crate::dist::component::Transaction; use crate::dist::dist::DEFAULT_DIST_SERVER; diff --git a/src/dist/dist.rs b/src/dist/dist.rs index 57fc5dcdd0..153a87f4f7 100644 --- a/src/dist/dist.rs +++ b/src/dist/dist.rs @@ -1154,8 +1154,6 @@ fn date_from_manifest_date(date_str: &str) -> Option { #[cfg(test)] mod tests { - use rustup_macros::unit_test as test; - use super::*; #[test] diff --git a/src/dist/manifestation/tests.rs b/src/dist/manifestation/tests.rs index cba55e722b..9916217af8 100644 --- a/src/dist/manifestation/tests.rs +++ b/src/dist/manifestation/tests.rs @@ -14,8 +14,6 @@ use anyhow::{anyhow, Result}; use tokio::{runtime::Handle, task}; use url::Url; -use rustup_macros::unit_test as test; - use crate::{ currentprocess::{Process, TestProcess}, dist::{ diff --git a/src/dist/triple.rs b/src/dist/triple.rs index fc58a1de63..73c2e390e7 100644 --- a/src/dist/triple.rs +++ b/src/dist/triple.rs @@ -54,8 +54,6 @@ impl PartialTargetTriple { #[cfg(test)] mod test { - use rustup_macros::unit_test as test; - use super::*; #[test] diff --git a/src/env_var.rs b/src/env_var.rs index d6b54e380c..ce3a9eb046 100644 --- a/src/env_var.rs +++ b/src/env_var.rs @@ -46,8 +46,6 @@ mod tests { use std::collections::HashMap; use std::ffi::{OsStr, OsString}; - use rustup_macros::unit_test as test; - use super::*; use crate::currentprocess::TestProcess; use crate::test::{with_saved_path, Env}; diff --git a/src/lib.rs b/src/lib.rs index 983a334a66..c28048cc21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,8 +92,6 @@ pub mod utils; #[cfg(test)] mod tests { - use rustup_macros::unit_test as test; - use crate::{is_proxyable_tools, DUP_TOOLS, TOOLS}; #[test] diff --git a/src/toolchain/toolchain.rs b/src/toolchain/toolchain.rs index d902877a3b..07b6a11160 100644 --- a/src/toolchain/toolchain.rs +++ b/src/toolchain/toolchain.rs @@ -185,7 +185,7 @@ impl<'a> Toolchain<'a> { // versions of Cargo did. Rustup and Cargo should be in sync now (both // using the same `home` crate), but this is retained to ensure cargo // and rustup agree in older versions. - if let Ok(cargo_home) = utils::cargo_home(self.cfg.process) { + if let Ok(cargo_home) = self.cfg.process.cargo_home() { cmd.env("CARGO_HOME", &cargo_home); } @@ -243,7 +243,7 @@ impl<'a> Toolchain<'a> { // proxy bins don't exist. We'll just be running whatever happens to // be on the PATH. let mut path_entries = vec![]; - if let Ok(cargo_home) = utils::cargo_home(self.cfg.process) { + if let Ok(cargo_home) = self.cfg.process.cargo_home() { path_entries.push(cargo_home.join("bin")); } diff --git a/src/utils/units.rs b/src/utils/units.rs index 7dbf64a632..365c99d7c5 100644 --- a/src/utils/units.rs +++ b/src/utils/units.rs @@ -77,8 +77,6 @@ impl Display for Size { #[cfg(test)] mod tests { - use rustup_macros::unit_test as test; - #[test] fn unit_formatter_test() { use crate::utils::units::{Size, Unit, UnitMode}; diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 05f85415be..1452de69a2 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -5,7 +5,6 @@ use std::path::{Path, PathBuf}; use std::process::ExitStatus; use anyhow::{anyhow, bail, Context, Result}; -use home::env as home; use retry::delay::{jitter, Fibonacci}; use retry::{retry, OperationResult}; use sha2::Sha256; @@ -483,18 +482,6 @@ pub fn current_exe() -> Result { env::current_exe().context(RustupError::LocatingWorkingDir) } -pub(crate) fn home_dir(process: &Process) -> Option { - home::home_dir_with_env(process) -} - -pub(crate) fn cargo_home(process: &Process) -> Result { - home::cargo_home_with_env(process).context("failed to determine cargo home") -} - -pub(crate) fn rustup_home(process: &Process) -> Result { - home::rustup_home_with_env(process).context("failed to determine rustup home dir") -} - pub(crate) fn format_path_for_display(path: &str) -> String { let unc_present = path.find(r"\\?\"); @@ -679,8 +666,6 @@ pub(crate) fn home_dir_from_passwd() -> Option { #[cfg(test)] mod tests { - use rustup_macros::unit_test as test; - use super::*; #[test] diff --git a/tests/suite/cli_exact.rs b/tests/suite/cli_exact.rs index 31e8008171..188ba9f183 100644 --- a/tests/suite/cli_exact.rs +++ b/tests/suite/cli_exact.rs @@ -6,7 +6,6 @@ use rustup::test::{ mock::clitools::{self, set_current_dist_date, with_update_server, Config, Scenario}, this_host_triple, }; -use rustup_macros::integration_test as test; /// Start a test with Scenario::None fn test(f: &dyn Fn(&mut Config)) { diff --git a/tests/suite/cli_inst_interactive.rs b/tests/suite/cli_inst_interactive.rs index 66b72f7e0e..76eba7887a 100644 --- a/tests/suite/cli_inst_interactive.rs +++ b/tests/suite/cli_inst_interactive.rs @@ -10,7 +10,6 @@ use rustup::test::{ this_host_triple, with_saved_path, }; use rustup::utils::raw; -use rustup_macros::integration_test as test; fn run_input(config: &Config, args: &[&str], input: &str) -> SanitizedOutput { run_input_with_env(config, args, input, &[]) diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index f77fa5b35e..75a3c17639 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -10,7 +10,6 @@ use rustup::test::{ this_host_triple, }; use rustup::utils::utils; -use rustup_macros::integration_test as test; pub fn setup(f: &dyn Fn(&mut Config)) { clitools::test(Scenario::SimpleV2, f); diff --git a/tests/suite/cli_paths.rs b/tests/suite/cli_paths.rs index 591121217c..4bcd20e401 100644 --- a/tests/suite/cli_paths.rs +++ b/tests/suite/cli_paths.rs @@ -11,11 +11,9 @@ mod unix { use std::fs; use std::path::PathBuf; - use rustup::utils::raw; - use rustup_macros::integration_test as test; - use super::INIT_NONE; use rustup::test::mock::clitools::{self, Scenario}; + use rustup::utils::raw; // Let's write a fake .rc which looks vaguely like a real script. const FAKE_RC: &str = r#" @@ -390,11 +388,9 @@ export PATH="$HOME/apple/bin" #[cfg(windows)] mod windows { + use super::INIT_NONE; use rustup::test::mock::clitools::{self, Scenario}; use rustup::test::{get_path, with_saved_path}; - use rustup_macros::integration_test as test; - - use super::INIT_NONE; #[test] /// Smoke test for end-to-end code connectivity of the installer path mgmt on windows. diff --git a/tests/suite/cli_rustup.rs b/tests/suite/cli_rustup.rs index b1558419c4..5eb5486d2a 100644 --- a/tests/suite/cli_rustup.rs +++ b/tests/suite/cli_rustup.rs @@ -7,7 +7,6 @@ use std::{env::consts::EXE_SUFFIX, path::Path}; use rustup::for_host; use rustup::test::this_host_triple; use rustup::utils::raw; -use rustup_macros::integration_test as test; use rustup::test::mock::{ self, diff --git a/tests/suite/cli_self_upd.rs b/tests/suite/cli_self_upd.rs index ed875dff75..a410db0781 100644 --- a/tests/suite/cli_self_upd.rs +++ b/tests/suite/cli_self_upd.rs @@ -21,7 +21,6 @@ use rustup::test::{ }; use rustup::utils::{raw, utils}; use rustup::{for_host, DUP_TOOLS, TOOLS}; -use rustup_macros::integration_test as test; #[cfg(windows)] use rustup::test::with_saved_reg_value; diff --git a/tests/suite/cli_ui.rs b/tests/suite/cli_ui.rs index c5f66359d2..0f931f2ffc 100644 --- a/tests/suite/cli_ui.rs +++ b/tests/suite/cli_ui.rs @@ -1,7 +1,5 @@ use std::{fs, path::PathBuf}; -use rustup_macros::integration_test as test; - #[test] fn rustup_ui_doc_text_tests() { let t = trycmd::TestCases::new(); diff --git a/tests/suite/cli_v1.rs b/tests/suite/cli_v1.rs index b353c75c17..dcc916b302 100644 --- a/tests/suite/cli_v1.rs +++ b/tests/suite/cli_v1.rs @@ -4,8 +4,6 @@ use std::fs; use rustup::for_host; -use rustup_macros::integration_test as test; - use rustup::test::mock::clitools::{self, set_current_dist_date, Config, Scenario}; pub fn setup(f: &dyn Fn(&mut Config)) { diff --git a/tests/suite/cli_v2.rs b/tests/suite/cli_v2.rs index a0c6acdaa7..17ef861f54 100644 --- a/tests/suite/cli_v2.rs +++ b/tests/suite/cli_v2.rs @@ -8,7 +8,6 @@ use rustup::dist::dist::TargetTriple; use rustup::for_host; use rustup::test::mock::clitools::{self, set_current_dist_date, Config, Scenario}; use rustup::test::this_host_triple; -use rustup_macros::integration_test as test; pub fn setup(f: &dyn Fn(&mut Config)) { clitools::test(Scenario::SimpleV2, f); diff --git a/tests/suite/dist_install.rs b/tests/suite/dist_install.rs index cf80fc363e..614a20955c 100644 --- a/tests/suite/dist_install.rs +++ b/tests/suite/dist_install.rs @@ -10,7 +10,6 @@ use rustup::dist::prefix::InstallPrefix; use rustup::dist::temp; use rustup::dist::Notification; use rustup::utils::utils; -use rustup_macros::integration_test as test; use rustup::test::mock::{MockComponentBuilder, MockFile, MockInstallerBuilder};