From d31f468ad8733712db5b247299fdd4108adf07a4 Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Mon, 6 Oct 2025 17:17:51 +0200 Subject: [PATCH] Revert "meson: use vcs_tag() instead of custom script" This reverts commit e4edf9203b3fb5b7fe27de404c5b4a200b2a3ecc. Meson is unfortunately not quite ready yet, and prints stderr noise when _not_ building from a git clone. Part-of: --- .gitlab-ci.yml | 1 + bin/git_sha1_gen.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ bin/meson.build | 1 + src/git_sha1.h.in | 1 - src/meson.build | 9 ++++---- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 bin/git_sha1_gen.py delete mode 100644 src/git_sha1.h.in diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 71c0c77b559..17784cf9005 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -290,6 +290,7 @@ include: - if: *is-merge-attempt changes: &all_paths - VERSION + - bin/git_sha1_gen.py - bin/install_megadrivers.py - bin/symbols-check.py - bin/ci/**/* diff --git a/bin/git_sha1_gen.py b/bin/git_sha1_gen.py new file mode 100644 index 00000000000..a457b310d48 --- /dev/null +++ b/bin/git_sha1_gen.py @@ -0,0 +1,50 @@ +""" +Generate the contents of the git_sha1.h file. +""" + +import argparse +import os +import os.path +import subprocess +import sys + + +def get_git_sha1(): + """Try to get the git SHA1 with git rev-parse.""" + git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git') + try: + git_sha1 = subprocess.check_output([ + 'git', + '--git-dir=' + git_dir, + 'rev-parse', + 'HEAD', + ], stderr=open(os.devnull, 'w')).decode("ascii") + except Exception: + # don't print anything if it fails + git_sha1 = '' + return git_sha1 + + +def write_if_different(contents): + """ + Avoid touching the output file if it doesn't need modifications + Useful to avoid triggering rebuilds when nothing has changed. + """ + if os.path.isfile(args.output): + with open(args.output, 'r') as file: + if file.read() == contents: + return + with open(args.output, 'w') as file: + file.write(contents) + + +parser = argparse.ArgumentParser() +parser.add_argument('--output', help='File to write the #define in', + required=True) +args = parser.parse_args() + +git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10] +if git_sha1: + write_if_different('#define MESA_GIT_SHA1 " (git-' + git_sha1 + ')"') +else: + write_if_different('#define MESA_GIT_SHA1 ""') diff --git a/bin/meson.build b/bin/meson.build index 8749a69c349..e6664d7fe74 100644 --- a/bin/meson.build +++ b/bin/meson.build @@ -1,6 +1,7 @@ # Copyright © 2017 Eric Engestrom # SPDX-License-Identifier: MIT +git_sha1_gen_py = files('git_sha1_gen.py') gen_vs_module_defs_py = files('gen_vs_module_defs.py') gen_vs_module_defs_normal_command = [ prog_python, gen_vs_module_defs_py, diff --git a/src/git_sha1.h.in b/src/git_sha1.h.in deleted file mode 100644 index 1cc80cccb63..00000000000 --- a/src/git_sha1.h.in +++ /dev/null @@ -1 +0,0 @@ -#define MESA_GIT_SHA1 @VCS_TAG@ diff --git a/src/meson.build b/src/meson.build index ae9dcffad6d..fdfb2dc246f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,11 +33,12 @@ glsl_util_files = files( 'mesa/program/dummy_errors.c', ) -sha1_h = vcs_tag( - input : 'git_sha1.h.in', +sha1_h = custom_target( + 'git_sha1.h', output : 'git_sha1.h', - command : ['git', 'show', '--no-patch', '--abbrev=10', '--format=" (git-%h)"'], - fallback : '""', + command : [prog_python, git_sha1_gen_py, '--output', '@OUTPUT@'], + build_by_default : true, + build_always_stale : true, # commit sha1 can change without having touched these files ) if cc.get_argument_syntax() == 'msvc'