Skip to content

Commit 7379ff2

Browse files
committed
Make bootstrap command caching opt-in
It was too dangerous to cache by default, and was it causing real bugs.
1 parent d327d65 commit 7379ff2

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,10 +1581,6 @@ impl Builder<'_> {
15811581
/// `host`.
15821582
pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
15831583
let mut cmd = command(self.tool_exe(tool));
1584-
1585-
// Do not cache tool invocations, as they can have side effects
1586-
cmd.do_not_cache();
1587-
15881584
let compiler = self.compiler(0, self.config.host_target);
15891585
let host = &compiler.host;
15901586
// Prepares the `cmd` provided to be able to run the `compiler` provided.

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ impl Cargo {
132132
}
133133

134134
pub fn into_cmd(self) -> BootstrapCommand {
135-
let mut cmd: BootstrapCommand = self.into();
136-
// Disable caching for commands originating from Cargo-related operations.
137-
cmd.do_not_cache();
138-
cmd
135+
self.into()
139136
}
140137

141138
/// Same as [`Cargo::new`] except this one doesn't configure the linker with

src/bootstrap/src/utils/exec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ impl<'a> BootstrapCommand {
264264
self
265265
}
266266

267-
pub fn do_not_cache(&mut self) -> &mut Self {
268-
self.should_cache = false;
267+
/// Cache the command. If it will be executed multiple times with the exact same arguments
268+
/// and environment variables in the same bootstrap invocation, the previous result will be
269+
/// loaded from memory.
270+
pub fn cached(&mut self) -> &mut Self {
271+
self.should_cache = true;
269272
self
270273
}
271274

@@ -425,7 +428,7 @@ impl From<Command> for BootstrapCommand {
425428
fn from(command: Command) -> Self {
426429
let program = command.get_program().to_owned();
427430
Self {
428-
should_cache: true,
431+
should_cache: false,
429432
command,
430433
failure_behavior: BehaviorOnFailure::Exit,
431434
run_in_dry_run: false,

src/bootstrap/src/utils/helpers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
510510
#[track_caller]
511511
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
512512
let mut git = command("git");
513+
// git commands are almost always read-only, so cache them by default
514+
git.cached();
513515

514516
if let Some(source_dir) = source_dir {
515517
git.current_dir(source_dir);

0 commit comments

Comments
 (0)