From d0e442953ebb4819570ef8681ef84a9e04d8db2b Mon Sep 17 00:00:00 2001 From: Austin Appleby Date: Fri, 26 Jan 2024 19:00:45 -0800 Subject: [PATCH] ok, everything working pretty well --- build.py | 93 ++++++++++------------------------- examples/regex/regex_test.cpp | 1 + rules.py | 84 ++++++++++++------------------- tests/parseroni_test.cpp | 2 + 4 files changed, 60 insertions(+), 120 deletions(-) diff --git a/build.py b/build.py index acc0216..fb45ae8 100755 --- a/build.py +++ b/build.py @@ -6,46 +6,6 @@ #-fsanitize=undefined -matcheroni_test_o = hancho.queue( - rule_compile_cpp(file_in = "tests/matcheroni_test.cpp") -) - -print(matcheroni_test_o) - - -""" -mimo = hancho.config( - command = "echo {join(files_in)} {join(files_out)}", - files_in = ["tests/matcheroni_test.cpp", "tests/parseroni_test.cpp"], - files_out = ["foo", "bar"], -) -hancho.queue(mimo) - -miso = hancho.config( - command = "echo {join(files_in)} {file_out}", - files_in = ["tests/matcheroni_test.cpp", "tests/parseroni_test.cpp"], - file_out = "foo", -) -hancho.queue(miso) - -simo = hancho.config( - command = "echo {file_in} {join(files_out)}", - file_in = "tests/matcheroni_test.cpp", - files_out = ["foo", "bar"], -) -hancho.queue(simo) - -siso = hancho.config( - command = "echo {file_in} {file_out}", - file_in = "tests/matcheroni_test.cpp", - file_out = "foo", -) -hancho.queue(siso) -""" - - - -""" #------------------------------------------------------------------------------- # Tests @@ -53,18 +13,18 @@ #build obj/matcheroni/Parseroni.hpp.iwyu : iwyu matcheroni/Parseroni.hpp #build obj/matcheroni/Utilities.hpp.iwyu : iwyu matcheroni/Utilities.hpp -c_binary( +matcheroni_test = c_binary( name = "tests/matcheroni_test", srcs = ["tests/matcheroni_test.cpp"], ) -c_binary( +parseroni_test = c_binary( name = "tests/parseroni_test", srcs = ["tests/parseroni_test.cpp"], ) -run_test("tests/matcheroni_test", quiet = True) -run_test("tests/parseroni_test", quiet = True) +run_test(matcheroni_test, quiet = True) +run_test(parseroni_test, quiet = True) #------------------------------------------------------------------------------- # These are the various regex libraries that Matcheroni can be benchmarked @@ -85,23 +45,23 @@ regex_demo = c_binary( name = "examples/regex/regex_demo", srcs = ["examples/regex/regex_demo.cpp"], - libs = [regex_parser], + deps = [regex_parser], ) regex_benchmark = c_binary( name = "examples/regex/regex_benchmark", srcs = ["examples/regex/regex_benchmark.cpp"], - libs = [regex_parser], + deps = [regex_parser], sys_libs = "-lboost_system -lboost_regex", ) regex_test = c_binary( name = "examples/regex/regex_test", srcs = ["examples/regex/regex_test.cpp"], - libs = [regex_parser], + deps = [regex_parser], ) -run_test2(regex_test, quiet = True) +run_test(regex_test, quiet = True) #------------------------------------------------------------------------------- # INI parser example @@ -119,7 +79,7 @@ srcs = ["examples/toml/toml_parser.cpp", "examples/toml/toml_test.cpp"] ) -#run_test("examples/toml/toml_test") +run_test(toml_test, quiet = True) #------------------------------------------------------------------------------- # JSON parser example @@ -132,28 +92,28 @@ json_conformance = c_binary( name = "examples/json/json_conformance", srcs = ["examples/json/json_conformance.cpp"], - libs = [json_parser] + deps = [json_parser] ) json_benchmark = c_binary( name = "examples/json/json_benchmark", srcs = ["examples/json/json_benchmark.cpp"], - libs = [json_parser] + deps = [json_parser] ) json_demo = c_binary( name = "examples/json/json_demo", srcs = ["examples/json/json_demo.cpp"], - libs = [json_parser], + deps = [json_parser], ) json_test = c_binary( name = "examples/json/json_test", srcs = ["examples/json/json_test.cpp"], - libs = [json_parser] + deps = [json_parser] ) -run_test2(json_test, quiet = True) +run_test(json_test, quiet = True) #------------------------------------------------------------------------------- # Tutorial examples @@ -165,12 +125,12 @@ json_tut2a = c_binary(name = "tutorial/json_tut2a", srcs = ["tutorial/json_tut2a.cpp"]) json_tut2b = c_binary(name = "tutorial/json_tut2b", srcs = ["tutorial/json_tut2b.cpp"]) -run_test2(json_tut0a, quiet = True) -run_test2(json_tut1a, quiet = True) -run_test2(json_tut1b, quiet = True) -run_test2(json_tut1c, quiet = True) -run_test2(json_tut2a, quiet = True) -run_test2(json_tut2b, quiet = True) +run_test(json_tut0a, quiet = True) +run_test(json_tut1a, quiet = True) +run_test(json_tut1b, quiet = True) +run_test(json_tut1c, quiet = True) +run_test(json_tut2a, quiet = True) +run_test(json_tut2b, quiet = True) #------------------------------------------------------------------------------- # C lexer example (not finished) @@ -183,16 +143,16 @@ c_lexer_benchmark = c_binary( name = "examples/c_lexer_benchmark", srcs = ["examples/c_lexer/c_lexer_benchmark.cpp"], - libs = [c_lexer] + deps = [c_lexer] ) c_lexer_test = c_binary( name = "examples/c_lexer_test", srcs = ["examples/c_lexer/c_lexer_test.cpp"], - libs = [c_lexer] + deps = [c_lexer] ) -run_test2(c_lexer_test, quiet = True) +run_test(c_lexer_test, quiet = True) #------------------------------------------------------------------------------- # C parser example (not finished) @@ -209,13 +169,13 @@ c_parser_benchmark = c_binary( name = "examples/c_parser_benchmark", srcs = ["examples/c_parser/c_parser_benchmark.cpp"], - libs = [c_lexer, c_parser] + deps = [c_lexer, c_parser] ) c_parser_test = c_binary( name = "examples/c_parser_test", srcs = ["examples/c_parser/c_parser_test.cpp"], - libs = [c_lexer, c_parser] + deps = [c_lexer, c_parser] ) # Broken? @@ -226,10 +186,9 @@ tiny_c_parser = c_binary( name = "tutorial/tiny_c_parser", srcs = ["tutorial/tiny_c_parser.cpp"], - libs = [c_lexer, c_parser] + deps = [c_lexer, c_parser] ) #------------------------------------------------------------------------------- -""" hancho.build() diff --git a/examples/regex/regex_test.cpp b/examples/regex/regex_test.cpp index 58e3f60..875b6f8 100644 --- a/examples/regex/regex_test.cpp +++ b/examples/regex/regex_test.cpp @@ -1,5 +1,6 @@ #include int main(int argc, char** argv) { + printf("All tests pass\n"); return 0; } diff --git a/rules.py b/rules.py index ab1d662..a191aa1 100644 --- a/rules.py +++ b/rules.py @@ -12,7 +12,7 @@ parser = argparse.ArgumentParser() parser.add_argument('--verbose', default=False, action='store_true', help='Print verbose build info') parser.add_argument('--serial', default=False, action='store_true', help='Do not parallelize commands') -parser.add_argument('--dry_run', default=False, action='store_true', help='Do not run commands') +parser.add_argument('--dryrun', default=False, action='store_true', help='Do not run commands') parser.add_argument('--debug', default=False, action='store_true', help='Dump debugging information') parser.add_argument('--dotty', default=False, action='store_true', help='Dump dependency graph as dotty') parser.add_argument('--release', default=False, action='store_true', help='Release-mode optimized build') @@ -21,14 +21,14 @@ hancho.config.verbose = flags.verbose hancho.config.serial = flags.serial -hancho.config.dry_run = flags.dry_run +hancho.config.dryrun = flags.dryrun hancho.config.debug = flags.debug hancho.config.dotty = flags.dotty hancho.config.force = flags.force #------------------------------------------------------------------------------- -base_config = hancho.config( +base_config = hancho.config.extend( name = "base_config", build_type = "debug", out_dir = "build/{build_type}", @@ -37,98 +37,76 @@ if flags.release: base_config.build_type = "release" -rule_compile_cpp = base_config( +#------------------------------------------------------------------------------- + +rule_compile_cpp = base_config.extend( name = "rule_compile_cpp", description = "Compiling {file_in} -> {file_out} ({build_type})", - #files_out = ["{out_dir}/{swap_ext(file_in, '.o')}"], - #files_out = ["{out_dir}/{swap_ext(file_in, '.o')}"], - file_out = "{out_dir}/{swap_ext(file_in, '.o')}", - command = "{toolchain}-g++ {build_opt} {cpp_std} {warnings} {depfile} {includes} {defines} -c {file_in} -o {file_out}", - build_opt = "{'-O3' if build_type == 'release' else '-g -O0'}", + command = "{toolchain}-g++ {cpp_std} {build_opt} {warnings} {depfile} {includes} {defines} -c {file_in} -o {file_out}", + toolchain = "x86_64-linux-gnu", cpp_std = "-std=c++20", + build_opt = "{'-O3' if build_type == 'release' else '-g -O0'}", warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable", depfile = "-MMD -MF {file_out}.d", includes = "-I.", defines = "", + file_out = "{out_dir}/{swap_ext(file_in, '.o')}", ) -#------------------------------------------------------------------------------- - -link_c_lib = base_config( +link_c_lib = base_config.extend( name = "link_c_lib", description = "Bundling {file_out}", command = "ar rcs {file_out} {join(files_in)}", ) -link_c_bin = base_config( +link_c_bin = base_config.extend( name = "link_c_bin", description = "Linking {file_out}", - command = "{toolchain}-g++ {join(files_in)} {join(libs)} {sys_libs} -o {file_out}", + command = "{toolchain}-g++ {build_opt} {warnings} {join(files_in)} {join(deps)} {sys_libs} -o {file_out}", + build_opt = "{'-O3' if build_type == 'release' else '-g -O0'}", toolchain = "x86_64-linux-gnu", - sys_libs = "" + warnings = "-Wall", + sys_libs = "", ) -test_rule = base_config( +test_rule = base_config.extend( name = "test_rule", description = "Running test {file_in}", command = "rm -f {file_out} && {file_in} {args} && touch {file_out}", + file_out = "{file_in}_pass", args = "", ) #------------------------------------------------------------------------------- def run_test(name, **kwargs): - c = test_rule( - files_in = [path.join("{out_dir}", name)], - files_out = [path.join("{out_dir}", name) + "_pass"], - **kwargs) - hancho.queue(c) - -def run_test2(name, **kwargs): - c = test_rule( - files_in = [name], - files_out = [name + "_pass"], - **kwargs) - hancho.queue(c) + return test_rule(file_in = name, **kwargs) #------------------------------------------------------------------------------- def compile_srcs(srcs, **kwargs): objs = [] for src_file in srcs: - obj_file = path.splitext(src_file)[0] + ".o" - obj_file = path.join("{out_dir}", obj_file) - c = rule_compile_cpp( - files_in = [src_file], - files_out = [obj_file], - **kwargs - ) - objs.append(hancho.queue(c)[0]) + result = rule_compile_cpp(file_in = src_file, **kwargs) + objs.append(result) return objs #------------------------------------------------------------------------------- -def c_binary(*, name, srcs, libs = [], deps = [], **kwargs): - c = link_c_bin( - files_in = compile_srcs(srcs, **kwargs), - files_out = [path.join("{out_dir}", name)], - libs = libs, - deps = libs + deps, - **kwargs) - return hancho.queue(c)[0] +def c_binary(*, name, srcs, **kwargs): + return link_c_bin( + files_in = compile_srcs(srcs, **kwargs), + file_out = "{out_dir}/" + name, + **kwargs + ) #------------------------------------------------------------------------------- -def c_library(*, name, srcs, libs = [], deps = [], **kwargs): - objs = compile_srcs(srcs, **kwargs) - - c = link_c_lib( - files_in = objs + libs, - files_out = [path.join("{out_dir}", name)], - libs = libs, - deps = libs + deps, +def c_library(*, name, srcs, **kwargs): + return link_c_lib( + files_in = compile_srcs(srcs, **kwargs), + file_out = "{out_dir}/" + name, **kwargs) - return hancho.queue(c)[0] #------------------------------------------------------------------------------- diff --git a/tests/parseroni_test.cpp b/tests/parseroni_test.cpp index 0fffb1a..0251141 100644 --- a/tests/parseroni_test.cpp +++ b/tests/parseroni_test.cpp @@ -273,10 +273,12 @@ void test_pathological() { //------------------------------------------------------------------------------ int main(int argc, char** argv) { + printf("parseroni_test begin\n"); test_basic(); test_rewind(); test_begin_end(); test_pathological(); + printf("parseroni_test done\n"); return 0; }