Skip to content

Commit 183a31b

Browse files
authored
Rollup merge of rust-lang#112084 - ozkanonur:improvements, r=clubby789
enhancements on build_helper utilization and rustdoc-gui-test This change provides codebase improvements, resolves `FIXME` in `rustdoc-gui-test` and makes `rustdoc-gui` test able to find local `node_modules` directory outside of the source root.
2 parents f589451 + c64db2c commit 183a31b

19 files changed

+92
-82
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4289,6 +4289,7 @@ dependencies = [
42894289
name = "rustdoc-gui-test"
42904290
version = "0.1.0"
42914291
dependencies = [
4292+
"build_helper",
42924293
"compiletest",
42934294
"getopts",
42944295
"walkdir",

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl StepDescription {
381381
eprintln!(
382382
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
383383
);
384-
crate::detail_exit(1);
384+
crate::detail_exit_macro!(1);
385385
}
386386
}
387387
}
@@ -1355,7 +1355,7 @@ impl<'a> Builder<'a> {
13551355
"error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
13561356
);
13571357
eprintln!("help: try `rustup component add clippy`");
1358-
crate::detail_exit(1);
1358+
crate::detail_exit_macro!(1);
13591359
});
13601360
if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
13611361
rustflags.arg("--cfg=bootstrap");

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ pub fn run_cargo(
16861686
});
16871687

16881688
if !ok {
1689-
crate::detail_exit(1);
1689+
crate::detail_exit_macro!(1);
16901690
}
16911691

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

src/bootstrap/config.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::channel::{self, GitInfo};
2323
pub use crate::flags::Subcommand;
2424
use crate::flags::{Color, Flags, Warnings};
2525
use crate::util::{exe, output, t};
26+
use build_helper::detail_exit_macro;
2627
use once_cell::sync::OnceCell;
2728
use serde::{Deserialize, Deserializer};
2829
use serde_derive::Deserialize;
@@ -579,7 +580,7 @@ macro_rules! define_config {
579580
panic!("overriding existing option")
580581
} else {
581582
eprintln!("overriding existing option: `{}`", stringify!($field));
582-
crate::detail_exit(2);
583+
detail_exit_macro!(2);
583584
}
584585
} else {
585586
self.$field = other.$field;
@@ -678,7 +679,7 @@ impl<T> Merge for Option<T> {
678679
panic!("overriding existing option")
679680
} else {
680681
eprintln!("overriding existing option");
681-
crate::detail_exit(2);
682+
detail_exit_macro!(2);
682683
}
683684
} else {
684685
*self = other;
@@ -944,7 +945,7 @@ impl Config {
944945
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
945946
.unwrap_or_else(|err| {
946947
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
947-
crate::detail_exit(2);
948+
detail_exit_macro!(2);
948949
})
949950
}
950951
Self::parse_inner(args, get_toml)
@@ -978,7 +979,7 @@ impl Config {
978979
eprintln!(
979980
"Cannot use both `llvm_bolt_profile_generate` and `llvm_bolt_profile_use` at the same time"
980981
);
981-
crate::detail_exit(1);
982+
detail_exit_macro!(1);
982983
}
983984

984985
// Infer the rest of the configuration.
@@ -1094,7 +1095,7 @@ impl Config {
10941095
}
10951096
}
10961097
eprintln!("failed to parse override `{option}`: `{err}");
1097-
crate::detail_exit(2)
1098+
detail_exit_macro!(2)
10981099
}
10991100
toml.merge(override_toml, ReplaceOpt::Override);
11001101

@@ -1810,7 +1811,7 @@ impl Config {
18101811
println!("help: maybe your repository history is too shallow?");
18111812
println!("help: consider disabling `download-rustc`");
18121813
println!("help: or fetch enough history to include one upstream commit");
1813-
crate::detail_exit(1);
1814+
crate::detail_exit_macro!(1);
18141815
}
18151816

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

src/bootstrap/download.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use std::{
77
process::{Command, Stdio},
88
};
99

10+
use build_helper::util::try_run;
1011
use once_cell::sync::OnceCell;
1112
use xz2::bufread::XzDecoder;
1213

1314
use crate::{
1415
config::RustfmtMetadata,
1516
llvm::detect_llvm_sha,
1617
t,
17-
util::{check_run, exe, program_out_of_date, try_run},
18+
util::{check_run, exe, program_out_of_date},
1819
Config,
1920
};
2021

