Skip to content

Commit d6de276

Browse files
committed
squash the commits
implement detail_exit but I'm not sure it is right. not create new file and write detail exit in lib.rs replace std::process::exit to detail_exit that is not related to code runnning. remove pub
1 parent 4045ce6 commit d6de276

File tree

12 files changed

+48
-41
lines changed

12 files changed

+48
-41
lines changed

src/bootstrap/builder.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,7 @@ impl StepDescription {
348348
eprintln!(
349349
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
350350
);
351-
#[cfg(not(test))]
352-
std::process::exit(1);
353-
#[cfg(test)]
354-
// so we can use #[should_panic]
355-
panic!()
351+
crate::detail_exit(1);
356352
}
357353
}
358354
}
@@ -1001,7 +997,7 @@ impl<'a> Builder<'a> {
1001997
if !help_on_error.is_empty() {
1002998
eprintln!("{}", help_on_error);
1003999
}
1004-
std::process::exit(1);
1000+
crate::detail_exit(1);
10051001
}
10061002
}
10071003

@@ -1430,7 +1426,7 @@ impl<'a> Builder<'a> {
14301426
"error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
14311427
);
14321428
eprintln!("help: try `rustup component add clippy`");
1433-
std::process::exit(1);
1429+
crate::detail_exit(1);
14341430
});
14351431
if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
14361432
rustflags.arg("--cfg=bootstrap");

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fs;
1313
use std::io::prelude::*;
1414
use std::io::BufReader;
1515
use std::path::{Path, PathBuf};
16-
use std::process::{exit, Command, Stdio};
16+
use std::process::{Command, Stdio};
1717
use std::str;
1818

1919
use serde::Deserialize;
@@ -1328,7 +1328,7 @@ pub fn run_cargo(
13281328
});
13291329

13301330
if !ok {
1331-
exit(1);
1331+
crate::detail_exit(1);
13321332
}
13331333

13341334
// Ok now we need to actually find all the files listed in `toplevel`. We've

src/bootstrap/config.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::ffi::OsStr;
1111
use std::fmt;
1212
use std::fs;
1313
use std::path::{Path, PathBuf};
14-
use std::process::{exit, Command};
14+
use std::process::Command;
1515
use std::str::FromStr;
1616

1717
use crate::builder::{Builder, TaskPath};
@@ -805,8 +805,6 @@ impl Config {
805805
let get_toml = |_| TomlConfig::default();
806806
#[cfg(not(test))]
807807
let get_toml = |file: &Path| {
808-
use std::process;
809-
810808
let contents =
811809
t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
812810
// Deserialize to Value and then TomlConfig to prevent the Deserialize impl of
@@ -817,7 +815,7 @@ impl Config {
817815
Ok(table) => table,
818816
Err(err) => {
819817
eprintln!("failed to parse TOML configuration '{}': {}", file.display(), err);
820-
process::exit(2);
818+
crate::detail_exit(2);
821819
}
822820
}
823821
};
@@ -1487,7 +1485,7 @@ fn download_ci_rustc_commit(
14871485
println!("help: maybe your repository history is too shallow?");
14881486
println!("help: consider disabling `download-rustc`");
14891487
println!("help: or fetch enough history to include one upstream commit");
1490-
exit(1);
1488+
crate::detail_exit(1);
14911489
}
14921490

14931491
// Warn if there were changes to the compiler or standard library since the ancestor commit.

src/bootstrap/flags.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! has various flags to configure how it's run.
55
66
use std::path::PathBuf;
7-
use std::process;
87

98
use getopts::Options;
109

@@ -261,7 +260,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
261260
// subcommand.
262261
println!("{}\n", subcommand_help);
263262
let exit_code = if args.is_empty() { 0 } else { 1 };
264-
process::exit(exit_code);
263+
crate::detail_exit(exit_code);
265264
}
266265
};
267266

@@ -347,7 +346,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
347346
} else if verbose {
348347
panic!("No paths available for subcommand `{}`", subcommand.as_str());
349348
}
350-
process::exit(exit_code);
349+
crate::detail_exit(exit_code);
351350
};
352351

