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] 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