Make bootstrap command caching opt-in

It was too dangerous to cache by default, and was it causing real bugs.
This commit is contained in:
Jakub Beránek 2025-08-25 14:31:22 +02:00
parent d327d651e2
commit 7379ff2809
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
4 changed files with 9 additions and 11 deletions

View file

@ -1581,10 +1581,6 @@ impl Builder<'_> {
/// `host`.
pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand {
let mut cmd = command(self.tool_exe(tool));
// Do not cache tool invocations, as they can have side effects
cmd.do_not_cache();
let compiler = self.compiler(0, self.config.host_target);
let host = &compiler.host;
// Prepares the `cmd` provided to be able to run the `compiler` provided.

View file

@ -132,10 +132,7 @@ impl Cargo {
}
pub fn into_cmd(self) -> BootstrapCommand {
let mut cmd: BootstrapCommand = self.into();
// Disable caching for commands originating from Cargo-related operations.
cmd.do_not_cache();
cmd
self.into()
}
/// Same as [`Cargo::new`] except this one doesn't configure the linker with

View file

@ -264,8 +264,11 @@ impl<'a> BootstrapCommand {
self
}
pub fn do_not_cache(&mut self) -> &mut Self {
self.should_cache = false;
/// Cache the command. If it will be executed multiple times with the exact same arguments
/// and environment variables in the same bootstrap invocation, the previous result will be
/// loaded from memory.
pub fn cached(&mut self) -> &mut Self {
self.should_cache = true;
self
}
@ -425,7 +428,7 @@ impl From<Command> for BootstrapCommand {
fn from(command: Command) -> Self {
let program = command.get_program().to_owned();
Self {
should_cache: true,
should_cache: false,
command,
failure_behavior: BehaviorOnFailure::Exit,
run_in_dry_run: false,

View file

@ -510,6 +510,8 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
#[track_caller]
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
let mut git = command("git");
// git commands are almost always read-only, so cache them by default
git.cached();
if let Some(source_dir) = source_dir {
git.current_dir(source_dir);