353352
// Done specifying what options are possible, so do the getopts parsing
@@ -379,7 +378,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
379378
"Sorry, I couldn't figure out which subcommand you were trying to specify.\n\
380379
You may need to move some options to after the subcommand.\n"
381380
);
382-
process::exit(1);
381+
crate::detail_exit(1);
383382
}
384383
// Extra help text for some commands
385384
match subcommand {
@@ -600,7 +599,7 @@ Arguments:
600599
eprintln!("error: {}", err);
601600
eprintln!("help: the available profiles are:");
602601
eprint!("{}", Profile::all_for_help("- "));
603-
std::process::exit(1);
602+
crate::detail_exit(1);
604603
})
605604
} else {
606605
t!(crate::setup::interactive_path())
@@ -614,7 +613,7 @@ Arguments:
614613
|| matches.opt_str("keep-stage-std").is_some()
615614
{
616615
eprintln!("--keep-stage not yet supported for x.py check");
617-
process::exit(1);
616+
crate::detail_exit(1);
618617
}
619618
}
620619

@@ -805,7 +804,7 @@ fn parse_deny_warnings(matches: &getopts::Matches) -> Option<bool> {
805804
Some("warn") => Some(false),
806805
Some(value) => {
807806
eprintln!(r#"invalid value for --warnings: {:?}, expected "warn" or "deny""#, value,);
808-
process::exit(1);
807+
crate::detail_exit(1);
809808
}
810809
None => None,
811810
}

src/bootstrap/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
3232
code, run `./x.py fmt` instead.",
3333
cmd_debug,
3434
);
35-
std::process::exit(1);
35+
crate::detail_exit(1);
3636
}
3737
}
3838
}
@@ -114,7 +114,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
114114

115115
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
116116
eprintln!("./x.py fmt is not supported on this channel");
117-
std::process::exit(1);
117+
crate::detail_exit(1);
118118
});
119119
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
120120
let src = build.src.clone();

src/bootstrap/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use std::env;
109109
use std::fs::{self, File};
110110
use std::io;
111111
use std::path::{Path, PathBuf};
112-
use std::process::{self, Command};
112+
use std::process::Command;
113113
use std::str;
114114

115115
use filetime::FileTime;
@@ -711,7 +711,7 @@ impl Build {
711711
for failure in failures.iter() {
712712
eprintln!(" - {}\n", failure);
713713
}
714-
process::exit(1);
714+
detail_exit(1);
715715
}
716716

717717
#[cfg(feature = "build-metrics")]
@@ -1617,7 +1617,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
16171617
to download LLVM rather than building it.
16181618
"
16191619
);
1620-
std::process::exit(1);
1620+
detail_exit(1);
16211621
}
16221622
}
16231623

@@ -1646,6 +1646,20 @@ fn chmod(path: &Path, perms: u32) {
16461646
#[cfg(windows)]
16471647
fn chmod(_path: &Path, _perms: u32) {}
16481648

1649+
/// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.)
1650+
/// If the test is running and code is an error code, it will cause a panic.
1651+
fn detail_exit(code: i32) -> ! {
1652+
// Successful exit
1653+
if code == 0 {
1654+
std::process::exit(0);
1655+
}
1656+
if cfg!(test) {
1657+
panic!("status code: {}", code);
1658+
} else {
1659+
std::panic::resume_unwind(Box::new(code));
1660+
}
1661+
}
1662+
16491663
impl Compiler {
16501664
pub fn with_stage(mut self, stage: u32) -> Compiler {
16511665
self.stage = stage;

src/bootstrap/sanity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ You should install cmake, or set `download-ci-llvm = true` in the
104104
than building it.
105105
"
106106
);
107-
std::process::exit(1);
107+
crate::detail_exit(1);
108108
}
109109
}
110110

src/bootstrap/setup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn setup(config: &Config, profile: Profile) {
9494
"note: this will use the configuration in {}",
9595
profile.include_path(&config.src).display()
9696
);
97-
std::process::exit(1);
97+
crate::detail_exit(1);
9898
}
9999

