Files
TheRock/compiler/amd-llvm/llvm/utils/gn/build/write_vcsrevision.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

102 lines
3.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Gets the current revision and writes it to VCSRevision.h."""
import argparse
import os
import subprocess
import sys
import shutil
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
LLVM_DIR = os.path.dirname(os.path.dirname(os.path.dirname(THIS_DIR)))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"-d",
"--depfile",
help="if set, writes a depfile that causes this script "
"to re-run each time the current revision changes",
)
parser.add_argument(
"--write-git-rev",
action="store_true",
help="if set, writes git revision, else writes #undef",
)
parser.add_argument(
"--name",
action="append",
help="if set, writes a depfile that causes this script "
"to re-run each time the current revision changes",
)
parser.add_argument("vcs_header", help="path to the output file to write")
args = parser.parse_args()
vcsrevision_contents = ""
if args.write_git_rev:
git, use_shell = shutil.which("git"), False
if not git:
git = shutil.which("git.exe")
if not git:
git, use_shell = shutil.which("git.bat"), True
git_dir = (
subprocess.check_output(
[git, "rev-parse", "--git-dir"], cwd=LLVM_DIR, shell=use_shell
)
.decode()
.strip()
)
if not os.path.isdir(git_dir):
print('.git dir not found at "%s"' % git_dir, file=sys.stderr)
return 1
rev = (
subprocess.check_output(
[git, "rev-parse", "--short", "HEAD"], cwd=git_dir, shell=use_shell
)
.decode()
.strip()
)
url = (
subprocess.check_output(
[git, "remote", "get-url", "origin"], cwd=git_dir, shell=use_shell
)
.decode()
.strip()
)
for name in args.name:
vcsrevision_contents += '#define %s_REVISION "%s"\n' % (name, rev)
vcsrevision_contents += '#define %s_REPOSITORY "%s"\n' % (name, url)
else:
for name in args.name:
vcsrevision_contents += "#undef %s_REVISION\n" % name
vcsrevision_contents += "#undef %s_REPOSITORY\n" % name
# If the output already exists and is identical to what we'd write,
# return to not perturb the existing file's timestamp.
if (
os.path.exists(args.vcs_header)
and open(args.vcs_header).read() == vcsrevision_contents
):
return 0
# http://neugierig.org/software/blog/2014/11/binary-revisions.html
if args.depfile:
build_dir = os.getcwd()
with open(args.depfile, "w") as depfile:
depfile.write(
"%s: %s\n"
% (
args.vcs_header,
os.path.relpath(os.path.join(git_dir, "logs", "HEAD"), build_dir),
)
)
open(args.vcs_header, "w").write(vcsrevision_contents)
if __name__ == "__main__":
sys.exit(main())