Skip to content

Commit 51fbd14

Browse files
committed
Initialize the execution context in parse_inner, start using dry run from the execution context, add getters and setters in the config, and update the tests and other relevant areas accordingly.
1 parent e9ced50 commit 51fbd14

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl Builder<'_> {
551551
let libdir = self.rustc_libdir(compiler);
552552

553553
let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
554-
if self.is_verbose() && !matches!(self.config.dry_run, DryRun::SelfCheck) {
554+
if self.is_verbose() && !matches!(self.config.get_dry_run(), DryRun::SelfCheck) {
555555
println!("using sysroot {sysroot_str}");
556556
}
557557

src/bootstrap/src/core/builder/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,15 @@ impl StepDescription {
443443

444444
fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
445445
if builder.config.skip.iter().any(|e| pathset.has(e, builder.kind)) {
446-
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
446+
if !matches!(builder.config.get_dry_run(), DryRun::SelfCheck) {
447447
println!("Skipping {pathset:?} because it is excluded");
448448
}
449449
return true;
450450
}
451451

452-
if !builder.config.skip.is_empty() && !matches!(builder.config.dry_run, DryRun::SelfCheck) {
452+
if !builder.config.skip.is_empty()
453+
&& !matches!(builder.config.get_dry_run(), DryRun::SelfCheck)
454+
{
453455
builder.verbose(|| {
454456
println!(
455457
"{:?} not skipped for {:?} -- not in {:?}",

src/bootstrap/src/core/builder/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
2222
let mut config = Config::parse(Flags::parse(cmd));
2323
// don't save toolstates
2424
config.save_toolstates = None;
25-
config.dry_run = DryRun::SelfCheck;
25+
config.set_dry_run(DryRun::SelfCheck);
2626

2727
// Ignore most submodules, since we don't need them for a dry run, and the
2828
// tests run much faster without them.

src/bootstrap/src/core/config/config.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub struct Config {
131131
pub jobs: Option<u32>,
132132
pub cmd: Subcommand,
133133
pub incremental: bool,
134-
pub dry_run: DryRun,
135134
pub dump_bootstrap_shims: bool,
136135
/// Arguments appearing after `--` to be forwarded to tools,
137136
/// e.g. `--fix-broken` or test arguments.
@@ -364,16 +363,20 @@ impl Config {
364363
}
365364
}
366365

366+
pub fn set_dry_run(&mut self, dry_run: DryRun) {
367+
self.exec_ctx.set_dry_run(dry_run);
368+
}
369+
370+
pub fn get_dry_run(&self) -> &DryRun {
371+
self.exec_ctx.get_dry_run()
372+
}
373+
367374
#[cfg_attr(
368375
feature = "tracing",
369376
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::parse", skip_all)
370377
)]
371378
pub fn parse(flags: Flags) -> Config {
372-
let mut exec_ctx = ExecutionContext::new();
373-
exec_ctx.set_dry_run(if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled });
374-
exec_ctx.set_verbose(flags.verbose);
375-
exec_ctx.set_fail_fast(flags.cmd.fail_fast());
376-
Self::parse_inner(flags, Self::get_toml, exec_ctx)
379+
Self::parse_inner(flags, Self::get_toml)
377380
}
378381

379382
#[cfg_attr(
@@ -388,9 +391,12 @@ impl Config {
388391
pub(crate) fn parse_inner(
389392
mut flags: Flags,
390393
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
391-
exec_ctx: ExecutionContext,
392394
) -> Config {
393395
let mut config = Config::default_opts();
396+
let mut exec_ctx = ExecutionContext::new();
397+
exec_ctx.set_verbose(flags.verbose);
398+
exec_ctx.set_fail_fast(flags.cmd.fail_fast());
399+
394400
config.exec_ctx = exec_ctx;
395401

396402
// Set flags.
@@ -420,7 +426,7 @@ impl Config {
420426
config.on_fail = flags.on_fail;
421427
config.cmd = flags.cmd;
422428
config.incremental = flags.incremental;
423-
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
429+
config.set_dry_run(if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled });
424430
config.dump_bootstrap_shims = flags.dump_bootstrap_shims;
425431
config.keep_stage = flags.keep_stage;
426432
config.keep_stage_std = flags.keep_stage_std;

src/bootstrap/src/lib.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ pub struct Build {
196196
crates: HashMap<String, Crate>,
197197
crate_paths: HashMap<PathBuf, String>,
198198
is_sudo: bool,
199-
delayed_failures: RefCell<Vec<String>>,
200199
prerelease_version: Cell<Option<u32>>,
201200

202201
#[cfg(feature = "build-metrics")]
@@ -457,7 +456,6 @@ impl Build {
457456
crates: HashMap::new(),
458457
crate_paths: HashMap::new(),
459458
is_sudo,
460-
delayed_failures: RefCell::new(Vec::new()),
461459
prerelease_version: Cell::new(None),
462460

463461
#[cfg(feature = "build-metrics")]
@@ -672,8 +670,7 @@ impl Build {
672670
#[cfg(feature = "tracing")]
673671
let _sanity_check_span =
674672
span!(tracing::Level::DEBUG, "(1) executing dry-run sanity-check").entered();
675-
self.config.dry_run = DryRun::SelfCheck;
676-
self.config.exec_ctx.set_dry_run(DryRun::SelfCheck);
673+
self.config.set_dry_run(DryRun::SelfCheck);
677674
let builder = builder::Builder::new(self);
678675
builder.execute_cli();
679676
}
@@ -683,8 +680,7 @@ impl Build {
683680
#[cfg(feature = "tracing")]
684681
let _actual_run_span =
685682
span!(tracing::Level::DEBUG, "(2) executing actual run").entered();
686-
self.config.dry_run = DryRun::Disabled;
687-
self.config.exec_ctx.set_dry_run(DryRun::Disabled);
683+
self.config.set_dry_run(DryRun::Disabled);
688684
let builder = builder::Builder::new(self);
689685
builder.execute_cli();
690686
}
@@ -700,14 +696,7 @@ impl Build {
700696
debug!("checking for postponed test failures from `test --no-fail-fast`");
701697

702698
// Check for postponed failures from `test --no-fail-fast`.
703-
let failures = self.delayed_failures.borrow();
704-
if !failures.is_empty() {
705-
eprintln!("\n{} command(s) did not execute successfully:\n", failures.len());
706-
for failure in failures.iter() {
707-
eprintln!(" - {failure}\n");
708-
}
709-
exit!(1);
710-
}
699+
self.config.exec_ctx().report_failures_and_exit();
711700

712701
#[cfg(feature = "build-metrics")]
713702
self.metrics.persist(self);
@@ -956,7 +945,7 @@ impl Build {
956945
}
957946

958947
fn info(&self, msg: &str) {
959-
match self.config.dry_run {
948+
match self.config.get_dry_run() {
960949
DryRun::SelfCheck => (),
961950
DryRun::Disabled | DryRun::UserSelected => {
962951
println!("{msg}");
@@ -1079,7 +1068,7 @@ impl Build {
10791068

10801069
#[track_caller]
10811070
fn group(&self, msg: &str) -> Option<gha::Group> {
1082-
match self.config.dry_run {
1071+
match self.config.get_dry_run() {
10831072
DryRun::SelfCheck => None,
10841073
DryRun::Disabled | DryRun::UserSelected => Some(gha::group(msg)),
10851074
}

src/bootstrap/src/utils/execution_context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ impl ExecutionContext {
2828
}
2929
}
3030

31+
pub fn get_dry_run(&self) -> &DryRun {
32+
&self.dry_run
33+
}
34+
3135
pub fn verbose(&self, f: impl Fn()) {
3236
if self.is_verbose() {
3337
f()

0 commit comments

Comments
 (0)