@@ -300,20 +300,17 @@ impl<'a> BootstrapCommand {
300
300
}
301
301
}
302
302
303
- pub fn cache_key ( & self ) -> Option < CommandCacheKey > {
304
- if !self . should_cache {
305
- return None ;
306
- }
303
+ pub fn cache_key ( & self ) -> CommandCacheKey {
307
304
let command = & self . command ;
308
- Some ( CommandCacheKey {
305
+ CommandCacheKey {
309
306
program : command. get_program ( ) . into ( ) ,
310
307
args : command. get_args ( ) . map ( OsStr :: to_os_string) . collect ( ) ,
311
308
envs : command
312
309
. get_envs ( )
313
310
. map ( |( k, v) | ( k. to_os_string ( ) , v. map ( |val| val. to_os_string ( ) ) ) )
314
311
. collect ( ) ,
315
312
cwd : command. get_current_dir ( ) . map ( Path :: to_path_buf) ,
316
- } )
313
+ }
317
314
}
318
315
}
319
316
@@ -503,7 +500,7 @@ enum CommandState<'a> {
503
500
stdout : OutputMode ,
504
501
stderr : OutputMode ,
505
502
executed_at : & ' a Location < ' a > ,
506
- cache_key : Option < CommandCacheKey > ,
503
+ cache_key : CommandCacheKey ,
507
504
start_time : Instant ,
508
505
} ,
509
506
}
@@ -603,11 +600,10 @@ impl ExecutionContext {
603
600
) -> DeferredCommand < ' a > {
604
601
let cache_key = command. cache_key ( ) ;
605
602
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) {
608
604
command. mark_as_executed ( ) ;
609
605
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 ) ) ;
611
607
return DeferredCommand { state : CommandState :: Cached ( cached_output) } ;
612
608
}
613
609
@@ -751,7 +747,8 @@ impl<'a> DeferredCommand<'a> {
751
747
Self :: finish_process ( process, command, stdout, stderr, executed_at, exec_ctx) ;
752
748
753
749
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
755
752
{
756
753
exec_ctx. command_cache . insert ( cache_key. clone ( ) , output. clone ( ) ) ;
757
754
let duration = start_time. elapsed ( ) ;
0 commit comments