@@ -335,6 +335,7 @@ use crate::util;
335335use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
336336use crate :: util:: interning:: InternedString ;
337337use crate :: util:: { internal, path_args, profile} ;
338+ use crate :: CARGO_ENV ;
338339
339340use super :: custom_build:: BuildDeps ;
340341use super :: job:: { Job , Work } ;
@@ -712,6 +713,7 @@ impl LocalFingerprint {
712713 mtime_cache : & mut HashMap < PathBuf , FileTime > ,
713714 pkg_root : & Path ,
714715 target_root : & Path ,
716+ cargo_exe : & Path ,
715717 ) -> CargoResult < Option < StaleItem > > {
716718 match self {
717719 // We need to parse `dep_info`, learn about the crate's dependencies.
@@ -727,7 +729,21 @@ impl LocalFingerprint {
727729 None => return Ok ( Some ( StaleItem :: MissingFile ( dep_info) ) ) ,
728730 } ;
729731 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+ } ;
731747 if current == * previous {
732748 continue ;
733749 }
@@ -980,6 +996,7 @@ impl Fingerprint {
980996 mtime_cache : & mut HashMap < PathBuf , FileTime > ,
981997 pkg_root : & Path ,
982998 target_root : & Path ,
999+ cargo_exe : & Path ,
9831000 ) -> CargoResult < ( ) > {
9841001 assert ! ( !self . fs_status. up_to_date( ) ) ;
9851002
@@ -1071,7 +1088,9 @@ impl Fingerprint {
10711088 // files for this package itself. If we do find something log a helpful
10721089 // message and bail out so we stay stale.
10731090 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+ {
10751094 item. log ( ) ;
10761095 return Ok ( ( ) ) ;
10771096 }
@@ -1256,7 +1275,13 @@ fn calculate(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Arc<Fingerpri
12561275 // After we built the initial `Fingerprint` be sure to update the
12571276 // `fs_status` field of it.
12581277 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+ ) ?;
12601285
12611286 let fingerprint = Arc :: new ( fingerprint) ;
12621287 cx. fingerprints
@@ -1850,9 +1875,13 @@ pub fn translate_dep_info(
18501875 // you write a binary that does `println!("{}", env!("OUT_DIR"))` we won't
18511876 // recompile that if you move the target directory. Hopefully that's not too
18521877 // 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.
18531882 on_disk_info
18541883 . env
1855- . retain ( |( key, _) | !rustc_cmd. get_envs ( ) . contains_key ( key) ) ;
1884+ . retain ( |( key, _) | !rustc_cmd. get_envs ( ) . contains_key ( key) || key == CARGO_ENV ) ;
18561885
18571886 for file in depinfo. files {
18581887 // The path may be absolute or relative, canonical or not. Make sure
0 commit comments