Skip to content

Commit e7ba330

Browse files
committed
Auto merge of #1108 - brson:cleanup, r=Diggsey
Cleanup r? @Diggsey
2 parents b8b620d + e42a3ac commit e7ba330

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/rustup-cli/main.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
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;
4-
#[macro_use]
518
extern crate rustup_utils;
619
#[macro_use]
720
extern crate error_chain;
821

9-
#[macro_use]
1022
extern crate clap;
1123
extern crate regex;
12-
#[macro_use]
1324
extern crate rustup;
1425
extern crate term;
1526
extern crate itertools;
@@ -54,29 +65,26 @@ use rustup_dist::dist::TargetTriple;
5465
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
5566

5667
fn main() {
57-
if let Err(ref e) = run_multirust() {
68+
if let Err(ref e) = run_rustup() {
5869
common::report_error(e);
5970
std::process::exit(1);
6071
}
6172
}
6273

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

71-
// Do various things to clean up past messes
72-
// FIXME: Remove this soon to get it out of the proxy path
79+
// Do various hacks to clean up past messes
7380
do_compatibility_hacks();
7481

7582
// The name of arg0 determines how the program is going to behave
7683
let arg0 = env::args().next().map(PathBuf::from);
7784
let name = arg0.as_ref()
7885
.and_then(|a| a.file_stem())
7986
.and_then(|a| a.to_str());
87+
8088
match name {
8189
Some("rustup") => {
8290
rustup_mode::main()
@@ -123,6 +131,16 @@ fn run_multirust() -> Result<()> {
123131
}
124132
}
125133

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+
126144
fn do_compatibility_hacks() {
127145
make_environment_compatible();
128146
fix_windows_reg_key();

src/rustup-dist/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ extern crate toml;
88
extern crate flate2;
99
extern crate tar;
1010
extern crate url;
11-
#[macro_use]
1211
extern crate rustup_utils;
1312
#[macro_use]
1413
extern crate error_chain;

src/rustup/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![recursion_limit = "1024"]
22

33
extern crate rustup_dist;
4-
#[macro_use]
54
extern crate rustup_utils;
65
#[macro_use]
76
extern crate error_chain;

0 commit comments

Comments
 (0)