From 1d9c5c2c6b5e177732a5617dec49ea8ade057c4b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 3 Nov 2025 18:36:20 -0500 Subject: [PATCH] Fix determining Verilator revision when within git submodules without tags. --- Changes | 1 + Makefile.in | 2 +- src/Makefile.in | 1 + src/config_rev | 58 +++++++++++++++++++++++++++++-------------------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Changes b/Changes index c2394d2fe..e1dcfea15 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,7 @@ Verilator 5.043 devel * Optimize away calls to empty functions (#6626). [Geza Lore] * Fix `--timing` with `--x-initial-edge` (#6603) (#6631). [Krzysztof Bieganski, Antmicro Ltd.] * Fix merging of impure assignments in gate optimization (#6629) (#6630). [Geza Lore] +* Fix determining Verilator revision when within git submodules without tags. Verilator 5.042 2025-11-02 diff --git a/Makefile.in b/Makefile.in index a1ec1d163..7a8aaf79a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -781,7 +781,7 @@ clean mostlyclean distclean maintainer-clean:: distclean maintainer-clean:: rm -f *.info* *.1 $(INFOS) $(INFOS_OLD) $(VL_INST_MAN_FILES) - rm -f Makefile config.status config.cache config.log TAGS + rm -f Makefile config.status config.cache config.log configure~ TAGS rm -f verilator_bin* verilator_coverage_bin* rm -f bin/verilator_bin* bin/verilator_coverage_bin* rm -f include/verilated.mk include/verilated_config.h diff --git a/src/Makefile.in b/src/Makefile.in index 1fb95ab68..41742f8b0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -108,6 +108,7 @@ clang-format: maintainer-copy:: clean mostlyclean distclean maintainer-clean:: + -rm -f config_rev.h -rm -rf obj_* *.log *.dmp *.vpd core -rm -f *.o *.d *_gen_* -rm -f *__gen* obj_* diff --git a/src/config_rev b/src/config_rev index 2b32b57d6..8c36d2197 100755 --- a/src/config_rev +++ b/src/config_rev @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # mypy: disallow-untyped-defs -# pylint: disable=C0103,C0114 +# pylint: disable=C0103,C0114,C0116 ###################################################################### # # Copyright 2005-2025 by Wilson Snyder. This program is free software; you @@ -17,32 +17,44 @@ import os import re import sys +from datetime import datetime, timezone + + +def get_rev() -> str: + if 'VERILATOR_SRC_VERSION' in os.environ: + # e.g. Ubuntu package build + return os.environ['VERILATOR_SRC_VERSION'] + + data = os.popen('git describe --always').read() + + result = "vUNKNOWN" + + m = re.search(r'^(v[0-9].*)', data) + if m: + # e.g. in a complate verilator checkout with tags + result = m.group(1) + result = re.sub('_', '.', result) + else: + # e.g. in a sparse submodule checkout without tags + m = re.search(r'^([a-f0-9]+)$', data) + if m: + result = "vUNKNOWN-" + datetime.now(timezone.utc).strftime("%Y%m%d") + "-" + m.group(1) + + data = os.popen('git status').read() + if (re.search('Changed but not updated', data, flags=re.IGNORECASE) + or re.search('Changes to be committed', data, flags=re.IGNORECASE) + or re.search('Changes not staged', data, flags=re.IGNORECASE)): + result += " (mod)" + + return result + + parser = argparse.ArgumentParser() parser.add_argument('directory') Args = parser.parse_args() os.chdir(Args.directory) -if 'VERILATOR_SRC_VERSION' in os.environ: - rev = os.environ['VERILATOR_SRC_VERSION'] -else: - rev = 'UNKNOWN_REV' - -data = os.popen('git describe').read() - -match = re.search(r'^(v[0-9].*)', data) -if match: - rev = match.group(1) -rev = re.sub('_', '.', rev) - -data = os.popen('git status').read() -if (re.search('Changed but not updated', data, flags=re.IGNORECASE) - or re.search('Changes to be committed', data, flags=re.IGNORECASE) - or re.search('Changes not staged', data, flags=re.IGNORECASE)): - rev += " (mod)" - +rev = get_rev() +print("config_rev using " + rev, file=sys.stderr) print("static const char* const DTVERSION_rev = \"" + rev + "\";") - -# Warn after the print, so at least the header has good contents -if re.search('UNKNOWN', rev): - print("%Warning: No git revision found in config_rev.py", file=sys.stderr)