Skip to content

Commit a18dc47

Browse files
committed
add cach cmd to execution context
1 parent 3324086 commit a18dc47

File tree

2 files changed

+54
-44
lines changed

2 files changed

+54
-44
lines changed

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

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ impl Config {
442442
exec_ctx.set_verbose(flags_verbose);
443443
exec_ctx.set_fail_fast(flags_cmd.fail_fast());
444444

445-
config.exec_ctx = exec_ctx;
446-
447445
// Set flags.
448446
config.paths = std::mem::take(&mut flags_paths);
449447

@@ -484,8 +482,52 @@ impl Config {
484482
config.is_running_on_ci = flags_ci.unwrap_or(CiEnv::is_ci());
485483
config.skip_std_check_if_no_download_rustc = flags_skip_std_check_if_no_download_rustc;
486484

487-
// Infer the rest of the configuration.
485+
// Locate the configuration file using the following priority (first match wins):
486+
// 1. `--config <path>` (explicit flag)
487+
// 2. `RUST_BOOTSTRAP_CONFIG` environment variable
488+
// 3. `./bootstrap.toml` (local file)
489+
// 4. `<root>/bootstrap.toml`
490+
// 5. `./config.toml` (fallback for backward compatibility)
491+
// 6. `<root>/config.toml`
492+
let toml_path = flags_config
493+
.clone()
494+
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from));
495+
let using_default_path = toml_path.is_none();
496+
let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("bootstrap.toml"));
497+
498+
if using_default_path && !toml_path.exists() {
499+
toml_path = config.src.join(PathBuf::from("bootstrap.toml"));
500+
if !toml_path.exists() {
501+
toml_path = PathBuf::from("config.toml");
502+
if !toml_path.exists() {
503+
toml_path = config.src.join(PathBuf::from("config.toml"));
504+
}
505+
}
506+
}
507+
508+
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
509+
// but not if `bootstrap.toml` hasn't been created.
510+
let mut toml = if !using_default_path || toml_path.exists() {
511+
config.config = Some(if cfg!(not(test)) {
512+
toml_path = toml_path.canonicalize().unwrap();
513+
toml_path.clone()
514+
} else {
515+
toml_path.clone()
516+
});
517+
get_toml(&toml_path).unwrap_or_else(|e| {
518+
eprintln!("ERROR: Failed to parse '{}': {e}", toml_path.display());
519+
exit!(2);
520+
})
521+
} else {
522+
config.config = None;
523+
TomlConfig::default()
524+
};
525+
526+
exec_ctx.set_cache_cmd(toml.cache_cmd.unwrap_or_default());
488527

528+
config.exec_ctx = exec_ctx;
529+
530+
// Infer the rest of the configuration.
489531
if let Some(src) = flags_src {
490532
config.src = src
491533
} else {
@@ -545,47 +587,6 @@ impl Config {
545587

546588
config.stage0_metadata = build_helper::stage0_parser::parse_stage0_file();
547589

548-
// Locate the configuration file using the following priority (first match wins):
549-
// 1. `--config <path>` (explicit flag)
550-
// 2. `RUST_BOOTSTRAP_CONFIG` environment variable
551-
// 3. `./bootstrap.toml` (local file)
552-
// 4. `<root>/bootstrap.toml`
553-
// 5. `./config.toml` (fallback for backward compatibility)
554-
// 6. `<root>/config.toml`
555-
let toml_path = flags_config
556-
.clone()
557-
.or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from));
558-
let using_default_path = toml_path.is_none();
559-
let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("bootstrap.toml"));
560-
561-
if using_default_path && !toml_path.exists() {
562-
toml_path = config.src.join(PathBuf::from("bootstrap.toml"));
563-
if !toml_path.exists() {
564-
toml_path = PathBuf::from("config.toml");
565-
if !toml_path.exists() {
566-
toml_path = config.src.join(PathBuf::from("config.toml"));
567-
}
568-
}
569-
}
570-
571-
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
572-
// but not if `bootstrap.toml` hasn't been created.
573-
let mut toml = if !using_default_path || toml_path.exists() {
574-
config.config = Some(if cfg!(not(test)) {
575-
toml_path = toml_path.canonicalize().unwrap();
576-
toml_path.clone()
577-
} else {
578-
toml_path.clone()
579-
});
580-
get_toml(&toml_path).unwrap_or_else(|e| {
581-
eprintln!("ERROR: Failed to parse '{}': {e}", toml_path.display());
582-
exit!(2);
583-
})
584-
} else {
585-
config.config = None;
586-
TomlConfig::default()
587-
};
588-
589590
if cfg!(test) {
590591
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
591592
// same ones used to call the tests (if custom ones are not defined in the toml). If we

src/bootstrap/src/utils/execution_context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct ExecutionContext {
2121
pub fail_fast: bool,
2222
delayed_failures: Arc<Mutex<Vec<String>>>,
2323
command_cache: Arc<CommandCache>,
24+
cache_cmd: bool,
2425
}
2526

2627
#[derive(Default)]
@@ -58,6 +59,14 @@ impl ExecutionContext {
5859
&self.dry_run
5960
}
6061

62+
pub fn cache_cmd(&self) -> bool {
63+
self.cache_cmd
64+
}
65+
66+
pub fn set_cache_cmd(&mut self, cache_cmd: bool) {
67+
self.cache_cmd = cache_cmd;
68+
}
69+
6170
pub fn verbose(&self, f: impl Fn()) {
6271
if self.is_verbose() {
6372
f()

0 commit comments

Comments
 (0)