Skip to content

Commit 527678e

Browse files
committed
feat(rustc): parse and store commit-hash
1 parent e96176f commit 527678e

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 `verbose_version`.
32+
pub commit_hash: String,
3133
cache: Mutex<Cache>,
3234
}
3335

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

8498
Ok(Rustc {
8599
path,
@@ -88,6 +102,7 @@ impl Rustc {
88102
verbose_version,
89103
version,
90104
host,
105+
commit_hash,
91106
cache: Mutex::new(cache),
92107
})
93108
}

0 commit comments

Comments
 (0)