From 8175fb5d0a5c0a387703705d20d6eb543ea67afe Mon Sep 17 00:00:00 2001 From: Asherah Connor Date: Wed, 3 Jul 2024 13:26:53 +0300 Subject: [PATCH] build: use IL from plan, not on disk. We haven't extracted it yet. --- src/niar/build.py | 2 +- src/niar/cmdrunner.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/niar/build.py b/src/niar/build.py index c0a4289..14c4f93 100644 --- a/src/niar/build.py +++ b/src/niar/build.py @@ -76,7 +76,7 @@ def main(np: Project, args): # The outf doesn't exist here; it's only used for the digest name basis. cr.add_process(execute_build, - infs=[np.path.build(subdir, fn)], + infs=[{np.path.build(subdir, fn): plan.files[fn]}], outf=np.path.build(subdir, np.name)) cr.run() diff --git a/src/niar/cmdrunner.py b/src/niar/cmdrunner.py index 7004d25..07422d8 100644 --- a/src/niar/cmdrunner.py +++ b/src/niar/cmdrunner.py @@ -14,7 +14,7 @@ class CompilationUnit: self.cmd = cmd else: self.cmd = [str(el) for el in cmd] - self.infs = [str(p) for p in infs] + self.infs = infs self.outf = str(outf) if outf else None self.chdir = chdir @@ -50,14 +50,12 @@ class CompilationUnit: def digest_str(s): digest_bytes(s.encode()) - sorted_in_paths = list(self.infs) - sorted_in_paths.sort() + infs = self.process_infs() - digest_int(len(sorted_in_paths)) - for in_path in sorted_in_paths: + digest_int(len(infs)) + for in_path in sorted(infs.keys()): digest_str(in_path) - with open(in_path, "rb") as f: - digest_bytes(f.read()) + digest_bytes(infs[in_path]) if not inspect.isfunction(self.cmd): digest_int(len(self.cmd)) @@ -66,7 +64,18 @@ class CompilationUnit: return m.hexdigest() - + def process_infs(self): + r = {} + for inf in self.infs: + if isinstance(inf, dict): + for k, v in inf.items(): + if isinstance(v, str): + v = v.encode() + r[str(k)] = v + else: + with open(inf, "rb") as f: + r[str(inf)] = f.read() + return r class CommandRunner: cus: list[CompilationUnit]