build: add sha-1/date to generated verilog, change git_version to git_revision
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 23 Apr 2019 10:59:25 +0000 (12:59 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 23 Apr 2019 10:59:25 +0000 (12:59 +0200)
litex/build/altera/quartus.py
litex/build/lattice/diamond.py
litex/build/lattice/icestorm.py
litex/build/lattice/trellis.py
litex/build/microsemi/libero_soc.py
litex/build/tools.py
litex/build/xilinx/ise.py
litex/build/xilinx/vivado.py
litex/gen/fhdl/verilog.py

index e296fc4b6476e08ab9b2f191060c5503e6e2d4cf..29f695eb276828b84beb08faeb478b353a77bf5a 100644 (file)
@@ -111,7 +111,7 @@ def _build_files(device, sources, vincpaths, named_sc, named_pc, build_name):
 
 
 def _run_quartus(build_name, quartus_path):
-    build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\n"
+    build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\n"
     build_script_contents += """
 
 set -e
index 34ed7b4d4391e900da8b54744e9e291057767df9..56179faa91588bb206068410a5eb38c6c5b57df0 100644 (file)
@@ -72,12 +72,12 @@ def _build_files(device, sources, vincpaths, build_name):
 def _build_script(build_name, device, toolchain_path, ver=None):
     if sys.platform in ("win32", "cygwin"):
         script_ext = ".bat"
-        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_revision() + "\n\n"
         copy_stmt = "copy"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
         copy_stmt = "cp"
         fail_stmt = ""
 
index 3983c7cafc7ebe7aaf265f2fbe475bda12790be5..71d3d97358cf75aa582c31e1ce90fb1630de6d7c 100644 (file)
@@ -35,11 +35,11 @@ def _build_pre_pack(vns, freq_cstrs):
 def _build_script(source, build_template, build_name, **kwargs):
     if sys.platform in ("win32", "cygwin"):
         script_ext = ".bat"
-        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_revision() + "\n\n"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
         fail_stmt = ""
 
     for s in build_template:
index 570f9c88e52e783464b4218baed4fe844b45ca8a..2790b28d74fc63726704c18b5adb19ffa38b4624 100644 (file)
@@ -75,11 +75,11 @@ def _build_script(source, build_template, build_name, architecture,
                   package, freq_constraint):
     if sys.platform in ("win32", "cygwin"):
         script_ext = ".bat"
-        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_revision() + "\n\n"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
         fail_stmt = ""
 
     for s in build_template:
index 0dbf2e9465f57a9f327d19a3ce086cc26d4bf009..e38e0590b185f47e0d825b2859eb498406c0e95a 100644 (file)
@@ -181,12 +181,12 @@ def _build_timing_sdc(vns, clocks, false_paths, build_name, additional_timing_co
 def _build_script(build_name, device, toolchain_path, ver=None):
     if sys.platform in ("win32", "cygwin"):
         script_ext = ".bat"
-        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_revision() + "\n\n"
         copy_stmt = "copy"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\n"
         copy_stmt = "cp"
         fail_stmt = " || exit 1"
 
index bfa8108b0706a585f0c330e9d3c08acf12c313aa..d0d90c7fb9236b67a1ac2a23ddd96a8cf55a1d59 100644 (file)
@@ -89,5 +89,5 @@ else:
     def cygpath(p):
         return p
 
-def git_version():
-    return subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8")
+def git_revision():
+    return subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).strip().decode("utf-8")
index 0bb19d4988893ce8d1ecba20bfd6cb2fc87f5670..bbf9a5b589dcedf8b7157181e516cc8503e842bb 100644 (file)
@@ -91,13 +91,13 @@ def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
         source_cmd = "call "
         script_ext = ".bat"
         shell = ["cmd", "/c"]
-        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_revision() + "\n"
         fail_stmt = " || exit /b"
     else:
         source_cmd = "source "
         script_ext = ".sh"
         shell = ["bash"]
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
         fail_stmt = ""
     if source:
         settings = common.settings(ise_path, ver, "ISE_DS")
index 93e6fe22eb6b3bab59cb74d192982b1e6fa6361c..4a940021e6961c010c872e255c18218e757a448f 100644 (file)
@@ -58,13 +58,13 @@ def _build_xdc(named_sc, named_pc):
 
 def _run_vivado(build_name, vivado_path, source, ver=None):
     if sys.platform == "win32" or sys.platform == "cygwin":
-        build_script_contents = "REM Autogenerated by LiteX / git: " + tools.git_version() + "\n"
+        build_script_contents = "REM Autogenerated by LiteX / git: " + tools.git_revision() + "\n"
         build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
         build_script_file = "build_" + build_name + ".bat"
         tools.write_to_file(build_script_file, build_script_contents)
         command = build_script_file
     else:
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
         # Only source Vivado settings if not already in our $PATH
         if not find_executable("vivado"):
             # For backwards compatibility with ISE paths, also
index 773c763f14b78c7722fd9fc4fb410f5aa926552c..6ab317a7659657d08627cef4093998e2317d75f6 100644 (file)
@@ -1,6 +1,8 @@
 from functools import partial
 from operator import itemgetter
 import collections
+import time
+import datetime
 
 from migen.fhdl.structure import *
 from migen.fhdl.structure import _Operator, _Slice, _Assign, _Fragment
@@ -8,6 +10,8 @@ from migen.fhdl.tools import *
 from migen.fhdl.namer import build_namespace
 from migen.fhdl.conv_output import ConvOutput
 
+from litex.build.tools import git_revision
+
 
 _reserved_keywords = {
     "always", "and", "assign", "automatic", "begin", "buf", "bufif0", "bufif1",
@@ -402,7 +406,12 @@ def convert(f, ios=None, name="top",
     ns.clock_domains = f.clock_domains
     r.ns = ns
 
-    src = "/* Machine-generated using LiteX gen */\n"
+    src = "//" + "-"*60 + "\n"
+    src +=  "// Generated by Migen & LiteX / ".format(git_revision())
+    src += git_revision() + " / "
+    src += "{}\n".format(datetime.datetime.fromtimestamp(
+                time.time()).strftime("%Y-%m-%d %H:%M:%S"))
+    src += "//" + "-"*60 + "\n"
     src += _printheader(f, ios, name, ns, attr_translate,
                         reg_initialization=reg_initialization)
     if regular_comb: