From 829b4cc32fb1954580b9e2eb54445eee7da84a99 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:17:18 +1200 Subject: [PATCH 1/5] Add linkmode --link Symlinks files instead of copying them. --- sbysrc/sby.py | 7 ++++++- sbysrc/sby_cmdline.py | 2 ++ sbysrc/sby_core.py | 17 ++++++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 31835be..c0bd24e 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -54,6 +54,7 @@ dump_taskinfo = args.dump_taskinfo dump_files = args.dump_files reusedir = False setupmode = args.setupmode +linkmode = args.linkmode autotune = args.autotune autotune_config = args.autotune_config sequential = args.sequential @@ -62,6 +63,10 @@ init_config_file = args.init_config_file status_show = args.status status_reset = args.status_reset +if autotune and linkmode: + print("ERROR: --link flag currently not available with --autotune") + sys.exit(1) + if status_show or status_reset: target = workdir_prefix or workdir or sbyfile if target is None: @@ -495,7 +500,7 @@ def start_task(taskloop, taskname): task.exit_callback = exit_callback if not autotune: - task.setup_procs(setupmode) + task.setup_procs(setupmode, linkmode) task.task_local_abort = not throw_err return task diff --git a/sbysrc/sby_cmdline.py b/sbysrc/sby_cmdline.py index 812c0c5..dabc209 100644 --- a/sbysrc/sby_cmdline.py +++ b/sbysrc/sby_cmdline.py @@ -70,6 +70,8 @@ def parser_func(release_version='unknown SBY version'): 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("--link", action="store_true", dest="linkmode", + help="make symbolic links to source files instead of copying them") parser.add_argument("--status", action="store_true", dest="status", help="summarize the contents of the status database") diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index c181c18..691e278 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -947,7 +947,7 @@ class SbyTask(SbyConfig): if not os.path.isdir(path): os.makedirs(path) - def copy_src(self): + def copy_src(self, linkmode=False): self.makedirs(self.workdir + "/src") for dstfile, lines in self.verbatim_files.items(): @@ -969,8 +969,15 @@ class SbyTask(SbyConfig): if basedir != "" and not os.path.exists(basedir): os.makedirs(basedir) - self.log(f"Copy '{os.path.abspath(srcfile)}' to '{os.path.abspath(dstfile)}'.") - if os.path.isdir(srcfile): + if linkmode: + verb = "Link" + else: + verb = "Copy" + self.log(f"{verb} '{os.path.abspath(srcfile)}' to '{os.path.abspath(dstfile)}'.") + + if linkmode: + os.symlink(os.path.relpath(srcfile, basedir), dstfile) + elif os.path.isdir(srcfile): copytree(srcfile, dstfile, dirs_exist_ok=True) else: copyfile(srcfile, dstfile) @@ -1308,7 +1315,7 @@ class SbyTask(SbyConfig): self.status_db = SbyStatusDb(status_path, self) - def setup_procs(self, setupmode): + def setup_procs(self, setupmode, linkmode=False): self.handle_non_engine_options() if self.opt_smtc is not None: for engine_idx, engine in self.engine_list(): @@ -1329,7 +1336,7 @@ class SbyTask(SbyConfig): if self.reusedir: rmtree(f"{self.workdir}/model", ignore_errors=True) else: - self.copy_src() + self.copy_src(linkmode) if setupmode: self.retcode = 0 From 67ffd25c494a2dadffc2e1c5d5af9459c2ef09a3 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:18:32 +1200 Subject: [PATCH 2/5] Test --link functionality --- tests/links/Makefile | 2 ++ tests/links/dir/script.ys | 3 +++ tests/links/prv32fmcmp.v | 1 + tests/links/symlink.py | 12 ++++++++++++ tests/links/symlink.sby | 18 ++++++++++++++++++ tests/links/symlink.sh | 9 +++++++++ 6 files changed, 45 insertions(+) create mode 100644 tests/links/Makefile create mode 100644 tests/links/dir/script.ys create mode 120000 tests/links/prv32fmcmp.v create mode 100644 tests/links/symlink.py create mode 100644 tests/links/symlink.sby create mode 100644 tests/links/symlink.sh diff --git a/tests/links/Makefile b/tests/links/Makefile new file mode 100644 index 0000000..758a7f7 --- /dev/null +++ b/tests/links/Makefile @@ -0,0 +1,2 @@ +SUBDIR=links +include ../make/subdir.mk diff --git a/tests/links/dir/script.ys b/tests/links/dir/script.ys new file mode 100644 index 0000000..4daa0c1 --- /dev/null +++ b/tests/links/dir/script.ys @@ -0,0 +1,3 @@ +read -sv picorv32.v +read -sv prv32fmcmp.v +prep -top prv32fmcmp diff --git a/tests/links/prv32fmcmp.v b/tests/links/prv32fmcmp.v new file mode 120000 index 0000000..6c064ca --- /dev/null +++ b/tests/links/prv32fmcmp.v @@ -0,0 +1 @@ +../unsorted/prv32fmcmp.v \ No newline at end of file diff --git a/tests/links/symlink.py b/tests/links/symlink.py new file mode 100644 index 0000000..a761397 --- /dev/null +++ b/tests/links/symlink.py @@ -0,0 +1,12 @@ +import os +from pathlib import Path +import sys + +def main(): + workdir, task = sys.argv[1:] + src = Path(workdir) / "src" + for srcfile in src.iterdir(): + assert(srcfile.is_symlink() == (task == "link")) + +if __name__ == "__main__": + main() diff --git a/tests/links/symlink.sby b/tests/links/symlink.sby new file mode 100644 index 0000000..8ac4017 --- /dev/null +++ b/tests/links/symlink.sby @@ -0,0 +1,18 @@ +[tasks] +link +copy + +[options] +mode prep + +[engines] +btor btormc + +[script] +read -noverific +script dir/script.ys + +[files] +../../docs/examples/demos/picorv32.v +prv32fmcmp.v +dir diff --git a/tests/links/symlink.sh b/tests/links/symlink.sh new file mode 100644 index 0000000..e919293 --- /dev/null +++ b/tests/links/symlink.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +if [[ $TASK == link ]]; then + flags="--setup --link" +else + flags="--setup" +fi +python3 $SBY_MAIN -f $SBY_FILE $TASK $flags +python3 ${SBY_FILE%.sby}.py $WORKDIR $TASK From 658c83dd841512ffefbb0f8e1f5ba4c88691a6ec Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:30:12 +1200 Subject: [PATCH 3/5] Fix autotune copy_src Gets me every time. --- sbysrc/sby_autotune.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbysrc/sby_autotune.py b/sbysrc/sby_autotune.py index b861890..aa40134 100644 --- a/sbysrc/sby_autotune.py +++ b/sbysrc/sby_autotune.py @@ -649,7 +649,7 @@ class SbyAutotuneTask(SbyTask): def engine_list(self): return [(self.candidate.engine_idx, self.candidate.engine)] - def copy_src(self): + def copy_src(self, _): pass def model(self, model_name): From 2a16a48a606fcb2648a71d6fa62ecaa12eaaaa70 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Tue, 1 Jul 2025 10:50:46 +1200 Subject: [PATCH 4/5] collect_tests.py: Ignore sby status dirs Status directories are normally ignored because they have a sqlite file, but it's possible to create a status dir without a database when using `--setup`. --- tests/make/collect_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/make/collect_tests.py b/tests/make/collect_tests.py index acfb799..1f9b2c9 100644 --- a/tests/make/collect_tests.py +++ b/tests/make/collect_tests.py @@ -52,6 +52,8 @@ def collect(path): continue tests.append(entry) for entry in path.glob("*"): + if entry.with_suffix(".sby").exists(): + continue if entry.is_dir(): collect(entry) From b80a843995436727e4ddf9bee992c493215b860a Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 5 Jul 2025 15:46:40 +1200 Subject: [PATCH 5/5] tests/links: heredocs are never linked --- tests/links/symlink.py | 8 +++++++- tests/links/symlink.sby | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/links/symlink.py b/tests/links/symlink.py index a761397..a6a06d5 100644 --- a/tests/links/symlink.py +++ b/tests/links/symlink.py @@ -6,7 +6,13 @@ def main(): workdir, task = sys.argv[1:] src = Path(workdir) / "src" for srcfile in src.iterdir(): - assert(srcfile.is_symlink() == (task == "link")) + if srcfile.name == "heredoc": + assert(not srcfile.is_symlink()) + with open(srcfile, "r") as f: + local_contents = f.readline() + assert(local_contents.strip() == 'log foo') + else: + assert(srcfile.is_symlink() == (task == "link")) if __name__ == "__main__": main() diff --git a/tests/links/symlink.sby b/tests/links/symlink.sby index 8ac4017..52fa881 100644 --- a/tests/links/symlink.sby +++ b/tests/links/symlink.sby @@ -16,3 +16,6 @@ script dir/script.ys ../../docs/examples/demos/picorv32.v prv32fmcmp.v dir + +[file heredoc] +log foo