Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Jan 31, 2024
1 parent ae4c82c commit d712bfa
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 39 deletions.
67 changes: 51 additions & 16 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
#!/usr/bin/python3
# Experimental use of hancho.py, beware

import os, sys

print("importing hancho")
sys.stdout.flush()
import hancho
print("importing hancho done")
sys.stdout.flush()

print()
print("========================================")
print(f"loading matcheroni/build.py")
print(f"file {__file__}")
print(f"cwd {os.getcwd()}")
print()

hancho.include("rules.hancho")
hancho.include("examples/examples.hancho")





print(f"os.getcwd {os.getcwd()}")







"""
./rules.hancho
./tests/hancho
./examples/hancho
./examples/c_lexer/hancho
./examples/regex/hancho
"""


hancho.load("rules.hancho")

print(c_binary)

hancho.load("examples/c_lexer/hancho")
#hancho.load("tests/build.hancho")
#hancho.include("rules.hancho")
#hancho.include("tests/build.hancho")


"""
Expand Down Expand Up @@ -51,7 +86,7 @@
deps = [regex_parser],
)
test_rule(file_in = regex_test, quiet = True)
test_rule(files_in = [regex_test], quiet = True)
#-------------------------------------------------------------------------------
# INI parser example
Expand All @@ -64,7 +99,7 @@
with hancho.cwd("toml"):
toml_test = c_binary(name = "toml_test", srcs = ["toml_parser.cpp", "toml_test.cpp"])
test_rule(file_in = toml_test, quiet = True)
test_rule(files_in = [toml_test], quiet = True)
#-------------------------------------------------------------------------------
# JSON parser example
Expand Down Expand Up @@ -99,7 +134,7 @@
deps = [json_parser]
)
test_rule(file_in = json_test, quiet = True)
test_rule(files_in = [json_test], quiet = True)
#-------------------------------------------------------------------------------
# C lexer example (not finished)
Expand All @@ -122,7 +157,7 @@
deps = [c_lexer]
)
test_rule(file_in = c_lexer_test, quiet = True)
test_rule(files_in = [c_lexer_test], quiet = True)
#-------------------------------------------------------------------------------
# C parser example (not finished)
Expand Down Expand Up @@ -150,7 +185,7 @@
)
# Broken?
#test_rule(file_in = "examples/c_parser_test", quiet = True)
#test_rule(files_in = [c_parser_test], quiet = True)
#-------------------------------------------------------------------------------
# Tutorial examples
Expand All @@ -163,12 +198,12 @@
json_tut2a = c_binary(name = "json_tut2a", srcs = ["json_tut2a.cpp"])
json_tut2b = c_binary(name = "json_tut2b", srcs = ["json_tut2b.cpp"])
test_rule(file_in = json_tut0a, quiet = True)
test_rule(file_in = json_tut1a, quiet = True)
test_rule(file_in = json_tut1b, quiet = True)
test_rule(file_in = json_tut1c, quiet = True)
test_rule(file_in = json_tut2a, quiet = True)
test_rule(file_in = json_tut2b, quiet = True)
test_rule(files_in = json_tut0a, quiet = True)
test_rule(files_in = json_tut1a, quiet = True)
test_rule(files_in = json_tut1b, quiet = True)
test_rule(files_in = json_tut1c, quiet = True)
test_rule(files_in = json_tut2a, quiet = True)
test_rule(files_in = json_tut2b, quiet = True)
tiny_c_parser = c_binary(
name = "tiny_c_parser",
Expand Down
11 changes: 9 additions & 2 deletions examples/c_lexer/hancho → examples/c_lexer/c_lexer.hancho
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
print()
print("========================================")
print(f"loading c_lexer/c_lexer.hancho")
print(f"file {__file__}")
print(f"cwd {os.getcwd()}")
print()

print(compile_cpp)

compile_cpp(file_in = "CLexer.cpp")
compile_cpp(files_in = ["CLexer.cpp"])

"""
c_lexer = c_library(
Expand All @@ -22,5 +29,5 @@ c_lexer_test = c_binary(
deps = [c_lexer]
)

test_rule(file_in = c_lexer_test, quiet = True)
test_rule(files_in = c_lexer_test, quiet = True)
"""
8 changes: 8 additions & 0 deletions examples/examples.hancho
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
print()
print("========================================")
print(f"loading examples/examples.hancho")
print(f"file {__file__}")
print(f"cwd {os.getcwd()}")
print()

hancho.include("c_lexer/c_lexer.hancho")
2 changes: 0 additions & 2 deletions examples/hancho

This file was deleted.

2 changes: 1 addition & 1 deletion examples/regex/hancho → examples/regex/regex.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ regex_test = c_binary(
deps = [regex_parser],
)

test_rule(file_in = regex_test, quiet = True)
test_rule(files_in = regex_test, quiet = True)
32 changes: 16 additions & 16 deletions rules.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ if flags.release:
#-------------------------------------------------------------------------------

compile_cpp = base_config.extend(
description = "Compiling {file_in} -> {file_out} ({build_type})",
command = "{toolchain}-g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {file_in} -o {file_out}",
description = "Compiling {files_in[0]} -> {files_out[0]} ({build_type})",
command = "{toolchain}-g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {files_in[0]} -o {files_out[0]}",

toolchain = "x86_64-linux-gnu",
cpp_std = "-std=c++20",
gcc_opt = "{'-O3' if build_type == 'release' else '-g -O0'} -MMD",
warnings = "-Wall -Werror -Wno-unused-variable -Wno-unused-local-typedefs -Wno-unused-but-set-variable",
includes = "-I.",
defines = "",
file_out = "{swap_ext(file_in, '.o')}",
depfile = "{swap_ext(file_in, '.d')}",
files_out = "{swap_ext(files_in[0], '.o')}",
depfile = "{swap_ext(files_in[0], '.d')}",
)

link_c_lib = base_config.extend(
description = "Bundling {file_out}",
command = "ar rcs {file_out} {join(files_in)}",
description = "Bundling {files_out[0]}",
command = "ar rcs {files_out[0]} {join(files_in)}",
)

link_c_bin = base_config.extend(
description = "Linking {file_out}",
command = "{toolchain}-g++ {ld_opt} {warnings} {join(files_in)} {join(deps)} {sys_libs} -o {file_out}",
description = "Linking {files_out[0]}",
command = "{toolchain}-g++ {ld_opt} {warnings} {join(files_in)} {join(deps)} {sys_libs} -o {files_out[0]}",

toolchain = "x86_64-linux-gnu",
ld_opt = "{'-O3' if build_type == 'release' else '-g -O0'}",
Expand All @@ -61,32 +61,32 @@ link_c_bin = base_config.extend(
)

test_rule = base_config.extend(
description = "Running test {file_in}",
command = "rm -f {file_out} && {file_in} {args} && touch {file_out}",
file_out = "{file_in}_pass",
description = "Running test {files_in[0]}",
command = "rm -f {files_out[0]} && {files_in[0]} {args} && touch {files_out[0]}",
files_out = ["{files_in[0]}_pass"],
args = "",
)

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

def compile_srcs(srcs, **kwargs):
return [compile_cpp(file_in = f, **kwargs) for f in srcs]
return [compile_cpp(files_in = [f], **kwargs) for f in srcs]

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

def c_binary(*, name, srcs, **kwargs):
return link_c_bin(
files_in = compile_srcs(srcs, **kwargs),
file_out = name,
files_in = compile_srcs(srcs, **kwargs),
files_out = [name],
**kwargs
)

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

def c_library(*, name, srcs, **kwargs):
return link_c_lib(
files_in = compile_srcs(srcs, **kwargs),
file_out = name,
files_in = compile_srcs(srcs, **kwargs),
files_out = [name],
**kwargs)

#-------------------------------------------------------------------------------
4 changes: 2 additions & 2 deletions tests/hancho
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ parseroni_test = c_binary(
srcs = ["parseroni_test.cpp"],
)

test_rule(file_in = matcheroni_test, quiet = True)
test_rule(file_in = parseroni_test, quiet = True)
test_rule(files_in = matcheroni_test, quiet = True)
test_rule(files_in = parseroni_test, quiet = True)
Empty file removed tests/run_tests.hancho
Empty file.

0 comments on commit d712bfa

Please sign in to comment.