Skip to content

Commit e76ae3e

Browse files
authored
Rollup merge of #113644 - jyn514:bootstrap-cleanups, r=albertlarsan68
misc bootstrap cleanups - rename `detail_exit_macro` to `exit` - remove unnecessary `Builder::new_standalone` function - support `x suggest` with build-metrics
2 parents da18cf8 + dc48a8b commit e76ae3e

17 files changed

+56
-68
lines changed

src/bootstrap/builder.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl StepDescription {
395395
eprintln!(
396396
"note: if you are adding a new Step to bootstrap itself, make sure you register it with `describe!`"
397397
);
398-
crate::detail_exit_macro!(1);
398+
crate::exit!(1);
399399
}
400400
}
401401
}
@@ -939,21 +939,6 @@ impl<'a> Builder<'a> {
939939
Self::new_internal(build, kind, paths.to_owned())
940940
}
941941

942-
/// Creates a new standalone builder for use outside of the normal process
943-
pub fn new_standalone(
944-
build: &mut Build,
945-
kind: Kind,
946-
paths: Vec<PathBuf>,
947-
stage: Option<u32>,
948-
) -> Builder<'_> {
949-
// FIXME: don't mutate `build`
950-
if let Some(stage) = stage {
951-
build.config.stage = stage;
952-
}
953-
954-
Self::new_internal(build, kind, paths.to_owned())
955-
}
956-
957942
pub fn execute_cli(&self) {
958943
self.run_step_descriptions(&Builder::get_step_descriptions(self.kind), &self.paths);
959944
}
@@ -1375,7 +1360,7 @@ impl<'a> Builder<'a> {
13751360
"error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component"
13761361
);
13771362
eprintln!("help: try `rustup component add clippy`");
1378-
crate::detail_exit_macro!(1);
1363+
crate::exit!(1);
13791364
});
13801365
if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") {
13811366
rustflags.arg("--cfg=bootstrap");

src/bootstrap/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ pub fn run_cargo(
18201820
});
18211821

18221822
if !ok {
1823-
crate::detail_exit_macro!(1);
1823+
crate::exit!(1);
18241824
}
18251825

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

src/bootstrap/config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +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;
26+
use build_helper::exit;
2727
use once_cell::sync::OnceCell;
2828
use semver::Version;
2929
use serde::{Deserialize, Deserializer};
@@ -646,7 +646,7 @@ macro_rules! define_config {
646646
panic!("overriding existing option")
647647
} else {
648648
eprintln!("overriding existing option: `{}`", stringify!($field));
649-
detail_exit_macro!(2);
649+
exit!(2);
650650
}
651651
} else {
652652
self.$field = other.$field;
@@ -745,7 +745,7 @@ impl<T> Merge for Option<T> {
745745
panic!("overriding existing option")
746746
} else {
747747
eprintln!("overriding existing option");
748-
detail_exit_macro!(2);
748+
exit!(2);
749749
}
750750
} else {
751751
*self = other;
@@ -1101,7 +1101,7 @@ impl Config {
11011101
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
11021102
.unwrap_or_else(|err| {
11031103
eprintln!("failed to parse TOML configuration '{}': {err}", file.display());
1104-
detail_exit_macro!(2);
1104+
exit!(2);
11051105
})
11061106
}
11071107
Self::parse_inner(args, get_toml)
@@ -1135,7 +1135,7 @@ impl Config {
11351135
eprintln!(
11361136
"Cannot use both `llvm_bolt_profile_generate` and `llvm_bolt_profile_use` at the same time"
11371137
);
1138-
detail_exit_macro!(1);
1138+
exit!(1);
11391139
}
11401140

11411141
// Infer the rest of the configuration.
@@ -1259,7 +1259,7 @@ impl Config {
12591259
}
12601260
}
12611261
eprintln!("failed to parse override `{option}`: `{err}");
1262-
detail_exit_macro!(2)
1262+
exit!(2)
12631263
}
12641264
toml.merge(override_toml, ReplaceOpt::Override);
12651265

