@@ -9,7 +9,7 @@ use lazycell::LazyCell;
9
9
use log:: info;
10
10
11
11
use super :: { BuildContext , Context , FileFlavor , Kind , Layout } ;
12
- use crate :: core:: compiler:: Unit ;
12
+ use crate :: core:: compiler:: { CompileMode , Unit } ;
13
13
use crate :: core:: { TargetKind , Workspace } ;
14
14
use crate :: util:: { self , CargoResult } ;
15
15
@@ -294,106 +294,137 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
294
294
bcx : & BuildContext < ' a , ' cfg > ,
295
295
) -> CargoResult < Arc < Vec < OutputFile > > > {
296
296
let out_dir = self . out_dir ( unit) ;
297
- let file_stem = self . file_stem ( unit) ;
298
- let link_stem = self . link_stem ( unit) ;
299
- let info = if unit. kind == Kind :: Host {
300
- & bcx. host_info
301
- } else {
302
- & bcx. target_info
303
- } ;
304
297
305
- let mut ret = Vec :: new ( ) ;
306
- let mut unsupported = Vec :: new ( ) ;
307
- {
308
- if unit. mode . is_check ( ) {
298
+ let ret = match unit. mode {
299
+ CompileMode :: Check { .. } => {
309
300
// This may be confusing. rustc outputs a file named `lib*.rmeta`
310
301
// for both libraries and binaries.
302
+ let file_stem = self . file_stem ( unit) ;
311
303
let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
312
- ret . push ( OutputFile {
304
+ vec ! [ OutputFile {
313
305
path,
314
306
hardlink: None ,
315
307
export_path: None ,
316
308
flavor: FileFlavor :: Linkable { rmeta: false } ,
317
- } ) ;
318
- } else {
319
- let mut add = |crate_type : & str , flavor : FileFlavor | -> CargoResult < ( ) > {
320
- let crate_type = if crate_type == "lib" {
321
- "rlib"
322
- } else {
323
- crate_type
324
- } ;
325
- let file_types = info. file_types (
326
- crate_type,
327
- flavor,
328
- unit. target . kind ( ) ,
329
- bcx. target_triple ( ) ,
330
- ) ?;
309
+ } ]
310
+ }
311
+ CompileMode :: Doc { .. } => {
312
+ let path = out_dir. join ( unit. target . crate_name ( ) ) . join ( "index.html" ) ;
313
+ vec ! [ OutputFile {
314
+ path,
315
+ hardlink: None ,
316
+ export_path: None ,
317
+ flavor: FileFlavor :: Normal ,
318
+ } ]
319
+ }
320
+ CompileMode :: RunCustomBuild => {
321
+ // At this time, this code path does not handle build script
322
+ // outputs.
323
+ vec ! [ ]
324
+ }
325
+ CompileMode :: Doctest => {
326
+ // Doctests are built in a temporary directory and then
327
+ // deleted. There is the `--persist-doctests` unstable flag,
328
+ // but Cargo does not know about that.
329
+ vec ! [ ]
330
+ }
331
+ CompileMode :: Test | CompileMode :: Build | CompileMode :: Bench => {
332
+ self . calc_outputs_rustc ( unit, bcx, & out_dir) ?
333
+ }
334
+ } ;
335
+ info ! ( "Target filenames: {:?}" , ret) ;
331
336
332
- match file_types {
333
- Some ( types) => {
334
- for file_type in types {
335
- let path = out_dir. join ( file_type. filename ( & file_stem) ) ;
336
- let hardlink = link_stem
337
- . as_ref ( )
338
- . map ( |& ( ref ld, ref ls) | ld. join ( file_type. filename ( ls) ) ) ;
339
- let export_path = if unit. target . is_custom_build ( ) {
340
- None
341
- } else {
342
- self . export_dir . as_ref ( ) . and_then ( |export_dir| {
343
- hardlink. as_ref ( ) . and_then ( |hardlink| {
344
- Some ( export_dir. join ( hardlink. file_name ( ) . unwrap ( ) ) )
345
- } )
346
- } )
347
- } ;
348
- ret. push ( OutputFile {
349
- path,
350
- hardlink,
351
- export_path,
352
- flavor : file_type. flavor ,
353
- } ) ;
354
- }
355
- }
356
- // Not supported; don't worry about it.
357
- None => {
358
- unsupported. push ( crate_type. to_string ( ) ) ;
359
- }
360
- }
361
- Ok ( ( ) )
362
- } ;
363
- // info!("{:?}", unit);
364
- match * unit. target . kind ( ) {
365
- TargetKind :: Bin
366
- | TargetKind :: CustomBuild
367
- | TargetKind :: ExampleBin
368
- | TargetKind :: Bench
369
- | TargetKind :: Test => {
370
- add ( "bin" , FileFlavor :: Normal ) ?;
371
- }
372
- TargetKind :: Lib ( ..) | TargetKind :: ExampleLib ( ..) if unit. mode . is_any_test ( ) => {
373
- add ( "bin" , FileFlavor :: Normal ) ?;
374
- }
375
- TargetKind :: ExampleLib ( ref kinds) | TargetKind :: Lib ( ref kinds) => {
376
- for kind in kinds {
377
- add (
378
- kind. crate_type ( ) ,
379
- if kind. linkable ( ) {
380
- FileFlavor :: Linkable { rmeta : false }
381
- } else {
382
- FileFlavor :: Normal
383
- } ,
384
- ) ?;
385
- }
386
- let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
387
- if !unit. target . requires_upstream_objects ( ) {
388
- ret. push ( OutputFile {
389
- path,
390
- hardlink : None ,
391
- export_path : None ,
392
- flavor : FileFlavor :: Linkable { rmeta : true } ,
393
- } ) ;
394
- }
337
+ Ok ( Arc :: new ( ret) )
338
+ }
339
+
340
+ fn calc_outputs_rustc (
341
+ & self ,
342
+ unit : & Unit < ' a > ,
343
+ bcx : & BuildContext < ' a , ' cfg > ,
344
+ out_dir : & Path ,
345
+ ) -> CargoResult < Vec < OutputFile > > {
346
+ let mut ret = Vec :: new ( ) ;
347
+ let mut unsupported = Vec :: new ( ) ;
348
+
349
+ let link_stem = self . link_stem ( unit) ;
350
+ let info = if unit. kind == Kind :: Host {
351
+ & bcx. host_info
352
+ } else {
353
+ & bcx. target_info
354
+ } ;
355
+ let file_stem = self . file_stem ( unit) ;
356
+
357
+ let mut add = |crate_type : & str , flavor : FileFlavor | -> CargoResult < ( ) > {
358
+ let crate_type = if crate_type == "lib" {
359
+ "rlib"
360
+ } else {
361
+ crate_type
362
+ } ;
363
+ let file_types =
364
+ info. file_types ( crate_type, flavor, unit. target . kind ( ) , bcx. target_triple ( ) ) ?;
365
+
366
+ match file_types {
367
+ Some ( types) => {
368
+ for file_type in types {
369
+ let path = out_dir. join ( file_type. filename ( & file_stem) ) ;
370
+ let hardlink = link_stem
371
+ . as_ref ( )
372
+ . map ( |& ( ref ld, ref ls) | ld. join ( file_type. filename ( ls) ) ) ;
373
+ let export_path = if unit. target . is_custom_build ( ) {
374
+ None
375
+ } else {
376
+ self . export_dir . as_ref ( ) . and_then ( |export_dir| {
377
+ hardlink. as_ref ( ) . and_then ( |hardlink| {
378
+ Some ( export_dir. join ( hardlink. file_name ( ) . unwrap ( ) ) )
379
+ } )
380
+ } )
381
+ } ;
382
+ ret. push ( OutputFile {
383
+ path,
384
+ hardlink,
385
+ export_path,
386
+ flavor : file_type. flavor ,
387
+ } ) ;
395
388
}
396
389
}
390
+ // Not supported; don't worry about it.
391
+ None => {
392
+ unsupported. push ( crate_type. to_string ( ) ) ;
393
+ }
394
+ }
395
+ Ok ( ( ) )
396
+ } ;
397
+ match * unit. target . kind ( ) {
398
+ TargetKind :: Bin
399
+ | TargetKind :: CustomBuild
400
+ | TargetKind :: ExampleBin
401
+ | TargetKind :: Bench
402
+ | TargetKind :: Test => {
403
+ add ( "bin" , FileFlavor :: Normal ) ?;
404
+ }
405
+ TargetKind :: Lib ( ..) | TargetKind :: ExampleLib ( ..) if unit. mode . is_any_test ( ) => {
406
+ add ( "bin" , FileFlavor :: Normal ) ?;
407
+ }
408
+ TargetKind :: ExampleLib ( ref kinds) | TargetKind :: Lib ( ref kinds) => {
409
+ for kind in kinds {
410
+ add (
411
+ kind. crate_type ( ) ,
412
+ if kind. linkable ( ) {
413
+ FileFlavor :: Linkable { rmeta : false }
414
+ } else {
415
+ FileFlavor :: Normal
416
+ } ,
417
+ ) ?;
418
+ }
419
+ let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
420
+ if !unit. target . requires_upstream_objects ( ) {
421
+ ret. push ( OutputFile {
422
+ path,
423
+ hardlink : None ,
424
+ export_path : None ,
425
+ flavor : FileFlavor :: Linkable { rmeta : true } ,
426
+ } ) ;
427
+ }
397
428
}
398
429
}
399
430
if ret. is_empty ( ) {
@@ -413,9 +444,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
413
444
bcx. target_triple( )
414
445
) ;
415
446
}
416
- info ! ( "Target filenames: {:?}" , ret) ;
417
-
418
- Ok ( Arc :: new ( ret) )
447
+ Ok ( ret)
419
448
}
420
449
}
421
450
0 commit comments