Skip to content

Commit

Permalink
ok, everything working pretty well
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Jan 27, 2024
1 parent cbdf890 commit d0e4429
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 120 deletions.
93 changes: 26 additions & 67 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,25 @@
#-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

#build obj/matcheroni/Matcheroni.hpp.iwyu : iwyu matcheroni/Matcheroni.hpp
#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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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?
Expand All @@ -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()
1 change: 1 addition & 0 deletions examples/regex/regex_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>

int main(int argc, char** argv) {
printf("All tests pass\n");
return 0;
}
84 changes: 31 additions & 53 deletions rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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}",
Expand All @@ -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]

#-------------------------------------------------------------------------------
2 changes: 2 additions & 0 deletions tests/parseroni_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d0e4429

Please sign in to comment.