@@ -99,24 +99,16 @@ fn print_error(tool: &str, submodule: &str) {
9999 crate :: exit!( 3 ) ;
100100}
101101
102- fn check_changed_files ( toolstates : & HashMap < Box < str > , ToolState > ) {
102+ fn check_changed_files ( builder : & Builder < ' _ > , toolstates : & HashMap < Box < str > , ToolState > ) {
103103 // Changed files
104104 let output = helpers:: git ( None )
105+ . capture ( )
105106 . arg ( "diff" )
106107 . arg ( "--name-status" )
107108 . arg ( "HEAD" )
108109 . arg ( "HEAD^" )
109- . as_command_mut ( )
110- . output ( ) ;
111- let output = match output {
112- Ok ( o) => o,
113- Err ( e) => {
114- eprintln ! ( "Failed to get changed files: {e:?}" ) ;
115- crate :: exit!( 1 ) ;
116- }
117- } ;
118-
119- let output = t ! ( String :: from_utf8( output. stdout) ) ;
110+ . run ( builder)
111+ . stdout ( ) ;
120112
121113 for ( tool, submodule) in STABLE_TOOLS . iter ( ) . chain ( NIGHTLY_TOOLS . iter ( ) ) {
122114 let changed = output. lines ( ) . any ( |l| l. starts_with ( 'M' ) && l. ends_with ( submodule) ) ;
@@ -186,8 +178,8 @@ impl Step for ToolStateCheck {
186178 crate :: exit!( 1 ) ;
187179 }
188180
189- check_changed_files ( & toolstates) ;
190- checkout_toolstate_repo ( ) ;
181+ check_changed_files ( builder , & toolstates) ;
182+ checkout_toolstate_repo ( builder ) ;
191183 let old_toolstate = read_old_toolstate ( ) ;
192184
193185 for ( tool, _) in STABLE_TOOLS . iter ( ) {
@@ -231,7 +223,7 @@ impl Step for ToolStateCheck {
231223 }
232224
233225 if builder. config . channel == "nightly" && env:: var_os ( "TOOLSTATE_PUBLISH" ) . is_some ( ) {
234- commit_toolstate_change ( & toolstates) ;
226+ commit_toolstate_change ( builder , & toolstates) ;
235227 }
236228 }
237229
@@ -315,55 +307,34 @@ fn toolstate_repo() -> String {
315307const TOOLSTATE_DIR : & str = "rust-toolstate" ;
316308
317309/// Checks out the toolstate repo into `TOOLSTATE_DIR`.
318- fn checkout_toolstate_repo ( ) {
310+ fn checkout_toolstate_repo ( builder : & Builder < ' _ > ) {
319311 if let Ok ( token) = env:: var ( "TOOLSTATE_REPO_ACCESS_TOKEN" ) {
320- prepare_toolstate_config ( & token) ;
312+ prepare_toolstate_config ( builder , & token) ;
321313 }
322314 if Path :: new ( TOOLSTATE_DIR ) . exists ( ) {
323315 eprintln ! ( "Cleaning old toolstate directory..." ) ;
324316 t ! ( fs:: remove_dir_all( TOOLSTATE_DIR ) ) ;
325317 }
326318
327- let status = helpers:: git ( None )
319+ helpers:: git ( None )
328320 . arg ( "clone" )
329321 . arg ( "--depth=1" )
330322 . arg ( toolstate_repo ( ) )
331323 . arg ( TOOLSTATE_DIR )
332- . as_command_mut ( )
333- . status ( ) ;
334- let success = match status {
335- Ok ( s) => s. success ( ) ,
336- Err ( _) => false ,
337- } ;
338- if !success {
339- panic ! ( "git clone unsuccessful (status: {status:?})" ) ;
340- }
324+ . run ( builder) ;
341325}
342326
343327/// Sets up config and authentication for modifying the toolstate repo.
344- fn prepare_toolstate_config ( token : & str ) {
345- fn git_config ( key : & str , value : & str ) {
346- let status = helpers:: git ( None )
347- . arg ( "config" )
348- . arg ( "--global" )
349- . arg ( key)
350- . arg ( value)
351- . as_command_mut ( )
352- . status ( ) ;
353- let success = match status {
354- Ok ( s) => s. success ( ) ,
355- Err ( _) => false ,
356- } ;
357- if !success {
358- panic ! ( "git config key={key} value={value} failed (status: {status:?})" ) ;
359- }
328+ fn prepare_toolstate_config ( builder : & Builder < ' _ > , token : & str ) {
329+ fn git_config ( builder : & Builder < ' _ > , key : & str , value : & str ) {
330+ helpers:: git ( None ) . arg ( "config" ) . arg ( "--global" ) . arg ( key) . arg ( value) . run ( builder) ;
360331 }
361332
362333 // If changing anything here, then please check that `src/ci/publish_toolstate.sh` is up to date
363334 // as well.
364- git_config ( "user.email" , "7378925+rust-toolstate-update@users.noreply.github.com" ) ;
365- git_config ( "user.name" , "Rust Toolstate Update" ) ;
366- git_config ( "credential.helper" , "store" ) ;
335+ git_config ( builder , "user.email" , "7378925+rust-toolstate-update@users.noreply.github.com" ) ;
336+ git_config ( builder , "user.name" , "Rust Toolstate Update" ) ;
337+ git_config ( builder , "credential.helper" , "store" ) ;
367338
368339 let credential = format ! ( "https://{token}:x-oauth-basic@github.com\n " , ) ;
369340 let git_credential_path = PathBuf :: from ( t ! ( env:: var( "HOME" ) ) ) . join ( ".git-credentials" ) ;
@@ -403,55 +374,51 @@ fn read_old_toolstate() -> Vec<RepoState> {
403374///
404375/// * See <https://help.github.com/articles/about-commit-email-addresses/>
405376/// if a private email by GitHub is wanted.
406- fn commit_toolstate_change ( current_toolstate : & ToolstateData ) {
377+ fn commit_toolstate_change ( builder : & Builder < ' _ > , current_toolstate : & ToolstateData ) {
407378 let message = format ! ( "({} CI update)" , OS . expect( "linux/windows only" ) ) ;
408379 let mut success = false ;
409380 for _ in 1 ..=5 {
410381 // Upload the test results (the new commit-to-toolstate mapping) to the toolstate repo.
411382 // This does *not* change the "current toolstate"; that only happens post-landing
412383 // via `src/ci/docker/publish_toolstate.sh`.
413- publish_test_results ( current_toolstate) ;
384+ publish_test_results ( builder , current_toolstate) ;
414385
415386 // `git commit` failing means nothing to commit.
416- let status = t ! ( helpers:: git( Some ( Path :: new( TOOLSTATE_DIR ) ) )
387+ let status = helpers:: git ( Some ( Path :: new ( TOOLSTATE_DIR ) ) )
388+ . allow_failure ( )
417389 . arg ( "commit" )
418390 . arg ( "-a" )
419391 . arg ( "-m" )
420392 . arg ( & message)
421- . as_command_mut( )
422- . status( ) ) ;
423- if !status. success ( ) {
393+ . run ( builder) ;
394+ if !status. is_success ( ) {
424395 success = true ;
425396 break ;
426397 }
427398
428- let status = t ! ( helpers:: git( Some ( Path :: new( TOOLSTATE_DIR ) ) )
399+ let status = helpers:: git ( Some ( Path :: new ( TOOLSTATE_DIR ) ) )
400+ . allow_failure ( )
429401 . arg ( "push" )
430402 . arg ( "origin" )
431403 . arg ( "master" )
432- . as_command_mut( )
433- . status( ) ) ;
404+ . run ( builder) ;
434405 // If we successfully push, exit.
435- if status. success ( ) {
406+ if status. is_success ( ) {
436407 success = true ;
437408 break ;
438409 }
439410 eprintln ! ( "Sleeping for 3 seconds before retrying push" ) ;
440411 std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 3 ) ) ;
441- let status = t ! ( helpers:: git( Some ( Path :: new( TOOLSTATE_DIR ) ) )
412+ helpers:: git ( Some ( Path :: new ( TOOLSTATE_DIR ) ) )
442413 . arg ( "fetch" )
443414 . arg ( "origin" )
444415 . arg ( "master" )
445- . as_command_mut( )
446- . status( ) ) ;
447- assert ! ( status. success( ) ) ;
448- let status = t ! ( helpers:: git( Some ( Path :: new( TOOLSTATE_DIR ) ) )
416+ . run ( builder) ;
417+ helpers:: git ( Some ( Path :: new ( TOOLSTATE_DIR ) ) )
449418 . arg ( "reset" )
450419 . arg ( "--hard" )
451420 . arg ( "origin/master" )
452- . as_command_mut( )
453- . status( ) ) ;
454- assert ! ( status. success( ) ) ;
421+ . run ( builder) ;
455422 }
456423
457424 if !success {
@@ -464,9 +431,8 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
464431/// These results will later be promoted to `latest.json` by the
465432/// `publish_toolstate.py` script if the PR passes all tests and is merged to
466433/// master.
467- fn publish_test_results ( current_toolstate : & ToolstateData ) {
468- let commit = t ! ( helpers:: git( None ) . arg( "rev-parse" ) . arg( "HEAD" ) . as_command_mut( ) . output( ) ) ;
469- let commit = t ! ( String :: from_utf8( commit. stdout) ) ;
434+ fn publish_test_results ( builder : & Builder < ' _ > , current_toolstate : & ToolstateData ) {
435+ let commit = helpers:: git ( None ) . capture ( ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . run ( builder) . stdout ( ) ;
470436
471437 let toolstate_serialized = t ! ( serde_json:: to_string( & current_toolstate) ) ;
472438
0 commit comments