@@ -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
@@ -146,6 +146,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
146
146
pub fn out_dir ( & self , unit : & Unit < ' a > ) -> PathBuf {
147
147
if unit. mode . is_doc ( ) {
148
148
self . layout ( unit. kind ) . root ( ) . parent ( ) . unwrap ( ) . join ( "doc" )
149
+ } else if unit. mode . is_doc_test ( ) {
150
+ panic ! ( "doc tests do not have an out dir" ) ;
149
151
} else if unit. target . is_custom_build ( ) {
150
152
self . build_script_dir ( unit)
151
153
} else if unit. target . is_example ( ) {
@@ -293,107 +295,139 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
293
295
unit : & Unit < ' a > ,
294
296
bcx : & BuildContext < ' a , ' cfg > ,
295
297
) -> CargoResult < Arc < Vec < OutputFile > > > {
298
+ let ret = match unit. mode {
299
+ CompileMode :: Check { .. } => {
300
+ // This may be confusing. rustc outputs a file named `lib*.rmeta`
301
+ // for both libraries and binaries.
302
+ let file_stem = self . file_stem ( unit) ;
303
+ let path = self . out_dir ( unit) . join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
304
+ vec ! [ OutputFile {
305
+ path,
306
+ hardlink: None ,
307
+ export_path: None ,
308
+ flavor: FileFlavor :: Linkable { rmeta: false } ,
309
+ } ]
310
+ }
311
+ CompileMode :: Doc { .. } => {
312
+ let path = self
313
+ . out_dir ( unit)
314
+ . join ( unit. target . crate_name ( ) )
315
+ . join ( "index.html" ) ;
316
+ vec ! [ OutputFile {
317
+ path,
318
+ hardlink: None ,
319
+ export_path: None ,
320
+ flavor: FileFlavor :: Normal ,
321
+ } ]
322
+ }
323
+ CompileMode :: RunCustomBuild => {
324
+ // At this time, this code path does not handle build script
325
+ // outputs.
326
+ vec ! [ ]
327
+ }
328
+ CompileMode :: Doctest => {
329
+ // Doctests are built in a temporary directory and then
330
+ // deleted. There is the `--persist-doctests` unstable flag,
331
+ // but Cargo does not know about that.
332
+ vec ! [ ]
333
+ }
334
+ CompileMode :: Test | CompileMode :: Build | CompileMode :: Bench => {
335
+ self . calc_outputs_rustc ( unit, bcx) ?
336
+ }
337
+ } ;
338
+ info ! ( "Target filenames: {:?}" , ret) ;
339
+
340
+ Ok ( Arc :: new ( ret) )
341
+ }
342
+
343
+ fn calc_outputs_rustc (
344
+ & self ,
345
+ unit : & Unit < ' a > ,
346
+ bcx : & BuildContext < ' a , ' cfg > ,
347
+ ) -> CargoResult < Vec < OutputFile > > {
348
+ let mut ret = Vec :: new ( ) ;
349
+ let mut unsupported = Vec :: new ( ) ;
350
+
296
351
let out_dir = self . out_dir ( unit) ;
297
- let file_stem = self . file_stem ( unit) ;
298
352
let link_stem = self . link_stem ( unit) ;
299
353
let info = if unit. kind == Kind :: Host {
300
354
& bcx. host_info
301
355
} else {
302
356
& bcx. target_info
303
357
} ;
358
+ let file_stem = self . file_stem ( unit) ;
304
359
305
- let mut ret = Vec :: new ( ) ;
306
- let mut unsupported = Vec :: new ( ) ;
307
- {
308
- if unit. mode . is_check ( ) {
309
- // This may be confusing. rustc outputs a file named `lib*.rmeta`
310
- // for both libraries and binaries.
311
- let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
312
- ret. push ( OutputFile {
313
- path,
314
- hardlink : None ,
315
- export_path : None ,
316
- flavor : FileFlavor :: Linkable { rmeta : false } ,
317
- } ) ;
360
+ let mut add = |crate_type : & str , flavor : FileFlavor | -> CargoResult < ( ) > {
361
+ let crate_type = if crate_type == "lib" {
362
+ "rlib"
318
363
} 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
- ) ?;
331
-
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
- }
364
+ crate_type
365
+ } ;
366
+ let file_types =
367
+ info. file_types ( crate_type, flavor, unit. target . kind ( ) , bcx. target_triple ( ) ) ?;
368
+
369
+ match file_types {
370
+ Some ( types) => {
371
+ for file_type in types {
372
+ let path = out_dir. join ( file_type. filename ( & file_stem) ) ;
373
+ let hardlink = link_stem
374
+ . as_ref ( )
375
+ . map ( |& ( ref ld, ref ls) | ld. join ( file_type. filename ( ls) ) ) ;
376
+ let export_path = if unit. target . is_custom_build ( ) {
377
+ None
378
+ } else {
379
+ self . export_dir . as_ref ( ) . and_then ( |export_dir| {
380
+ hardlink. as_ref ( ) . and_then ( |hardlink| {
381
+ Some ( export_dir. join ( hardlink. file_name ( ) . unwrap ( ) ) )
382
+ } )
383
+ } )
384
+ } ;
385
+ ret. push ( OutputFile {
386
+ path,
387
+ hardlink,
388
+ export_path,
389
+ flavor : file_type. flavor ,
390
+ } ) ;
395
391
}
396
392
}
393
+ // Not supported; don't worry about it.
394
+ None => {
395
+ unsupported. push ( crate_type. to_string ( ) ) ;
396
+ }
397
+ }
398
+ Ok ( ( ) )
399
+ } ;
400
+ match * unit. target . kind ( ) {
401
+ TargetKind :: Bin
402
+ | TargetKind :: CustomBuild
403
+ | TargetKind :: ExampleBin
404
+ | TargetKind :: Bench
405
+ | TargetKind :: Test => {
406
+ add ( "bin" , FileFlavor :: Normal ) ?;
407
+ }
408
+ TargetKind :: Lib ( ..) | TargetKind :: ExampleLib ( ..) if unit. mode . is_any_test ( ) => {
409
+ add ( "bin" , FileFlavor :: Normal ) ?;
410
+ }
411
+ TargetKind :: ExampleLib ( ref kinds) | TargetKind :: Lib ( ref kinds) => {
412
+ for kind in kinds {
413
+ add (
414
+ kind. crate_type ( ) ,
415
+ if kind. linkable ( ) {
416
+ FileFlavor :: Linkable { rmeta : false }
417
+ } else {
418
+ FileFlavor :: Normal
419
+ } ,
420
+ ) ?;
421
+ }
422
+ let path = out_dir. join ( format ! ( "lib{}.rmeta" , file_stem) ) ;
423
+ if !unit. target . requires_upstream_objects ( ) {
424
+ ret. push ( OutputFile {
425
+ path,
426
+ hardlink : None ,
427
+ export_path : None ,
428
+ flavor : FileFlavor :: Linkable { rmeta : true } ,
429
+ } ) ;
430
+ }
397
431
}
398
432
}
399
433
if ret. is_empty ( ) {
@@ -413,9 +447,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
413
447
bcx. target_triple( )
414
448
) ;
415
449
}
416
- info ! ( "Target filenames: {:?}" , ret) ;
417
-
418
- Ok ( Arc :: new ( ret) )
450
+ Ok ( ret)
419
451
}
420
452
}
421
453
@@ -439,6 +471,10 @@ fn compute_metadata<'a, 'cfg>(
439
471
cx : & Context < ' a , ' cfg > ,
440
472
metas : & mut HashMap < Unit < ' a > , Option < Metadata > > ,
441
473
) -> Option < Metadata > {
474
+ if unit. mode . is_doc_test ( ) {
475
+ // Doc tests do not have metadata.
476
+ return None ;
477
+ }
442
478
// No metadata for dylibs because of a couple issues:
443
479
// - macOS encodes the dylib name in the executable,
444
480
// - Windows rustc multiple files of which we can't easily link all of them.
0 commit comments