mirror of
https://github.com/YosysHQ/sby.git
synced 2025-04-05 22:14:08 +00:00
Add --dumptaskinfo option to output some .sby metadata as json
This commit is contained in:
parent
a190994098
commit
6daa434d85
|
@ -17,9 +17,9 @@
|
|||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
import argparse, os, sys, shutil, tempfile, re
|
||||
import argparse, json, os, sys, shutil, tempfile, re
|
||||
##yosys-sys-path##
|
||||
from sby_core import SbyTask, SbyAbort, process_filename
|
||||
from sby_core import SbyConfig, SbyTask, SbyAbort, process_filename
|
||||
import time, platform
|
||||
|
||||
class DictAction(argparse.Action):
|
||||
|
@ -72,6 +72,8 @@ parser.add_argument("--dumptasks", action="store_true", dest="dump_tasks",
|
|||
help="print the list of tasks")
|
||||
parser.add_argument("--dumpdefaults", action="store_true", dest="dump_defaults",
|
||||
help="print the list of default tasks")
|
||||
parser.add_argument("--dumptaskinfo", action="store_true", dest="dump_taskinfo",
|
||||
help="output a summary of tasks as JSON")
|
||||
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",
|
||||
|
@ -102,6 +104,7 @@ dump_cfg = args.dump_cfg
|
|||
dump_tags = args.dump_tags
|
||||
dump_tasks = args.dump_tasks
|
||||
dump_defaults = args.dump_defaults
|
||||
dump_taskinfo = args.dump_taskinfo
|
||||
dump_files = args.dump_files
|
||||
reusedir = False
|
||||
setupmode = args.setupmode
|
||||
|
@ -367,6 +370,21 @@ if dump_tasks or dump_defaults or dump_tags:
|
|||
print(name)
|
||||
sys.exit(0)
|
||||
|
||||
if dump_taskinfo:
|
||||
_, _, tasknames, _ = read_sbyconfig(sbydata, None)
|
||||
taskinfo = {}
|
||||
for taskname in tasknames or [None]:
|
||||
task_sbyconfig, _, _, _ = read_sbyconfig(sbydata, taskname)
|
||||
taskinfo[taskname or ""] = info = {}
|
||||
cfg = SbyConfig()
|
||||
cfg.parse_config(task_sbyconfig)
|
||||
taskinfo[taskname or ""] = {
|
||||
"mode": cfg.options.get("mode"),
|
||||
"engines": cfg.engines,
|
||||
}
|
||||
print(json.dumps(taskinfo, indent=2))
|
||||
sys.exit(0)
|
||||
|
||||
if len(tasknames) == 0:
|
||||
_, _, tasknames, _ = read_sbyconfig(sbydata, None)
|
||||
if len(tasknames) == 0:
|
||||
|
|
|
@ -209,14 +209,110 @@ class SbyAbort(BaseException):
|
|||
pass
|
||||
|
||||
|
||||
class SbyTask:
|
||||
def __init__(self, sbyconfig, workdir, early_logs, reusedir):
|
||||
class SbyConfig:
|
||||
def __init__(self):
|
||||
self.options = dict()
|
||||
self.used_options = set()
|
||||
self.engines = list()
|
||||
self.script = list()
|
||||
self.files = dict()
|
||||
self.verbatim_files = dict()
|
||||
pass
|
||||
|
||||
def parse_config(self, f):
|
||||
mode = None
|
||||
|
||||
for line in f:
|
||||
raw_line = line
|
||||
if mode in ["options", "engines", "files"]:
|
||||
line = re.sub(r"\s*(\s#.*)?$", "", line)
|
||||
if line == "" or line[0] == "#":
|
||||
continue
|
||||
else:
|
||||
line = line.rstrip()
|
||||
# print(line)
|
||||
if mode is None and (len(line) == 0 or line[0] == "#"):
|
||||
continue
|
||||
match = re.match(r"^\s*\[(.*)\]\s*$", line)
|
||||
if match:
|
||||
entries = match.group(1).split()
|
||||
if len(entries) == 0:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
|
||||
if entries[0] == "options":
|
||||
mode = "options"
|
||||
if len(self.options) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "engines":
|
||||
mode = "engines"
|
||||
if len(self.engines) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "script":
|
||||
mode = "script"
|
||||
if len(self.script) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "file":
|
||||
mode = "file"
|
||||
if len(entries) != 2:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
current_verbatim_file = entries[1]
|
||||
if current_verbatim_file in self.verbatim_files:
|
||||
self.error(f"duplicate file: {entries[1]}")
|
||||
self.verbatim_files[current_verbatim_file] = list()
|
||||
continue
|
||||
|
||||
if entries[0] == "files":
|
||||
mode = "files"
|
||||
if len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
|
||||
if mode == "options":
|
||||
entries = line.split()
|
||||
if len(entries) != 2:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
self.options[entries[0]] = entries[1]
|
||||
continue
|
||||
|
||||
if mode == "engines":
|
||||
entries = line.split()
|
||||
self.engines.append(entries)
|
||||
continue
|
||||
|
||||
if mode == "script":
|
||||
self.script.append(line)
|
||||
continue
|
||||
|
||||
if mode == "files":
|
||||
entries = line.split()
|
||||
if len(entries) == 1:
|
||||
self.files[os.path.basename(entries[0])] = entries[0]
|
||||
elif len(entries) == 2:
|
||||
self.files[entries[0]] = entries[1]
|
||||
else:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if mode == "file":
|
||||
self.verbatim_files[current_verbatim_file].append(raw_line)
|
||||
continue
|
||||
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
|
||||
def error(self, logmessage):
|
||||
raise SbyAbort(logmessage)
|
||||
|
||||
class SbyTask(SbyConfig):
|
||||
def __init__(self, sbyconfig, workdir, early_logs, reusedir):
|
||||
super().__init__()
|
||||
self.used_options = set()
|
||||
self.models = dict()
|
||||
self.workdir = workdir
|
||||
self.reusedir = reusedir
|
||||
|
@ -550,94 +646,8 @@ class SbyTask:
|
|||
assert 0
|
||||
|
||||
def run(self, setupmode):
|
||||
mode = None
|
||||
key = None
|
||||
|
||||
with open(f"{self.workdir}/config.sby", "r") as f:
|
||||
for line in f:
|
||||
raw_line = line
|
||||
if mode in ["options", "engines", "files"]:
|
||||
line = re.sub(r"\s*(\s#.*)?$", "", line)
|
||||
if line == "" or line[0] == "#":
|
||||
continue
|
||||
else:
|
||||
line = line.rstrip()
|
||||
# print(line)
|
||||
if mode is None and (len(line) == 0 or line[0] == "#"):
|
||||
continue
|
||||
match = re.match(r"^\s*\[(.*)\]\s*$", line)
|
||||
if match:
|
||||
entries = match.group(1).split()
|
||||
if len(entries) == 0:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
|
||||
if entries[0] == "options":
|
||||
mode = "options"
|
||||
if len(self.options) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "engines":
|
||||
mode = "engines"
|
||||
if len(self.engines) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "script":
|
||||
mode = "script"
|
||||
if len(self.script) != 0 or len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if entries[0] == "file":
|
||||
mode = "file"
|
||||
if len(entries) != 2:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
current_verbatim_file = entries[1]
|
||||
if current_verbatim_file in self.verbatim_files:
|
||||
self.error(f"duplicate file: {entries[1]}")
|
||||
self.verbatim_files[current_verbatim_file] = list()
|
||||
continue
|
||||
|
||||
if entries[0] == "files":
|
||||
mode = "files"
|
||||
if len(entries) != 1:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
|
||||
if mode == "options":
|
||||
entries = line.split()
|
||||
if len(entries) != 2:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
self.options[entries[0]] = entries[1]
|
||||
continue
|
||||
|
||||
if mode == "engines":
|
||||
entries = line.split()
|
||||
self.engines.append(entries)
|
||||
continue
|
||||
|
||||
if mode == "script":
|
||||
self.script.append(line)
|
||||
continue
|
||||
|
||||
if mode == "files":
|
||||
entries = line.split()
|
||||
if len(entries) == 1:
|
||||
self.files[os.path.basename(entries[0])] = entries[0]
|
||||
elif len(entries) == 2:
|
||||
self.files[entries[0]] = entries[1]
|
||||
else:
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
continue
|
||||
|
||||
if mode == "file":
|
||||
self.verbatim_files[current_verbatim_file].append(raw_line)
|
||||
continue
|
||||
|
||||
self.error(f"sby file syntax error: {line}")
|
||||
self.parse_config(f)
|
||||
|
||||
self.handle_str_option("mode", None)
|
||||
|
||||
|
|
Loading…
Reference in a new issue