Skip to content

Commit

Permalink
tutorials work again
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Apr 8, 2024
1 parent 9c168af commit 7f035af
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
44 changes: 26 additions & 18 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tutorial/build.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -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")
13 changes: 3 additions & 10 deletions tutorial/src/tut40_src.hancho
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions tutorial/tut20.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 0 additions & 2 deletions tutorial/tut40.hancho
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 7f035af

Please sign in to comment.