diff --git a/build.hancho b/build.hancho index cb975a5..bf7daaa 100644 --- a/build.hancho +++ b/build.hancho @@ -2,13 +2,15 @@ print("Building Matcheroni with Hancho") -build_config.build_tag = "debug" - -build_config.load("examples/c_lexer/c_lexer.hancho") -build_config.load("examples/c_parser/c_parser.hancho") -build_config.load("examples/ini/ini.hancho") -build_config.load("examples/json/json.hancho") -build_config.load("examples/regex/regex.hancho") -build_config.load("examples/toml/toml.hancho") -build_config.load("examples/tutorial/tutorial.hancho") -build_config.load("tests/tests.hancho") +hancho.build_tag = "debug" + +c_lexer = hancho.load("examples/c_lexer/c_lexer.hancho") +c_parser = hancho.load("examples/c_parser/c_parser.hancho", + c_lexer_lib = c_lexer.c_lexer_lib) + +hancho.load("examples/ini/ini.hancho") +hancho.load("examples/json/json.hancho") +hancho.load("examples/regex/regex.hancho") +hancho.load("examples/toml/toml.hancho") +hancho.load("tests/tests.hancho") +hancho.load("examples/tutorial/tutorial.hancho", c_lexer_lib=c_lexer.c_lexer_lib, c_parser_lib = c_parser.c_parser_lib) diff --git a/config/rules.hancho b/config/rules.hancho index 5082dca..60d67da 100644 --- a/config/rules.hancho +++ b/config/rules.hancho @@ -2,24 +2,24 @@ #------------------------------------------------------------------------------- -compile_cpp = build_config.rule( +compile_cpp = hancho.command( desc = "Compiling {rel_source_files} -> {rel_build_files} ({build_tag})", command = "g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {rel_source_files} -o {rel_build_files}", cpp_std = "-std=c++20", gcc_opt = "{'-O3' if build_tag == 'release' else '-g -O0'} -MMD", warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable", - includes = "-I.", + includes = "-I{repo_path}", defines = "", build_files = "{swap_ext(source_files, '.o')}", build_deps = "{swap_ext(source_files, '.d')}", ) -link_c_lib = build_config.rule( +link_c_lib = hancho.command( desc = "Bundling {rel_build_files}", command = "ar rcs {rel_build_files} {rel_source_files}", ) -link_c_bin = build_config.rule( +link_c_bin = hancho.command( desc = "Linking {rel_build_files}", command = "g++ {ld_opt} {warnings} {rel_source_files} {libs} {sys_libs} -o {rel_build_files}", ld_opt = "{'-O3' if build_tag == 'release' else '-g -O0'}", @@ -28,7 +28,7 @@ link_c_bin = build_config.rule( warnings = "-Wall", ) -test_rule = build_config.rule( +run_c_test = hancho.command( desc = "Running test {rel_source_files}", command = "rm -f {rel_build_files} && {rel_source_files} {args} && touch {rel_build_files}", build_files = "{swap_ext(source_files, '.pass')}", @@ -47,6 +47,6 @@ def c_library(source_files, build_files, **kwargs): return link_c_lib(compile_srcs(source_files, **kwargs), build_files, **kwargs) def c_test(source_files, build_files, **kwargs): - return test_rule(c_binary(source_files, build_files, **kwargs), **kwargs) + return run_c_test(c_binary(source_files, build_files, **kwargs), **kwargs) #------------------------------------------------------------------------------- diff --git a/examples/c_lexer/c_lexer.hancho b/examples/c_lexer/c_lexer.hancho index 94d956f..c3cfc7f 100644 --- a/examples/c_lexer/c_lexer.hancho +++ b/examples/c_lexer/c_lexer.hancho @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # Matcheroni C lexer demo -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") c_lexer_lib = rules.c_library( ["CLexer.cpp", "CToken.cpp"], diff --git a/examples/c_parser/c_parser.hancho b/examples/c_parser/c_parser.hancho index 3ce4549..18110d3 100644 --- a/examples/c_parser/c_parser.hancho +++ b/examples/c_parser/c_parser.hancho @@ -1,19 +1,19 @@ #------------------------------------------------------------------------------- # C parser example (not finished) -rules = build_config.include("{repo_path}/config/rules.hancho") +import sys -c_lexer = build_config.load("../c_lexer/c_lexer.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") c_parser_lib = rules.c_library( - ["CContext.cpp", "CNode.cpp", "CScope.cpp"], - "c_parser.a", + source_files = ["CContext.cpp", "CNode.cpp", "CScope.cpp"], + build_files = "c_parser.a", ) rules.c_binary( "c_parser_benchmark.cpp", "c_parser_benchmark", - libs = [c_lexer.c_lexer_lib, c_parser_lib], + libs = [hancho.c_lexer_lib, c_parser_lib], ) # Broken? diff --git a/examples/ini/ini.hancho b/examples/ini/ini.hancho index 155c507..513f782 100644 --- a/examples/ini/ini.hancho +++ b/examples/ini/ini.hancho @@ -1,6 +1,6 @@ #------------------------------------------------------------------------------- # INI parser example -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") ini_parser_lib = rules.c_library("ini_parser.cpp", "ini_parser.a") diff --git a/examples/json/json.hancho b/examples/json/json.hancho index e62117c..6eea377 100644 --- a/examples/json/json.hancho +++ b/examples/json/json.hancho @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # Matcheroni JSON parser example -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") json_parser = rules.c_library( ["json_matcher.cpp", "json_parser.cpp"], diff --git a/examples/regex/regex.hancho b/examples/regex/regex.hancho index 9a12f2b..f65c97f 100644 --- a/examples/regex/regex.hancho +++ b/examples/regex/regex.hancho @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # Matcheroni regex parsing example -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") # These are the various regex libraries that Matcheroni can be benchmarked # against. CTRE and SRELL require that you copy their header into matcheroni/. diff --git a/examples/toml/toml.hancho b/examples/toml/toml.hancho index 1bd76f8..79c5573 100644 --- a/examples/toml/toml.hancho +++ b/examples/toml/toml.hancho @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # TOML parser example -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") toml_lib = rules.c_library( "toml_parser.cpp", diff --git a/examples/tutorial/tutorial.hancho b/examples/tutorial/tutorial.hancho index c2787d7..ce94b20 100644 --- a/examples/tutorial/tutorial.hancho +++ b/examples/tutorial/tutorial.hancho @@ -1,20 +1,17 @@ #------------------------------------------------------------------------------- # Tutorial examples -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") -c_lexer = build_config.load("../c_lexer/c_lexer.hancho") -c_parser = build_config.load("../c_parser/c_parser.hancho") - -rules.c_test("json_tut0a.cpp", "json_tut0a", quiet = True) -rules.c_test("json_tut1a.cpp", "json_tut1a", quiet = True) -rules.c_test("json_tut1b.cpp", "json_tut1b", quiet = True) -rules.c_test("json_tut1c.cpp", "json_tut1c", quiet = True) -rules.c_test("json_tut2a.cpp", "json_tut2a", quiet = True) -rules.c_test("json_tut2b.cpp", "json_tut2b", quiet = True) +rules.c_test("json_tut0a.cpp", "json_tut0a", command_path="{repo_path}", quiet = True) +rules.c_test("json_tut1a.cpp", "json_tut1a", command_path="{repo_path}", quiet = True) +rules.c_test("json_tut1b.cpp", "json_tut1b", command_path="{repo_path}", quiet = True) +rules.c_test("json_tut1c.cpp", "json_tut1c", command_path="{repo_path}", quiet = True) +rules.c_test("json_tut2a.cpp", "json_tut2a", command_path="{repo_path}", quiet = True) +rules.c_test("json_tut2b.cpp", "json_tut2b", command_path="{repo_path}", quiet = True) rules.c_binary( "tiny_c_parser.cpp", "tiny_c_parser", - libs = [c_lexer.c_lexer_lib, c_parser.c_parser_lib], + libs = [hancho.c_lexer_lib, hancho.c_parser_lib], ) diff --git a/tests/tests.hancho b/tests/tests.hancho index 39d128e..67ae0c0 100644 --- a/tests/tests.hancho +++ b/tests/tests.hancho @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # Tests -rules = build_config.include("{repo_path}/config/rules.hancho") +rules = hancho.load("{repo_path}/config/rules.hancho") #build obj/matcheroni/Matcheroni.hpp.iwyu : iwyu matcheroni/Matcheroni.hpp #build obj/matcheroni/Parseroni.hpp.iwyu : iwyu matcheroni/Parseroni.hpp