@@ -9,6 +9,7 @@ mod command;
99pub mod diff;
1010pub mod fs_wrapper;
1111pub mod llvm;
12+ mod macros;
1213pub mod run;
1314pub mod rustc;
1415pub mod rustdoc;
@@ -37,6 +38,8 @@ pub use run::{cmd, run, run_fail, run_with_args};
3738pub use rustc:: { aux_build, bare_rustc, rustc, Rustc } ;
3839pub use rustdoc:: { bare_rustdoc, rustdoc, Rustdoc } ;
3940
41+ use command:: { Command , CompletedProcess } ;
42+
4043#[ track_caller]
4144#[ must_use]
4245pub fn env_var ( name : & str ) -> String {
@@ -538,116 +541,3 @@ pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
538541 env:: set_current_dir ( original_dir) . unwrap ( ) ;
539542 fs:: remove_dir_all ( tmpdir) . unwrap ( ) ;
540543}
541-
542- /// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
543- /// containing a `cmd: Command` field. The provided helpers are:
544- ///
545- /// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
546- /// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
547- /// new specific helper methods over relying on these generic argument providers.
548- /// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
549- /// methods of the same name on [`Command`].
550- /// 3. Output and execution: `run` and `run_fail` are provided. These are
551- /// higher-level convenience methods which wait for the command to finish running and assert
552- /// that the command successfully ran or failed as expected. They return
553- /// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed
554- /// process.
555- ///
556- /// Example usage:
557- ///
558- /// ```ignore (illustrative)
559- /// struct CommandWrapper { cmd: Command } // <- required `cmd` field
560- ///
561- /// crate::impl_common_helpers!(CommandWrapper);
562- ///
563- /// impl CommandWrapper {
564- /// // ... additional specific helper methods
565- /// }
566- /// ```
567- macro_rules! impl_common_helpers {
568- ( $wrapper: ident) => {
569- impl $wrapper {
570- /// Specify an environment variable.
571- pub fn env<K , V >( & mut self , key: K , value: V ) -> & mut Self
572- where
573- K : AsRef <:: std:: ffi:: OsStr >,
574- V : AsRef <:: std:: ffi:: OsStr >,
575- {
576- self . cmd. env( key, value) ;
577- self
578- }
579-
580- /// Remove an environmental variable.
581- pub fn env_remove<K >( & mut self , key: K ) -> & mut Self
582- where
583- K : AsRef <:: std:: ffi:: OsStr >,
584- {
585- self . cmd. env_remove( key) ;
586- self
587- }
588-
589- /// Generic command argument provider. Prefer specific helper methods if possible.
590- /// Note that for some executables, arguments might be platform specific. For C/C++
591- /// compilers, arguments might be platform *and* compiler specific.
592- pub fn arg<S >( & mut self , arg: S ) -> & mut Self
593- where
594- S : AsRef <:: std:: ffi:: OsStr >,
595- {
596- self . cmd. arg( arg) ;
597- self
598- }
599-
600- /// Generic command arguments provider. Prefer specific helper methods if possible.
601- /// Note that for some executables, arguments might be platform specific. For C/C++
602- /// compilers, arguments might be platform *and* compiler specific.
603- pub fn args<V , S >( & mut self , args: V ) -> & mut Self
604- where
605- V : AsRef <[ S ] >,
606- S : AsRef <:: std:: ffi:: OsStr >,
607- {
608- self . cmd. args( args. as_ref( ) ) ;
609- self
610- }
611-
612- /// Inspect what the underlying [`Command`] is up to the
613- /// current construction.
614- pub fn inspect<I >( & mut self , inspector: I ) -> & mut Self
615- where
616- I : FnOnce ( & :: std:: process:: Command ) ,
617- {
618- self . cmd. inspect( inspector) ;
619- self
620- }
621-
622- /// Run the constructed command and assert that it is successfully run.
623- #[ track_caller]
624- pub fn run( & mut self ) -> crate :: command:: CompletedProcess {
625- self . cmd. run( )
626- }
627-
628- /// Run the constructed command and assert that it does not successfully run.
629- #[ track_caller]
630- pub fn run_fail( & mut self ) -> crate :: command:: CompletedProcess {
631- self . cmd. run_fail( )
632- }
633-
634- /// Run the command but do not check its exit status.
635- /// Only use if you explicitly don't care about the exit status.
636- /// Prefer to use [`Self::run`] and [`Self::run_fail`]
637- /// whenever possible.
638- #[ track_caller]
639- pub fn run_unchecked( & mut self ) -> crate :: command:: CompletedProcess {
640- self . cmd. run_unchecked( )
641- }
642-
643- /// Set the path where the command will be run.
644- pub fn current_dir<P : AsRef <:: std:: path:: Path >>( & mut self , path: P ) -> & mut Self {
645- self . cmd. current_dir( path) ;
646- self
647- }
648- }
649- } ;
650- }
651-
652- use crate :: command:: { Command , CompletedProcess } ;
653- pub ( crate ) use impl_common_helpers;
0 commit comments