From: Clifford Wolf Date: Thu, 27 Jun 2019 11:55:25 +0000 (+0200) Subject: Merge branch 'feature_file_paths' of https://github.com/gs-jgj/SymbiYosys into staging X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cc37c497d5757aae7a47ff39c55256d54884d344;p=SymbiYosys.git Merge branch 'feature_file_paths' of https://github.com/gs-jgj/SymbiYosys into staging --- cc37c497d5757aae7a47ff39c55256d54884d344 diff --cc sbysrc/sby.py index d82b7a3,b45613f..53212d7 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@@ -17,78 -17,117 +17,81 @@@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # -import os, sys, getopt, shutil, tempfile +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 -sbyfile = None -workdir = None -tasknames = list() -opt_force = False -opt_backup = False -opt_tmpdir = False -exe_paths = dict() -throw_err = False -dump_cfg = False -dump_files = False -dump_tasks = False +class DictAction(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + assert isinstance(getattr(namespace, self.dest), dict), "Use ArgumentParser.set_defaults() to initialize {} to dict()".format(self.dest) + name = option_string.lstrip(parser.prefix_chars).replace("-", "_") + getattr(namespace, self.dest)[name] = values + +parser = argparse.ArgumentParser(prog="sby", + usage="%(prog)s [options] [.sby [tasknames] | ]") +parser.set_defaults(exe_paths=dict()) + +parser.add_argument("-d", metavar="", dest="workdir", + help="set workdir name (ignored if is given as a positional argument). default: (without .sby)") +parser.add_argument("-f", action="store_true", dest="force", + help="remove workdir if it already exists") +parser.add_argument("-b", action="store_true", dest="backup", + help="backup workdir if it already exists") +parser.add_argument("-t", action="store_true", dest="tmpdir", + help="run in a temporary workdir (remove when finished)") +parser.add_argument("-T", metavar="", action="append", dest="tasknames", + default=list(), + help="add taskname (useful when sby file is read from stdin, ignored if tasknames are given as positional arguments)") +parser.add_argument("-E", action="store_true", dest="throw_err", + help="throw an exception (incl stack trace) for most errors") + +parser.add_argument("--yosys", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--abc", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--smtbmc", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--suprove", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--aigbmc", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--avy", metavar="", + action=DictAction, dest="exe_paths") +parser.add_argument("--btormc", metavar="", + action=DictAction, dest="exe_paths", + help="configure which executable to use for the respective tool") +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") + +parser.add_argument("sbyfile", metavar=".sby | ", nargs="?", + help=".sby file OR directory containing config.sby file (causes -d to be ignored if is used)") +parser.add_argument("arg_tasknames", metavar="tasknames", nargs="*", + help="tasks to run (only valid when is used, causes -T to be ignored)") + +args = parser.parse_args() + +sbyfile = args.sbyfile +workdir = args.workdir +tasknames = args.arg_tasknames if args.arg_tasknames else args.tasknames +opt_force = args.force +opt_backup = args.backup +opt_tmpdir = args.tmpdir +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 = False - -def usage(): - print(""" -sby [options] [.sby [tasknames] | ] - - -d - set workdir name. default: (without .sby) - - -f - remove workdir if it already exists - - -b - backup workdir if it already exists - - -t - run in a temporary workdir (remove when finished) - - -T taskname - add taskname (useful when sby file is read from stdin) - - -E - throw an exception (incl stack trace) for most errors - - --yosys - --abc - --smtbmc - --suprove - --aigbmc - --avy - --btormc - configure which executable to use for the respective tool - - --dumpcfg - print the pre-processed configuration file - - --dumpfiles - print the input files of the pre-processed configuration file - - --dumptasks - print the list of tasks - - --setup - set up the working directory and exit -""") - sys.exit(1) - -try: - opts, args = getopt.getopt(sys.argv[1:], "d:btfT:E", ["yosys=", - "abc=", "smtbmc=", "suprove=", "aigbmc=", "avy=", "btormc=", - "dumpcfg", "dumpfiles", "dumptasks", "setup"]) -except: - usage() - -for o, a in opts: - if o == "-d": - workdir = a - elif o == "-f": - opt_force = True - elif o == "-b": - opt_backup = True - elif o == "-t": - opt_tmpdir = True - elif o == "-T": - tasknames.append(a) - elif o == "-E": - throw_err = True - elif o == "--yosys": - exe_paths["yosys"] = a - elif o == "--abc": - exe_paths["abc"] = a - elif o == "--smtbmc": - exe_paths["smtbmc"] = a - elif o == "--suprove": - exe_paths["suprove"] = a - elif o == "--aigbmc": - exe_paths["aigbmc"] = a - elif o == "--avy": - exe_paths["avy"] = a - elif o == "--btormc": - 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": - setupmode = True - else: - usage() - -if len(args) > 0: - sbyfile = args[0] +setupmode = args.setupmode + +if sbyfile is not None: if os.path.isdir(sbyfile): workdir = sbyfile sbyfile += "/config.sby" @@@ -110,7 -149,10 +113,6 @@@ print("ERROR: Sby file does not have .sby file extension.", file=sys.stderr) sys.exit(1) -if len(args) > 1: - tasknames = args[1:] - -- early_logmsgs = list() def early_log(workdir, msg):