From fe5390bbb850205400b056993a08cb3a7495ab1c Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 8 Jul 2024 12:27:35 +0200 Subject: [PATCH] Add --version option based on git describe --- .gitattributes | 1 + .gittag | 1 + Makefile | 10 +++++++++- src/eqy.py | 7 ++++++- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .gittag diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b9b5a29 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +/.gittag export-subst diff --git a/.gittag b/.gittag new file mode 100644 index 0000000..f4034a5 --- /dev/null +++ b/.gittag @@ -0,0 +1 @@ +$Format:%(describe)$ diff --git a/Makefile b/Makefile index 3018439..61aa8d1 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,12 @@ ifeq ($(OS), Windows_NT) PYTHON = $(shell cygpath -w -m $(PREFIX)/bin/python3) endif +ifeq ($(file < .gittag),$$Format:%(describe)$$) +YOSYS_RELEASE_VERSION := EQY $(shell git describe --dirty) +else +YOSYS_RELEASE_VERSION := EQY $(file < .gittag) +endif + build: src/eqy_combine.so src/eqy_partition.so src/eqy_recode.so DEBUG_CXXFLAGS := @@ -41,10 +47,12 @@ install: src/eqy_combine.so src/eqy_partition.so src/eqy_recode.so cp src/eqy_recode.so $(DESTDIR)$(PREFIX)/share/yosys/plugins/ ifeq ($(OS), Windows_NT) sed -e 's|##yosys-sys-path##|sys.path += [os.path.dirname(__file__) + p for p in ["/share/python3", "/../share/yosys/python3"]]|;' \ + -e "s|##yosys-release-version##|release_version = '$(YOSYS_RELEASE_VERSION)'|;" \ -e "s|#!/usr/bin/env python3|#!$(PYTHON)|" < src/eqy.py > $(DESTDIR)$(PREFIX)/bin/eqy-script.py gcc -DGUI=0 -O -s -o $(DESTDIR)$(PREFIX)/bin/eqy.exe extern/launcher.c else - sed 's|##yosys-sys-path##|sys.path += [os.path.dirname(__file__) + p for p in ["/share/python3", "/../share/yosys/python3"]]|;' < src/eqy.py > $(DESTDIR)$(PREFIX)/bin/eqy + sed -e 's|##yosys-sys-path##|sys.path += [os.path.dirname(__file__) + p for p in ["/share/python3", "/../share/yosys/python3"]]|;' \ + -e "s|##yosys-release-version##|release_version = '$(YOSYS_RELEASE_VERSION)'|;" < src/eqy.py > $(DESTDIR)$(PREFIX)/bin/eqy chmod +x $(DESTDIR)$(PREFIX)/bin/eqy endif diff --git a/src/eqy.py b/src/eqy.py index facd501..b555db7 100644 --- a/src/eqy.py +++ b/src/eqy.py @@ -25,6 +25,9 @@ from eqy_job import EqyJob, EqyTask +release_version = 'unknown EQY version' +##yosys-release-version## + def exit_with_error(error, retcode=1): print("ERROR:", error, file=sys.stderr) exit(retcode) @@ -102,6 +105,8 @@ def parse_args(ctx): action=DictAction, dest="exe_paths", help="configure which executable to use for the respective tool") + parser.add_argument('--version', action='version', version=release_version) + ctx.args = parser.parse_args() exe_paths = { @@ -1183,7 +1188,7 @@ def main(): build_recode(ctx.args, ctx, ctx.job) else: shutil.copyfile(f"{ctx.args.workdir}/gate.il", f"{ctx.args.workdir}/gate_recoded.il") - + build_combined(ctx.args, ctx, ctx.job) ctx.gold_ids = read_ids(ctx.args.workdir + "/gold.ids")