@@ -99,24 +99,16 @@ fn print_error(tool: &str, submodule: &str) {
99
99
crate :: exit!( 3 ) ;
100
100
}
101
101
102
- fn check_changed_files ( toolstates : & HashMap < Box < str > , ToolState > ) {
102
+ fn check_changed_files ( builder : & Builder < ' _ > , toolstates : & HashMap < Box < str > , ToolState > ) {
103
103
// Changed files
104
104
let output = helpers:: git ( None )
105
+ . capture ( )
105
106
. arg ( "diff" )
106
107
. arg ( "--name-status" )
107
108
. arg ( "HEAD" )
108
109
. 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 ( ) ;
120
112
121
113
for ( tool, submodule) in STABLE_TOOLS . iter ( ) . chain ( NIGHTLY_TOOLS . iter ( ) ) {
122
114
let changed = output. lines ( ) . any ( |l| l. starts_with ( 'M' ) && l. ends_with ( submodule) ) ;
@@ -186,8 +178,8 @@ impl Step for ToolStateCheck {
186
178
crate :: exit!( 1 ) ;
187
179
}
188
180
189
- check_changed_files ( & toolstates) ;
190
- checkout_toolstate_repo ( ) ;
181
+ check_changed_files ( builder , & toolstates) ;
182
+ checkout_toolstate_repo ( builder ) ;
191
183
let old_toolstate = read_old_toolstate ( ) ;
192
184
193
185
for ( tool, _) in STABLE_TOOLS . iter ( ) {
@@ -231,7 +223,7 @@ impl Step for ToolStateCheck {
231
223
}
232
224
233
225
if builder. config . channel == "nightly" && env:: var_os ( "TOOLSTATE_PUBLISH" ) . is_some ( ) {
234
- commit_toolstate_change ( & toolstates) ;
226
+ commit_toolstate_change ( builder , & toolstates) ;
235
227
}
236
228
}
237
229
@@ -315,55 +307,34 @@ fn toolstate_repo() -> String {
315
307
const TOOLSTATE_DIR : & str = "rust-toolstate" ;
316
308
317
309
/// Checks out the toolstate repo into `TOOLSTATE_DIR`.
318
- fn checkout_toolstate_repo ( ) {
310
+ fn checkout_toolstate_repo ( builder : & Builder < ' _ > ) {
319
311
if let Ok ( token) = env:: var ( "TOOLSTATE_REPO_ACCESS_TOKEN" ) {
320
- prepare_toolstate_config ( & token) ;
312
+ prepare_toolstate_config ( builder , & token) ;
321
313
}
322
314
if Path :: new ( TOOLSTATE_DIR ) . exists ( ) {
323
315
eprintln ! ( "Cleaning old toolstate directory..." ) ;
324
316
t ! ( fs:: remove_dir_all( TOOLSTATE_DIR ) ) ;
325
317
}
326
318
327
- let status = helpers:: git ( None )
319
+ helpers:: git ( None )
328
320
. arg ( "clone" )
329
321
. arg ( "--depth=1" )
330
322
. arg ( toolstate_repo ( ) )
331
323
. 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) ;
341
325
}
342
326
343
327
/// 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) ;
360
331
}
361
332
362
333
// If changing anything here, then please check that `src/ci/publish_toolstate.sh` is up to date
363
334
// as well.
364
- git_config ( "user.email" , "[email protected] " ) ;
365
- git_config ( "user.name" , "Rust Toolstate Update" ) ;
366
- git_config ( "credential.helper" , "store" ) ;
335
+ git_config ( builder , "user.email" , "[email protected] " ) ;
336
+ git_config ( builder , "user.name" , "Rust Toolstate Update" ) ;
337
+ git_config ( builder , "credential.helper" , "store" ) ;
367
338
368
339
let credential =
format ! ( "https://{token}:[email protected] \n " , ) ;
369
340
let git_credential_path = PathBuf :: from ( t ! ( env:: var( "HOME" ) ) ) . join ( ".git-credentials" ) ;
@@ -403,55 +374,51 @@ fn read_old_toolstate() -> Vec<RepoState> {
403
374
///
404
375
/// * See <https://help.github.com/articles/about-commit-email-addresses/>
405
376
/// 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 ) {
407
378
let message = format ! ( "({} CI update)" , OS . expect( "linux/windows only" ) ) ;
408
379
let mut success = false ;
409
380
for _ in 1 ..=5 {
410
381
// Upload the test results (the new commit-to-toolstate mapping) to the toolstate repo.
411
382
// This does *not* change the "current toolstate"; that only happens post-landing
412
383
// via `src/ci/docker/publish_toolstate.sh`.
413
- publish_test_results ( current_toolstate) ;
384
+ publish_test_results ( builder , current_toolstate) ;
414
385
415
386
// `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 ( )
417
389
. arg ( "commit" )
418
390
. arg ( "-a" )
419
391
. arg ( "-m" )
420
392
. arg ( & message)
421
- . as_command_mut( )
422
- . status( ) ) ;
423
- if !status. success ( ) {
393
+ . run ( builder) ;
394
+ if !status. is_success ( ) {
424
395
success = true ;
425
396
break ;
426
397
}
427
398
428
- let status = t ! ( helpers:: git( Some ( Path :: new( TOOLSTATE_DIR ) ) )
399
+ let status = helpers:: git ( Some ( Path :: new ( TOOLSTATE_DIR ) ) )
400
+ . allow_failure ( )
429
401
. arg ( "push" )
430
402
. arg ( "origin" )
431
403
. arg ( "master" )
432
- . as_command_mut( )
433
- . status( ) ) ;
404
+ . run ( builder) ;
434
405
// If we successfully push, exit.
435
- if status. success ( ) {
406
+ if status. is_success ( ) {
436
407
success = true ;
437
408
break ;
438
409
}
439
410
eprintln ! ( "Sleeping for 3 seconds before retrying push" ) ;
440
411
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 ) ) )
442
413
. arg ( "fetch" )
443
414
. arg ( "origin" )
444
415
. 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 ) ) )
449
418
. arg ( "reset" )
450
419
. arg ( "--hard" )
451
420
. arg ( "origin/master" )
452
- . as_command_mut( )
453
- . status( ) ) ;
454
- assert ! ( status. success( ) ) ;
421
+ . run ( builder) ;
455
422
}
456
423
457
424
if !success {
@@ -464,9 +431,8 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
464
431
/// These results will later be promoted to `latest.json` by the
465
432
/// `publish_toolstate.py` script if the PR passes all tests and is merged to
466
433
/// 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 ( ) ;
470
436
471
437
let toolstate_serialized = t ! ( serde_json:: to_string( & current_toolstate) ) ;
472
438
0 commit comments