@@ -335,6 +335,7 @@ use crate::util;
335
335
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
336
336
use crate :: util:: interning:: InternedString ;
337
337
use crate :: util:: { internal, path_args, profile} ;
338
+ use crate :: CARGO_ENV ;
338
339
339
340
use super :: custom_build:: BuildDeps ;
340
341
use super :: job:: { Job , Work } ;
@@ -712,6 +713,7 @@ impl LocalFingerprint {
712
713
mtime_cache : & mut HashMap < PathBuf , FileTime > ,
713
714
pkg_root : & Path ,
714
715
target_root : & Path ,
716
+ cargo_exe : & Path ,
715
717
) -> CargoResult < Option < StaleItem > > {
716
718
match self {
717
719
// We need to parse `dep_info`, learn about the crate's dependencies.
@@ -727,7 +729,21 @@ impl LocalFingerprint {
727
729
None => return Ok ( Some ( StaleItem :: MissingFile ( dep_info) ) ) ,
728
730
} ;
729
731
for ( key, previous) in info. env . iter ( ) {
730
- let current = env:: var ( key) . ok ( ) ;
732
+ let current = if key == CARGO_ENV {
733
+ Some (
734
+ cargo_exe
735
+ . to_str ( )
736
+ . ok_or_else ( || {
737
+ format_err ! (
738
+ "cargo exe path {} must be valid UTF-8" ,
739
+ cargo_exe. display( )
740
+ )
741
+ } ) ?
742
+ . to_string ( ) ,
743
+ )
744
+ } else {
745
+ env:: var ( key) . ok ( )
746
+ } ;
731
747
if current == * previous {
732
748
continue ;
733
749
}
@@ -980,6 +996,7 @@ impl Fingerprint {
980
996
mtime_cache : & mut HashMap < PathBuf , FileTime > ,
981
997
pkg_root : & Path ,
982
998
target_root : & Path ,
999
+ cargo_exe : & Path ,
983
1000
) -> CargoResult < ( ) > {
984
1001
assert ! ( !self . fs_status. up_to_date( ) ) ;
985
1002
@@ -1071,7 +1088,9 @@ impl Fingerprint {
1071
1088
// files for this package itself. If we do find something log a helpful
1072
1089
// message and bail out so we stay stale.
1073
1090
for local in self . local . get_mut ( ) . unwrap ( ) . iter ( ) {
1074
- if let Some ( item) = local. find_stale_item ( mtime_cache, pkg_root, target_root) ? {
1091
+ if let Some ( item) =
1092
+ local. find_stale_item ( mtime_cache, pkg_root, target_root, cargo_exe) ?
1093
+ {
1075
1094
item. log ( ) ;
1076
1095
return Ok ( ( ) ) ;
1077
1096
}
@@ -1256,7 +1275,13 @@ fn calculate(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Arc<Fingerpri
1256
1275
// After we built the initial `Fingerprint` be sure to update the
1257
1276
// `fs_status` field of it.
1258
1277
let target_root = target_root ( cx) ;
1259
- fingerprint. check_filesystem ( & mut cx. mtime_cache , unit. pkg . root ( ) , & target_root) ?;
1278
+ let cargo_exe = cx. bcx . config . cargo_exe ( ) ?;
1279
+ fingerprint. check_filesystem (
1280
+ & mut cx. mtime_cache ,
1281
+ unit. pkg . root ( ) ,
1282
+ & target_root,
1283
+ cargo_exe,
1284
+ ) ?;
1260
1285
1261
1286
let fingerprint = Arc :: new ( fingerprint) ;
1262
1287
cx. fingerprints
@@ -1850,9 +1875,13 @@ pub fn translate_dep_info(
1850
1875
// you write a binary that does `println!("{}", env!("OUT_DIR"))` we won't
1851
1876
// recompile that if you move the target directory. Hopefully that's not too
1852
1877
// bad of an issue for now...
1878
+ //
1879
+ // This also includes `CARGO` since if the code is explicitly wanting to
1880
+ // know that path, it should be rebuilt if it changes. The CARGO path is
1881
+ // not tracked elsewhere in the fingerprint.
1853
1882
on_disk_info
1854
1883
. env
1855
- . retain ( |( key, _) | !rustc_cmd. get_envs ( ) . contains_key ( key) ) ;
1884
+ . retain ( |( key, _) | !rustc_cmd. get_envs ( ) . contains_key ( key) || key == CARGO_ENV ) ;
1856
1885
1857
1886
for file in depinfo. files {
1858
1887
// The path may be absolute or relative, canonical or not. Make sure
0 commit comments