@@ -2007,7 +2007,7 @@ impl Config {
20072007
"Unexpected rustc version: {}, we should use {}/{} to build source with {}",
20082008
rustc_version, prev_version, source_version, source_version
20092009
);
2010-
detail_exit_macro!(1);
2010+
exit!(1);
20112011
}
20122012
}
20132013

@@ -2043,7 +2043,7 @@ impl Config {
20432043
println!("help: maybe your repository history is too shallow?");
20442044
println!("help: consider disabling `download-rustc`");
20452045
println!("help: or fetch enough history to include one upstream commit");
2046-
crate::detail_exit_macro!(1);
2046+
crate::exit!(1);
20472047
}
20482048

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

src/bootstrap/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl Config {
253253
if !help_on_error.is_empty() {
254254
eprintln!("{}", help_on_error);
255255
}
256-
crate::detail_exit_macro!(1);
256+
crate::exit!(1);
257257
}
258258
}
259259

src/bootstrap/flags.rs

Lines changed: 2 additions & 2 deletions
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_macro!(0);
196+
crate::exit!(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_macro!(1)
541+
crate::exit!(1)
542542
})
543543
};
544544
let mut buf = Vec::new();

src/bootstrap/format.rs

Lines changed: 2 additions & 2 deletions
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_macro!(1);
43+
crate::exit!(1);
4444
}
4545
true
4646
}
@@ -200,7 +200,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
200200

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

src/bootstrap/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +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;
30+
use build_helper::exit;
3131
use channel::GitInfo;
3232
use config::{DryRun, Target};
3333
use filetime::FileTime;
@@ -191,7 +191,7 @@ pub enum GitRepo {
191191
/// although most functions are implemented as free functions rather than
192192
/// methods specifically on this structure itself (to make it easier to
193193
/// organize).
194-
#[cfg_attr(not(feature = "build-metrics"), derive(Clone))]
194+
#[derive(Clone)]
195195
pub struct Build {
196196
/// User-specified configuration from `config.toml`.
197197
config: Config,
@@ -711,7 +711,7 @@ impl Build {
711711
for failure in failures.iter() {
712712
eprintln!(" - {}\n", failure);
713713
}
714-
detail_exit_macro!(1);
714+
exit!(1);
715715
}
716716

717717
#[cfg(feature = "build-metrics")]
@@ -1529,7 +1529,7 @@ impl Build {
15291529
"Error: Unable to find the stamp file {}, did you try to keep a nonexistent build stage?",
15301530
stamp.display()
15311531
);
1532-
crate::detail_exit_macro!(1);
1532+
crate::exit!(1);
15331533
}
15341534

15351535
let mut paths = Vec::new();
@@ -1721,7 +1721,7 @@ Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
17211721
to download LLVM rather than building it.
17221722
"
17231723
);
1724-
detail_exit_macro!(1);
1724+
exit!(1);
17251725
}
17261726
}
17271727

src/bootstrap/metrics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ pub(crate) struct BuildMetrics {
4040
state: RefCell<MetricsState>,
4141
}
4242

