From 80f815c020bf80bdf20ce63d1dacfdfef4521bb2 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 28 Aug 2021 18:12:51 -0700 Subject: [PATCH] [build] Return output from add_input call Allow for dependency chaining in *.module files by returning the expected output from a module.add_input() call. --- scripts/bonnibel/module.py | 14 +++++++++++--- scripts/bonnibel/source.py | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/bonnibel/module.py b/scripts/bonnibel/module.py index f4e0092..d659511 100644 --- a/scripts/bonnibel/module.py +++ b/scripts/bonnibel/module.py @@ -1,3 +1,8 @@ +def resolve(path): + if path.startswith('/') or path.startswith('$'): + return path + from pathlib import Path + return str(Path(path).resolve()) class Module: __fields = { @@ -122,6 +127,7 @@ class Module: if includes: build.variable("ccflags", ["${ccflags}"] + [f"-I{i}" for i in includes]) + build.variable("asflags", ["${asflags}"] + [f"-I{i}" for i in includes]) if libs: build.variable("libs", ["${libs}"] + libs) @@ -133,14 +139,14 @@ class Module: source = start while source and source.action: - output = source.get_output('${module_dir}') + output = source.output if source.action.rule: build.build( rule = source.action.rule, outputs = output.input, inputs = source.input, - implicit = [f'${{source_root}}/{p}' for p in source.deps or tuple()], + implicit = list(map(resolve, source.deps)), variables = {"name": source.name}, ) @@ -178,4 +184,6 @@ class Module: def add_input(self, path, **kwargs): from .source import Source - self.sources.append(Source(self.root, path, **kwargs)) + s = Source(self.root, path, **kwargs) + self.sources.append(s) + return str(s.output) diff --git a/scripts/bonnibel/source.py b/scripts/bonnibel/source.py index 3ea8609..be4dc44 100644 --- a/scripts/bonnibel/source.py +++ b/scripts/bonnibel/source.py @@ -56,14 +56,15 @@ class Source: self.__deps = deps def __str__(self): - return "{} {}:{}:{}".format(self.action, self.output, self.name, self.input) + return self.input @property def action(self): suffix = self.__path.suffix return self.Actions.get(suffix) - def get_output(self, output_root): + @property + def output(self): if not self.action: return None @@ -71,7 +72,7 @@ class Source: if path is None: path = self.action.output_of(self.__path) - return path and Source(output_root, path) + return path and Source("${module_dir}", path) deps = property(lambda self: self.__deps) name = property(lambda self: str(self.__path))