From 57276995b64b87bfa79d5102d2e8101b9b616fbc Mon Sep 17 00:00:00 2001 From: Jeppe Johansen Date: Wed, 8 May 2019 16:56:33 +0200 Subject: [PATCH 1/2] Add support for expanding environment variables. Signed-off-by: Jeppe Johansen --- sbysrc/sby_core.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index a66ea14..54e6c17 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -37,6 +37,14 @@ if os.name == "posix": signal.signal(signal.SIGINT, force_shutdown) signal.signal(signal.SIGTERM, force_shutdown) +def process_filename(filename): + if filename.startswith("~/"): + filename = os.environ['HOME'] + filename[1:] + + filename = os.path.expandvars(filename) + + return filename + class SbyTask: def __init__(self, job, info, deps, cmdline, logfile=None, logstderr=True): self.running = False @@ -290,8 +298,7 @@ class SbyJob: self.error("destination filename must be a relative path without /../: %s" % dstfile) dstfile = self.workdir + "/src/" + dstfile - if srcfile.startswith("~/"): - srcfile = os.environ['HOME'] + srcfile[1:] + srcfile = process_filename(srcfile) basedir = os.path.dirname(dstfile) if basedir != "" and not os.path.exists(basedir): From 021c3bb4c0fbc3638374222fd1b27f2ad271ced9 Mon Sep 17 00:00:00 2001 From: Jeppe Johansen Date: Wed, 8 May 2019 17:08:31 +0200 Subject: [PATCH 2/2] Add dumpfiles command line argument. Signed-off-by: Jeppe Johansen --- sbysrc/sby.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 70b5070..b45613f 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -19,7 +19,7 @@ import os, sys, getopt, shutil, tempfile ##yosys-sys-path## -from sby_core import SbyJob, SbyAbort +from sby_core import SbyJob, SbyAbort, process_filename from time import localtime sbyfile = None @@ -31,6 +31,7 @@ opt_tmpdir = False exe_paths = dict() throw_err = False dump_cfg = False +dump_files = False dump_tasks = False reusedir = False setupmode = False @@ -69,6 +70,9 @@ sby [options] [.sby [tasknames] | ] --dumpcfg print the pre-processed configuration file + --dumpfiles + print the input files of the pre-processed configuration file + --dumptasks print the list of tasks @@ -80,7 +84,7 @@ sby [options] [.sby [tasknames] | ] try: opts, args = getopt.getopt(sys.argv[1:], "d:btfT:E", ["yosys=", "abc=", "smtbmc=", "suprove=", "aigbmc=", "avy=", "btormc=", - "dumpcfg", "dumptasks", "setup"]) + "dumpcfg", "dumpfiles", "dumptasks", "setup"]) except: usage() @@ -113,6 +117,8 @@ for o, a in opts: exe_paths["btormc"] = a elif o == "--dumpcfg": dump_cfg = True + elif o == "--dumpfiles": + dump_files = True elif o == "--dumptasks": dump_tasks = True elif o == "--setup": @@ -270,6 +276,38 @@ if dump_cfg: print("\n".join(sbyconfig)) sys.exit(0) +if dump_files: + file_set = set() + + def find_files(taskname): + sbyconfig, _ = read_sbyconfig(sbydata, taskname) + + start_index = -1 + for i in range(len(sbyconfig)): + if sbyconfig[i].strip() == "[files]": + start_index = i + break + + if start_index == -1: + return + + for line in sbyconfig[start_index+1:]: + line = line.strip() + if line.startswith("["): + break + if line == "" or line.startswith("#"): + continue + filename = line.split()[-1] + file_set.add(process_filename(filename)) + + if len(tasknames): + for taskname in tasknames: + find_files(taskname) + else: + find_files(None) + print("\n".join(file_set)) + sys.exit(0) + if len(tasknames) == 0: _, tasknames = read_sbyconfig(sbydata, None) if len(tasknames) == 0: