Skip to content
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
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[alias]
dev-install = "run -- --no-modify-path -y"
run-rustup = ["run", "--config", "env.RUSTUP_FORCE_ARG0='rustup'"]
xfmt = ["fmt", "--all", "--", "--config-path=.rustfmt.unstable.toml"]
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ jobs:
restore-keys: ${{ github.base_ref }}-${{ runner.os }}-cargo-clippy-target-dir-${{ steps.cargo-target-cache.outputs.rust_hash }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rustup using ./rustup-init.sh
run: |
sh ./rustup-init.sh --default-toolchain=stable --profile=minimal -c=rustfmt -c=clippy -y
sh ./rustup-init.sh --default-toolchain=stable --profile=minimal -c=clippy -y
- name: Run the centos check within the docker image
run: |
docker run \
Expand Down Expand Up @@ -1578,7 +1578,8 @@ jobs:
git diff --exit-code
- name: Run Rust formatting checks
run: |
cargo fmt --all --check
rustup toolchain install nightly --profile=minimal -c=rustfmt
cargo +nightly xfmt --check
- name: Run cargo check and clippy
run: |
cargo check --all --all-targets --features test
Expand Down
2 changes: 2 additions & 0 deletions .rustfmt.unstable.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
5 changes: 3 additions & 2 deletions ci/actions-templates/centos-fmt-clippy-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs: # skip-all
restore-keys: ${{ github.base_ref }}-${{ runner.os }}-cargo-clippy-target-dir-${{ steps.cargo-target-cache.outputs.rust_hash }}-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rustup using ./rustup-init.sh
run: |
sh ./rustup-init.sh --default-toolchain=stable --profile=minimal -c=rustfmt -c=clippy -y
sh ./rustup-init.sh --default-toolchain=stable --profile=minimal -c=clippy -y
- name: Run the centos check within the docker image
run: |
docker run \
Expand Down Expand Up @@ -78,7 +78,8 @@ jobs: # skip-all
git diff --exit-code
- name: Run Rust formatting checks
run: |
cargo fmt --all --check
rustup toolchain install nightly --profile=minimal -c=rustfmt
cargo +nightly xfmt --check
- name: Run cargo check and clippy
run: |
cargo check --all --all-targets --features test
Expand Down
18 changes: 9 additions & 9 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ use anyhow::{Context, anyhow};
use rs_tracing::{
close_trace_file, close_trace_file_internal, open_trace_file, trace_to_file_internal,
};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

use rustup::cli::errors::CliError;
#[cfg(windows)]
use rustup::cli::self_update;
use rustup::cli::{common, log, proxy_mode, rustup_mode, setup_mode};
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
use rustup::errors::RustupError;
use rustup::is_proxyable_tools;
use rustup::process::Process;
use rustup::utils;
use rustup::{
cli::{common, errors::CliError, log, proxy_mode, rustup_mode, setup_mode},
env_var::RUST_RECURSION_COUNT_MAX,
errors::RustupError,
is_proxyable_tools,
process::Process,
utils,
};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};

