Skip to content

Commit 615424b

Browse files
committed
Reorganize platform-dependent imports in self_update
1 parent 6ad9ed5 commit 615424b

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/cli/self_update.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@
3030
//! Deleting the running binary during uninstall is tricky
3131
//! and racy on Windows.
3232
33-
#[cfg(unix)]
34-
mod shell;
35-
#[cfg(feature = "test")]
36-
pub(crate) mod test;
37-
#[cfg(unix)]
38-
mod unix;
39-
#[cfg(windows)]
40-
mod windows;
41-
mod os {
42-
#[cfg(unix)]
43-
pub(crate) use super::unix::*;
44-
#[cfg(windows)]
45-
pub(crate) use super::windows::*;
46-
}
47-
4833
use std::borrow::Cow;
4934
use std::env::consts::EXE_SUFFIX;
5035
use std::fs;
@@ -82,10 +67,26 @@ use crate::{
8267
DUP_TOOLS, TOOLS,
8368
};
8469

85-
use os::*;
86-
pub(crate) use os::{run_update, self_replace};
70+
#[cfg(unix)]
71+
mod shell;
72+
#[cfg(feature = "test")]
73+
pub(crate) mod test;
74+
75+
#[cfg(unix)]
76+
mod unix;
77+
#[cfg(unix)]
78+
use unix::{delete_rustup_and_cargo_home, do_add_to_path, do_remove_from_path};
79+
#[cfg(unix)]
80+
pub(crate) use unix::{run_update, self_replace};
81+
82+
#[cfg(windows)]
83+
mod windows;
8784
#[cfg(windows)]
8885
pub use windows::complete_windows_uninstall;
86+
#[cfg(windows)]
87+
use windows::{delete_rustup_and_cargo_home, do_add_to_path, do_remove_from_path};
88+
#[cfg(windows)]
89+
pub(crate) use windows::{run_update, self_replace};
8990

9091
pub(crate) struct InstallOpts<'a> {
9192
pub default_host_triple: Option<String>,
@@ -557,19 +558,20 @@ pub(crate) async fn install(
557558
}
558559

559560
#[cfg(unix)]
560-
do_anti_sudo_check(no_prompt, process)?;
561+
unix::do_anti_sudo_check(no_prompt, process)?;
561562

562563
let mut term = process.stdout().terminal(process);
563564

564565
#[cfg(windows)]
565-
if let Some(plan) = do_msvc_check(&opts, process) {
566+
if let Some(plan) = windows::do_msvc_check(&opts, process) {
567+
use windows::{VsInstallPlan, ContinueInstall};
566568
if no_prompt {
567569
warn!("installing msvc toolchain without its prerequisites");
568570
} else if !quiet && plan == VsInstallPlan::Automatic {
569571
md(&mut term, MSVC_AUTO_INSTALL_MESSAGE);
570572
match windows::choose_vs_install(process)? {
571573
Some(VsInstallPlan::Automatic) => {
572-
match try_install_msvc(&opts, process).await {
574+
match windows::try_install_msvc(&opts, process).await {
573575
Err(e) => {
574576
// Make sure the console doesn't exit before the user can
575577
// see the error and give the option to continue anyway.
@@ -580,7 +582,7 @@ pub(crate) async fn install(
580582
}
581583
}
582584
Ok(ContinueInstall::No) => {
583-
ensure_prompt(process)?;
585+
windows::ensure_prompt(process)?;
584586
return Ok(utils::ExitCode(0));
585587
}
586588
_ => {}
@@ -638,7 +640,7 @@ pub(crate) async fn install(
638640
// window closes.
639641
#[cfg(windows)]
640642
if !no_prompt {
641-
ensure_prompt(process)?;
643+
windows::ensure_prompt(process)?;
642644
}
643645

644646
return Ok(utils::ExitCode(1));
@@ -672,7 +674,7 @@ pub(crate) async fn install(
672674
// On windows, where installation happens in a console
673675
// that may have opened just for this purpose, require
674676
// the user to press a key to continue.
675-
ensure_prompt(process)?;
677+
windows::ensure_prompt(process)?;
676678
}
677679

678680
Ok(utils::ExitCode(0))
@@ -928,11 +930,11 @@ async fn maybe_install_rust(
928930
install_bins(process)?;
929931

930932
#[cfg(unix)]
931-
do_write_env_files(process)?;
933+
unix::do_write_env_files(process)?;
932934

933935
if !opts.no_modify_path {
934936
#[cfg(windows)]
935-
do_add_to_programs(process)?;
937+
windows::do_add_to_programs(process)?;
936938
do_add_to_path(process)?;
937939
}
938940

@@ -1021,7 +1023,7 @@ pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::Exi
10211023
// Remove CARGO_HOME/bin from PATH
10221024
do_remove_from_path(process)?;
10231025
#[cfg(windows)]
1024-
do_remove_from_programs()?;
1026+
windows::do_remove_from_programs()?;
10251027

10261028
// Delete everything in CARGO_HOME *except* the rustup bin
10271029

0 commit comments

Comments
 (0)