Skip to content

Commit 9e60b16

Browse files
committed
feat(rustc): parse and store commit-hash
1 parent af75652 commit 9e60b16

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/cargo/util/rustc.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub struct Rustc {
2828
pub version: semver::Version,
2929
/// The host triple (arch-platform-OS), this comes from verbose_version.
3030
pub host: InternedString,
31+
/// The rustc full commit hash, this comes from version_version`.
32+
pub commit_hash: String,
3133
cache: Mutex<Cache>,
3234
}
3335

@@ -81,6 +83,18 @@ impl Rustc {
8183
verbose_version
8284
)
8385
})?;
86+
let commit_hash = {
87+
let hash = extract("commit-hash: ")?;
88+
assert!(
89+
hash.chars().all(|ch| ch.is_ascii_hexdigit()),
90+
"commit hash must be a hex string"
91+
);
92+
assert!(
93+
hash.len() == 40 || hash.len() == 64,
94+
"hex string must be generated from sha1 or sha256"
95+
);
96+
hash.to_string()
97+
};
8498

8599
Ok(Rustc {
86100
path,
@@ -89,6 +103,7 @@ impl Rustc {
89103
verbose_version,
90104
version,
91105
host,
106+
commit_hash,
92107
cache: Mutex::new(cache),
93108
})
94109
}

0 commit comments

Comments
 (0)