@@ -77,7 +77,6 @@ pub struct CommandCacheKey {
7777/// [allow_failure]: BootstrapCommand::allow_failure
7878/// [delay_failure]: BootstrapCommand::delay_failure
7979pub struct BootstrapCommand {
80- cache_key : CommandCacheKey ,
8180 command : Command ,
8281 pub failure_behavior : BehaviorOnFailure ,
8382 // Run the command even during dry run
@@ -91,17 +90,9 @@ pub struct BootstrapCommand {
9190impl < ' a > BootstrapCommand {
9291 #[ track_caller]
9392 pub fn new < S : AsRef < OsStr > > ( program : S ) -> Self {
94- Self {
95- should_cache : true ,
96- cache_key : CommandCacheKey {
97- program : program. as_ref ( ) . to_os_string ( ) ,
98- ..CommandCacheKey :: default ( )
99- } ,
100- ..Command :: new ( program) . into ( )
101- }
93+ Self { should_cache : true , ..Command :: new ( program) . into ( ) }
10294 }
10395 pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
104- self . cache_key . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
10596 self . command . arg ( arg. as_ref ( ) ) ;
10697 self
10798 }
@@ -126,7 +117,6 @@ impl<'a> BootstrapCommand {
126117 K : AsRef < OsStr > ,
127118 V : AsRef < OsStr > ,
128119 {
129- self . cache_key . envs . push ( ( key. as_ref ( ) . to_os_string ( ) , val. as_ref ( ) . to_os_string ( ) ) ) ;
130120 self . command . env ( key, val) ;
131121 self
132122 }
@@ -145,7 +135,6 @@ impl<'a> BootstrapCommand {
145135 }
146136
147137 pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Self {
148- self . cache_key . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
149138 self . command . current_dir ( dir) ;
150139 self
151140 }
@@ -239,8 +228,8 @@ impl<'a> BootstrapCommand {
239228 }
240229 }
241230
242- pub fn cache_key ( & self ) -> CommandCacheKey {
243- self . cache_key . clone ( )
231+ pub fn cache_key ( & self ) -> Option < CommandCacheKey > {
232+ ( ! self . should_cache ) . then ( || self . into ( ) )
244233 }
245234}
246235
@@ -255,9 +244,7 @@ impl From<Command> for BootstrapCommand {
255244 #[ track_caller]
256245 fn from ( command : Command ) -> Self {
257246 let program = command. get_program ( ) . to_owned ( ) ;
258-
259247 Self {
260- cache_key : CommandCacheKey :: default ( ) ,
261248 should_cache : false ,
262249 command,
263250 failure_behavior : BehaviorOnFailure :: Exit ,
@@ -267,6 +254,21 @@ impl From<Command> for BootstrapCommand {
267254 }
268255}
269256
257+ impl From < & BootstrapCommand > for CommandCacheKey {
258+ fn from ( value : & BootstrapCommand ) -> Self {
259+ let command = & value. command ;
260+ CommandCacheKey {
261+ program : command. get_program ( ) . into ( ) ,
262+ args : command. get_args ( ) . map ( OsStr :: to_os_string) . collect ( ) ,
263+ envs : command
264+ . get_envs ( )
265+ . filter_map ( |( k, v_opt) | v_opt. map ( |v| ( k. to_owned ( ) , v. to_owned ( ) ) ) )
266+ . collect ( ) ,
267+ cwd : command. get_current_dir ( ) . map ( Path :: to_path_buf) ,
268+ }
269+ }
270+ }
271+
270272/// Represents the current status of `BootstrapCommand`.
271273#[ derive( Clone , PartialEq ) ]
272274enum CommandStatus {
0 commit comments