11use std:: env;
2- use std:: ffi:: { OsStr , OsString } ;
2+ use std:: ffi:: OsString ;
33use std:: path:: Path ;
4- use std:: process:: { Command , Output } ;
4+ use std:: process:: Command ;
55
66use crate :: { handle_failed_output, tmp_dir} ;
77
@@ -21,6 +21,8 @@ pub struct Rustc {
2121 cmd : Command ,
2222}
2323
24+ crate :: impl_common_helpers!( Rustc ) ;
25+
2426fn setup_common ( ) -> Command {
2527 let rustc = env:: var ( "RUSTC" ) . unwrap ( ) ;
2628 let mut cmd = Command :: new ( rustc) ;
@@ -120,12 +122,6 @@ impl Rustc {
120122 self
121123 }
122124
123- /// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
124- pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Self {
125- self . cmd . arg ( arg) ;
126- self
127- }
128-
129125 /// Specify the crate type.
130126 pub fn crate_type ( & mut self , crate_type : & str ) -> & mut Self {
131127 self . cmd . arg ( "--crate-type" ) ;
@@ -139,53 +135,4 @@ impl Rustc {
139135 self . cmd . arg ( edition) ;
140136 self
141137 }
142-
143- /// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
144- pub fn args < S : AsRef < OsStr > > ( & mut self , args : & [ S ] ) -> & mut Self {
145- self . cmd . args ( args) ;
146- self
147- }
148-
149- pub fn env ( & mut self , name : impl AsRef < OsStr > , value : impl AsRef < OsStr > ) -> & mut Self {
150- self . cmd . env ( name, value) ;
151- self
152- }
153-
154- // Command inspection, output and running helper methods
155-
156- /// Get the [`Output`][std::process::Output] of the finished `rustc` process.
157- pub fn output ( & mut self ) -> Output {
158- self . cmd . output ( ) . unwrap ( )
159- }
160-
161- /// Run the constructed `rustc` command and assert that it is successfully run.
162- #[ track_caller]
163- pub fn run ( & mut self ) -> Output {
164- let caller_location = std:: panic:: Location :: caller ( ) ;
165- let caller_line_number = caller_location. line ( ) ;
166-
167- let output = self . cmd . output ( ) . unwrap ( ) ;
168- if !output. status . success ( ) {
169- handle_failed_output ( & format ! ( "{:#?}" , self . cmd) , output, caller_line_number) ;
170- }
171- output
172- }
173-
174- #[ track_caller]
175- pub fn run_fail ( & mut self ) -> Output {
176- let caller_location = std:: panic:: Location :: caller ( ) ;
177- let caller_line_number = caller_location. line ( ) ;
178-
179- let output = self . cmd . output ( ) . unwrap ( ) ;
180- if output. status . success ( ) {
181- handle_failed_output ( & format ! ( "{:#?}" , self . cmd) , output, caller_line_number) ;
182- }
183- output
184- }
185-
186- /// Inspect what the underlying [`Command`] is up to the current construction.
187- pub fn inspect ( & mut self , f : impl FnOnce ( & Command ) ) -> & mut Self {
188- f ( & self . cmd ) ;
189- self
190- }
191138}
0 commit comments