@@ -245,7 +246,7 @@ impl Config {
245246
if !help_on_error.is_empty() {
246247
eprintln!("{}", help_on_error);
247248
}
248-
crate::detail_exit(1);
249+
crate::detail_exit_macro!(1);
249250
}
250251
}
251252

src/bootstrap/flags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl Flags {
193193
} else {
194194
panic!("No paths available for subcommand `{}`", subcommand.as_str());
195195
}
196-
crate::detail_exit(0);
196+
crate::detail_exit_macro!(0);
197197
}
198198

199199
Flags::parse_from(it)
@@ -538,7 +538,7 @@ pub fn get_completion<G: clap_complete::Generator>(shell: G, path: &Path) -> Opt
538538
} else {
539539
std::fs::read_to_string(path).unwrap_or_else(|_| {
540540
eprintln!("couldn't read {}", path.display());
541-
crate::detail_exit(1)
541+
crate::detail_exit_macro!(1)
542542
})
543543
};
544544
let mut buf = Vec::new();

src/bootstrap/format.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
4040
code, run `./x.py fmt` instead.",
4141
cmd_debug,
4242
);
43-
crate::detail_exit(1);
43+
crate::detail_exit_macro!(1);
4444
}
4545
true
4646
}
@@ -196,7 +196,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
196196

197197
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
198198
eprintln!("./x.py fmt is not supported on this channel");
199-
crate::detail_exit(1);
199+
crate::detail_exit_macro!(1);
200200
});
201201
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
202202
let src = build.src.clone();

src/bootstrap/lib.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::process::{Command, Stdio};
2727
use std::str;
2828

2929
use build_helper::ci::{gha, CiEnv};
30+
use build_helper::detail_exit_macro;
3031
use channel::GitInfo;
3132
use config::{DryRun, Target};
3233
use filetime::FileTime;
@@ -699,7 +700,7 @@ impl Build {
699700
for failure in failures.iter() {
700701
eprintln!(" - {}\n", failure);
701702
}
702-
detail_exit(1);
703+
detail_exit_macro!(1);
703704
}
704705

705706
#[cfg(feature = "build-metrics")]
@@ -1482,7 +1483,7 @@ impl Build {
14821483
"Error: Unable to find the stamp file {}, did you try to keep a nonexistent build stage?",
14831484
stamp.display()
14841485
);
1485-
crate::detail_exit(1);
1486+
crate::detail_exit_macro!(1);
14861487
}
14871488

14881489
let mut paths = Vec::new();
@@ -1674,7 +1675,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
16741675
to download LLVM rather than building it.
16751676
"
16761677
);
1677-
detail_exit(1);
1678+
detail_exit_macro!(1);
16781679
}
16791680
}
16801681

