@@ -77,7 +77,6 @@ pub struct CommandCacheKey {
77
77
/// [allow_failure]: BootstrapCommand::allow_failure
78
78
/// [delay_failure]: BootstrapCommand::delay_failure
79
79
pub struct BootstrapCommand {
80
- cache_key : CommandCacheKey ,
81
80
command : Command ,
82
81
pub failure_behavior : BehaviorOnFailure ,
83
82
// Run the command even during dry run
@@ -91,17 +90,9 @@ pub struct BootstrapCommand {
91
90
impl < ' a > BootstrapCommand {
92
91
#[ track_caller]
93
92
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 ( ) }
102
94
}
103
95
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
104
- self . cache_key . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
105
96
self . command . arg ( arg. as_ref ( ) ) ;
106
97
self
107
98
}
@@ -126,7 +117,6 @@ impl<'a> BootstrapCommand {
126
117
K : AsRef < OsStr > ,
127
118
V : AsRef < OsStr > ,
128
119
{
129
- self . cache_key . envs . push ( ( key. as_ref ( ) . to_os_string ( ) , val. as_ref ( ) . to_os_string ( ) ) ) ;
130
120
self . command . env ( key, val) ;
131
121
self
132
122
}
@@ -145,7 +135,6 @@ impl<'a> BootstrapCommand {
145
135
}
146
136
147
137
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 ( ) ) ;
149
138
self . command . current_dir ( dir) ;
150
139
self
151
140
}
@@ -239,8 +228,8 @@ impl<'a> BootstrapCommand {
239
228
}
240
229
}
241
230
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 ( ) )
244
233
}
245
234
}
246
235
@@ -255,9 +244,7 @@ impl From<Command> for BootstrapCommand {
255
244
#[ track_caller]
256
245
fn from ( command : Command ) -> Self {
257
246
let program = command. get_program ( ) . to_owned ( ) ;
258
-
259
247
Self {
260
- cache_key : CommandCacheKey :: default ( ) ,
261
248
should_cache : false ,
262
249
command,
263
250
failure_behavior : BehaviorOnFailure :: Exit ,
@@ -267,6 +254,21 @@ impl From<Command> for BootstrapCommand {
267
254
}
268
255
}
269
256
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
+
270
272
/// Represents the current status of `BootstrapCommand`.
271
273
#[ derive( Clone , PartialEq ) ]
272
274
enum CommandStatus {
0 commit comments