@@ -25,8 +25,8 @@ use crate::dist;
25
25
use crate :: dist:: pkg;
26
26
use crate :: mock_command:: CommandCreatorSync ;
27
27
use crate :: util:: {
28
- decode_path, encode_path, hash_all, Digest , HashToDigest , MetadataCtimeExt , TimeMacroFinder ,
29
- Timestamp ,
28
+ decode_path, encode_path, hash_all, Digest , HashToDigest , MetadataCtimeExt , OsStrExt ,
29
+ TimeMacroFinder , Timestamp ,
30
30
} ;
31
31
use async_trait:: async_trait;
32
32
use fs_err as fs;
@@ -1435,6 +1435,13 @@ static CACHED_ENV_VARS: Lazy<HashSet<&'static OsStr>> = Lazy::new(|| {
1435
1435
. collect ( )
1436
1436
} ) ;
1437
1437
1438
+ const NON_HASHABLE_ARGS : & [ & str ] = & [
1439
+ "-fdebug-prefix-map" ,
1440
+ "-fmacro-prefix-map" ,
1441
+ "-ffile-prefix-map" ,
1442
+ "-fdebug-compilation-dir" ,
1443
+ ] ;
1444
+
1438
1445
/// Compute the hash key of `compiler` compiling `preprocessor_output` with `args`.
1439
1446
pub fn hash_key (
1440
1447
compiler_digest : & str ,
@@ -1453,7 +1460,13 @@ pub fn hash_key(
1453
1460
m. update ( & [ plusplus as u8 ] ) ;
1454
1461
m. update ( CACHE_VERSION ) ;
1455
1462
m. update ( language. as_str ( ) . as_bytes ( ) ) ;
1456
- for arg in arguments {
1463
+ ' arg_loop: for arg in arguments {
1464
+ for non_hashable in NON_HASHABLE_ARGS {
1465
+ if arg. to_string_lossy ( ) . starts_with ( non_hashable) {
1466
+ // Skip non-hashable arguments.
1467
+ continue ' arg_loop;
1468
+ }
1469
+ }
1457
1470
arg. hash ( & mut HashToDigest { digest : & mut m } ) ;
1458
1471
}
1459
1472
for hash in extra_hashes {
@@ -1567,6 +1580,32 @@ mod test {
1567
1580
) ;
1568
1581
}
1569
1582
1583
+ #[ test]
1584
+ fn test_hash_key_non_hashable_args ( ) {
1585
+ let digest = "abcd" ;
1586
+ const PREPROCESSED : & [ u8 ] = b"hello world" ;
1587
+
1588
+ let args = ovec ! [ "arg1" , "arg2" , "arg3" ] ;
1589
+ let mut args_with_non_hashable: Vec < OsString > = NON_HASHABLE_ARGS
1590
+ . iter ( )
1591
+ . map ( |s| OsString :: from ( s) )
1592
+ . collect ( ) ;
1593
+
1594
+ args_with_non_hashable. extend ( args. clone ( ) ) ;
1595
+ assert_neq ! (
1596
+ hash_key( digest, Language :: C , & args, & [ ] , & [ ] , PREPROCESSED , false ) ,
1597
+ hash_key(
1598
+ digest,
1599
+ Language :: C ,
1600
+ & args_with_non_hashable,
1601
+ & [ ] ,
1602
+ & [ ] ,
1603
+ PREPROCESSED ,
1604
+ false
1605
+ )
1606
+ ) ;
1607
+ }
1608
+
1570
1609
#[ test]
1571
1610
fn test_hash_key_preprocessed_content_differs ( ) {
1572
1611
let args = ovec ! [ "a" , "b" , "c" ] ;
0 commit comments