Skip to content

Commit e42a3ac

Browse files
committed
Clean up main a bit
1 parent b2f11b1 commit e42a3ac

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/rustup-cli/main.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
//! The main rustup commandline application
2+
//!
3+
//! The rustup binary is a chimera, changing its behavior based on the
4+
//! name of the binary. This is used most prominently to enable
5+
//! rustup's tool 'proxies' - that is, rustup itself and the rustup
6+
//! proxies are the same binary; when the binary is called 'rustup' or
7+
//! 'rustup.exe' rustup behaves like the rustup commandline
8+
//! application; when it is called 'rustc' it behaves as a proxy to
9+
//! 'rustc'.
10+
//!
11+
//! This scheme is further used to distingush the rustup installer,
12+
//! called 'rustup-init' which is again just the rustup binary under a
13+
//! different name.
14+
115
#![recursion_limit = "1024"]
216

317
extern crate rustup_dist;
@@ -51,29 +65,26 @@ use rustup_dist::dist::TargetTriple;
5165
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
5266

5367
fn main() {
54-
if let Err(ref e) = run_multirust() {
68+
if let Err(ref e) = run_rustup() {
5569
common::report_error(e);
5670
std::process::exit(1);
5771
}
5872
}
5973

60-
fn run_multirust() -> Result<()> {
61-
// Guard against infinite recursion
62-
let recursion_count = env::var("RUST_RECURSION_COUNT").ok()
63-
.and_then(|s| s.parse().ok()).unwrap_or(0);
64-
if recursion_count > RUST_RECURSION_COUNT_MAX {
65-
return Err(ErrorKind::InfiniteRecursion.into());
66-
}
74+
fn run_rustup() -> Result<()> {
75+
// Guard against infinite proxy recursion. This mostly happens due to
76+
// bugs in rustup.
77+
do_recursion_guard()?;
6778

68-
// Do various things to clean up past messes
69-
// FIXME: Remove this soon to get it out of the proxy path
79+
// Do various hacks to clean up past messes
7080
do_compatibility_hacks();
7181

7282
// The name of arg0 determines how the program is going to behave
7383
let arg0 = env::args().next().map(PathBuf::from);
7484
let name = arg0.as_ref()
7585
.and_then(|a| a.file_stem())
7686
.and_then(|a| a.to_str());
87+
7788
match name {
7889
Some("rustup") => {
7990
rustup_mode::main()
@@ -120,6 +131,16 @@ fn run_multirust() -> Result<()> {
120131
}
121132
}
122133

134+
fn do_recursion_guard() -> Result<()> {
135+
let recursion_count = env::var("RUST_RECURSION_COUNT").ok()
136+
.and_then(|s| s.parse().ok()).unwrap_or(0);
137+
if recursion_count > RUST_RECURSION_COUNT_MAX {
138+
return Err(ErrorKind::InfiniteRecursion.into());
139+
}
140+
141+
Ok(())
142+
}
143+
123144
fn do_compatibility_hacks() {
124145
make_environment_compatible();
125146
fix_windows_reg_key();

0 commit comments

Comments
 (0)