Skip to content

Commit

Permalink
Ditch Command, fix flags, fix task cancellation, better error reporti…
Browse files Browse the repository at this point in the history
…ng, etc.
  • Loading branch information
aappleby committed Nov 1, 2024
1 parent aedeb26 commit 6ce5177
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 341 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ options:
```python
# examples/hello_world/build.hancho

compile_cpp = hancho.command(
compile_cpp = hancho.Config(
desc = "Compiling C++ {in_src} -> {out_obj}",
command = "g++ -c {in_src} -o {out_obj}",
in_src = None,
out_obj = "{swap_ext(in_src, '.o')}",
c_deps = "{swap_ext(in_src, '.d')}",
)

link_cpp_bin = hancho.command(
link_cpp_bin = hancho.Config(
desc = "Linking C++ bin {out_bin}",
command = "g++ {in_objs} -o {out_bin}",
in_objs = None,
Expand Down
14 changes: 7 additions & 7 deletions base_rules.hancho
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
####################################################################################################
# Utils

touch_outputs = hancho.Command(
touch_outputs = hancho.Config(
command="touch {in_files}",
in_files=None,
)
Expand Down Expand Up @@ -29,7 +29,7 @@ riscv64_toolchain = hancho.Config(

# ----------------------------------------

check_cpp = hancho.Command(
check_cpp = hancho.Config(
desc = "Checking C++ syntax of {rel(in_src)}",
command = "{toolchain.compiler} {flags} {joined_warnings} {joined_defines} {joined_includes} -c {rel(in_src)} && touch {rel(out_ok)}",
in_src = None,
Expand All @@ -44,7 +44,7 @@ check_cpp = hancho.Command(

# ----------------------------------------

compile_cpp = hancho.Command(
compile_cpp = hancho.Config(
desc = "Compiling C++ {rel(in_src)} -> {rel(out_obj)} ({build_tag})",
command = "{toolchain.compiler} {flags} {joined_warnings} {joined_defines} {joined_includes} -c {rel(in_src)} -o {rel(out_obj)}",

Expand Down Expand Up @@ -76,7 +76,7 @@ if os.name == 'nt':

# ----------------------------------------

link_cpp_lib = hancho.Command(
link_cpp_lib = hancho.Config(
desc="Bundling C++ lib {rel(out_lib)}",
in_objs=None,
out_lib=None,
Expand All @@ -85,7 +85,7 @@ link_cpp_lib = hancho.Command(

# ----------------------------------------

link_cpp_bin = hancho.Command(
link_cpp_bin = hancho.Config(
desc="Linking C++ bin {rel(out_bin)}",
out_bin=None,
toolchain=default_toolchain,
Expand Down Expand Up @@ -137,7 +137,7 @@ def cpp_bin(hancho, *args, in_srcs=[], in_objs=[], in_libs=[], out_bin = [], **k
# Makefiles

def make(hancho, /, *args, in_makefile, **kwargs):
cmd = hancho.Command(
cmd = hancho.Config(
desc = "Run makefile {rel(in_makefile)}",
command = "make -C {make_dir} -f {make_file} {flags}", # > /dev/null
make_dir = "{path.dirname(in_makefile)}",
Expand All @@ -149,7 +149,7 @@ def make(hancho, /, *args, in_makefile, **kwargs):
####################################################################################################
# Tests

run_test = hancho.Command(
run_test = hancho.Config(
desc = "Running test {rel(in_test)}",
command = "{in_test} {args} && touch {out_pass}",
task_dir = "{test_dir}",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Task @ 0x727f0371d6a0 {
_out_files = [],
_state = 0,
_reason = None,
_promise = None,
_asyncio_task = None,
_loaded_files = [
"/home/aappleby/repos/hancho/tutorial/tut00.hancho",
],
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_world/build.hancho
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# examples/hello_world/build.hancho

compile_cpp = hancho.Command(
compile_cpp = hancho.Config(
desc = "Compiling C++ {in_src} -> {out_obj}",
command = "g++ -c {in_src} -o {out_obj}",
in_src = None,
Expand All @@ -11,7 +11,7 @@ compile_cpp = hancho.Command(
main_o = hancho(compile_cpp, in_src = "main.cpp")
util_o = hancho(compile_cpp, in_src = "util.cpp")

link_cpp_bin = hancho.Command(
link_cpp_bin = hancho.Config(
desc = "Linking C++ bin {out_bin}",
command = "g++ {in_objs} -o {out_bin}",
in_objs = None,
Expand Down
4 changes: 2 additions & 2 deletions examples/windows/build.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

hancho.c_depformat = "msvc"

compile = hancho.Command(
compile = hancho.Config(
command = "cl.exe /nologo /c {in_src} /sourceDependencies {c_deps} /Fo:{out_obj} > NUL",
desc = "Compile {in_src} -> {out_obj}",
in_src = None
out_obj = "{swap_ext(in_src, '.o')}",
c_deps = "{swap_ext(in_src, '.d')}",
)

link = hancho.Command(
link = hancho.Config(
command = "link.exe /nologo {libs} {in_objs} /out:{out_bin} > NUL",
desc = "Link {in_objs} -> {out_bin}",
in_objs = None,
Expand Down
10 changes: 5 additions & 5 deletions fpga_rules.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def chparams(c):
result.append(f"chparam -set {key} {val} {{top}};")
return result

yosys = hancho.Command(
yosys = hancho.Config(
desc = "Run yosys on {rel(in_sv)}",
command = "yosys -q -p 'read_verilog -defer {joined_includes} -sv {rel(in_sv)}; dump; {chparams(params)} synth_ice40 -json {rel(out_json)};'",
in_sv = None,
Expand All @@ -16,7 +16,7 @@ yosys = hancho.Command(
joined_includes = "{join_prefix('-I', get('includes', []))}",
)

nextpnr = hancho.Command(
nextpnr = hancho.Config(
desc = "Run nextpnr-ice40 on {rel(in_json)}",
command = "nextpnr-ice40 {flags} -q --json {rel(in_json)} --pcf {pcf} --{chip} --package {package} --asc {rel(out_asc)}",
in_json = None,
Expand All @@ -27,19 +27,19 @@ nextpnr = hancho.Command(
package = None,
)

icepack = hancho.Command(
icepack = hancho.Config(
desc = "Run icepack on {rel(in_asc)}",
command = "icepack {rel(in_asc)} {rel(out_bin)}",
in_asc = None,
out_bin = "{swap_ext(in_asc, '.bin')}",
)

iceprog = hancho.Command(
iceprog = hancho.Config(
desc = "Run iceprog on {rel(in_bin)}",
command = "iceprog -S {rel(in_bin)}",
)

synth = hancho.Command(
synth = hancho.Config(
desc = "Synth {rel(in_sv)}",
command = [
"yosys -p 'read_verilog -defer {joined_includes} -sv {rel(in_sv)}; dump; {chparams(params)} synth_ice40 -json {rel(out_json)};'",
Expand Down
Loading

0 comments on commit 6ce5177

Please sign in to comment.