88use crate :: core:: builder:: { Builder , RunConfig , ShouldRun , Step } ;
99use crate :: t;
1010use crate :: utils:: change_tracker:: CONFIG_CHANGE_HISTORY ;
11+ use crate :: utils:: exec:: command;
1112use crate :: utils:: helpers:: { self , hex_encode} ;
1213use crate :: Config ;
1314use sha2:: Digest ;
@@ -16,7 +17,6 @@ use std::fmt::Write as _;
1617use std:: fs:: File ;
1718use std:: io:: Write ;
1819use std:: path:: { Path , PathBuf , MAIN_SEPARATOR_STR } ;
19- use std:: process:: Command ;
2020use std:: str:: FromStr ;
2121use std:: { fmt, fs, io} ;
2222
@@ -266,20 +266,16 @@ impl Step for Link {
266266 }
267267 let stage_path =
268268 [ "build" , config. build . rustc_target_arg ( ) , "stage1" ] . join ( MAIN_SEPARATOR_STR ) ;
269- if !rustup_installed ( ) {
269+ if !rustup_installed ( builder ) {
270270 eprintln ! ( "`rustup` is not installed; cannot link `stage1` toolchain" ) ;
271271 } else if stage_dir_exists ( & stage_path[ ..] ) && !config. dry_run ( ) {
272- attempt_toolchain_link ( & stage_path[ ..] ) ;
272+ attempt_toolchain_link ( builder , & stage_path[ ..] ) ;
273273 }
274274 }
275275}
276276
277- fn rustup_installed ( ) -> bool {
278- Command :: new ( "rustup" )
279- . arg ( "--version" )
280- . stdout ( std:: process:: Stdio :: null ( ) )
281- . output ( )
282- . map_or ( false , |output| output. status . success ( ) )
277+ fn rustup_installed ( builder : & Builder < ' _ > ) -> bool {
278+ command ( "rustup" ) . capture_stdout ( ) . arg ( "--version" ) . run ( builder) . is_success ( )
283279}
284280
285281fn stage_dir_exists ( stage_path : & str ) -> bool {
@@ -289,8 +285,8 @@ fn stage_dir_exists(stage_path: &str) -> bool {
289285 }
290286}
291287
292- fn attempt_toolchain_link ( stage_path : & str ) {
293- if toolchain_is_linked ( ) {
288+ fn attempt_toolchain_link ( builder : & Builder < ' _ > , stage_path : & str ) {
289+ if toolchain_is_linked ( builder ) {
294290 return ;
295291 }
296292
@@ -301,7 +297,7 @@ fn attempt_toolchain_link(stage_path: &str) {
301297 return ;
302298 }
303299
304- if try_link_toolchain ( stage_path) {
300+ if try_link_toolchain ( builder , stage_path) {
305301 println ! (
306302 "Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
307303 ) ;
@@ -315,22 +311,24 @@ fn attempt_toolchain_link(stage_path: &str) {
315311 }
316312}
317313
318- fn toolchain_is_linked ( ) -> bool {
319- match Command :: new ( "rustup" )
314+ fn toolchain_is_linked ( builder : & Builder < ' _ > ) -> bool {
315+ match command ( "rustup" )
316+ . capture_stdout ( )
317+ . allow_failure ( )
320318 . args ( [ "toolchain" , "list" ] )
321- . stdout ( std :: process :: Stdio :: piped ( ) )
322- . output ( )
319+ . run ( builder )
320+ . stdout_if_ok ( )
323321 {
324- Ok ( toolchain_list) => {
325- if !String :: from_utf8_lossy ( & toolchain_list. stdout ) . contains ( "stage1" ) {
322+ Some ( toolchain_list) => {
323+ if !toolchain_list. contains ( "stage1" ) {
326324 return false ;
327325 }
328326 // The toolchain has already been linked.
329327 println ! (
330328 "`stage1` toolchain already linked; not attempting to link `stage1` toolchain"
331329 ) ;
332330 }
333- Err ( _ ) => {
331+ None => {
334332 // In this case, we don't know if the `stage1` toolchain has been linked;
335333 // but `rustup` failed, so let's not go any further.
336334 println ! (
@@ -341,12 +339,12 @@ fn toolchain_is_linked() -> bool {
341339 true
342340}
343341
344- fn try_link_toolchain ( stage_path : & str ) -> bool {
345- Command :: new ( "rustup" )
346- . stdout ( std :: process :: Stdio :: null ( ) )
342+ fn try_link_toolchain ( builder : & Builder < ' _ > , stage_path : & str ) -> bool {
343+ command ( "rustup" )
344+ . capture_stdout ( )
347345 . args ( [ "toolchain" , "link" , "stage1" , stage_path] )
348- . output ( )
349- . map_or ( false , |output| output . status . success ( ) )
346+ . run ( builder )
347+ . is_success ( )
350348}
351349
352350fn ensure_stage1_toolchain_placeholder_exists ( stage_path : & str ) -> bool {
@@ -476,20 +474,18 @@ impl Step for Hook {
476474 if config. dry_run ( ) {
477475 return ;
478476 }
479- t ! ( install_git_hook_maybe( config) ) ;
477+ t ! ( install_git_hook_maybe( builder , config) ) ;
480478 }
481479}
482480
483481// install a git hook to automatically run tidy, if they want
484- fn install_git_hook_maybe ( config : & Config ) -> io:: Result < ( ) > {
482+ fn install_git_hook_maybe ( builder : & Builder < ' _ > , config : & Config ) -> io:: Result < ( ) > {
485483 let git = helpers:: git ( Some ( & config. src ) )
484+ . capture ( )
486485 . args ( [ "rev-parse" , "--git-common-dir" ] )
487- . as_command_mut ( )
488- . output ( )
489- . map ( |output| {
490- assert ! ( output. status. success( ) , "failed to run `git`" ) ;
491- PathBuf :: from ( t ! ( String :: from_utf8( output. stdout) ) . trim ( ) )
492- } ) ?;
486+ . run ( builder)
487+ . stdout ( ) ;
488+ let git = PathBuf :: from ( git. trim ( ) ) ;
493489 let hooks_dir = git. join ( "hooks" ) ;
494490 let dst = hooks_dir. join ( "pre-push" ) ;
495491 if dst. exists ( ) {
0 commit comments