From 7f035af01f47792bed9ba0a86bb29f1b5cad411e Mon Sep 17 00:00:00 2001 From: Austin Appleby Date: Mon, 8 Apr 2024 02:20:55 -0700 Subject: [PATCH] tutorials work again --- hancho.py | 44 +++++++++++++++++++++-------------- tutorial/build.hancho | 8 +++---- tutorial/src/tut40_src.hancho | 13 +++-------- tutorial/tut20.hancho | 12 +++++----- tutorial/tut40.hancho | 2 -- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/hancho.py b/hancho.py index 4524843..91c7080 100755 --- a/hancho.py +++ b/hancho.py @@ -285,9 +285,6 @@ def expand(self, variant): def collapse(self): return Config(**self.to_dict()) - def clone(self): - return Config(**self._fields) - def merge(self, *args, **kwargs): for arg in args: if isinstance(arg, Config): @@ -318,9 +315,18 @@ def task(self, source_files=None, build_files=None, *args, **kwargs): kwargs.setdefault('build_files', build_files) return Task(self, *args, **kwargs) + #default_mod_config = Config( + # name = "Mod Config", + # mod_file = MISSING, + # mod_path = MISSING, + # repo_path = MISSING, + # root_path = MISSING, + #) + def subrepo(self, subrepo_path, *args, **kwargs): subrepo_path = abs_path(self.expand(self.this_path) / self.expand(subrepo_path)) subrepo_config = Config( + self, name = "Repo Config", repo_path = subrepo_path, ) @@ -329,7 +335,8 @@ def subrepo(self, subrepo_path, *args, **kwargs): def include(self, hancho_file, *args, **kwargs): hancho_filepath = abs_path(self.expand(self.this_path) / self.expand(hancho_file)) - mod_config = self.clone( + mod_config = Config( + self, name = "Include Config", this_file = hancho_filepath, this_path = hancho_filepath.parent, @@ -339,7 +346,8 @@ def include(self, hancho_file, *args, **kwargs): def load(self, hancho_file, *args, **kwargs): hancho_filepath = abs_path(self.expand(self.this_path) / self.expand(hancho_file)) - mod_config = self.clone( + mod_config = Config( + self, name = "Mod Config", this_file = hancho_filepath, this_path = hancho_filepath.parent, @@ -353,12 +361,14 @@ def load(self, hancho_file, *args, **kwargs): class Rule(Config): """Rules are callable Configs that create a Task when called.""" - def __call__(self, source_files=None, build_files=None, *args, **kwargs): + def __call__(self, source_files = None, build_files = None, **kwargs): + args = [] if source_files is not None: - kwargs['source_files'] = source_files + args.append({'source_files': source_files}) if build_files is not None: - kwargs['build_files'] = build_files - return Task(self, *args, **kwargs) + args.append({'build_files': build_files}) + result = Task(self, *args, **kwargs) + return result #################################################################################################### # The template expansion / macro evaluation code requires some explanation. @@ -489,7 +499,7 @@ def __init__(self, *args, **kwargs): name = "Task Config", desc = "{source_files} -> {build_files}", command = MISSING, - command_path = Path.cwd(), + command_path = "{repo_path}", command_files = [], source_path = Path.cwd(), source_files = MISSING, @@ -550,6 +560,12 @@ def task_init(self): """All the setup steps needed before we run a task.""" # Expand all the critical fields + + #print("==========") + #print(expand(self.task_config, "{abs_build_files}")) + #print(expand(self.task_config, "{command_path}")) + #print("==========") + self.desc = expand(self.task_config, self.task_config.desc) self.command = flatten(expand(self.task_config, self.task_config.command)) self.command_path = abs_path(expand(self.task_config, self.task_config.command_path)) @@ -752,14 +768,6 @@ async def run_command(self, command): # fmt: off -default_mod_config = Config( - name = "Default Mod Config", - mod_file = MISSING, - mod_path = MISSING, - repo_path = MISSING, - root_path = MISSING, -) - helper_functions = Config( name = "Helper Functions", abs_path=abs_path, diff --git a/tutorial/build.hancho b/tutorial/build.hancho index f9f2161..543bbbf 100644 --- a/tutorial/build.hancho +++ b/tutorial/build.hancho @@ -23,7 +23,7 @@ test_build("tut14.hancho") test_build("tut15.hancho") test_build("tut16.hancho") -#test_build("tut20.hancho") -#test_build("tut30.hancho") -#test_build("tut40.hancho") -#test_build("tut50.hancho") +test_build("tut20.hancho") +test_build("tut30.hancho") +test_build("tut40.hancho") +test_build("tut50.hancho") diff --git a/tutorial/src/tut40_src.hancho b/tutorial/src/tut40_src.hancho index 611d132..be34597 100644 --- a/tutorial/src/tut40_src.hancho +++ b/tutorial/src/tut40_src.hancho @@ -1,11 +1,4 @@ -rules = build_config.include("{rules_path}/tut40_rules.hancho") +# tutorial/tut40_src.hancho -print("---------- tut40_src build_config") -print(build_config) -print("----------") - -rules.c_binary( - glob("*.cpp"), - "app", - config = build_config -) +rules = build_config.include("{repo_path}/tut40_rules.hancho") +rules.c_binary(glob("*.cpp"), "app", config = build_config) diff --git a/tutorial/tut20.hancho b/tutorial/tut20.hancho index 96dc9ed..224a3be 100644 --- a/tutorial/tut20.hancho +++ b/tutorial/tut20.hancho @@ -3,17 +3,17 @@ build_config.build_tag = "tut20" compile = build_config.rule( - desc = "Compile {rel_source_files} -> {rel_build_files}", - command = "g++ -MMD -c {rel_source_files} -o {rel_build_files}", - build_files = "{swap_ext(source_files, '.o')}", - build_deps = "{swap_ext(source_files, '.d')}", + desc = "Compile {rel_source_files}", + command = "g++ -MMD -c {rel_source_files} -o {rel_build_files}", + build_files = "{swap_ext(source_files, '.o')}", + build_deps = "{swap_ext(source_files, '.d')}", ) link = build_config.rule( - desc = "Link {rel_source_files} -> {rel_build_files}", + desc = "Link {rel_source_files} into {rel_build_files}", command = "g++ {rel_source_files} -o {rel_build_files}", ) main_o = compile("src/main.cpp") util_o = compile("src/util.cpp") -link([main_o, util_o], "app") +app = link([main_o, util_o], "app") diff --git a/tutorial/tut40.hancho b/tutorial/tut40.hancho index 2f8430a..35f99d0 100644 --- a/tutorial/tut40.hancho +++ b/tutorial/tut40.hancho @@ -1,6 +1,4 @@ # tutorial/tut40.hancho build_config.build_tag = "tut40" -build_config.rules_path = "{repo_path}" - build_config.load("src/tut40_src.hancho")