fn main() -> anyhow::Result<ExitCode> {
#[cfg(windows)]
Expand Down
14 changes: 8 additions & 6 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Just a dumping ground for cli stuff

use std::fmt::Display;
use std::fs;
use std::io::{BufRead, Write};
use std::path::Path;
use std::sync::LazyLock;
use std::{cmp, env};
use std::{
cmp, env,
fmt::Display,
fs,
io::{BufRead, Write},
path::Path,
sync::LazyLock,
};

use anstyle::Style;
use anyhow::{Context, anyhow};
Expand Down
20 changes: 11 additions & 9 deletions src/cli/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ mod imp {

#[cfg(windows)]
mod imp {
use std::io;
use std::mem;
use std::ptr;
use std::{io, mem, ptr};

use tracing::info;
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE};
use windows_sys::Win32::System::JobObjects::{
AssignProcessToJobObject, CreateJobObjectW, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
JOBOBJECT_EXTENDED_LIMIT_INFORMATION, JobObjectExtendedLimitInformation,
SetInformationJobObject,
use windows_sys::Win32::{
Foundation::{CloseHandle, HANDLE},
System::{
JobObjects::{
AssignProcessToJobObject, CreateJobObjectW, JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE,
JOBOBJECT_EXTENDED_LIMIT_INFORMATION, JobObjectExtendedLimitInformation,
SetInformationJobObject,
},
Threading::GetCurrentProcess,
},
};
use windows_sys::Win32::System::Threading::GetCurrentProcess;

pub(crate) struct Setup {
job: Handle,
Expand Down
13 changes: 8 additions & 5 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,14 @@ pub(crate) fn cleanup_self_updater(process: &Process) -> anyhow::Result<()> {
mod tests {
use std::collections::HashMap;

use crate::cli::self_update::InstallOpts;
use crate::config::Cfg;
use crate::dist::{PartialToolchainDesc, Profile};
use crate::test::{Env, test_dir, with_rustup_home};
use crate::{for_host, process::TestProcess};
use crate::{
cli::self_update::InstallOpts,
config::Cfg,
dist::{PartialToolchainDesc, Profile},
for_host,
process::TestProcess,
test::{Env, test_dir, with_rustup_home},
};

#[test]
fn default_toolchain_is_stable() {
Expand Down
6 changes: 2 additions & 4 deletions src/cli/self_update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
//! 1) using a shell script that updates PATH if the path is not in PATH
//! 2) sourcing this script (`. /path/to/script`) in any appropriate rc file

use std::borrow::Cow;
use std::path::PathBuf;
use std::{borrow::Cow, path::PathBuf};

use anyhow::bail;

Expand Down Expand Up @@ -206,8 +205,7 @@ struct Zsh;

impl Zsh {
fn zdotdir(process: &Process) -> anyhow::Result<PathBuf> {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};

if matches!(process.var("SHELL"), Ok(sh) if sh.contains("zsh")) {
match process.var("ZDOTDIR") {
Expand Down
15 changes: 9 additions & 6 deletions src/cli/self_update/unix.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{
path::{Path, PathBuf},
process::Command,
};

use anyhow::{Context, bail};
use tracing::{error, warn};

use super::install_bins;
use super::shell::{self, Posix, UnixShell};
use crate::process::Process;
use crate::utils;
use super::{
install_bins,
shell::{self, Posix, UnixShell},
};
use crate::{process::Process, utils};

// If the user is trying to install with sudo, on some systems this will
// result in writing root-owned files to the user's home directory, because
Expand Down
91 changes: 51 additions & 40 deletions src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::borrow::Cow;
use std::env::{consts::EXE_SUFFIX, split_paths};
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::io::Write;
use std::os::windows::ffi::OsStrExt;
use std::path::Path;
use std::process::Command;
use std::{
borrow::Cow,
env::{consts::EXE_SUFFIX, split_paths},
ffi::{OsStr, OsString},
fmt,
io::Write,
os::windows::ffi::OsStrExt,
path::Path,
process::Command,
};

use anyhow::{Context, anyhow};
use tracing::{info, warn};
Expand All @@ -15,14 +17,18 @@ use windows_registry::{CURRENT_USER, HSTRING, Key};
use windows_result::WIN32_ERROR;
use windows_sys::Win32::Foundation::{ERROR_FILE_NOT_FOUND, ERROR_INVALID_DATA};

use super::super::errors::CliError;
use super::common;
use super::{InstallOpts, install_bins, report_error};
use crate::cli::markdown::md;
use crate::dist::TargetTuple;
use crate::download::DownloadOptions;
use crate::process::{ColorableTerminal, Process};
use crate::utils;
use crate::{
cli::{
common,
errors::CliError,
markdown::md,
self_update::{InstallOpts, install_bins, report_error},
},
dist::TargetTuple,
download::DownloadOptions,
process::{ColorableTerminal, Process},
utils,
};

pub(crate) fn ensure_prompt(process: &Process) -> anyhow::Result<()> {
writeln!(process.stdout().lock(),)?;
Expand Down Expand Up @@ -376,15 +382,18 @@ pub fn complete_windows_uninstall(process: &Process) -> anyhow::Result<utils::Ex
}

pub(crate) fn wait_for_parent() -> anyhow::Result<()> {
use std::io;
use std::mem;
use windows_sys::Win32::Foundation::{CloseHandle, INVALID_HANDLE_VALUE, WAIT_OBJECT_0};
use windows_sys::Win32::Storage::FileSystem::SYNCHRONIZE;
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, PROCESSENTRY32, Process32First, Process32Next, TH32CS_SNAPPROCESS,
};
use windows_sys::Win32::System::Threading::{
GetCurrentProcessId, INFINITE, OpenProcess, WaitForSingleObject,
use std::{io, mem};

use windows_sys::Win32::{
Foundation::{CloseHandle, INVALID_HANDLE_VALUE, WAIT_OBJECT_0},
Storage::FileSystem::SYNCHRONIZE,
System::{
Diagnostics::ToolHelp::{
CreateToolhelp32Snapshot, PROCESSENTRY32, Process32First, Process32Next,
TH32CS_SNAPPROCESS,
},
Threading::{GetCurrentProcessId, INFINITE, OpenProcess, WaitForSingleObject},
},
};

unsafe {
Expand Down Expand Up @@ -454,9 +463,12 @@ pub(crate) fn do_add_to_path(process: &Process) -> anyhow::Result<()> {

fn _apply_new_path(new_path: Option<HSTRING>, process: &Process) -> anyhow::Result<()> {
use std::ptr;
use windows_sys::Win32::Foundation::{LPARAM, WPARAM};
use windows_sys::Win32::UI::WindowsAndMessaging::{
HWND_BROADCAST, SMTO_ABORTIFHUNG, SendMessageTimeoutA, WM_SETTINGCHANGE,

use windows_sys::Win32::{
Foundation::{LPARAM, WPARAM},
UI::WindowsAndMessaging::{
HWND_BROADCAST, SMTO_ABORTIFHUNG, SendMessageTimeoutA, WM_SETTINGCHANGE,
},
};

let Some(new_path) = new_path else {
Expand Down Expand Up @@ -705,14 +717,15 @@ pub(crate) fn self_replace(process: &Process) -> anyhow::Result<utils::ExitCode>
// .. augmented with this SO answer
// https://stackoverflow.com/questions/10319526/understanding-a-self-deleting-program-in-c
pub(crate) fn spawn_uninstall_gc(no_modify_path: bool, process: &Process) -> anyhow::Result<()> {
use std::io;
use std::ptr;
use std::thread;
use std::time::Duration;
use windows_sys::Win32::Foundation::{CloseHandle, GENERIC_READ, INVALID_HANDLE_VALUE};
use windows_sys::Win32::Security::SECURITY_ATTRIBUTES;
use windows_sys::Win32::Storage::FileSystem::{
CreateFileW, FILE_FLAG_DELETE_ON_CLOSE, FILE_SHARE_DELETE, FILE_SHARE_READ, OPEN_EXISTING,
use std::{io, ptr, thread, time::Duration};

use windows_sys::Win32::{
Foundation::{CloseHandle, GENERIC_READ, INVALID_HANDLE_VALUE},
Security::SECURITY_ATTRIBUTES,
Storage::FileSystem::{
CreateFileW, FILE_FLAG_DELETE_ON_CLOSE, FILE_SHARE_DELETE, FILE_SHARE_READ,
OPEN_EXISTING,
},
};

// CARGO_HOME, hopefully empty except for bin/rustup.exe
Expand Down Expand Up @@ -835,14 +848,12 @@ impl RegistryValueId {

#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::os::windows::ffi::OsStringExt;
use std::{collections::HashMap, os::windows::ffi::OsStringExt};

use windows_registry::Type;

use super::*;
use crate::process::TestProcess;
use crate::test::test_id;
use crate::{process::TestProcess, test::test_id};

fn test_process(test_id: &str) -> TestProcess {
let vars: HashMap<String, String> = [
Expand Down
8 changes: 5 additions & 3 deletions src/cli/topical_doc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};
use std::{
ffi::OsString,
fs,
path::{Path, PathBuf},
};

use anyhow::{Context, anyhow};

Expand Down
10 changes: 7 additions & 3 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ pub(crate) fn run_command_for_dir<S: AsRef<OsStr> + Debug>(

#[cfg(windows)]
fn exec(cmd: &mut Command) -> io::Result<ExitStatus> {
use windows_sys::Win32::Foundation::{FALSE, TRUE};
use windows_sys::Win32::System::Console::SetConsoleCtrlHandler;
use windows_sys::core::BOOL;
use windows_sys::{
Win32::{
Foundation::{FALSE, TRUE},
System::Console::SetConsoleCtrlHandler,
},
core::BOOL,
};

unsafe extern "system" fn ctrlc_handler(_: u32) -> BOOL {
// Do nothing. Let the child process handle it.
Expand Down
16 changes: 9 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt::{self, Debug, Display};
use std::io;
use std::io::Write;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{
fmt::{self, Debug, Display},
io,
io::Write,
ops::Deref,
path::{Path, PathBuf},
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};

use anyhow::{Context, anyhow, bail};
use chrono::{DateTime, NaiveDate};
Expand Down
Loading
Loading