Skip to content

Commit 294c598

Browse files
committed
avail cache key for all commands
1 parent 30b44dc commit 294c598

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/bootstrap/src/utils/exec.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,17 @@ impl<'a> BootstrapCommand {
300300
}
301301
}
302302

303-
pub fn cache_key(&self) -> Option<CommandCacheKey> {
304-
if !self.should_cache {
305-
return None;
306-
}
303+
pub fn cache_key(&self) -> CommandCacheKey {
307304
let command = &self.command;
308-
Some(CommandCacheKey {
305+
CommandCacheKey {
309306
program: command.get_program().into(),
310307
args: command.get_args().map(OsStr::to_os_string).collect(),
311308
envs: command
312309
.get_envs()
313310
.map(|(k, v)| (k.to_os_string(), v.map(|val| val.to_os_string())))
314311
.collect(),
315312
cwd: command.get_current_dir().map(Path::to_path_buf),
316-
})
313+
}
317314
}
318315
}
319316

@@ -503,7 +500,7 @@ enum CommandState<'a> {
503500
stdout: OutputMode,
504501
stderr: OutputMode,
505502
executed_at: &'a Location<'a>,
506-
cache_key: Option<CommandCacheKey>,
503+
cache_key: CommandCacheKey,
507504
start_time: Instant,
508505
},
509506
}
@@ -603,11 +600,10 @@ impl ExecutionContext {
603600
) -> DeferredCommand<'a> {
604601
let cache_key = command.cache_key();
605602

606-
if let Some(cached_output) = cache_key.as_ref().and_then(|key| self.command_cache.get(key))
607-
{
603+
if let Some(cached_output) = self.command_cache.get(&cache_key) {
608604
command.mark_as_executed();
609605
self.verbose(|| println!("Cache hit: {command:?}"));
610-
self.profiler.record(cache_key.unwrap(), Duration::from_secs(0));
606+
self.profiler.record(cache_key, Duration::from_secs(0));
611607
return DeferredCommand { state: CommandState::Cached(cached_output) };
612608
}
613609

@@ -751,7 +747,8 @@ impl<'a> DeferredCommand<'a> {
751747
Self::finish_process(process, command, stdout, stderr, executed_at, exec_ctx);
752748

753749
if (!exec_ctx.dry_run() || command.run_in_dry_run)
754-
&& let (Some(cache_key), Some(_)) = (&cache_key, output.status())
750+
&& output.status().is_some()
751+
&& command.should_cache
755752
{
756753
exec_ctx.command_cache.insert(cache_key.clone(), output.clone());
757754
let duration = start_time.elapsed();

0 commit comments

Comments
 (0)