From d5f099cd059bd74b0cdc026cd7268b38cfd45305 Mon Sep 17 00:00:00 2001 From: Austin Appleby Date: Sun, 6 Oct 2024 18:43:22 -0700 Subject: [PATCH] tweaks --- README.md | 48 +++++++++++++++++++++++++------ examples/hello_world/build.hancho | 2 +- hancho.py | 3 +- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 598c920..5160d3c 100644 --- a/README.md +++ b/README.md @@ -55,31 +55,61 @@ options: ## Simple Example examples/hello_world/build.hancho - -https://github.com/aappleby/hancho/blob/bff89ebdc69af000d3586c130cee744fabdc523c/examples/hello_world/build.hancho#L1-L24 +```python +import hancho + +compile_cpp = hancho.Command( + desc = "Compiling C++ {rel(in_src)} -> {rel(out_obj)}", + command = "g++ -c {rel(in_src)} -o {rel(out_obj)}", + in_src = None, + out_obj = "{swap_ext(in_src, '.o')}", + depfile = "{swap_ext(in_src, '.d')}", +) + +link_cpp_bin = hancho.Command( + desc = "Linking C++ bin {rel(out_bin)}", + command = "g++ {rel(in_objs)} -o {rel(out_bin)}", + in_objs = None, + out_bin = None, +) + +main_o = compile_cpp(in_src = "main.cpp") +util_o = compile_cpp(in_src = "util.cpp") + +main_app = link_cpp_bin( + in_objs = [main_o, util_o], + out_bin = "hello_world", +) +``` examples/hello_world/main.cpp +```cpp +// examples/hello_world/main.cpp +#include -https://github.com/aappleby/hancho/blob/bff89ebdc69af000d3586c130cee744fabdc523c/examples/hello_world/main.cpp#L1-L9 +int blah(); + +int main(int argc, char** argv) { + printf("Hello World %d\n", blah()); + return 0; +} +``` ```sh user@host:~/hancho/examples/hello_world$ ../../hancho.py --verbose Loading module /home/user/hancho/examples/hello_world/build.hancho Loading .hancho files took 0.000 seconds -[1/3] Compiling C++ main.cpp -> build/hello_world/main.o () +[1/3] Compiling C++ main.cpp -> build/hello_world/main.o Reason: Rebuilding because /home/user/hancho/examples/hello_world/build/hello_world/main.o is missing .$ g++ -c main.cpp -o build/hello_world/main.o -[2/3] Compiling C++ util.cpp -> build/hello_world/util.o () +[2/3] Compiling C++ util.cpp -> build/hello_world/util.o Reason: Rebuilding because /home/user/hancho/examples/hello_world/build/hello_world/util.o is missing .$ g++ -c util.cpp -o build/hello_world/util.o -[2/3] Compiling C++ util.cpp -> build/hello_world/util.o () -[2/3] Compiling C++ main.cpp -> build/hello_world/main.o () [3/3] Linking C++ bin build/hello_world/hello_world Reason: Rebuilding because /home/user/hancho/examples/hello_world/build/hello_world/hello_world is missing .$ g++ build/hello_world/main.o build/hello_world/util.o -o build/hello_world/hello_world -[3/3] Linking C++ bin build/hello_world/hello_world -Running 3 tasks took 0.043 seconds +Running 3 tasks took 0.044 seconds tasks total: 3 tasks passed: 3 tasks failed: 0 diff --git a/examples/hello_world/build.hancho b/examples/hello_world/build.hancho index f04bf35..704a63d 100644 --- a/examples/hello_world/build.hancho +++ b/examples/hello_world/build.hancho @@ -1,7 +1,7 @@ import hancho compile_cpp = hancho.Command( - desc = "Compiling C++ {rel(in_src)} -> {rel(out_obj)} ({build_tag})", + desc = "Compiling C++ {rel(in_src)} -> {rel(out_obj)}", command = "g++ -c {rel(in_src)} -o {rel(out_obj)}", in_src = None, out_obj = "{swap_ext(in_src, '.o')}", diff --git a/hancho.py b/hancho.py index d9cf7a2..6d40372 100755 --- a/hancho.py +++ b/hancho.py @@ -1150,11 +1150,12 @@ async def run_command(self, command): result.close() if self.verbose or not command_pass or self.stderr: - self.print_status() if self.stderr and not self.should_fail: + self.print_status() log("-----stderr-----") log(self.stderr, end="") if self.stdout: + self.print_status() log("-----stdout-----") log(self.stdout, end="")