@@ -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,28 +77,31 @@ 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
- should_cache : bool ,
85
-
80
+ cache_key : CommandCacheKey ,
86
81
command : Command ,
87
82
pub failure_behavior : BehaviorOnFailure ,
88
83
// Run the command even during dry run
89
84
pub run_always : bool ,
90
85
// This field makes sure that each command is executed (or disarmed) before it is dropped,
91
86
// to avoid forgetting to execute a command.
92
87
drop_bomb : DropBomb ,
88
+ should_cache : bool ,
93
89
}
94
90
95
91
impl < ' a > BootstrapCommand {
96
92
#[ track_caller]
97
93
pub fn new < S : AsRef < OsStr > > ( program : S ) -> Self {
98
- Self { should_cache : true , ..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
+ }
99
102
}
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
}
@@ -123,7 +126,7 @@ impl<'a> BootstrapCommand {
123
126
K : AsRef < OsStr > ,
124
127
V : AsRef < OsStr > ,
125
128
{
126
- 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 ( ) ) ) ;
127
130
self . command . env ( key, val) ;
128
131
self
129
132
}
@@ -142,7 +145,7 @@ impl<'a> BootstrapCommand {
142
145
}
143
146
144
147
pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Self {
145
- self . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
148
+ self . cache_key . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
146
149
self . command . current_dir ( dir) ;
147
150
self
148
151
}
@@ -237,12 +240,7 @@ impl<'a> BootstrapCommand {
237
240
}
238
241
239
242
pub fn cache_key ( & self ) -> CommandCacheKey {
240
- CommandCacheKey {
241
- program : self . program . clone ( ) ,
242
- args : self . args . clone ( ) ,
243
- envs : self . envs . clone ( ) ,
244
- cwd : self . cwd . clone ( ) ,
245
- }
243
+ self . cache_key . clone ( )
246
244
}
247
245
}
248
246
@@ -259,10 +257,7 @@ impl From<Command> for BootstrapCommand {
259
257
let program = command. get_program ( ) . to_owned ( ) ;
260
258
261
259
Self {
262
- program : program. clone ( ) ,
263
- args : Vec :: new ( ) ,
264
- envs : Vec :: new ( ) ,
265
- cwd : None ,
260
+ cache_key : CommandCacheKey :: default ( ) ,
266
261
should_cache : false ,
267
262
command,
268
263
failure_behavior : BehaviorOnFailure :: Exit ,
0 commit comments