Fix determining Verilator revision when within git submodules without tags.

This commit is contained in:
Wilson Snyder 2025-11-03 18:36:20 -05:00
parent c299b71677
commit 1d9c5c2c6b
4 changed files with 38 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -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_*

View File

@ -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)