Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid colliding with older Cargo fingerprint changes #8473

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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