From fcb31a1bc40b6c636aa95ad0978477ae074ad3e6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 11 Jul 2024 10:20:51 +0200 Subject: [PATCH 1/4] Fix home_dir() and current_dir() regression --- src/currentprocess.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/currentprocess.rs b/src/currentprocess.rs index dc43e1e7dd..40dc7908c0 100644 --- a/src/currentprocess.rs +++ b/src/currentprocess.rs @@ -130,17 +130,17 @@ impl Process { impl home::env::Env for Process { fn home_dir(&self) -> Option { match self { - Process::OSProcess(_) => self.var("HOME").ok().map(|v| v.into()), + Process::OSProcess(_) => home::env::OS_ENV.home_dir(), #[cfg(feature = "test")] - Process::TestProcess(_) => home::env::OS_ENV.home_dir(), + Process::TestProcess(_) => self.var("HOME").ok().map(|v| v.into()), } } fn current_dir(&self) -> Result { match self { - Process::OSProcess(_) => self.current_dir(), + Process::OSProcess(_) => home::env::OS_ENV.current_dir(), #[cfg(feature = "test")] - Process::TestProcess(_) => home::env::OS_ENV.current_dir(), + Process::TestProcess(_) => self.current_dir(), } } From d327554e948455a9fb81126d817abcf9e1a0dadb Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 11 Jul 2024 10:32:02 +0200 Subject: [PATCH 2/4] Forward to Process::var_os() directly --- src/currentprocess.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/currentprocess.rs b/src/currentprocess.rs index 40dc7908c0..6ff71b30f4 100644 --- a/src/currentprocess.rs +++ b/src/currentprocess.rs @@ -145,11 +145,7 @@ impl home::env::Env for Process { } fn var_os(&self, key: &str) -> Option { - match self { - Process::OSProcess(_) => self.var_os(key), - #[cfg(feature = "test")] - Process::TestProcess(_) => self.var_os(key), - } + self.var_os(key) } } From f256759466bc1418fc15973d89721c81d504a8a3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 11 Jul 2024 10:33:46 +0200 Subject: [PATCH 3/4] Rename currentprocess to process Co-authored-by: rami3l --- doc/dev-guide/src/coding-standards.md | 4 ++-- src/bin/rustup-init.rs | 2 +- src/cli/common.rs | 2 +- src/cli/download_tracker.rs | 2 +- src/cli/log.rs | 2 +- src/cli/markdown.rs | 2 +- src/cli/proxy_mode.rs | 2 +- src/cli/rustup_mode.rs | 8 ++++---- src/cli/self_update.rs | 4 ++-- src/cli/self_update/shell.rs | 2 +- src/cli/self_update/unix.rs | 2 +- src/cli/self_update/windows.rs | 4 ++-- src/cli/setup_mode.rs | 2 +- src/command.rs | 2 +- src/config.rs | 2 +- src/diskio/mod.rs | 2 +- src/diskio/test.rs | 2 +- src/dist/component/components.rs | 2 +- src/dist/component/package.rs | 2 +- src/dist/component/tests.rs | 2 +- src/dist/component/transaction.rs | 2 +- src/dist/download.rs | 2 +- src/dist/manifestation.rs | 2 +- src/dist/manifestation/tests.rs | 2 +- src/dist/mod.rs | 2 +- src/env_var.rs | 4 ++-- src/lib.rs | 2 +- src/{currentprocess.rs => process.rs} | 2 +- src/{currentprocess => process}/filesource.rs | 10 +++++----- src/{currentprocess => process}/terminalsource.rs | 2 +- src/test.rs | 10 +++++----- src/test/mock/clitools.rs | 4 ++-- src/utils/raw.rs | 2 +- src/utils/utils.rs | 2 +- tests/suite/dist_install.rs | 2 +- 35 files changed, 51 insertions(+), 51 deletions(-) rename src/{currentprocess.rs => process.rs} (99%) rename src/{currentprocess => process}/filesource.rs (93%) rename src/{currentprocess => process}/terminalsource.rs (99%) diff --git a/doc/dev-guide/src/coding-standards.md b/doc/dev-guide/src/coding-standards.md index 3834787cef..0c03207aa6 100644 --- a/doc/dev-guide/src/coding-standards.md +++ b/doc/dev-guide/src/coding-standards.md @@ -20,9 +20,9 @@ order. Any file that is not grouped like this can be rearranged whenever the file is touched - we're not precious about having it done in a separate commit, though that is helpful. -## No direct use of process state outside rustup::currentprocess +## No direct use of process state outside rustup::process -The `rustup::currentprocess` module abstracts the global state that is +The `rustup::process` module abstracts the global state that is `std::env::args`, `std::env::vars`, `std::io::std*`, `std::process::id`, `std::env::current_dir` and `std::process::exit` permitting threaded tests of the CLI logic; use `process()` rather than those APIs directly. diff --git a/src/bin/rustup-init.rs b/src/bin/rustup-init.rs index 8c1af11d55..591e81297c 100644 --- a/src/bin/rustup-init.rs +++ b/src/bin/rustup-init.rs @@ -29,10 +29,10 @@ use rustup::cli::rustup_mode; #[cfg(windows)] use rustup::cli::self_update; use rustup::cli::setup_mode; -use rustup::currentprocess::Process; use rustup::env_var::RUST_RECURSION_COUNT_MAX; use rustup::errors::RustupError; use rustup::is_proxyable_tools; +use rustup::process::Process; use rustup::utils::utils; #[tokio::main] diff --git a/src/cli/common.rs b/src/cli/common.rs index ee107aad79..1e6040a505 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -15,11 +15,11 @@ use tracing::{debug, error, info, trace, warn}; use super::self_update; use crate::cli::download_tracker::DownloadTracker; -use crate::currentprocess::{terminalsource, Process}; use crate::dist::{ manifest::ComponentStatus, notifications as dist_notifications, TargetTriple, ToolchainDesc, }; use crate::install::UpdateStatus; +use crate::process::{terminalsource, Process}; use crate::toolchain::{DistributableToolchain, LocalToolchainName, Toolchain, ToolchainName}; use crate::utils::notifications as util_notifications; use crate::utils::notify::NotificationLevel; diff --git a/src/cli/download_tracker.rs b/src/cli/download_tracker.rs index 25c53a49d7..d71505073c 100644 --- a/src/cli/download_tracker.rs +++ b/src/cli/download_tracker.rs @@ -3,9 +3,9 @@ use std::fmt; use std::io::Write; use std::time::{Duration, Instant}; -use crate::currentprocess::{terminalsource, Process}; use crate::dist::Notification as In; use crate::notifications::Notification; +use crate::process::{terminalsource, Process}; use crate::utils::units::{Size, Unit, UnitMode}; use crate::utils::Notification as Un; diff --git a/src/cli/log.rs b/src/cli/log.rs index 724ea4af1e..6331a8980c 100644 --- a/src/cli/log.rs +++ b/src/cli/log.rs @@ -14,7 +14,7 @@ use tracing_subscriber::{ reload, EnvFilter, Layer, Registry, }; -use crate::{currentprocess::Process, utils::notify::NotificationLevel}; +use crate::{process::Process, utils::notify::NotificationLevel}; pub fn tracing_subscriber( process: &Process, diff --git a/src/cli/markdown.rs b/src/cli/markdown.rs index b9e3ec5876..cd2b8ee5a2 100644 --- a/src/cli/markdown.rs +++ b/src/cli/markdown.rs @@ -3,7 +3,7 @@ use std::io::Write; use pulldown_cmark::{Event, Tag, TagEnd}; -use crate::currentprocess::terminalsource::{Attr, Color, ColorableTerminal}; +use crate::process::terminalsource::{Attr, Color, ColorableTerminal}; // Handles the wrapping of text written to the console struct LineWrapper<'a> { diff --git a/src/cli/proxy_mode.rs b/src/cli/proxy_mode.rs index 2e4573bc3b..753579aa0c 100644 --- a/src/cli/proxy_mode.rs +++ b/src/cli/proxy_mode.rs @@ -5,7 +5,7 @@ use anyhow::Result; use crate::{ cli::{common::set_globals, job, self_update}, command::run_command_for_dir, - currentprocess::Process, + process::Process, toolchain::ResolvableLocalToolchainName, }; diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index a5d5d17887..54845b007f 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -21,16 +21,16 @@ use crate::{ }, command, config::{ActiveReason, Cfg}, - currentprocess::{ - terminalsource::{self, ColorableTerminal}, - Process, - }, dist::{ manifest::{Component, ComponentStatus}, PartialToolchainDesc, Profile, TargetTriple, }, errors::RustupError, install::{InstallMethod, UpdateStatus}, + process::{ + terminalsource::{self, ColorableTerminal}, + Process, + }, toolchain::{ CustomToolchainName, DistributableToolchain, LocalToolchainName, MaybeResolvableToolchainName, ResolvableLocalToolchainName, ResolvableToolchainName, diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index 1d9887a750..9b13b940c6 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -55,10 +55,10 @@ use crate::{ markdown::md, }, config::Cfg, - currentprocess::{terminalsource, Process}, dist::{self, PartialToolchainDesc, Profile, TargetTriple, ToolchainDesc}, errors::RustupError, install::UpdateStatus, + process::{terminalsource, Process}, toolchain::{ DistributableToolchain, MaybeOfficialToolchainName, ResolvableToolchainName, Toolchain, ToolchainName, @@ -1257,7 +1257,7 @@ mod tests { use crate::cli::self_update::InstallOpts; use crate::dist::{PartialToolchainDesc, Profile}; use crate::test::{test_dir, with_rustup_home, Env}; - use crate::{currentprocess::TestProcess, for_host}; + use crate::{for_host, process::TestProcess}; #[test] fn default_toolchain_is_stable() { diff --git a/src/cli/self_update/shell.rs b/src/cli/self_update/shell.rs index af2c8601de..07f9168038 100644 --- a/src/cli/self_update/shell.rs +++ b/src/cli/self_update/shell.rs @@ -29,7 +29,7 @@ use std::path::PathBuf; use anyhow::{bail, Result}; use super::utils; -use crate::currentprocess::Process; +use crate::process::Process; pub(crate) type Shell = Box; diff --git a/src/cli/self_update/unix.rs b/src/cli/self_update/unix.rs index 1b6df84a19..f48006e855 100644 --- a/src/cli/self_update/unix.rs +++ b/src/cli/self_update/unix.rs @@ -6,7 +6,7 @@ use tracing::{error, warn}; use super::install_bins; use super::shell; -use crate::currentprocess::Process; +use crate::process::Process; use crate::utils::utils; use crate::utils::Notification; diff --git a/src/cli/self_update/windows.rs b/src/cli/self_update/windows.rs index faa84998ea..aee378936e 100644 --- a/src/cli/self_update/windows.rs +++ b/src/cli/self_update/windows.rs @@ -22,8 +22,8 @@ use super::super::errors::*; use super::common; use super::{install_bins, report_error, InstallOpts}; use crate::cli::{download_tracker::DownloadTracker, markdown::md}; -use crate::currentprocess::{terminalsource::ColorableTerminal, Process}; use crate::dist::TargetTriple; +use crate::process::{terminalsource::ColorableTerminal, Process}; use crate::utils::utils; use crate::utils::Notification; @@ -890,7 +890,7 @@ impl RegistryValueId { #[cfg(test)] mod tests { use super::*; - use crate::currentprocess::TestProcess; + use crate::process::TestProcess; fn wide(str: &str) -> Vec { OsString::from(str).encode_wide().collect() diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index 1c6a6d83ba..1df03d931b 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -10,8 +10,8 @@ use crate::{ common, self_update::{self, InstallOpts}, }, - currentprocess::Process, dist::Profile, + process::Process, toolchain::MaybeOfficialToolchainName, utils::utils, }; diff --git a/src/command.rs b/src/command.rs index a5f241e6a6..a94c4d382f 100644 --- a/src/command.rs +++ b/src/command.rs @@ -19,7 +19,7 @@ pub(crate) fn run_command_for_dir + Debug>( // FIXME rust-lang/rust#32254. It's not clear to me // when and why this is needed. - // TODO: currentprocess support for mocked file descriptor inheritance here: until + // TODO: process support for mocked file descriptor inheritance here: until // then tests that depend on rustups stdin being inherited won't work in-process. cmd.stdin(process::Stdio::inherit()); diff --git a/src/config.rs b/src/config.rs index c728e1afa1..575a10aafb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,12 +12,12 @@ use tracing::trace; use crate::{ cli::self_update::SelfUpdateMode, - currentprocess::Process, dist::{self, download::DownloadCfg, temp, PartialToolchainDesc, Profile, ToolchainDesc}, errors::RustupError, fallback_settings::FallbackSettings, install::UpdateStatus, notifications::*, + process::Process, settings::{MetadataVersion, Settings, SettingsFile}, toolchain::{ CustomToolchainName, DistributableToolchain, LocalToolchainName, PathBasedToolchainName, diff --git a/src/diskio/mod.rs b/src/diskio/mod.rs index d96ecb5fad..49e9793909 100644 --- a/src/diskio/mod.rs +++ b/src/diskio/mod.rs @@ -66,7 +66,7 @@ use std::{fmt::Debug, fs::OpenOptions}; use anyhow::{Context, Result}; -use crate::currentprocess::Process; +use crate::process::Process; use crate::utils::notifications::Notification; use threaded::PoolReference; diff --git a/src/diskio/test.rs b/src/diskio/test.rs index 0a9aa46010..94fa886bb9 100644 --- a/src/diskio/test.rs +++ b/src/diskio/test.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use anyhow::Result; use super::{get_executor, Executor, Item, Kind}; -use crate::currentprocess::TestProcess; +use crate::process::TestProcess; use crate::test::test_dir; impl Item { diff --git a/src/dist/component/components.rs b/src/dist/component/components.rs index 920c80c05c..7bbcb400a1 100644 --- a/src/dist/component/components.rs +++ b/src/dist/component/components.rs @@ -7,11 +7,11 @@ use std::path::{Path, PathBuf}; use anyhow::{bail, Result}; -use crate::currentprocess::Process; use crate::dist::component::package::{INSTALLER_VERSION, VERSION_FILE}; use crate::dist::component::transaction::Transaction; use crate::dist::prefix::InstallPrefix; use crate::errors::RustupError; +use crate::process::Process; use crate::utils::utils; const COMPONENTS_FILE: &str = "components"; diff --git a/src/dist/component/package.rs b/src/dist/component/package.rs index 442721f7ba..97b1d6af38 100644 --- a/src/dist/component/package.rs +++ b/src/dist/component/package.rs @@ -12,12 +12,12 @@ use anyhow::{anyhow, bail, Context, Result}; use tar::EntryType; use tracing::warn; -use crate::currentprocess::Process; use crate::diskio::{get_executor, CompletedIo, Executor, FileBuffer, Item, Kind, IO_CHUNK_SIZE}; use crate::dist::component::components::*; use crate::dist::component::transaction::*; use crate::dist::temp; use crate::errors::*; +use crate::process::Process; use crate::utils::notifications::Notification; use crate::utils::utils; diff --git a/src/dist/component/tests.rs b/src/dist/component/tests.rs index 3f32793cc4..70474378d2 100644 --- a/src/dist/component/tests.rs +++ b/src/dist/component/tests.rs @@ -2,13 +2,13 @@ use std::fs; use std::io::Write; use std::path::PathBuf; -use crate::currentprocess::TestProcess; use crate::dist::component::Transaction; use crate::dist::prefix::InstallPrefix; use crate::dist::temp; use crate::dist::Notification; use crate::dist::DEFAULT_DIST_SERVER; use crate::errors::RustupError; +use crate::process::TestProcess; use crate::utils::raw as utils_raw; use crate::utils::utils; diff --git a/src/dist/component/transaction.rs b/src/dist/component/transaction.rs index 9e1fe1402d..22afa9f076 100644 --- a/src/dist/component/transaction.rs +++ b/src/dist/component/transaction.rs @@ -14,11 +14,11 @@ use std::path::{Path, PathBuf}; use anyhow::{anyhow, Context, Result}; -use crate::currentprocess::Process; use crate::dist::notifications::*; use crate::dist::prefix::InstallPrefix; use crate::dist::temp; use crate::errors::*; +use crate::process::Process; use crate::utils::utils; /// A Transaction tracks changes to the file system, allowing them to diff --git a/src/dist/download.rs b/src/dist/download.rs index 51ce354a84..c45761cf8c 100644 --- a/src/dist/download.rs +++ b/src/dist/download.rs @@ -6,10 +6,10 @@ use anyhow::{anyhow, Context, Result}; use sha2::{Digest, Sha256}; use url::Url; -use crate::currentprocess::Process; use crate::dist::notifications::*; use crate::dist::temp; use crate::errors::*; +use crate::process::Process; use crate::utils::utils; const UPDATE_HASH_LEN: usize = 20; diff --git a/src/dist/manifestation.rs b/src/dist/manifestation.rs index a61349354b..e02afb3d25 100644 --- a/src/dist/manifestation.rs +++ b/src/dist/manifestation.rs @@ -9,7 +9,6 @@ use std::path::Path; use anyhow::{anyhow, bail, Context, Result}; use tokio_retry::{strategy::FixedInterval, RetryIf}; -use crate::currentprocess::Process; use crate::dist::component::{ Components, Package, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction, }; @@ -21,6 +20,7 @@ use crate::dist::prefix::InstallPrefix; use crate::dist::temp; use crate::dist::{Profile, TargetTriple, DEFAULT_DIST_SERVER}; use crate::errors::RustupError; +use crate::process::Process; use crate::utils::utils; pub(crate) const DIST_MANIFEST: &str = "multirust-channel-manifest.toml"; diff --git a/src/dist/manifestation/tests.rs b/src/dist/manifestation/tests.rs index 22b62a0a37..49cc4fb781 100644 --- a/src/dist/manifestation/tests.rs +++ b/src/dist/manifestation/tests.rs @@ -15,7 +15,6 @@ use anyhow::{anyhow, Result}; use url::Url; use crate::{ - currentprocess::TestProcess, dist::{ download::DownloadCfg, manifest::{Component, Manifest}, @@ -24,6 +23,7 @@ use crate::{ temp, Notification, Profile, TargetTriple, ToolchainDesc, DEFAULT_DIST_SERVER, }, errors::RustupError, + process::TestProcess, test::mock::{dist::*, MockComponentBuilder, MockFile, MockInstallerBuilder}, utils::{raw as utils_raw, utils}, }; diff --git a/src/dist/mod.rs b/src/dist/mod.rs index e2abf2aeb3..d46455d424 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -14,8 +14,8 @@ use tracing::{info, warn}; use crate::{ config::{dist_root_server, Cfg}, - currentprocess::Process, errors::RustupError, + process::Process, toolchain::ToolchainName, utils::utils, }; diff --git a/src/env_var.rs b/src/env_var.rs index d5d84c03f6..6b9863ad15 100644 --- a/src/env_var.rs +++ b/src/env_var.rs @@ -3,7 +3,7 @@ use std::env; use std::path::PathBuf; use std::process::Command; -use crate::currentprocess::Process; +use crate::process::Process; pub const RUST_RECURSION_COUNT_MAX: u32 = 20; @@ -49,7 +49,7 @@ mod tests { use super::*; #[cfg(windows)] use crate::cli::self_update::{RegistryGuard, USER_PATH}; - use crate::currentprocess::TestProcess; + use crate::process::TestProcess; use crate::test::Env; #[test] diff --git a/src/lib.rs b/src/lib.rs index ad507a930c..bacaafe8c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,6 @@ fn component_for_bin(binary: &str) -> Option<&'static str> { pub mod cli; mod command; mod config; -pub mod currentprocess; mod diskio; pub mod dist; pub mod env_var; @@ -80,6 +79,7 @@ pub mod errors; mod fallback_settings; mod install; pub mod notifications; +pub mod process; mod settings; #[cfg(feature = "test")] pub mod test; diff --git a/src/currentprocess.rs b/src/process.rs similarity index 99% rename from src/currentprocess.rs rename to src/process.rs index 6ff71b30f4..d3c8123d44 100644 --- a/src/currentprocess.rs +++ b/src/process.rs @@ -21,7 +21,7 @@ use tracing_subscriber::util::SubscriberInitExt; pub mod filesource; pub mod terminalsource; -/// Allows concrete types for the currentprocess abstraction. +/// Allows concrete types for the process abstraction. #[derive(Clone, Debug)] pub enum Process { OSProcess(OSProcess), diff --git a/src/currentprocess/filesource.rs b/src/process/filesource.rs similarity index 93% rename from src/currentprocess/filesource.rs rename to src/process/filesource.rs index 9f4c7b11b5..d6effcd150 100644 --- a/src/currentprocess/filesource.rs +++ b/src/process/filesource.rs @@ -1,7 +1,7 @@ use std::io::{self, BufRead, Read, Write}; use super::terminalsource::{ColorableTerminal, StreamSelector}; -use crate::currentprocess::Process; +use crate::process::Process; /// Stand-in for std::io::Stdin pub trait Stdin { @@ -48,9 +48,9 @@ impl WriterLock for io::StdoutLock<'_> {} impl Writer for io::Stdout { fn is_a_tty(&self, process: &Process) -> bool { match process { - crate::currentprocess::Process::OSProcess(p) => p.stdout_is_a_tty, + crate::process::Process::OSProcess(p) => p.stdout_is_a_tty, #[cfg(feature = "test")] - crate::currentprocess::Process::TestProcess(_) => unreachable!(), + crate::process::Process::TestProcess(_) => unreachable!(), } } @@ -68,9 +68,9 @@ impl WriterLock for io::StderrLock<'_> {} impl Writer for io::Stderr { fn is_a_tty(&self, process: &Process) -> bool { match process { - crate::currentprocess::Process::OSProcess(p) => p.stderr_is_a_tty, + crate::process::Process::OSProcess(p) => p.stderr_is_a_tty, #[cfg(feature = "test")] - crate::currentprocess::Process::TestProcess(_) => unreachable!(), + crate::process::Process::TestProcess(_) => unreachable!(), } } diff --git a/src/currentprocess/terminalsource.rs b/src/process/terminalsource.rs similarity index 99% rename from src/currentprocess/terminalsource.rs rename to src/process/terminalsource.rs index 0e36e5ad21..6c68dc0220 100644 --- a/src/currentprocess/terminalsource.rs +++ b/src/process/terminalsource.rs @@ -228,7 +228,7 @@ mod tests { use std::collections::HashMap; use super::*; - use crate::currentprocess::TestProcess; + use crate::process::TestProcess; use crate::test::Env; #[test] diff --git a/src/test.rs b/src/test.rs index 24e11442b9..42a3c728dc 100644 --- a/src/test.rs +++ b/src/test.rs @@ -15,8 +15,8 @@ use std::process::Command; #[cfg(test)] use anyhow::Result; -use crate::currentprocess::TestProcess; use crate::dist::TargetTriple; +use crate::process::TestProcess; #[cfg(windows)] pub use crate::cli::self_update::{get_path, RegistryGuard, RegistryValueId, USER_PATH}; @@ -112,15 +112,15 @@ fn tempdir_in_with_prefix>(path: P, prefix: &str) -> io::Result

String { if cfg!(target_os = "windows") { // For windows, this host may be different to the target: we may be diff --git a/src/test/mock/clitools.rs b/src/test/mock/clitools.rs index 93ead6004d..675e06ab78 100644 --- a/src/test/mock/clitools.rs +++ b/src/test/mock/clitools.rs @@ -22,7 +22,7 @@ use tempfile::TempDir; use url::Url; use crate::cli::rustup_mode; -use crate::currentprocess; +use crate::process; use crate::test as rustup_test; use crate::test::const_dist_dir; use crate::test::this_host_triple; @@ -797,7 +797,7 @@ impl Config { ); } - let tp = currentprocess::TestProcess::new(&*self.workdir.borrow(), &arg_strings, vars, ""); + let tp = process::TestProcess::new(&*self.workdir.borrow(), &arg_strings, vars, ""); let process_res = rustup_mode::main(tp.process.current_dir().unwrap(), &tp.process).await; // convert Err's into an ec let ec = match process_res { diff --git a/src/utils/raw.rs b/src/utils/raw.rs index aea44d4bea..17985532f2 100644 --- a/src/utils/raw.rs +++ b/src/utils/raw.rs @@ -8,7 +8,7 @@ use std::path::Path; use std::str; #[cfg(not(windows))] -use crate::currentprocess::Process; +use crate::process::Process; pub(crate) fn ensure_dir_exists, F: FnOnce(&Path)>( path: P, diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 293e1e1b08..4ccddab200 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -10,8 +10,8 @@ use retry::{retry, OperationResult}; use sha2::Sha256; use url::Url; -use crate::currentprocess::Process; use crate::errors::*; +use crate::process::Process; use crate::utils::notifications::Notification; use crate::utils::raw; diff --git a/tests/suite/dist_install.rs b/tests/suite/dist_install.rs index e11537c645..91998064fd 100644 --- a/tests/suite/dist_install.rs +++ b/tests/suite/dist_install.rs @@ -1,7 +1,6 @@ use std::fs::File; use std::io::Write; -use rustup::currentprocess::TestProcess; use rustup::dist::component::Components; use rustup::dist::component::Transaction; use rustup::dist::component::{DirectoryPackage, Package}; @@ -9,6 +8,7 @@ use rustup::dist::prefix::InstallPrefix; use rustup::dist::temp; use rustup::dist::Notification; use rustup::dist::DEFAULT_DIST_SERVER; +use rustup::process::TestProcess; use rustup::utils::utils; use rustup::test::mock::{MockComponentBuilder, MockFile, MockInstallerBuilder}; From 52157dff1132e1c90188b599e14a464541ef4e16 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 11 Jul 2024 10:34:17 +0200 Subject: [PATCH 4/4] Rename OSProcess to OsProcess --- src/process.rs | 34 +++++++++++++++++----------------- src/process/filesource.rs | 4 ++-- src/process/terminalsource.rs | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/process.rs b/src/process.rs index d3c8123d44..1491e6bbc0 100644 --- a/src/process.rs +++ b/src/process.rs @@ -24,14 +24,14 @@ pub mod terminalsource; /// Allows concrete types for the process abstraction. #[derive(Clone, Debug)] pub enum Process { - OSProcess(OSProcess), + OsProcess(OsProcess), #[cfg(feature = "test")] TestProcess(TestContext), } impl Process { pub fn os() -> Self { - Self::OSProcess(OSProcess::new()) + Self::OsProcess(OsProcess::new()) } pub fn name(&self) -> Option { @@ -61,7 +61,7 @@ impl Process { pub fn var(&self, key: &str) -> Result { match self { - Process::OSProcess(_) => env::var(key), + Process::OsProcess(_) => env::var(key), #[cfg(feature = "test")] Process::TestProcess(p) => match p.vars.get(key) { Some(val) => Ok(val.to_owned()), @@ -72,7 +72,7 @@ impl Process { pub(crate) fn var_os(&self, key: &str) -> Option { match self { - Process::OSProcess(_) => env::var_os(key), + Process::OsProcess(_) => env::var_os(key), #[cfg(feature = "test")] Process::TestProcess(p) => p.vars.get(key).map(OsString::from), } @@ -80,7 +80,7 @@ impl Process { pub(crate) fn args(&self) -> Box + '_> { match self { - Process::OSProcess(_) => Box::new(env::args()), + Process::OsProcess(_) => Box::new(env::args()), #[cfg(feature = "test")] Process::TestProcess(p) => Box::new(p.args.iter().cloned()), } @@ -88,7 +88,7 @@ impl Process { pub(crate) fn args_os(&self) -> Box + '_> { match self { - Process::OSProcess(_) => Box::new(env::args_os()), + Process::OsProcess(_) => Box::new(env::args_os()), #[cfg(feature = "test")] Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)), } @@ -96,7 +96,7 @@ impl Process { pub(crate) fn stdin(&self) -> Box { match self { - Process::OSProcess(_) => Box::new(io::stdin()), + Process::OsProcess(_) => Box::new(io::stdin()), #[cfg(feature = "test")] Process::TestProcess(p) => Box::new(filesource::TestStdin(p.stdin.clone())), } @@ -104,7 +104,7 @@ impl Process { pub(crate) fn stdout(&self) -> Box { match self { - Process::OSProcess(_) => Box::new(io::stdout()), + Process::OsProcess(_) => Box::new(io::stdout()), #[cfg(feature = "test")] Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())), } @@ -112,7 +112,7 @@ impl Process { pub(crate) fn stderr(&self) -> Box { match self { - Process::OSProcess(_) => Box::new(io::stderr()), + Process::OsProcess(_) => Box::new(io::stderr()), #[cfg(feature = "test")] Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stderr.clone())), } @@ -120,7 +120,7 @@ impl Process { pub fn current_dir(&self) -> io::Result { match self { - Process::OSProcess(_) => env::current_dir(), + Process::OsProcess(_) => env::current_dir(), #[cfg(feature = "test")] Process::TestProcess(p) => Ok(p.cwd.clone()), } @@ -130,7 +130,7 @@ impl Process { impl home::env::Env for Process { fn home_dir(&self) -> Option { match self { - Process::OSProcess(_) => home::env::OS_ENV.home_dir(), + Process::OsProcess(_) => home::env::OS_ENV.home_dir(), #[cfg(feature = "test")] Process::TestProcess(_) => self.var("HOME").ok().map(|v| v.into()), } @@ -138,7 +138,7 @@ impl home::env::Env for Process { fn current_dir(&self) -> Result { match self { - Process::OSProcess(_) => home::env::OS_ENV.current_dir(), + Process::OsProcess(_) => home::env::OS_ENV.current_dir(), #[cfg(feature = "test")] Process::TestProcess(_) => self.current_dir(), } @@ -152,23 +152,23 @@ impl home::env::Env for Process { // ----------- real process ----------------- #[derive(Clone, Debug)] -pub struct OSProcess { +pub struct OsProcess { pub(self) stderr_is_a_tty: bool, pub(self) stdout_is_a_tty: bool, } -impl OSProcess { +impl OsProcess { pub fn new() -> Self { - OSProcess { + OsProcess { stderr_is_a_tty: io::stderr().is_terminal(), stdout_is_a_tty: io::stdout().is_terminal(), } } } -impl Default for OSProcess { +impl Default for OsProcess { fn default() -> Self { - OSProcess::new() + OsProcess::new() } } diff --git a/src/process/filesource.rs b/src/process/filesource.rs index d6effcd150..33c17116be 100644 --- a/src/process/filesource.rs +++ b/src/process/filesource.rs @@ -48,7 +48,7 @@ impl WriterLock for io::StdoutLock<'_> {} impl Writer for io::Stdout { fn is_a_tty(&self, process: &Process) -> bool { match process { - crate::process::Process::OSProcess(p) => p.stdout_is_a_tty, + crate::process::Process::OsProcess(p) => p.stdout_is_a_tty, #[cfg(feature = "test")] crate::process::Process::TestProcess(_) => unreachable!(), } @@ -68,7 +68,7 @@ impl WriterLock for io::StderrLock<'_> {} impl Writer for io::Stderr { fn is_a_tty(&self, process: &Process) -> bool { match process { - crate::process::Process::OSProcess(p) => p.stderr_is_a_tty, + crate::process::Process::OsProcess(p) => p.stderr_is_a_tty, #[cfg(feature = "test")] crate::process::Process::TestProcess(_) => unreachable!(), } diff --git a/src/process/terminalsource.rs b/src/process/terminalsource.rs index 6c68dc0220..25a39591d1 100644 --- a/src/process/terminalsource.rs +++ b/src/process/terminalsource.rs @@ -27,12 +27,12 @@ impl StreamSelector { fn is_a_tty(&self, process: &Process) -> bool { match self { StreamSelector::Stdout => match process { - Process::OSProcess(p) => p.stdout_is_a_tty, + Process::OsProcess(p) => p.stdout_is_a_tty, #[cfg(feature = "test")] Process::TestProcess(_) => unreachable!(), }, StreamSelector::Stderr => match process { - Process::OSProcess(p) => p.stderr_is_a_tty, + Process::OsProcess(p) => p.stderr_is_a_tty, #[cfg(feature = "test")] Process::TestProcess(_) => unreachable!(), },