Skip to content

Commit

Permalink
Rollup merge of #112084 - ozkanonur:improvements, r=clubby789
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthiaskrgr authored May 31, 2023
2 parents f589451 + c64db2c commit 183a31b
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 82 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4289,6 +4289,7 @@ dependencies = [
name = "rustdoc-gui-test"
version = "0.1.0"
dependencies = [
"build_helper",
"compiletest",
"getopts",
"walkdir",
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl StepDescription {
eprintln!(
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ impl<'a> Builder<'a> {
"error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
);
eprintln!("help: try `rustup component add clippy`");
crate::detail_exit(1);
crate::detail_exit_macro!(1);
});
if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
rustflags.arg("--cfg=bootstrap");
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ pub fn run_cargo(
});

if !ok {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

// Ok now we need to actually find all the files listed in `toplevel`. We've
Expand Down
13 changes: 7 additions & 6 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::channel::{self, GitInfo};
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags, Warnings};
use crate::util::{exe, output, t};
use build_helper::detail_exit_macro;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Deserializer};
use serde_derive::Deserialize;
Expand Down Expand Up @@ -579,7 +580,7 @@ macro_rules! define_config {
panic!("overriding existing option")
} else {
eprintln!("overriding existing option: `{}`", stringify!($field));
crate::detail_exit(2);
detail_exit_macro!(2);
}
} else {
self.$field = other.$field;
Expand Down Expand Up @@ -678,7 +679,7 @@ impl<T> Merge for Option<T> {
panic!("overriding existing option")
} else {
eprintln!("overriding existing option");
crate::detail_exit(2);
detail_exit_macro!(2);
}
} else {
*self = other;
Expand Down Expand Up @@ -944,7 +945,7 @@ impl Config {
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
.unwrap_or_else(|err| {
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
crate::detail_exit(2);
detail_exit_macro!(2);
})
}
Self::parse_inner(args, get_toml)
Expand Down Expand Up @@ -978,7 +979,7 @@ impl Config {
eprintln!(
"Cannot use both `llvm_bolt_profile_generate` and `llvm_bolt_profile_use` at the same time"
);
crate::detail_exit(1);
detail_exit_macro!(1);
}

// Infer the rest of the configuration.
Expand Down Expand Up @@ -1094,7 +1095,7 @@ impl Config {
}
}
eprintln!("failed to parse override `{option}`: `{err}");
crate::detail_exit(2)
detail_exit_macro!(2)
}
toml.merge(override_toml, ReplaceOpt::Override);

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

// Warn if there were changes to the compiler or standard library since the ancestor commit.
Expand Down
5 changes: 3 additions & 2 deletions src/bootstrap/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use std::{
process::{Command, Stdio},
};

use build_helper::util::try_run;
use once_cell::sync::OnceCell;
use xz2::bufread::XzDecoder;

use crate::{
config::RustfmtMetadata,
llvm::detect_llvm_sha,
t,
util::{check_run, exe, program_out_of_date, try_run},
util::{check_run, exe, program_out_of_date},
Config,
};

Expand Down Expand Up @@ -245,7 +246,7 @@ impl Config {
if !help_on_error.is_empty() {
eprintln!("{}", help_on_error);
}
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl Flags {
} else {
panic!("No paths available for subcommand `{}`", subcommand.as_str());
}
crate::detail_exit(0);
crate::detail_exit_macro!(0);
}

Flags::parse_from(it)
Expand Down Expand Up @@ -538,7 +538,7 @@ pub fn get_completion<G: clap_complete::Generator>(shell: G, path: &Path) -> Opt
} else {
std::fs::read_to_string(path).unwrap_or_else(|_| {
eprintln!("couldn't read {}", path.display());
crate::detail_exit(1)
crate::detail_exit_macro!(1)
})
};
let mut buf = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
code, run `./x.py fmt` instead.",
cmd_debug,
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
true
}
Expand Down Expand Up @@ -196,7 +196,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {

let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
eprintln!("./x.py fmt is not supported on this channel");
crate::detail_exit(1);
crate::detail_exit_macro!(1);
});
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());
let src = build.src.clone();
Expand Down
19 changes: 4 additions & 15 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::process::{Command, Stdio};
use std::str;

use build_helper::ci::{gha, CiEnv};
use build_helper::detail_exit_macro;
use channel::GitInfo;
use config::{DryRun, Target};
use filetime::FileTime;
Expand Down Expand Up @@ -699,7 +700,7 @@ impl Build {
for failure in failures.iter() {
eprintln!(" - {}\n", failure);
}
detail_exit(1);
detail_exit_macro!(1);
}

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

