22//!
33//! This module provides a structured way to execute and manage commands efficiently,
44//! ensuring controlled failure handling and output management.
5+ #![ allow( warnings) ]
6+
7+ use std:: collections:: HashMap ;
58use std:: ffi:: OsStr ;
69use std:: fmt:: { Debug , Formatter } ;
10+ use std:: hash:: { Hash , Hasher } ;
711use std:: path:: Path ;
812use std:: process:: { Command , CommandArgs , CommandEnvs , ExitStatus , Output , Stdio } ;
13+ use std:: sync:: Mutex ;
914
1015use build_helper:: ci:: CiEnv ;
1116use build_helper:: drop_bomb:: DropBomb ;
1217
1318use super :: execution_context:: { DeferredCommand , ExecutionContext } ;
19+ use crate :: PathBuf ;
1420
1521/// What should be done when the command fails.
1622#[ derive( Debug , Copy , Clone ) ]
@@ -63,6 +69,11 @@ impl OutputMode {
6369/// [allow_failure]: BootstrapCommand::allow_failure
6470/// [delay_failure]: BootstrapCommand::delay_failure
6571pub struct BootstrapCommand {
72+ program : String ,
73+ args : Vec < String > ,
74+ envs : Vec < ( String , String ) > ,
75+ cwd : Option < PathBuf > ,
76+
6677 command : Command ,
6778 pub failure_behavior : BehaviorOnFailure ,
6879 // Run the command even during dry run
@@ -79,6 +90,8 @@ impl<'a> BootstrapCommand {
7990 }
8091
8192 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 ( ) ) ;
8295 self . command . arg ( arg. as_ref ( ) ) ;
8396 self
8497 }
@@ -88,7 +101,9 @@ impl<'a> BootstrapCommand {
88101 I : IntoIterator < Item = S > ,
89102 S : AsRef < OsStr > ,
90103 {
91- self . command . args ( args) ;
104+ args. into_iter ( ) . for_each ( |arg| {
105+ self . arg ( arg) ;
106+ } ) ;
92107 self
93108 }
94109
@@ -97,6 +112,9 @@ impl<'a> BootstrapCommand {
97112 K : AsRef < OsStr > ,
98113 V : AsRef < OsStr > ,
99114 {
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 ( ) ) ) ;
100118 self . command . env ( key, val) ;
101119 self
102120 }
@@ -115,6 +133,7 @@ impl<'a> BootstrapCommand {
115133 }
116134
117135 pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Self {
136+ self . cwd = Some ( dir. as_ref ( ) . to_path_buf ( ) ) ;
118137 self . command . current_dir ( dir) ;
119138 self
120139 }
@@ -221,6 +240,10 @@ impl From<Command> for BootstrapCommand {
221240 let program = command. get_program ( ) . to_owned ( ) ;
222241
223242 Self {
243+ program : program. clone ( ) . into_string ( ) . unwrap ( ) ,
244+ args : Vec :: new ( ) ,
245+ envs : Vec :: new ( ) ,
246+ cwd : None ,
224247 command,
225248 failure_behavior : BehaviorOnFailure :: Exit ,
226249 run_always : false ,
@@ -230,6 +253,7 @@ impl From<Command> for BootstrapCommand {
230253}
231254
232255/// Represents the current status of `BootstrapCommand`.
256+ #[ derive( Clone , PartialEq ) ]
233257enum CommandStatus {
234258 /// The command has started and finished with some status.
235259 Finished ( ExitStatus ) ,
@@ -246,6 +270,7 @@ pub fn command<S: AsRef<OsStr>>(program: S) -> BootstrapCommand {
246270}
247271
248272/// Represents the output of an executed process.
273+ #[ derive( Clone , PartialEq ) ]
249274pub struct CommandOutput {
250275 status : CommandStatus ,
251276 stdout : Option < Vec < u8 > > ,
0 commit comments