diff --git a/sbysrc/sby.py b/sbysrc/sby.py index d82b7a3..53212d7 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -19,7 +19,7 @@ import argparse, os, sys, shutil, tempfile ##yosys-sys-path## -from sby_core import SbyJob, SbyAbort +from sby_core import SbyJob, SbyAbort, process_filename from time import localtime class DictAction(argparse.Action): @@ -65,6 +65,8 @@ parser.add_argument("--dumpcfg", action="store_true", dest="dump_cfg", help="print the pre-processed configuration file") parser.add_argument("--dumptasks", action="store_true", dest="dump_tasks", help="print the list of tasks") +parser.add_argument("--dumpfiles", action="store_true", dest="dump_files", + help="print the list of source files") parser.add_argument("--setup", action="store_true", dest="setupmode", help="set up the working directory and exit") @@ -85,6 +87,7 @@ exe_paths = args.exe_paths throw_err = args.throw_err dump_cfg = args.dump_cfg dump_tasks = args.dump_tasks +dump_files = args.dump_files reusedir = False setupmode = args.setupmode @@ -110,7 +113,6 @@ if sbyfile is not None: print("ERROR: Sby file does not have .sby file extension.", file=sys.stderr) sys.exit(1) - early_logmsgs = list() def early_log(workdir, msg): @@ -234,6 +236,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: 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):