Skip to content

Commit

Permalink
Auto merge of #8473 - alexcrichton:fix-fingerprint-loc, r=ehuss
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 9, 2020
2 parents 4f74d9b + 15d4960 commit 62123e4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 62123e4

Please sign in to comment.