update_build_version.py produce deterministic header. (#5426)

When building, .git directory may not exist in current
directory (e.g. chromium build), so it will produce
with current timestamp, which becomes non-deterministic build.

Check if repo_path is in git repository and use git info.
Also fix fallback logic when 'git describe' failed.
'git rev-parse HEAD' result was not used because it didn't
update success.
This commit is contained in:
Fumitoshi Ukai 2023-10-19 01:49:51 +09:00 committed by GitHub
parent 5bb595091b
commit a9c61d1376
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,10 +112,11 @@ def describe(repo_path):
successful, returns the output; otherwise returns 'unknown hash, <date>'."""
# if we're in a git repository, attempt to extract version info
if os.path.exists(".git"):
success, output = command_output(["git", "rev-parse", "--show-toplevel"], repo_path)
if success:
success, output = command_output(["git", "describe"], repo_path)
if not success:
output = command_output(["git", "rev-parse", "HEAD"], repo_path)
success, output = command_output(["git", "rev-parse", "HEAD"], repo_path)
if success:
# decode() is needed here for Python3 compatibility. In Python2,