[3.14] gh-142454: Make the JIT digest more deterministic by sorting the files in Tools/jit (GH-142455) (#142485)

gh-142454: Make the JIT digest more deterministic by sorting the files in Tools/jit (GH-142455)
(cherry picked from commit bcf90de8ba)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-12-09 19:50:53 +01:00 committed by GitHub
parent 8cb65ca1dd
commit 7621bbd828
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -0,0 +1,4 @@
When calculating the digest of the JIT stencils input, sort the hashed files
by filenames before adding their content to the hasher. This ensures
deterministic hash input and hence deterministic hash, independent on
filesystem order.

View file

@ -72,7 +72,7 @@ def _compute_digest(self) -> str:
# Exclude cache files from digest computation to ensure reproducible builds.
if dirpath.endswith("__pycache__"):
continue
for filename in filenames:
for filename in sorted(filenames):
hasher.update(pathlib.Path(dirpath, filename).read_bytes())
return hasher.hexdigest()