43+
/// NOTE: this isn't really cloning anything, but `x suggest` doesn't need metrics so this is probably ok.
44+
impl Clone for BuildMetrics {
45+
fn clone(&self) -> Self {
46+
Self::init()
47+
}
48+
}
49+
4350
impl BuildMetrics {
4451
pub(crate) fn init() -> Self {
4552
let state = RefCell::new(MetricsState {

src/bootstrap/render_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn try_run_tests(builder: &Builder<'_>, cmd: &mut Command, stream: bo
3030

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

src/bootstrap/sanity.rs

Lines changed: 1 addition & 1 deletion
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_macro!(1);
107+
crate::exit!(1);
108108
}
109109
}
110110

src/bootstrap/setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn setup_config_toml(path: &PathBuf, profile: Profile, config: &Config) {
203203
"note: this will use the configuration in {}",
204204
profile.include_path(&config.src).display()
205205
);
206-
crate::detail_exit_macro!(1);
206+
crate::exit!(1);
207207
}
208208

209209
let settings = format!(
@@ -389,7 +389,7 @@ pub fn interactive_path() -> io::Result<Profile> {
389389
io::stdin().read_line(&mut input)?;
390390
if input.is_empty() {
391391
eprintln!("EOF on stdin, when expecting answer to question. Giving up.");
392-
crate::detail_exit_macro!(1);
392+
crate::exit!(1);
393393
}
394394
break match parse_with_abbrev(&input) {
395395
Ok(profile) => profile,

src/bootstrap/suggest.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ use std::str::FromStr;
44

55
use std::path::PathBuf;
66

7-
use crate::{
8-
builder::{Builder, Kind},
9-
tool::Tool,
10-
};
7+
use clap::Parser;
118

12-
#[cfg(feature = "build-metrics")]
13-
pub fn suggest(builder: &Builder<'_>, run: bool) {
14-
panic!("`x suggest` is not supported with `build-metrics`")
15-
}
9+
use crate::{builder::Builder, tool::Tool};
1610

1711
/// Suggests a list of possible `x.py` commands to run based on modified files in branch.
18-
#[cfg(not(feature = "build-metrics"))]
1912
pub fn suggest(builder: &Builder<'_>, run: bool) {
2013
let suggestions =
2114
builder.tool_cmd(Tool::SuggestTests).output().expect("failed to run `suggest-tests` tool");
@@ -67,12 +60,13 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
6760

6861
if run {
6962
for sug in suggestions {
70-
let mut build = builder.build.clone();
71-
72-
let builder =
73-
Builder::new_standalone(&mut build, Kind::parse(&sug.0).unwrap(), sug.2, sug.1);
74-
75-
builder.execute_cli()
63+
let mut build: crate::Build = builder.build.clone();
64+
build.config.paths = sug.2;
65+
build.config.cmd = crate::flags::Flags::parse_from(["x.py", sug.0]).cmd;
66+
if let Some(stage) = sug.1 {
67+
build.config.stage = stage;
68+
}
69+
build.build();
7670
}
7771
} else {
7872
println!("help: consider using the `--run` flag to automatically run suggested tests");

src/bootstrap/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ impl Step for Clippy {
833833
}
834834

835835
if !builder.config.cmd.bless() {
836-
crate::detail_exit_macro!(1);
836+
crate::exit!(1);
837837
}
838838
}
839839
}
@@ -1141,7 +1141,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
11411141
PATH = inferred_rustfmt_dir.display(),
11421142
CHAN = builder.config.channel,
11431143
);
1144-
crate::detail_exit_macro!(1);
1144+
crate::exit!(1);
11451145
}
11461146
crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
11471147
}
@@ -1164,7 +1164,7 @@ help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy`
11641164
eprintln!(
11651165
"x.py completions were changed; run `x.py run generate-completions` to update them"
11661166
);
1167-
crate::detail_exit_macro!(1);
1167+
crate::exit!(1);
11681168
}
11691169
}
11701170
}
@@ -1475,7 +1475,7 @@ help: to test the compiler, use `--stage 1` instead
14751475
help: to test the standard library, use `--stage 0 library/std` instead
14761476
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`."
14771477
);
1478-
crate::detail_exit_macro!(1);
1478+
crate::exit!(1);
14791479
}
14801480

14811481
let mut compiler = self.compiler;

src/bootstrap/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Step for ToolBuild {
117117

118118
if !is_expected {
119119
if !is_optional_tool {
120-
crate::detail_exit_macro!(1);
120+
crate::exit!(1);
121121
} else {
122122
None
123123
}

src/bootstrap/toolstate.rs

Lines changed: 4 additions & 4 deletions
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_macro!(3);
94+
crate::exit!(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_macro!(1);
109+
crate::exit!(1);
110110
}
111111
};
112112

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

179179
if did_error {
180-
crate::detail_exit_macro!(1);
180+
crate::exit!(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_macro!(1);
226+
crate::exit!(1);
227227
}
228228

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

0 commit comments

Comments
 (0)