diff --git a/build.hancho b/build.hancho index 84d9fd9..39b8044 100644 --- a/build.hancho +++ b/build.hancho @@ -1,3 +1,6 @@ +config.verbose = True +config.jobs = 1 + Rule()([], [], desc = "Run all tests", command = "cd tests && rm -rf build && ./test.py 2> /dev/null") Rule()([], [], desc = "Build all tutorials", command = "cd tutorial && rm -rf build && hancho --quiet") Rule()([], [], desc = "Build hello_world", command = "cd examples/hello_world && rm -rf build && hancho --quiet") diff --git a/hancho.py b/hancho.py index 64d5b74..e156673 100755 --- a/hancho.py +++ b/hancho.py @@ -112,22 +112,14 @@ def touch(name): if isinstance(name, Rule): for f in name.files_out: touch(f) - if os.path.exists(name): + return name.files_out + elif os.path.exists(name): os.utime(name, None) + return name else: with open(name, "w") as file: file.write("") - - -async def async_touch(task): - """Convenience helper method""" - for name in task.files_out: - if os.path.exists(name): - os.utime(name, None) - else: - with open(name, "w") as file: - file.write("") - return task.files_out + return name ################################################################################ diff --git a/tests/rules.hancho b/tests/rules.hancho index d22eecd..bc146bb 100644 --- a/tests/rules.hancho +++ b/tests/rules.hancho @@ -14,5 +14,5 @@ compile_cpp = Rule( ) touch_outputs = Rule( - command = async_touch + command = touch ) diff --git a/tutorial/tut4.hancho b/tutorial/tut4.hancho index 3cee4f6..072ce43 100644 --- a/tutorial/tut4.hancho +++ b/tutorial/tut4.hancho @@ -1,11 +1,11 @@ # tutorial/tut4.hancho - Async/await and custom commands import asyncio -import os config.build_dir = "build/tut4" -# You can use promises that return arrays of filenames in place of actual -# filenames in rules. +# Functions (synchronous or asynchronous) that return filenames or arrays of +# filenames can be used in place of actual filenames in rules. + async def do_slow_thing(): print("Doing slow thing") await asyncio.sleep(0.1) @@ -19,8 +19,10 @@ echo = Rule( echo(do_slow_thing(), []) # You can also use them in the command field. -async def custom_command(task): - await async_touch(task) +def custom_command(task): + for f in task.files_out: + with open(f, "a") as file: + file.write("asdf\n") return task.files_out custom_rule = Rule(