@@ -2316,6 +2316,8 @@ LLVM version: 9.0
2316
2316
fn linking_interrupted ( ) {
2317
2317
// Interrupt during the linking phase shouldn't leave test executable as "fresh".
2318
2318
2319
+ // This is used to detect when linking starts, then to pause the linker so
2320
+ // that the test can kill cargo.
2319
2321
let listener = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
2320
2322
let addr = listener. local_addr ( ) . unwrap ( ) ;
2321
2323
@@ -2367,6 +2369,8 @@ fn linking_interrupted() {
2367
2369
"CARGO_TARGET_{}_LINKER" ,
2368
2370
rustc_host( ) . to_uppercase( ) . replace( '-' , "_" )
2369
2371
) ;
2372
+ // NOTE: This assumes that the path to the linker is not in the
2373
+ // fingerprint. But maybe it should be?
2370
2374
let mut cmd = p
2371
2375
. cargo ( "test --test t1 --no-run" )
2372
2376
. env ( & linker_env, linker. bin ( "linker" ) )
@@ -2381,8 +2385,21 @@ fn linking_interrupted() {
2381
2385
2382
2386
// Interrupt the child.
2383
2387
child. kill ( ) . unwrap ( ) ;
2384
- // Note: rustc and the linker are still running, let them exit here.
2385
- conn. write ( b"X" ) . unwrap ( ) ;
2388
+ child. wait ( ) . unwrap ( ) ;
2389
+ // Note: rustc and the linker may still be running because we didn't kill
2390
+ // the entire process group. Normally, when a user hits Ctrl-C, everything
2391
+ // is killed. However, setting up process groups in a cross-platform test
2392
+ // is a pain, and there's no easy way to know when everything has been
2393
+ // killed. This write will tell them to exit, pretending that they died
2394
+ // before finishing. Ignore the error, because (sometimes?) on Windows
2395
+ // everything is already killed.
2396
+ let _ = conn. write ( b"X" ) ;
2397
+ // Sleep a bit to allow rustc to clean up and exit. I have seen some race
2398
+ // conditions on macOS where clang dies with `no such
2399
+ // file...t1-HASH.rcgu.o`. I think what is happening is that the old rustc
2400
+ // process is still running, and deletes the `*.o` files while the command
2401
+ // below is trying to write them. Not sure if that is macOS-specific.
2402
+ std:: thread:: sleep ( std:: time:: Duration :: new ( 2 , 0 ) ) ;
2386
2403
2387
2404
// Build again, shouldn't be fresh.
2388
2405
p. cargo ( "test --test t1" )
0 commit comments