@@ -491,6 +491,119 @@ fn future_incompat_should_output_to_build_dir() {
491
491
assert_exists ( & p. root ( ) . join ( "build-dir/.future-incompat-report.json" ) ) ;
492
492
}
493
493
494
+ mod templating {
495
+ use cargo_test_support:: paths;
496
+
497
+ use super :: * ;
498
+
499
+ #[ cargo_test]
500
+ fn workspace_root ( ) {
501
+ let p = project ( ) ;
502
+ let root = p. root ( ) ;
503
+ let p = p
504
+ . file ( "src/main.rs" , r#"fn main() { println!("Hello, World!") }"# )
505
+ . file (
506
+ ".cargo/config.toml" ,
507
+ & format ! (
508
+ r#"
509
+ [build]
510
+ build-dir = "{}/build-dir"
511
+ target-dir = "target-dir"
512
+ "# ,
513
+ root. display( )
514
+ ) ,
515
+ )
516
+ . build ( ) ;
517
+
518
+ p. cargo ( "build -Z build-dir" )
519
+ . masquerade_as_nightly_cargo ( & [ "build-dir" ] )
520
+ . enable_mac_dsym ( )
521
+ . run ( ) ;
522
+
523
+ assert_build_dir_layout ( p. root ( ) . join ( "build-dir" ) , "debug" ) ;
524
+ assert_artifact_dir_layout ( p. root ( ) . join ( "target-dir" ) , "debug" ) ;
525
+
526
+ // Verify the binary was uplifted to the target-dir
527
+ assert_exists ( & p. root ( ) . join ( & format ! ( "target-dir/debug/foo{EXE_SUFFIX}" ) ) ) ;
528
+ }
529
+
530
+ #[ cargo_test]
531
+ fn cargo_cache ( ) {
532
+ let p = project ( )
533
+ . file ( "src/main.rs" , r#"fn main() { println!("Hello, World!") }"# )
534
+ . file (
535
+ ".cargo/config.toml" ,
536
+ & format ! (
537
+ r#"
538
+ [build]
539
+ build-dir = "{}/build-dir"
540
+ target-dir = "target-dir"
541
+ "# ,
542
+ paths:: home( ) . join( ".cargo" ) . display( )
543
+ ) ,
544
+ )
545
+ . build ( ) ;
546
+
547
+ p. cargo ( "build -Z build-dir" )
548
+ . masquerade_as_nightly_cargo ( & [ "build-dir" ] )
549
+ . enable_mac_dsym ( )
550
+ . run ( ) ;
551
+
552
+ assert_build_dir_layout ( paths:: home ( ) . join ( ".cargo/build-dir" ) , "debug" ) ;
553
+ assert_artifact_dir_layout ( p. root ( ) . join ( "target-dir" ) , "debug" ) ;
554
+
555
+ // Verify the binary was uplifted to the target-dir
556
+ assert_exists ( & p. root ( ) . join ( & format ! ( "target-dir/debug/foo{EXE_SUFFIX}" ) ) ) ;
557
+ }
558
+
559
+ #[ cargo_test]
560
+ fn workspace_manfiest_path_hash ( ) {
561
+ let p = project ( )
562
+ . file ( "src/main.rs" , r#"fn main() { println!("Hello, World!") }"# )
563
+ . file (
564
+ "Cargo.toml" ,
565
+ r#"
566
+ [package]
567
+ name = "foo"
568
+ version = "1.0.0"
569
+ authors = []
570
+ edition = "2015"
571
+ "# ,
572
+ )
573
+ . file (
574
+ ".cargo/config.toml" ,
575
+ r#"
576
+ [build]
577
+ build-dir = "foo/a70a942ddb7da6b4/build-dir"
578
+ target-dir = "target-dir"
579
+ "# ,
580
+ )
581
+ . build ( ) ;
582
+
583
+ p. cargo ( "build -Z build-dir" )
584
+ . masquerade_as_nightly_cargo ( & [ "build-dir" ] )
585
+ . enable_mac_dsym ( )
586
+ . run ( ) ;
587
+
588
+ let foo_dir = p. root ( ) . join ( "foo" ) ;
589
+ assert_exists ( & foo_dir) ;
590
+
591
+ // Since the hash will change between test runs simply find the first directory in `foo`
592
+ // and assume that is the hash dir.
593
+ let mut dirs = std:: fs:: read_dir ( foo_dir) . unwrap ( ) . into_iter ( ) ;
594
+ let hash_dir = dirs. next ( ) . unwrap ( ) . unwrap ( ) ;
595
+ // Validate there are no other directories in `foo`
596
+ assert ! ( dirs. next( ) . is_none( ) ) ;
597
+
598
+ let build_dir = hash_dir. path ( ) . join ( "build-dir" ) ;
599
+ assert_build_dir_layout ( build_dir, "debug" ) ;
600
+ assert_artifact_dir_layout ( p. root ( ) . join ( "target-dir" ) , "debug" ) ;
601
+
602
+ // Verify the binary was uplifted to the target-dir
603
+ assert_exists ( & p. root ( ) . join ( & format ! ( "target-dir/debug/foo{EXE_SUFFIX}" ) ) ) ;
604
+ }
605
+ }
606
+
494
607
#[ track_caller]
495
608
fn assert_build_dir_layout ( path : PathBuf , profile : & str ) {
496
609
assert_dir_layout ( path, profile, true ) ;
0 commit comments