Commit 13c5a2bd authored by Dimitris Lampridis's avatar Dimitris Lampridis

tools: add version info from tag to gen_sourceid.py

parent 9f42c8dd
......@@ -8,6 +8,7 @@
with open("sourceid_{}_pkg.vhd".format(project), "w") as f:
import subprocess
import time
import re
# Extract current commit id.
try:
......@@ -26,6 +27,12 @@ with open("sourceid_{}_pkg.vhd".format(project), "w") as f:
except:
dirty = True
try:
version = re.search("\d+\.\d+\.\d+", tag)
major,minor,patch = [int(x) for x in version.group().split('.')]
except:
major = minor = patch = 0
if dirty:
# There is no room for a dirty flag, just erase half of the bytes, so
# that's obvious it's not a real sha1, and still leaves enough to
......@@ -42,4 +49,6 @@ with open("sourceid_{}_pkg.vhd".format(project), "w") as f:
f.write("package sourceid_{}_pkg is\n".format(project))
f.write(" constant sourceid : std_logic_vector(127 downto 0) :=\n")
f.write(' x"{}";\n'.format(sourceid))
f.write(" constant version : std_logic_vector(31 downto 0) := ")
f.write('x"{:02x}{:02x}{:04x}";\n'.format(major & 0xff, minor & 0xff, patch & 0xffff))
f.write('end sourceid_{}_pkg;\n'.format(project))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment