From c810ed0046167de8840f8ffd167d771310903053 Mon Sep 17 00:00:00 2001 From: bors Date: Thu, 9 Jul 2020 15:50:43 +0000 Subject: [PATCH] Auto merge of #8473 - alexcrichton:fix-fingerprint-loc, r=ehuss Avoid colliding with older Cargo fingerprint changes The fingerprint format Cargo stores changed recently in a way that older Cargos cannot understand. Unfortunately though older Cargos are colliding on some compilation units trying to read the new format and they're bailing out. This commit fixes this issue by ensuring that the location for fingerprint metadata is different in older Cargos and newer Cargos. Fingerprint metadata is always stored in a location with a hash in the file name. This hash typically includes the hash of rustc's version information itself, but for units which don't have a `Metadata` it's a much simpler hash which is much more likely to collide with other versions of Cargo. The fix in this commit is to extract the metadata version that we're hashing to a constant, and then also hash it for generating a filesystem location to house fingerprint data for a unit that has no `Metadata`. Closes #8472 Closes #8298 --- .../compiler/context/compilation_files.rs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 13ee773d450..9ed6fd11f7a 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -13,6 +13,15 @@ use crate::core::compiler::{CompileMode, CompileTarget, CrateType, FileType, Uni use crate::core::{Target, TargetKind, Workspace}; use crate::util::{self, CargoResult, StableHasher}; +/// This is a generic version number that can be changed to make +/// backwards-incompatible changes to any file structures in the output +/// directory. For example, the fingerprint files or the build-script +/// output files. Normally cargo updates ship with rustc updates which will +/// cause a new hash due to the rustc version changing, but this allows +/// cargo to be extra careful to deal with different versions of cargo that +/// use the same rustc version. +const METADATA_VERSION: u8 = 2; + /// The `Metadata` is a hash used to make unique file names for each unit in a /// build. It is also use for symbol mangling. /// @@ -162,7 +171,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { /// Used for the metadata when `metadata` returns `None`. pub fn target_short_hash(&self, unit: &Unit) -> String { let hashable = unit.pkg.package_id().stable_hash(self.ws.root()); - util::short_hash(&hashable) + util::short_hash(&(METADATA_VERSION, hashable)) } /// Returns the directory where the artifacts for the given unit are @@ -483,14 +492,7 @@ fn compute_metadata( } let mut hasher = StableHasher::new(); - // This is a generic version number that can be changed to make - // backwards-incompatible changes to any file structures in the output - // directory. For example, the fingerprint files or the build-script - // output files. Normally cargo updates ship with rustc updates which will - // cause a new hash due to the rustc version changing, but this allows - // cargo to be extra careful to deal with different versions of cargo that - // use the same rustc version. - 2.hash(&mut hasher); + METADATA_VERSION.hash(&mut hasher); // Unique metadata per (name, source, version) triple. This'll allow us // to pull crates from anywhere without worrying about conflicts.