From 359849b1694eb281dc6a6ac25fea08f6089b2ab8 Mon Sep 17 00:00:00 2001 From: Koute Date: Mon, 16 May 2022 21:25:15 +0900 Subject: [PATCH] Make sure the commit hash is always of the same length in `impl_version` (#11404) * Make sure the commit hash is always of the same length in `impl_version` * Add a comment regarding the length of the commit hash --- substrate/utils/build-script-utils/src/version.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/substrate/utils/build-script-utils/src/version.rs b/substrate/utils/build-script-utils/src/version.rs index 9432f23e9b..19b507ba26 100644 --- a/substrate/utils/build-script-utils/src/version.rs +++ b/substrate/utils/build-script-utils/src/version.rs @@ -22,7 +22,10 @@ pub fn generate_cargo_keys() { let commit = if let Ok(hash) = std::env::var("SUBSTRATE_CLI_GIT_COMMIT_HASH") { Cow::from(hash.trim().to_owned()) } else { - match Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output() { + // We deliberately set the length here to `11` to ensure that + // the emitted hash is always of the same length; otherwise + // it can (and will!) vary between different build environments. + match Command::new("git").args(&["rev-parse", "--short=11", "HEAD"]).output() { Ok(o) if o.status.success() => { let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned(); Cow::from(sha)