build: add migen and litex git revision to generated file
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 23 Apr 2019 15:40:24 +0000 (17:40 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 23 Apr 2019 15:40:24 +0000 (17:40 +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

index 29f695eb276828b84beb08faeb478b353a77bf5a..b34de9c175bfc17238df709846fd15f6e67c9656 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_revision() + "\n"
+    build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
     build_script_contents += """
 
 set -e
index 56179faa91588bb206068410a5eb38c6c5b57df0..95e634d2820f44d1e21b3b992948c0f024b22813 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_revision() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
         copy_stmt = "copy"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
         copy_stmt = "cp"
         fail_stmt = ""
 
index 71d3d97358cf75aa582c31e1ce90fb1630de6d7c..90bbdefaf42ed5ee9507f3a7bbc743e82a6a9939 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_revision() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
         fail_stmt = ""
 
     for s in build_template:
index 2790b28d74fc63726704c18b5adb19ffa38b4624..6558466a447470b7cd9730e6aa3fb0158d54c5d2 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_revision() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
         fail_stmt = ""
 
     for s in build_template:
index e38e0590b185f47e0d825b2859eb498406c0e95a..670a0c331018c9559817ce86d665bd1bc65910e1 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_revision() + "\n\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
         copy_stmt = "copy"
         fail_stmt = " || exit /b"
     else:
         script_ext = ".sh"
-        build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_revision() + "\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
         copy_stmt = "cp"
         fail_stmt = " || exit 1"
 
index da8631b97029089d2adce93e53cb75da7ba7ac47..5cd92eb434663ac71c2a5e3aa33c3e25b13ed5a3 100644 (file)
@@ -91,13 +91,27 @@ else:
     def cygpath(p):
         return p
 
-def git_revision():
-    return "--------"
+def get_migen_get_revision():
+    import migen
+    d = os.getcwd()
+    os.chdir(os.path.dirname(migen.__file__))
+    r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    os.chdir(d)
+    return r
+
+def get_litex_get_revision():
+    import litex
+    d = os.getcwd()
+    os.chdir(os.path.dirname(litex.__file__))
+    r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])[:-1].decode("utf-8")
+    os.chdir(d)
+    return r
 
 def generated_banner(line_comment="//"):
-    r = line_comment + "-"*60 + "\n"
-    r += line_comment + " Generated by Migen & LiteX / "
-    r += git_revision() + " / "
+    r = line_comment + "-"*80 + "\n"
+    r += line_comment + " Auto-generated by Migen ({}) & LiteX ({}) on ".format(
+        get_migen_get_revision(),
+        get_litex_get_revision())
     r += "{}\n".format(datetime.datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S"))
-    r += line_comment + "-"*60 + "\n"
+    r += line_comment + "-"*80 + "\n"
     return r
\ No newline at end of file
index bbf9a5b589dcedf8b7157181e516cc8503e842bb..9a048575918cc81e6fca26c9ec5e62e9a5c49946 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_revision() + "\n"
+        build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_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_revision() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
         fail_stmt = ""
     if source:
         settings = common.settings(ise_path, ver, "ISE_DS")
index 4a940021e6961c010c872e255c18218e757a448f..fb039d0ef0962f9f5a7e3e1d0e5339a9f76b0636 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_revision() + "\n"
+        build_script_contents = "REM Autogenerated by LiteX / git: " + tools.get_litex_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_revision() + "\nset -e\n"
+        build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_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