100100
let settings = format!(
@@ -287,7 +287,7 @@ pub fn interactive_path() -> io::Result<Profile> {
287287
io::stdin().read_line(&mut input)?;
288288
if input.is_empty() {
289289
eprintln!("EOF on stdin, when expecting answer to question. Giving up.");
290-
std::process::exit(1);
290+
crate::detail_exit(1);
291291
}
292292
break match parse_with_abbrev(&input) {
293293
Ok(profile) => profile,

src/bootstrap/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl Step for Clippy {
673673
}
674674

675675
if !builder.config.cmd.bless() {
676-
std::process::exit(1);
676+
crate::detail_exit(1);
677677
}
678678

679679
let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
@@ -1021,7 +1021,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
10211021
PATH = inferred_rustfmt_dir.display(),
10221022
CHAN = builder.config.channel,
10231023
);
1024-
std::process::exit(1);
1024+
crate::detail_exit(1);
10251025
}
10261026
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
10271027
}
@@ -1251,7 +1251,7 @@ help: to test the compiler, use `--stage 1` instead
12511251
help: to test the standard library, use `--stage 0 library/std` instead
12521252
note: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
12531253
);
1254-
std::process::exit(1);
1254+
crate::detail_exit(1);
12551255
}
12561256

12571257
let compiler = self.compiler;

src/bootstrap/tool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashSet;
22
use std::env;
33
use std::fs;
44
use std::path::{Path, PathBuf};
5-
use std::process::{exit, Command};
5+
use std::process::Command;
66

77
use crate::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
88
use crate::channel::GitInfo;
@@ -204,7 +204,7 @@ impl Step for ToolBuild {
204204

205205
if !is_expected {
206206
if !is_optional_tool {
207-
exit(1);
207+
crate::detail_exit(1);
208208
} else {
209209
None
210210
}

src/bootstrap/toolstate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn print_error(tool: &str, submodule: &str) {
9393
eprintln!("If you do NOT intend to update '{}', please ensure you did not accidentally", tool);
9494
eprintln!("change the submodule at '{}'. You may ask your reviewer for the", submodule);
9595
eprintln!("proper steps.");
96-
std::process::exit(3);
96+
crate::detail_exit(3);
9797
}
9898

9999
fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
@@ -108,7 +108,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
108108
Ok(o) => o,
109109
Err(e) => {
110110
eprintln!("Failed to get changed files: {:?}", e);
111-
std::process::exit(1);
111+
crate::detail_exit(1);
112112
}
113113
};
114114

@@ -179,7 +179,7 @@ impl Step for ToolStateCheck {
179179
}
180180

181181
if did_error {
182-
std::process::exit(1);
182+
crate::detail_exit(1);
183183
}
184184

185185
check_changed_files(&toolstates);
@@ -225,7 +225,7 @@ impl Step for ToolStateCheck {
225225
}
226226

227227
if did_error {
228-
std::process::exit(1);
228+
crate::detail_exit(1);
229229
}
230230

231231
if builder.config.channel == "nightly" && env::var_os("TOOLSTATE_PUBLISH").is_some() {

src/bootstrap/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
336336

337337
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
338338
if !try_run(cmd, print_cmd_on_fail) {
339-
std::process::exit(1);
339+
crate::detail_exit(1);
340340
}
341341
}
342342

@@ -375,7 +375,7 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
375375

376376
pub fn run_suppressed(cmd: &mut Command) {
377377
if !try_run_suppressed(cmd) {
378-
std::process::exit(1);
378+
crate::detail_exit(1);
379379
}
380380
}
381381

@@ -465,7 +465,7 @@ fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
465465

466466
fn fail(s: &str) -> ! {
467467
eprintln!("\n\n{}\n\n", s);
468-
std::process::exit(1);
468+
crate::detail_exit(1);
469469
}
470470

471471
/// Copied from `std::path::absolute` until it stabilizes.

0 commit comments

Comments
 (0)