let mut paths = Vec::new();
Expand Down Expand Up @@ -1674,7 +1675,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
to download LLVM rather than building it.
"
);
detail_exit(1);
detail_exit_macro!(1);
}
}

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

/// If code is not 0 (successful exit status), exit status is 101 (rust's default error code.)
/// If the test is running and code is an error code, it will cause a panic.
fn detail_exit(code: i32) -> ! {
// if in test and code is an error code, panic with status code provided
if cfg!(test) {
panic!("status code: {}", code);
} else {
// otherwise,exit with provided status code
std::process::exit(code);
}
}

impl Compiler {
pub fn with_stage(mut self, stage: u32) -> Compiler {
self.stage = stage;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command) -> bool {

if !run_tests(builder, cmd) {
if builder.fail_fast {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
} else {
let mut failures = builder.delayed_failures.borrow_mut();
failures.push(format!("{cmd:?}"));
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ You should install cmake, or set `download-ci-llvm = true` in the
than building it.
"
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
"note: this will use the configuration in {}",
profile.include_path(&config.src).display()
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

let settings = format!(
Expand Down Expand Up @@ -380,7 +380,7 @@ pub fn interactive_path() -> io::Result<Profile> {
io::stdin().read_line(&mut input)?;
if input.is_empty() {
eprintln!("EOF on stdin, when expecting answer to question. Giving up.");
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
break match parse_with_abbrev(&input) {
Ok(profile) => profile,
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl Step for Clippy {
}

if !builder.config.cmd.bless() {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
Expand Down Expand Up @@ -1085,7 +1085,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
PATH = inferred_rustfmt_dir.display(),
CHAN = builder.config.channel,
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
}
Expand All @@ -1108,7 +1108,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
eprintln!(
"x.py completions were changed; run `x.py run generate-completions` to update them"
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}
}
Expand Down Expand Up @@ -1329,7 +1329,7 @@ help: to test the compiler, use `--stage 1` instead
help: to test the standard library, use `--stage 0 library/std` instead
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`."
);
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

let mut compiler = self.compiler;
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Step for ToolBuild {

if !is_expected {
if !is_optional_tool {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
} else {
None
}
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/toolstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn print_error(tool: &str, submodule: &str) {
eprintln!("If you do NOT intend to update '{}', please ensure you did not accidentally", tool);
eprintln!("change the submodule at '{}'. You may ask your reviewer for the", submodule);
eprintln!("proper steps.");
crate::detail_exit(3);
crate::detail_exit_macro!(3);
}

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

Expand Down Expand Up @@ -177,7 +177,7 @@ impl Step for ToolStateCheck {
}

if did_error {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

check_changed_files(&toolstates);
Expand Down Expand Up @@ -223,7 +223,7 @@ impl Step for ToolStateCheck {
}

if did_error {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}

if builder.config.channel == "nightly" && env::var_os("TOOLSTATE_PUBLISH").is_some() {
Expand Down
25 changes: 3 additions & 22 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Simple things like testing the various filesystem operations here and there,
//! not a lot of interesting happenings here unfortunately.

use build_helper::util::{fail, try_run};
use std::env;
use std::fs;
use std::io;
Expand Down Expand Up @@ -230,25 +231,10 @@ pub fn is_valid_test_suite_arg<'a, P: AsRef<Path>>(

pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
if !try_run(cmd, print_cmd_on_fail) {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}

pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
let status = match cmd.status() {
Ok(status) => status,
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
};
if !status.success() && print_cmd_on_fail {
println!(
"\n\ncommand did not execute successfully: {:?}\n\
expected success, got: {}\n\n",
cmd, status
);
}
status.success()
}

pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
let status = match cmd.status() {
Ok(status) => status,
Expand All @@ -269,7 +255,7 @@ pub fn check_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {

pub fn run_suppressed(cmd: &mut Command) {
if !try_run_suppressed(cmd) {
crate::detail_exit(1);
crate::detail_exit_macro!(1);
}
}

Expand Down Expand Up @@ -374,11 +360,6 @@ fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
})
}

fn fail(s: &str) -> ! {
eprintln!("\n\n{}\n\n", s);
crate::detail_exit(1);
}

/// Copied from `std::path::absolute` until it stabilizes.
///
/// FIXME: this shouldn't exist.
Expand Down
1 change: 1 addition & 0 deletions src/tools/build_helper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod ci;
pub mod git;
pub mod util;
Loading

0 comments on commit 183a31b

Please sign in to comment.