@@ -1739,18 +1740,6 @@ fn chmod(path: &Path, perms: u32) {
17391740
#[cfg(windows)]
17401741
fn chmod(_path: &Path, _perms: u32) {}
17411742

1742-
/// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.)
1743-
/// If the test is running and code is an error code, it will cause a panic.
1744-
fn detail_exit(code: i32) -> ! {
1745-
// if in test and code is an error code, panic with status code provided
1746-
if cfg!(test) {
1747-
panic!("status code: {}", code);
1748-
} else {
1749-
// otherwise,exit with provided status code
1750-
std::process::exit(code);
1751-
}
1752-
}
1753-
17541743
impl Compiler {
17551744
pub fn with_stage(mut self, stage: u32) -> Compiler {
17561745
self.stage = stage;

src/bootstrap/render_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command) -> bool {
3030

3131
if !run_tests(builder, cmd) {
3232
if builder.fail_fast {
33-
crate::detail_exit(1);
33+
crate::detail_exit_macro!(1);
3434
} else {
3535
let mut failures = builder.delayed_failures.borrow_mut();
3636
failures.push(format!("{cmd:?}"));

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-
crate::detail_exit(1);
107+
crate::detail_exit_macro!(1);
108108
}
109109
}
110110

src/bootstrap/setup.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
194194
"note: this will use the configuration in {}",
195195
profile.include_path(&config.src).display()
196196
);
197-
crate::detail_exit(1);
197+
crate::detail_exit_macro!(1);
198198
}
199199

200200
let settings = format!(
@@ -380,7 +380,7 @@ pub fn interactive_path() -> io::Result<Profile> {
380380
io::stdin().read_line(&mut input)?;
381381
if input.is_empty() {
382382
eprintln!("EOF on stdin, when expecting answer to question. Giving up.");
383-
crate::detail_exit(1);
383+
crate::detail_exit_macro!(1);
384384
}
385385
break match parse_with_abbrev(&input) {
386386
Ok(profile) => profile,

src/bootstrap/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ impl Step for Clippy {
773773
}
774774

775775
if !builder.config.cmd.bless() {
776-
crate::detail_exit(1);
776+
crate::detail_exit_macro!(1);
777777
}
778778

779779
let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
@@ -1085,7 +1085,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
10851085
PATH = inferred_rustfmt_dir.display(),
10861086
CHAN = builder.config.channel,
10871087
);
1088-
crate::detail_exit(1);
1088+
crate::detail_exit_macro!(1);
10891089
}
10901090
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
10911091
}
@@ -1108,7 +1108,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
11081108
eprintln!(
11091109
"x.py completions were changed; run `x.py run generate-completions` to update them"
11101110
);
1111-
crate::detail_exit(1);
1111+
crate::detail_exit_macro!(1);
11121112
}
11131113
}
11141114
}
@@ -1329,7 +1329,7 @@ help: to test the compiler, use `--stage 1` instead
13291329
help: to test the standard library, use `--stage 0 library/std` instead
13301330
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`."
13311331
);
1332-
crate::detail_exit(1);
1332+
crate::detail_exit_macro!(1);
13331333
}
13341334

13351335
let mut compiler = self.compiler;

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Step for ToolBuild {
116116

117117
if !is_expected {
118118
if !is_optional_tool {
119-
crate::detail_exit(1);
119+
crate::detail_exit_macro!(1);
120120
} else {
121121
None
122122
}

src/bootstrap/toolstate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn print_error(tool: &str, submodule: &str) {
9191
eprintln!("If you do NOT intend to update '{}', please ensure you did not accidentally", tool);
9292
eprintln!("change the submodule at '{}'. You may ask your reviewer for the", submodule);
9393
eprintln!("proper steps.");
94-
crate::detail_exit(3);
94+
crate::detail_exit_macro!(3);
9595
}
9696

9797
fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
@@ -106,7 +106,7 @@ fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
106106
Ok(o) => o,
107107
Err(e) => {
108108
eprintln!("Failed to get changed files: {:?}", e);
109-
crate::detail_exit(1);
109+
crate::detail_exit_macro!(1);
110110
}
111111
};
112112

@@ -177,7 +177,7 @@ impl Step for ToolStateCheck {
177177
}
178178

179179
if did_error {
180-
crate::detail_exit(1);
180+
crate::detail_exit_macro!(1);
181181
}
182182

183183
check_changed_files(&toolstates);
@@ -223,7 +223,7 @@ impl Step for ToolStateCheck {
223223
}
224224

225225
if did_error {
226-
crate::detail_exit(1);
226+
crate::detail_exit_macro!(1);
227227
}
228228

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

src/bootstrap/util.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Simple things like testing the various filesystem operations here and there,
44
//! not a lot of interesting happenings here unfortunately.
55
6+
use build_helper::util::{fail, try_run};
67
use std::env;
78
use std::fs;
89
use std::io;
@@ -230,25 +231,10 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(
230231

231232
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
232233
if !try_run(cmd, print_cmd_on_fail) {
233-
crate::detail_exit(1);
234+
crate::detail_exit_macro!(1);
234235
}
235236
}
236237

237-
pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
238-
let status = match cmd.status() {
239-
Ok(status) => status,
240-
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
241-
};
242-
if !status.success() && print_cmd_on_fail {
243-
println!(
244-
"\n\ncommand did not execute successfully: {:?}\n\
245-
expected success, got: {}\n\n",
246-
cmd, status
247-
);
248-
}
249-
status.success()
250-
}
251-
252238
pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
253239
let status = match cmd.status() {
254240
Ok(status) => status,
@@ -269,7 +255,7 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
269255

270256
pub fn run_suppressed(cmd: &mut Command) {
271257
if !try_run_suppressed(cmd) {
272-
crate::detail_exit(1);
258+
crate::detail_exit_macro!(1);
273259
}
274260
}
275261

@@ -374,11 +360,6 @@ fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
374360
})
375361
}
376362

377-
fn fail(s: &str) -> ! {
378-
eprintln!("\n\n{}\n\n", s);
379-
crate::detail_exit(1);
380-
}
381-
382363
/// Copied from `std::path::absolute` until it stabilizes.
383364
///
384365
/// FIXME: this shouldn't exist.

src/tools/build_helper/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod ci;
22
pub mod git;
3+
pub mod util;

0 commit comments

Comments
 (0)