187
187
//! See the `A-rebuild-detection` flag on the issue tracker for more:
188
188
//! <https://github.com/rust-lang/cargo/issues?q=is%3Aissue+is%3Aopen+label%3AA-rebuild-detection>
189
189
190
- use std:: collections:: HashMap ;
190
+ use std:: collections:: hash_map :: { Entry , HashMap } ;
191
191
use std:: env;
192
192
use std:: fs;
193
193
use std:: hash:: { self , Hasher } ;
@@ -539,6 +539,7 @@ impl LocalFingerprint {
539
539
/// file accesses.
540
540
fn find_stale_file (
541
541
& self ,
542
+ mtime_cache : & mut HashMap < PathBuf , FileTime > ,
542
543
pkg_root : & Path ,
543
544
target_root : & Path ,
544
545
) -> CargoResult < Option < StaleFile > > {
@@ -550,7 +551,7 @@ impl LocalFingerprint {
550
551
LocalFingerprint :: CheckDepInfo { dep_info } => {
551
552
let dep_info = target_root. join ( dep_info) ;
552
553
if let Some ( paths) = parse_dep_info ( pkg_root, target_root, & dep_info) ? {
553
- Ok ( find_stale_file ( & dep_info, paths. iter ( ) ) )
554
+ Ok ( find_stale_file ( mtime_cache , & dep_info, paths. iter ( ) ) )
554
555
} else {
555
556
Ok ( Some ( StaleFile :: Missing ( dep_info) ) )
556
557
}
@@ -559,6 +560,7 @@ impl LocalFingerprint {
559
560
// We need to verify that no paths listed in `paths` are newer than
560
561
// the `output` path itself, or the last time the build script ran.
561
562
LocalFingerprint :: RerunIfChanged { output, paths } => Ok ( find_stale_file (
563
+ mtime_cache,
562
564
& target_root. join ( output) ,
563
565
paths. iter ( ) . map ( |p| pkg_root. join ( p) ) ,
564
566
) ) ,
@@ -756,7 +758,12 @@ impl Fingerprint {
756
758
/// dependencies up to this unit as well. This function assumes that the
757
759
/// unit starts out as `FsStatus::Stale` and then it will optionally switch
758
760
/// it to `UpToDate` if it can.
759
- fn check_filesystem ( & mut self , pkg_root : & Path , target_root : & Path ) -> CargoResult < ( ) > {
761
+ fn check_filesystem (
762
+ & mut self ,
763
+ mtime_cache : & mut HashMap < PathBuf , FileTime > ,
764
+ pkg_root : & Path ,
765
+ target_root : & Path ,
766
+ ) -> CargoResult < ( ) > {
760
767
assert ! ( !self . fs_status. up_to_date( ) ) ;
761
768
762
769
let mut mtimes = HashMap :: new ( ) ;
@@ -840,7 +847,7 @@ impl Fingerprint {
840
847
// files for this package itself. If we do find something log a helpful
841
848
// message and bail out so we stay stale.
842
849
for local in self . local . get_mut ( ) . unwrap ( ) . iter ( ) {
843
- if let Some ( file) = local. find_stale_file ( pkg_root, target_root) ? {
850
+ if let Some ( file) = local. find_stale_file ( mtime_cache , pkg_root, target_root) ? {
844
851
file. log ( ) ;
845
852
return Ok ( ( ) ) ;
846
853
}
@@ -1015,7 +1022,7 @@ fn calculate<'a, 'cfg>(
1015
1022
// After we built the initial `Fingerprint` be sure to update the
1016
1023
// `fs_status` field of it.
1017
1024
let target_root = target_root ( cx) ;
1018
- fingerprint. check_filesystem ( unit. pkg . root ( ) , & target_root) ?;
1025
+ fingerprint. check_filesystem ( & mut cx . mtime_cache , unit. pkg . root ( ) , & target_root) ?;
1019
1026
1020
1027
let fingerprint = Arc :: new ( fingerprint) ;
1021
1028
cx. fingerprints . insert ( * unit, Arc :: clone ( & fingerprint) ) ;
@@ -1098,13 +1105,10 @@ fn calculate_normal<'a, 'cfg>(
1098
1105
} )
1099
1106
}
1100
1107
1101
- // We want to use the mtime for files if we're a path source, but if we're a
1102
- // git/registry source, then the mtime of files may fluctuate, but they won't
1103
- // change so long as the source itself remains constant (which is the
1104
- // responsibility of the source)
1108
+ /// Whether or not the fingerprint should track the dependencies from the
1109
+ /// dep-info file for this unit.
1105
1110
fn use_dep_info ( unit : & Unit < ' _ > ) -> bool {
1106
- let path = unit. pkg . summary ( ) . source_id ( ) . is_path ( ) ;
1107
- !unit. mode . is_doc ( ) && path
1111
+ !unit. mode . is_doc ( )
1108
1112
}
1109
1113
1110
1114
/// Calculate a fingerprint for an "execute a build script" unit. This is an
@@ -1422,11 +1426,7 @@ pub fn parse_dep_info(
1422
1426
}
1423
1427
} )
1424
1428
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
1425
- if paths. is_empty ( ) {
1426
- Ok ( None )
1427
- } else {
1428
- Ok ( Some ( paths) )
1429
- }
1429
+ Ok ( Some ( paths) )
1430
1430
}
1431
1431
1432
1432
fn pkg_fingerprint ( bcx : & BuildContext < ' _ , ' _ > , pkg : & Package ) -> CargoResult < String > {
@@ -1439,7 +1439,11 @@ fn pkg_fingerprint(bcx: &BuildContext<'_, '_>, pkg: &Package) -> CargoResult<Str
1439
1439
source. fingerprint ( pkg)
1440
1440
}
1441
1441
1442
- fn find_stale_file < I > ( reference : & Path , paths : I ) -> Option < StaleFile >
1442
+ fn find_stale_file < I > (
1443
+ mtime_cache : & mut HashMap < PathBuf , FileTime > ,
1444
+ reference : & Path ,
1445
+ paths : I ,
1446
+ ) -> Option < StaleFile >
1443
1447
where
1444
1448
I : IntoIterator ,
1445
1449
I :: Item : AsRef < Path > ,
@@ -1451,9 +1455,15 @@ where
1451
1455
1452
1456
for path in paths {
1453
1457
let path = path. as_ref ( ) ;
1454
- let path_mtime = match paths:: mtime ( path) {
1455
- Ok ( mtime) => mtime,
1456
- Err ( ..) => return Some ( StaleFile :: Missing ( path. to_path_buf ( ) ) ) ,
1458
+ let path_mtime = match mtime_cache. entry ( path. to_path_buf ( ) ) {
1459
+ Entry :: Occupied ( o) => * o. get ( ) ,
1460
+ Entry :: Vacant ( v) => {
1461
+ let mtime = match paths:: mtime ( path) {
1462
+ Ok ( mtime) => mtime,
1463
+ Err ( ..) => return Some ( StaleFile :: Missing ( path. to_path_buf ( ) ) ) ,
1464
+ } ;
1465
+ * v. insert ( mtime)
1466
+ }
1457
1467
} ;
1458
1468
1459
1469
// TODO: fix #5918.
@@ -1540,6 +1550,9 @@ impl DepInfoPathType {
1540
1550
/// The `rustc_cwd` argument is the absolute path to the cwd of the compiler
1541
1551
/// when it was invoked.
1542
1552
///
1553
+ /// If the `allow_package` argument is false, then package-relative paths are
1554
+ /// skipped and ignored.
1555
+ ///
1543
1556
/// The serialized Cargo format will contain a list of files, all of which are
1544
1557
/// relative if they're under `root`. or absolute if they're elsewhere.
1545
1558
pub fn translate_dep_info (
@@ -1548,6 +1561,7 @@ pub fn translate_dep_info(
1548
1561
rustc_cwd : & Path ,
1549
1562
pkg_root : & Path ,
1550
1563
target_root : & Path ,
1564
+ allow_package : bool ,
1551
1565
) -> CargoResult < ( ) > {
1552
1566
let target = parse_rustc_dep_info ( rustc_dep_info) ?;
1553
1567
let deps = & target
@@ -1561,6 +1575,9 @@ pub fn translate_dep_info(
1561
1575
let ( ty, path) = if let Ok ( stripped) = file. strip_prefix ( target_root) {
1562
1576
( DepInfoPathType :: TargetRootRelative , stripped)
1563
1577
} else if let Ok ( stripped) = file. strip_prefix ( pkg_root) {
1578
+ if !allow_package {
1579
+ continue ;
1580
+ }
1564
1581
( DepInfoPathType :: PackageRootRelative , stripped)
1565
1582
} else {
1566
1583
// It's definitely not target root relative, but this is an absolute path (since it was
0 commit comments