Skip to content

Commit 81ee86b

Browse files
committed
add execution context to bootstrap workflow
1 parent 3ab5e60 commit 81ee86b

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

src/bootstrap/src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ fn main() {
2929
}
3030

3131
debug!("parsing flags");
32-
let flags = Flags::parse(&args);
32+
let (flags, exec_ctx) = Flags::parse(&args);
3333
debug!("parsing config based on flags");
34-
let config = Config::parse(flags);
34+
let config = Config::parse(flags, exec_ctx);
3535

3636
let mut build_lock;
3737
let _build_lock_guard;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::core::config::flags::Subcommand;
2222
use crate::core::config::{DryRun, TargetSelection};
2323
use crate::utils::cache::Cache;
2424
use crate::utils::exec::{BootstrapCommand, command};
25+
use crate::utils::execution_context::ExecutionContext;
2526
use crate::utils::helpers::{self, LldThreads, add_dylib_path, exe, libdir, linker_args, t};
2627
use crate::{Build, Crate, trace};
2728

@@ -1633,4 +1634,14 @@ impl<'a> Builder<'a> {
16331634
self.info(&format!("{err}\n"));
16341635
}
16351636
}
1637+
1638+
pub fn exec_ctx(&self) -> &ExecutionContext {
1639+
&self.config.exec_ctx
1640+
}
1641+
}
1642+
1643+
impl<'a> AsRef<ExecutionContext> for Builder<'a> {
1644+
fn as_ref(&self) -> &ExecutionContext {
1645+
self.exec_ctx()
1646+
}
16361647
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::core::config::{
4747
};
4848
use crate::core::download::is_download_ci_available;
4949
use crate::utils::channel;
50+
use crate::utils::execution_context::ExecutionContext;
5051
use crate::utils::helpers::exe;
5152
use crate::{Command, GitInfo, OnceLock, TargetSelection, check_ci_llvm, helpers, output, t};
5253

@@ -304,6 +305,8 @@ pub struct Config {
304305
/// This is mostly for RA as building the stage1 compiler to check the library tree
305306
/// on each code change might be too much for some computers.
306307
pub skip_std_check_if_no_download_rustc: bool,
308+
309+
pub exec_ctx: ExecutionContext,
307310
}
308311

309312
impl Config {
@@ -364,8 +367,8 @@ impl Config {
364367
feature = "tracing",
365368
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::parse", skip_all)
366369
)]
367-
pub fn parse(flags: Flags) -> Config {
368-
Self::parse_inner(flags, Self::get_toml)
370+
pub fn parse(flags: Flags, exec_ctx: ExecutionContext) -> Config {
371+
Self::parse_inner(flags, Self::get_toml, exec_ctx)
369372
}
370373

371374
#[cfg_attr(
@@ -380,8 +383,10 @@ impl Config {
380383
pub(crate) fn parse_inner(
381384
mut flags: Flags,
382385
get_toml: impl Fn(&Path) -> Result<TomlConfig, toml::de::Error>,
386+
exec_ctx: ExecutionContext,
383387
) -> Config {
384388
let mut config = Config::default_opts();
389+
config.exec_ctx = exec_ctx;
385390

386391
// Set flags.
387392
config.paths = std::mem::take(&mut flags.paths);
@@ -1741,4 +1746,18 @@ impl Config {
17411746
_ => !self.is_system_llvm(target),
17421747
}
17431748
}
1749+
1750+
pub fn exec_ctx(&self) -> &ExecutionContext {
1751+
&self.exec_ctx
1752+
}
1753+
1754+
pub fn git_info(&self, omit_git_hash: bool, dir: &Path) -> GitInfo {
1755+
GitInfo::new(omit_git_hash, dir, self)
1756+
}
1757+
}
1758+
1759+
impl AsRef<ExecutionContext> for Config {
1760+
fn as_ref(&self) -> &ExecutionContext {
1761+
&self.exec_ctx
1762+
}
17441763
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::core::build_steps::setup::Profile;
1414
use crate::core::builder::{Builder, Kind};
1515
use crate::core::config::Config;
1616
use crate::core::config::target_selection::{TargetSelectionList, target_selection_list};
17-
use crate::{Build, DocTests};
17+
use crate::utils::execution_context::ExecutionContext;
18+
use crate::{Build, DocTests, DryRun};
1819

1920
#[derive(Copy, Clone, Default, Debug, ValueEnum)]
2021
pub enum Color {
@@ -209,7 +210,8 @@ impl Flags {
209210
HelpVerboseOnly::try_parse_from(normalize_args(args))
210211
{
211212
println!("NOTE: updating submodules before printing available paths");
212-
let config = Config::parse(Self::parse(&[String::from("build")]));
213+
let (flags, exec_ctx) = Self::parse(&[String::from("build")]);
214+
let config = Config::parse(flags, exec_ctx);
213215
let build = Build::new(config);
214216
let paths = Builder::get_help(&build, subcommand);
215217
if let Some(s) = paths {
@@ -227,8 +229,13 @@ impl Flags {
227229
feature = "tracing",
228230
instrument(level = "trace", name = "Flags::parse", skip_all, fields(args = ?args))
229231
)]
230-
pub fn parse(args: &[String]) -> Self {
231-
Flags::parse_from(normalize_args(args))
232+
pub fn parse(args: &[String]) -> (Self, ExecutionContext) {
233+
let mut exec_ctx = ExecutionContext::new();
234+
let flags = Flags::parse_from(normalize_args(args));
235+
exec_ctx.set_dry_run(if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled });
236+
exec_ctx.set_verbose(flags.verbose);
237+
exec_ctx.set_fail_fast(flags.cmd.fail_fast());
238+
(flags, exec_ctx)
232239
}
233240
}
234241

src/bootstrap/src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod cc_detect;
88
pub(crate) mod change_tracker;
99
pub(crate) mod channel;
1010
pub(crate) mod exec;
11+
pub(crate) mod execution_context;
1112
pub(crate) mod helpers;
1213
pub(crate) mod job;
1314
pub(crate) mod render_tests;

0 commit comments

Comments
 (0)