diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index 4a9339bd992..019ce61e97d 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -335,6 +335,7 @@ use crate::util; use crate::util::errors::{CargoResult, CargoResultExt}; use crate::util::interning::InternedString; use crate::util::{internal, path_args, profile}; +use crate::CARGO_ENV; use super::custom_build::BuildDeps; use super::job::{Job, Work}; @@ -712,6 +713,7 @@ impl LocalFingerprint { mtime_cache: &mut HashMap, pkg_root: &Path, target_root: &Path, + cargo_exe: &Path, ) -> CargoResult> { match self { // We need to parse `dep_info`, learn about the crate's dependencies. @@ -727,7 +729,21 @@ impl LocalFingerprint { None => return Ok(Some(StaleItem::MissingFile(dep_info))), }; for (key, previous) in info.env.iter() { - let current = env::var(key).ok(); + let current = if key == CARGO_ENV { + Some( + cargo_exe + .to_str() + .ok_or_else(|| { + format_err!( + "cargo exe path {} must be valid UTF-8", + cargo_exe.display() + ) + })? + .to_string(), + ) + } else { + env::var(key).ok() + }; if current == *previous { continue; } @@ -980,6 +996,7 @@ impl Fingerprint { mtime_cache: &mut HashMap, pkg_root: &Path, target_root: &Path, + cargo_exe: &Path, ) -> CargoResult<()> { assert!(!self.fs_status.up_to_date()); @@ -1071,7 +1088,9 @@ impl Fingerprint { // files for this package itself. If we do find something log a helpful // message and bail out so we stay stale. for local in self.local.get_mut().unwrap().iter() { - if let Some(item) = local.find_stale_item(mtime_cache, pkg_root, target_root)? { + if let Some(item) = + local.find_stale_item(mtime_cache, pkg_root, target_root, cargo_exe)? + { item.log(); return Ok(()); } @@ -1256,7 +1275,13 @@ fn calculate(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult