@@ -4,7 +4,10 @@ use std::fs;
4
4
5
5
use cargo_test_support:: prelude:: * ;
6
6
use cargo_test_support:: registry:: Package ;
7
- use cargo_test_support:: { basic_manifest, paths, project, project_in_home, rustc_host, str} ;
7
+ use cargo_test_support:: {
8
+ basic_manifest, paths, project, project_in_home, rustc_host, str, RawOutput ,
9
+ } ;
10
+ use snapbox:: Assert ;
8
11
9
12
#[ cargo_test]
10
13
fn env_rustflags_normal_source ( ) {
@@ -1478,36 +1481,44 @@ fn env_rustflags_misspelled_build_script() {
1478
1481
1479
1482
#[ cargo_test]
1480
1483
fn remap_path_prefix_ignored ( ) {
1481
- // Ensure that --remap-path-prefix does not affect metadata hash.
1482
- let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1483
- p. cargo ( "build" ) . run ( ) ;
1484
- let rlibs = p
1485
- . glob ( "target/debug/deps/*.rlib" )
1486
- . collect :: < Result < Vec < _ > , _ > > ( )
1487
- . unwrap ( ) ;
1488
- assert_eq ! ( rlibs. len( ) , 1 ) ;
1489
- p. cargo ( "clean" ) . run ( ) ;
1490
-
1491
- let check_metadata_same = || {
1492
- let rlibs2 = p
1493
- . glob ( "target/debug/deps/*.rlib" )
1494
- . collect :: < Result < Vec < _ > , _ > > ( )
1495
- . unwrap ( ) ;
1496
- assert_eq ! ( rlibs, rlibs2) ;
1484
+ let get_c_metadata_re =
1485
+ regex:: Regex :: new ( r".*(--crate-name [^ ]*).*(-C ?metadata=[^ ]*).*" ) . unwrap ( ) ;
1486
+ let get_c_metadata = |output : RawOutput | {
1487
+ let stderr = String :: from_utf8 ( output. stderr ) . unwrap ( ) ;
1488
+ let mut c_metadata = get_c_metadata_re
1489
+ . captures_iter ( & stderr)
1490
+ . map ( |c| {
1491
+ let ( _, [ name, c_metadata] ) = c. extract ( ) ;
1492
+ format ! ( "{name} {c_metadata}" )
1493
+ } )
1494
+ . collect :: < Vec < _ > > ( ) ;
1495
+ assert ! (
1496
+ !c_metadata. is_empty( ) ,
1497
+ "`{get_c_metadata_re:?}` did not match:\n ```\n {stderr}\n ```"
1498
+ ) ;
1499
+ c_metadata. sort ( ) ;
1500
+ c_metadata. join ( "\n " )
1497
1501
} ;
1498
1502
1499
- p. cargo ( "build" )
1503
+ let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1504
+
1505
+ let build_output = p
1506
+ . cargo ( "build -v" )
1500
1507
. env (
1501
1508
"RUSTFLAGS" ,
1502
1509
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" ,
1503
1510
)
1504
1511
. run ( ) ;
1505
- check_metadata_same ( ) ;
1512
+ let build_c_metadata = dbg ! ( get_c_metadata ( build_output ) ) ;
1506
1513
1507
1514
p. cargo ( "clean" ) . run ( ) ;
1508
- p. cargo ( "rustc -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" )
1515
+
1516
+ let rustc_output = p
1517
+ . cargo ( "rustc -v -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" )
1509
1518
. run ( ) ;
1510
- check_metadata_same ( ) ;
1519
+ let rustc_c_metadata = dbg ! ( get_c_metadata( rustc_output) ) ;
1520
+
1521
+ Assert :: new ( ) . eq ( rustc_c_metadata, build_c_metadata) ;
1511
1522
}
1512
1523
1513
1524
#[ cargo_test]
0 commit comments