@@ -248,14 +248,24 @@ impl Toolchain {
248
248
}
249
249
} ) ;
250
250
251
- let mut cmd = match ( script, cfg. args . timeout ) {
252
- ( Some ( script) , None ) => {
251
+ let target_dir = format ! ( "target-{}" , self . rustup_name( ) ) ;
252
+ // Used in filecheck mode
253
+ let llir_path = PathBuf :: from ( & target_dir)
254
+ . join ( "debug" )
255
+ . join ( "deps" )
256
+ . join ( "output.ll" ) ;
257
+
258
+ let mut cmd = match ( script, cfg. args . timeout , & cfg. args . filecheck ) {
259
+ ( Some ( _) , _, Some ( _) ) => {
260
+ panic ! ( "incompatbile options `--script` and `--filecheck` used" ) ;
261
+ }
262
+ ( Some ( script) , None , None ) => {
253
263
let mut cmd = Command :: new ( script) ;
254
264
cmd. env ( "RUSTUP_TOOLCHAIN" , self . rustup_name ( ) ) ;
255
265
cmd. args ( & cfg. args . command_args ) ;
256
266
cmd
257
267
}
258
- ( None , None ) => {
268
+ ( None , None , None ) => {
259
269
let mut cmd = Command :: new ( "cargo" ) ;
260
270
cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
261
271
if cfg. args . command_args . is_empty ( ) {
@@ -265,15 +275,15 @@ impl Toolchain {
265
275
}
266
276
cmd
267
277
}
268
- ( Some ( script) , Some ( timeout) ) => {
278
+ ( Some ( script) , Some ( timeout) , None ) => {
269
279
let mut cmd = Command :: new ( "timeout" ) ;
270
280
cmd. arg ( timeout. to_string ( ) ) ;
271
281
cmd. arg ( script) ;
272
282
cmd. args ( & cfg. args . command_args ) ;
273
283
cmd. env ( "RUSTUP_TOOLCHAIN" , self . rustup_name ( ) ) ;
274
284
cmd
275
285
}
276
- ( None , Some ( timeout) ) => {
286
+ ( None , Some ( timeout) , None ) => {
277
287
let mut cmd = Command :: new ( "timeout" ) ;
278
288
cmd. arg ( timeout. to_string ( ) ) ;
279
289
cmd. arg ( "cargo" ) ;
@@ -285,9 +295,39 @@ impl Toolchain {
285
295
}
286
296
cmd
287
297
}
298
+ ( None , None , Some ( _) ) => {
299
+ let mut cmd = Command :: new ( "cargo" ) ;
300
+ cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
301
+ if cfg. args . command_args . is_empty ( ) {
302
+ cmd. arg ( "rustc" )
303
+ . arg ( "--" )
304
+ . arg ( "-Copt-level=3" )
305
+ . arg ( "-Cdebuginfo=0" )
306
+ . arg ( format ! ( "--emit=llvm-ir={}" , llir_path. display( ) ) ) ;
307
+ } else {
308
+ cmd. args ( & cfg. args . command_args ) ;
309
+ }
310
+ cmd
311
+ }
312
+ ( None , Some ( timeout) , Some ( _) ) => {
313
+ let mut cmd = Command :: new ( "timeout" ) ;
314
+ cmd. arg ( timeout. to_string ( ) ) ;
315
+ cmd. arg ( "cargo" ) ;
316
+ cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
317
+ if cfg. args . command_args . is_empty ( ) {
318
+ cmd. arg ( "rustc" )
319
+ . arg ( "--" )
320
+ . arg ( "-Copt-level=3" )
321
+ . arg ( "-Cdebuginfo=0" )
322
+ . arg ( format ! ( "--emit=llvm-ir={}" , llir_path. display( ) ) ) ;
323
+ } else {
324
+ cmd. args ( & cfg. args . command_args ) ;
325
+ }
326
+ cmd
327
+ }
288
328
} ;
289
329
cmd. current_dir ( & cfg. args . test_dir ) ;
290
- cmd. env ( "CARGO_TARGET_DIR" , format ! ( "target-{}" , self . rustup_name ( ) ) ) ;
330
+ cmd. env ( "CARGO_TARGET_DIR" , & target_dir ) ;
291
331
if let Some ( target) = & cfg. args . target {
292
332
cmd. env ( "CARGO_BUILD_TARGET" , target) ;
293
333
}
@@ -319,6 +359,44 @@ impl Toolchain {
319
359
io:: stdout ( ) . write_all ( & output. stdout ) . unwrap ( ) ;
320
360
io:: stderr ( ) . write_all ( & output. stderr ) . unwrap ( ) ;
321
361
}
362
+
363
+ let Some ( check_file) = & cfg. args . filecheck else {
364
+ return output;
365
+ } ;
366
+
367
+ if !output. status . success ( ) {
368
+ return output;
369
+ }
370
+
371
+ let filecheck_path = cfg
372
+ . args
373
+ . filecheck_path
374
+ . clone ( )
375
+ . unwrap_or_else ( || PathBuf :: from ( "FileCheck" ) ) ;
376
+
377
+ let mut cmd = Command :: new ( filecheck_path) ;
378
+ cmd. arg ( "--input-file" )
379
+ . arg (
380
+ PathBuf :: from ( target_dir)
381
+ . join ( "debug" )
382
+ . join ( "deps" )
383
+ . join ( "output.ll" ) ,
384
+ )
385
+ . arg ( check_file) ;
386
+
387
+ cmd. stdout ( default_stdio ( ) ) ;
388
+ cmd. stderr ( default_stdio ( ) ) ;
389
+ let output = match cmd. output ( ) {
390
+ Ok ( output) => output,
391
+ Err ( err) => {
392
+ panic ! ( "thiserror::Errored to run {:?}: {:?}" , cmd, err) ;
393
+ }
394
+ } ;
395
+ if must_capture_output && emit_output {
396
+ io:: stdout ( ) . write_all ( & output. stdout ) . unwrap ( ) ;
397
+ io:: stderr ( ) . write_all ( & output. stderr ) . unwrap ( ) ;
398
+ }
399
+
322
400
output
323
401
}
324
402
0 commit comments