From 9e60b16b04a50710f291088bd520006ab9ab9b0a Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 1 Sep 2023 22:10:17 +0100 Subject: [PATCH] feat(rustc): parse and store `commit-hash` --- src/cargo/util/rustc.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index 238145af6810..1bda0cc739cb 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -28,6 +28,8 @@ pub struct Rustc { pub version: semver::Version, /// The host triple (arch-platform-OS), this comes from verbose_version. pub host: InternedString, + /// The rustc full commit hash, this comes from version_version`. + pub commit_hash: String, cache: Mutex, } @@ -81,6 +83,18 @@ impl Rustc { verbose_version ) })?; + let commit_hash = { + let hash = extract("commit-hash: ")?; + assert!( + hash.chars().all(|ch| ch.is_ascii_hexdigit()), + "commit hash must be a hex string" + ); + assert!( + hash.len() == 40 || hash.len() == 64, + "hex string must be generated from sha1 or sha256" + ); + hash.to_string() + }; Ok(Rustc { path, @@ -89,6 +103,7 @@ impl Rustc { verbose_version, version, host, + commit_hash, cache: Mutex::new(cache), }) }