Skip to content

Commit

Permalink
feat(rustc): parse and store commit-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Sep 8, 2023
1 parent af75652 commit 9e60b16
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cache>,
}

Expand Down Expand Up @@ -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,
Expand All @@ -89,6 +103,7 @@ impl Rustc {
verbose_version,
version,
host,
commit_hash,
cache: Mutex::new(cache),
})
}
Expand Down

0 comments on commit 9e60b16

Please sign in to comment.