From eff141da2d9910fe2ad45724d6d96ba632eddce7 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 23 Apr 2019 06:03:12 +0200 Subject: [PATCH] build: add git version (sha-1) used to create the scripts --- litex/build/altera/quartus.py | 3 ++- litex/build/lattice/diamond.py | 4 ++-- litex/build/lattice/icestorm.py | 4 ++-- litex/build/lattice/trellis.py | 4 ++-- litex/build/microsemi/libero_soc.py | 4 ++-- litex/build/tools.py | 3 +++ litex/build/xilinx/ise.py | 4 ++-- litex/build/xilinx/vivado.py | 4 ++-- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/litex/build/altera/quartus.py b/litex/build/altera/quartus.py index b26f75968..e296fc4b6 100644 --- a/litex/build/altera/quartus.py +++ b/litex/build/altera/quartus.py @@ -111,7 +111,8 @@ 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 + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\n" + build_script_contents += """ set -e diff --git a/litex/build/lattice/diamond.py b/litex/build/lattice/diamond.py index 9160f8f00..34ed7b4d4 100644 --- a/litex/build/lattice/diamond.py +++ b/litex/build/lattice/diamond.py @@ -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\n\n" + build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n" copy_stmt = "copy" fail_stmt = " || exit /b" else: script_ext = ".sh" - build_script_contents = "# Autogenerated by LiteX\nset -e\n\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n" copy_stmt = "cp" fail_stmt = "" diff --git a/litex/build/lattice/icestorm.py b/litex/build/lattice/icestorm.py index 3f4ccc973..3983c7caf 100644 --- a/litex/build/lattice/icestorm.py +++ b/litex/build/lattice/icestorm.py @@ -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\n\n" + build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n" fail_stmt = " || exit /b" else: script_ext = ".sh" - build_script_contents = "# Autogenerated by LiteX\nset -e\n\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n" fail_stmt = "" for s in build_template: diff --git a/litex/build/lattice/trellis.py b/litex/build/lattice/trellis.py index d1ad5b783..570f9c88e 100644 --- a/litex/build/lattice/trellis.py +++ b/litex/build/lattice/trellis.py @@ -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\n\n" + build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n" fail_stmt = " || exit /b" else: script_ext = ".sh" - build_script_contents = "# Autogenerated by LiteX\nset -e\n\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n" fail_stmt = "" for s in build_template: diff --git a/litex/build/microsemi/libero_soc.py b/litex/build/microsemi/libero_soc.py index c3e42f449..0dbf2e946 100644 --- a/litex/build/microsemi/libero_soc.py +++ b/litex/build/microsemi/libero_soc.py @@ -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\n\n" + build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n\n" copy_stmt = "copy" fail_stmt = " || exit /b" else: script_ext = ".sh" - build_script_contents = "# Autogenerated by LiteX\n\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\n" copy_stmt = "cp" fail_stmt = " || exit 1" diff --git a/litex/build/tools.py b/litex/build/tools.py index 313abaea4..bfa8108b0 100644 --- a/litex/build/tools.py +++ b/litex/build/tools.py @@ -88,3 +88,6 @@ if sys.platform == "cygwin": else: def cygpath(p): return p + +def git_version(): + return subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8") diff --git a/litex/build/xilinx/ise.py b/litex/build/xilinx/ise.py index 0242279d4..cd3e2d183 100644 --- a/litex/build/xilinx/ise.py +++ b/litex/build/xilinx/ise.py @@ -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\n" + build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.git_version() + "\n" fail_stmt = " || exit /b" else: source_cmd = "source " script_ext = ".sh" shell = ["bash"] - build_script_contents = "# Autogenerated by LiteX\nset -e\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\nset -e\n" fail_stmt = "" if source: settings = common.settings(ise_path, ver, "ISE_DS") diff --git a/litex/build/xilinx/vivado.py b/litex/build/xilinx/vivado.py index d04ff2d45..93e6fe22e 100644 --- a/litex/build/xilinx/vivado.py +++ b/litex/build/xilinx/vivado.py @@ -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\n" + build_script_contents = "REM Autogenerated by LiteX / git: " + tools.git_version() + "\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\nset -e\n" + build_script_contents = "# Autogenerated by LiteX / git: " + tools.git_version() + "\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