@@ -57,9 +57,9 @@ impl OutputMode {
57
57
58
58
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Default ) ]
59
59
pub struct CommandCacheKey {
60
- program : String ,
61
- args : Vec < String > ,
62
- envs : Vec < ( String , String ) > ,
60
+ program : OsString ,
61
+ args : Vec < OsString > ,
62
+ envs : Vec < ( OsString , OsString ) > ,
63
63
cwd : Option < PathBuf > ,
64
64
}
65
65
@@ -77,32 +77,39 @@ pub struct CommandCacheKey {
77
77
/// [allow_failure]: BootstrapCommand::allow_failure
78
78
/// [delay_failure]: BootstrapCommand::delay_failure
79
79
pub struct BootstrapCommand {
80
- program : OsString ,
81
- args : Vec < OsString > ,
82
- envs : Vec < ( OsString , OsString ) > ,
83
- cwd : Option < PathBuf > ,
84
-
80
+ cache_key : CommandCacheKey ,
85
81
command : Command ,
86
82
pub failure_behavior : BehaviorOnFailure ,
87
83
// Run the command even during dry run
88
84
pub run_always : bool ,
89
85
// This field makes sure that each command is executed (or disarmed) before it is dropped,
90
86
// to avoid forgetting to execute a command.
91
87
drop_bomb : DropBomb ,
88
+ should_cache : bool ,
92
89
}
93
90
94
91
impl < ' a > BootstrapCommand {
95
92
#[ track_caller]
96
93
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Self {
97
- Command :: new ( program) . into ( )
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
+ }
98
102
}
99
-
100
103
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
101
- self . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
104
+ self . cache_key . args . push ( arg. as_ref ( ) . to_os_string ( ) ) ;
102
105
self . command . arg ( arg. as_ref ( ) ) ;
103
106
self
104
107
}
105
108
109
+ pub fn should_cache ( & self ) -> bool {
110
+ self . should_cache
111
+ }
112
+
106
113
pub fn args < I , S > ( & mut self , args : I ) -> & mut Self
107
114
where
108
115
I : IntoIterator < Item = S > ,
@@ -119,7 +126,7 @@ impl<'a> BootstrapCommand {
119
126
K : AsRef < OsStr > ,
120
127
V : AsRef < OsStr > ,
121
128
{
122
- self . envs . push ( ( key. as_ref ( ) . to_os_string ( ) , val. as_ref ( ) . to_os_string ( ) ) ) ;
129
+ self . cache_key . envs . push ( ( key. as_ref ( ) . to_os_string ( ) , val. as_ref ( ) . to_os_string ( ) ) ) ;
123
130
self . command . env ( key, val) ;
124
131
self
125
132
}
@@ -138,7 +145,7 @@ impl<'a> BootstrapCommand {
138
145
}
139
146
140
147
pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Self {
141
- self . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
148
+ self . cache_key . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
142
149
self . command . current_dir ( dir) ;
143
150
self
144
151
}
@@ -205,6 +212,7 @@ impl<'a> BootstrapCommand {
205
212
// We don't know what will happen with the returned command, so we need to mark this
206
213
// command as executed proactively.
207
214
self . mark_as_executed ( ) ;
215
+ self . should_cache = false ;
208
216
& mut self . command
209
217
}
210
218
@@ -232,12 +240,7 @@ impl<'a> BootstrapCommand {
232
240
}
233
241
234
242
pub fn cache_key ( & self ) -> CommandCacheKey {
235
- CommandCacheKey {
236
- program : self . program . clone ( ) ,
237
- args : self . args . clone ( ) ,
238
- envs : self . envs . clone ( ) ,
239
- cwd : self . cwd . clone ( ) ,
240
- }
243
+ self . cache_key . clone ( )
241
244
}
242
245
}
243
246
@@ -254,10 +257,8 @@ impl From<Command> for BootstrapCommand {
254
257
let program = command. get_program ( ) . to_owned ( ) ;
255
258
256
259
Self {
257
- program : program. clone ( ) ,
258
- args : Vec :: new ( ) ,
259
- envs : Vec :: new ( ) ,
260
- cwd : None ,
260
+ cache_key : CommandCacheKey :: default ( ) ,
261
+ should_cache : false ,
261
262
command,
262
263
failure_behavior : BehaviorOnFailure :: Exit ,
263
264
run_always : false ,
0 commit comments