@@ -230,11 +230,9 @@ fn compile<'a, 'cfg: 'a>(cx: &mut Context<'a, 'cfg>,
230
230
} else {
231
231
rustc ( cx, unit, exec. clone ( ) ) ?
232
232
} ;
233
- let link_work1 = link_targets ( cx, unit) ?;
234
- let link_work2 = link_targets ( cx, unit) ?;
235
233
// Need to link targets on both the dirty and fresh
236
- let dirty = work. then ( link_work1 ) . then ( dirty) ;
237
- let fresh = link_work2 . then ( fresh) ;
234
+ let dirty = work. then ( link_targets ( cx , unit , false ) ? ) . then ( dirty) ;
235
+ let fresh = link_targets ( cx , unit , true ) ? . then ( fresh) ;
238
236
( dirty, fresh, freshness)
239
237
} ;
240
238
jobs. enqueue ( cx, unit, Job :: new ( dirty, fresh) , freshness) ?;
@@ -291,10 +289,6 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
291
289
let json_messages = cx. build_config . json_messages ;
292
290
let package_id = unit. pkg . package_id ( ) . clone ( ) ;
293
291
let target = unit. target . clone ( ) ;
294
- let profile = unit. profile . clone ( ) ;
295
- let features = cx. resolve . features ( unit. pkg . package_id ( ) ) . iter ( )
296
- . map ( |s| s. to_owned ( ) )
297
- . collect ( ) ;
298
292
299
293
exec. init ( cx) ;
300
294
let exec = exec. clone ( ) ;
@@ -388,18 +382,6 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
388
382
fingerprint:: append_current_dir ( & dep_info_loc, & cwd) ?;
389
383
}
390
384
391
- if json_messages {
392
- machine_message:: emit ( machine_message:: Artifact {
393
- package_id : & package_id,
394
- target : & target,
395
- profile : & profile,
396
- features : features,
397
- filenames : filenames. iter ( ) . map ( |& ( ref src, _, _) | {
398
- src. display ( ) . to_string ( )
399
- } ) . collect ( ) ,
400
- } ) ;
401
- }
402
-
403
385
Ok ( ( ) )
404
386
} ) ) ;
405
387
@@ -435,38 +417,64 @@ fn rustc(cx: &mut Context, unit: &Unit, exec: Arc<Executor>) -> CargoResult<Work
435
417
436
418
/// Link the compiled target (often of form foo-{metadata_hash}) to the
437
419
/// final target. This must happen during both "Fresh" and "Compile"
438
- fn link_targets ( cx : & mut Context , unit : & Unit ) -> CargoResult < Work > {
420
+ fn link_targets ( cx : & mut Context , unit : & Unit , fresh : bool ) -> CargoResult < Work > {
439
421
let filenames = cx. target_filenames ( unit) ?;
422
+ let package_id = unit. pkg . package_id ( ) . clone ( ) ;
423
+ let target = unit. target . clone ( ) ;
424
+ let profile = unit. profile . clone ( ) ;
425
+ let features = cx. resolve . features_sorted ( & package_id) . into_iter ( )
426
+ . map ( |s| s. to_owned ( ) )
427
+ . collect ( ) ;
428
+ let json_messages = cx. build_config . json_messages ;
429
+
440
430
Ok ( Work :: new ( move |_| {
441
431
// If we're a "root crate", e.g. the target of this compilation, then we
442
432
// hard link our outputs out of the `deps` directory into the directory
443
433
// above. This means that `cargo build` will produce binaries in
444
434
// `target/debug` which one probably expects.
445
- for ( src, link_dst, _linkable) in filenames {
435
+ let mut destinations = vec ! [ ] ;
436
+ for & ( ref src, ref link_dst, _linkable) in filenames. iter ( ) {
446
437
// This may have been a `cargo rustc` command which changes the
447
438
// output, so the source may not actually exist.
448
- debug ! ( "Thinking about linking {} to {:?}" , src. display( ) , link_dst) ;
449
- if !src. exists ( ) || link_dst. is_none ( ) {
439
+ if !src. exists ( ) {
450
440
continue
451
441
}
452
- let dst = link_dst. unwrap ( ) ;
442
+ let dst = match link_dst. as_ref ( ) {
443
+ Some ( dst) => dst,
444
+ None => {
445
+ destinations. push ( src. display ( ) . to_string ( ) ) ;
446
+ continue ;
447
+ }
448
+ } ;
449
+ destinations. push ( dst. display ( ) . to_string ( ) ) ;
453
450
454
451
debug ! ( "linking {} to {}" , src. display( ) , dst. display( ) ) ;
455
452
if dst. exists ( ) {
456
453
fs:: remove_file ( & dst) . chain_error ( || {
457
454
human ( format ! ( "failed to remove: {}" , dst. display( ) ) )
458
455
} ) ?;
459
456
}
460
- fs:: hard_link ( & src, & dst)
457
+ fs:: hard_link ( src, dst)
461
458
. or_else ( |err| {
462
459
debug ! ( "hard link failed {}. falling back to fs::copy" , err) ;
463
- fs:: copy ( & src, & dst) . map ( |_| ( ) )
460
+ fs:: copy ( src, dst) . map ( |_| ( ) )
464
461
} )
465
462
. chain_error ( || {
466
463
human ( format ! ( "failed to link or copy `{}` to `{}`" ,
467
464
src. display( ) , dst. display( ) ) )
468
465
} ) ?;
469
466
}
467
+
468
+ if json_messages {
469
+ machine_message:: emit ( machine_message:: Artifact {
470
+ package_id : & package_id,
471
+ target : & target,
472
+ profile : & profile,
473
+ features : features,
474
+ filenames : destinations,
475
+ fresh : fresh,
476
+ } ) ;
477
+ }
470
478
Ok ( ( ) )
471
479
} ) )
472
480
}
0 commit comments