|
| 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 | +
|
1 | 15 | #![recursion_limit = "1024"]
|
2 | 16 |
|
3 | 17 | extern crate rustup_dist;
|
4 |
| -#[macro_use] |
5 | 18 | extern crate rustup_utils;
|
6 | 19 | #[macro_use]
|
7 | 20 | extern crate error_chain;
|
8 | 21 |
|
9 |
| -#[macro_use] |
10 | 22 | extern crate clap;
|
11 | 23 | extern crate regex;
|
12 |
| -#[macro_use] |
13 | 24 | extern crate rustup;
|
14 | 25 | extern crate term;
|
15 | 26 | extern crate itertools;
|
@@ -54,29 +65,26 @@ use rustup_dist::dist::TargetTriple;
|
54 | 65 | use rustup::env_var::RUST_RECURSION_COUNT_MAX;
|
55 | 66 |
|
56 | 67 | fn main() {
|
57 |
| - if let Err(ref e) = run_multirust() { |
| 68 | + if let Err(ref e) = run_rustup() { |
58 | 69 | common::report_error(e);
|
59 | 70 | std::process::exit(1);
|
60 | 71 | }
|
61 | 72 | }
|
62 | 73 |
|
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()?; |
70 | 78 |
|
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 |
73 | 80 | do_compatibility_hacks();
|
74 | 81 |
|
75 | 82 | // The name of arg0 determines how the program is going to behave
|
76 | 83 | let arg0 = env::args().next().map(PathBuf::from);
|
77 | 84 | let name = arg0.as_ref()
|
78 | 85 | .and_then(|a| a.file_stem())
|
79 | 86 | .and_then(|a| a.to_str());
|
| 87 | + |
80 | 88 | match name {
|
81 | 89 | Some("rustup") => {
|
82 | 90 | rustup_mode::main()
|
@@ -123,6 +131,16 @@ fn run_multirust() -> Result<()> {
|
123 | 131 | }
|
124 | 132 | }
|
125 | 133 |
|
| 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 | + |
126 | 144 | fn do_compatibility_hacks() {
|
127 | 145 | make_environment_compatible();
|
128 | 146 | fix_windows_reg_key();
|
|
0 commit comments