Skip to content

Commit 5f6d07b

Browse files
committed
Auto merge of rust-lang#13222 - dtolnay-contrib:deterministic, r=flip1995
Use a deterministic number of digits in rustc_tools_util commit hashes Using `git rev-parse --short` in rustc_tools_util causes nondeterministic compilation of projects that use `setup_version_info!` and `get_version_info!` when built from the exact same source code and git commit. The number of digits printed by `--short` is sensitive to how many other branches and tags in the repository have been fetched so far, what other commits have been worked on in other branches, how recently you had run `git gc`, platform-specific variation in git's default configuration, and platform differences in the sequence of steps performed by the release pipeline. Someone can compile a tool from a particular commit, switch branches to work on a different commit (or simply do a git fetch), go back to the first commit and be unable to reproduce the binary that was built from it previously. Currently, variation in short commit hashes causes Clippy version strings to be out of sync between different targets. On x86_64-unknown-linux-gnu: ```console $ clippy-driver +1.80.0 --version clippy 0.1.80 (0514789 2024-07-21) ``` Whereas on aarch64-apple-darwin: ```console $ clippy-driver +1.80.0 --version clippy 0.1.80 (0514789 2024-07-21) ``` --- changelog: none
2 parents c082bc2 + 9f6536c commit 5f6d07b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

rustc_tools_util/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ impl std::fmt::Debug for VersionInfo {
104104
#[must_use]
105105
pub fn get_commit_hash() -> Option<String> {
106106
let output = std::process::Command::new("git")
107-
.args(["rev-parse", "--short", "HEAD"])
107+
.args(["rev-parse", "HEAD"])
108108
.output()
109109
.ok()?;
110-
let stdout = output.status.success().then_some(output.stdout)?;
110+
let mut stdout = output.status.success().then_some(output.stdout)?;
111+
stdout.truncate(10);
111112
String::from_utf8(stdout).ok()
112113
}
113114

0 commit comments

Comments
 (0)