2
2
//!
3
3
//! This module provides a structured way to execute and manage commands efficiently,
4
4
//! ensuring controlled failure handling and output management.
5
+ #![ allow( warnings) ]
6
+
7
+ use std:: collections:: HashMap ;
5
8
use std:: ffi:: OsStr ;
6
9
use std:: fmt:: { Debug , Formatter } ;
10
+ use std:: hash:: { Hash , Hasher } ;
7
11
use std:: path:: Path ;
8
12
use std:: process:: { Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio } ;
13
+ use std:: sync:: Mutex ;
9
14
10
15
use build_helper:: ci:: CiEnv ;
11
16
use build_helper:: drop_bomb:: DropBomb ;
12
17
13
18
use super :: execution_context:: { DeferredCommand , ExecutionContext } ;
19
+ use crate :: PathBuf ;
14
20
15
21
/// What should be done when the command fails.
16
22
#[ derive( Debug , Copy , Clone ) ]
@@ -63,6 +69,11 @@ impl OutputMode {
63
69
/// [allow_failure]: BootstrapCommand::allow_failure
64
70
/// [delay_failure]: BootstrapCommand::delay_failure
65
71
pub struct BootstrapCommand {
72
+ program : String ,
73
+ args : Vec < String > ,
74
+ envs : Vec < ( String , String ) > ,
75
+ cwd : Option < PathBuf > ,
76
+
66
77
command : Command ,
67
78
pub failure_behavior : BehaviorOnFailure ,
68
79
// Run the command even during dry run
@@ -79,6 +90,8 @@ impl<'a> BootstrapCommand {
79
90
}
80
91
81
92
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
93
+ let arg_str = arg. as_ref ( ) . to_string_lossy ( ) . into_owned ( ) ;
94
+ self . args . push ( arg_str. clone ( ) ) ;
82
95
self . command . arg ( arg. as_ref ( ) ) ;
83
96
self
84
97
}
@@ -88,7 +101,9 @@ impl<'a> BootstrapCommand {
88
101
I : IntoIterator < Item = S > ,
89
102
S : AsRef < OsStr > ,
90
103
{
91
- self . command . args ( args) ;
104
+ args. into_iter ( ) . for_each ( |arg| {
105
+ self . arg ( arg) ;
106
+ } ) ;
92
107
self
93
108
}
94
109
@@ -97,6 +112,9 @@ impl<'a> BootstrapCommand {
97
112
K : AsRef < OsStr > ,
98
113
V : AsRef < OsStr > ,
99
114
{
115
+ let key_str = key. as_ref ( ) . to_string_lossy ( ) . into_owned ( ) ;
116
+ let val_str = val. as_ref ( ) . to_string_lossy ( ) . into_owned ( ) ;
117
+ self . envs . push ( ( key_str. clone ( ) , val_str. clone ( ) ) ) ;
100
118
self . command . env ( key, val) ;
101
119
self
102
120
}
@@ -115,6 +133,7 @@ impl<'a> BootstrapCommand {
115
133
}
116
134
117
135
pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Self {
136
+ self . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
118
137
self . command . current_dir ( dir) ;
119
138
self
120
139
}
@@ -226,6 +245,10 @@ impl From<Command> for BootstrapCommand {
226
245
let program = command. get_program ( ) . to_owned ( ) ;
227
246
228
247
Self {
248
+ program : program. clone ( ) . into_string ( ) . unwrap ( ) ,
249
+ args : Vec :: new ( ) ,
250
+ envs : Vec :: new ( ) ,
251
+ cwd : None ,
229
252
command,
230
253
failure_behavior : BehaviorOnFailure :: Exit ,
231
254
run_in_dry_run : false ,
@@ -235,6 +258,7 @@ impl From<Command> for BootstrapCommand {
235
258
}
236
259
237
260
/// Represents the current status of `BootstrapCommand`.
261
+ #[ derive( Clone , PartialEq ) ]
238
262
enum CommandStatus {
239
263
/// The command has started and finished with some status.
240
264
Finished ( ExitStatus ) ,
@@ -251,6 +275,7 @@ pub fn command<S: AsRef<OsStr>>(program: S) -> BootstrapCommand {
251
275
}
252
276
253
277
/// Represents the output of an executed process.
278
+ #[ derive( Clone , PartialEq ) ]
254
279
pub struct CommandOutput {
255
280
status : CommandStatus ,
256
281
stdout : Option < Vec < u8 > > ,
0 commit comments