Skip to content

Commit

Permalink
hax, trying to get everything working at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Aug 11, 2024
1 parent d1ffb5b commit cb597c5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 197 deletions.
25 changes: 14 additions & 11 deletions hancho.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ class Sentinel:
class Config:
"""A Config object is just a 'bag of fields'."""

def __init__(self, **kwargs):
def __init__(self, *args, **kwargs):
for arg in args:
self.update(arg)
self.update(kwargs)

#----------------------------------------
Expand Down Expand Up @@ -366,15 +368,16 @@ def __call__(self, *args, **kwargs):
Config.shuffle = False
Config.trace = False
Config.use_color = True

Config.should_fail = False
Config.is_test = False
Config.save_log = False

# fmt: on

####################################################################################################

def load_file(file_name, as_repo, **kwargs):
mod_config = Config(**kwargs)
def load_file(file_name, as_repo, args, kwargs):
mod_config = Config(*args, **kwargs)

file_name = mod_config.expand(file_name)
abs_file_path = join_path(Config.base_path, file_name)
Expand All @@ -386,11 +389,11 @@ def load_file(file_name, as_repo, **kwargs):

return app.load_module(repo_path, repo_name, file_path, file_name, mod_config)

def load(file_name, **kwargs):
return load_file(file_name, False, **kwargs)
def load(file_name, *args, **kwargs):
return load_file(file_name, as_repo=False, args=args, kwargs=kwargs)

def repo(file_name, **kwargs):
return load_file(file_name, True, **kwargs)
def repo(file_name, *args, **kwargs):
return load_file(file_name, as_repo=True, args=args, kwargs=kwargs)

def reset():
return app.reset()
Expand Down Expand Up @@ -999,17 +1002,17 @@ async def run_command(self, command):

command_pass = (self.returncode == 0) != self.should_fail

if self.is_test:
if self.save_log:
result = open(self.out_log, "w")
result.write("-----stderr-----\n")
result.write(self.stderr)
result.write("-----stdout-----\n")
result.write(self.stdout)
result.close()

if Config.verbose or not command_pass or self.stderr:
if self.verbose or not command_pass or self.stderr:
self.print_status()
if self.stderr:
if self.stderr and not self.should_fail:
log("-----stderr-----")
log(self.stderr, end="")
if self.stdout:
Expand Down
144 changes: 0 additions & 144 deletions metron_rules.hancho

This file was deleted.

78 changes: 36 additions & 42 deletions rules.hancho
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hancho
import os

####################################################################################################
# Utils
Expand All @@ -22,17 +23,14 @@ if os.name == 'nt':
depformat = "msvc",
)
elif os.name == 'posix':
exports.compile_cpp = hancho.command(
exports.compile_cpp = hancho.Command(
command = "gcc -MMD -c {rel_source_files} -o {rel_build_files}",
build_files = "{swap_ext(source_files, '.o')}",
build_deps = "{swap_ext(source_files, '.d')}",
depformat = "gcc",
)
else:
assert False

"""

"""

def link_c_bin(in_objs, out_bin, *args, **kwargs):
Expand All @@ -47,23 +45,21 @@ def link_c_bin(in_objs, out_bin, *args, **kwargs):

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

def compile_srcs(*args, in_srcs, **kwargs):
config = hancho.Config(*args, **kwargs)
command = hancho.Command(
desc = "Compiling {rel(in_src)} -> {rel(out_obj)} ({build_tag})",
command = "g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {rel(in_src)} -o {rel(out_obj)}",
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{repo_path}",
defines = "",
out_obj = "{swap_ext(in_src, '.o')}",
depfile = "{swap_ext(in_src, '.d')}",
**kwargs,
)
return [command(config, in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]

"""
#def compile_srcs(*args, in_srcs, **kwargs):
# config = hancho.Config(*args, **kwargs)
# command = hancho.Command(
# desc = "Compiling C++ {rel(in_src)} -> {rel(out_obj)} ({build_tag})",
# command = "g++ {cpp_std} {gcc_opt} {warnings} {includes} {defines} -c {rel(in_src)} -o {rel(out_obj)}",
# 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{repo_path}",
# defines = "",
# out_obj = "{swap_ext(in_src, '.o')}",
# depfile = "{swap_ext(in_src, '.d')}",
# **kwargs,
# )
# return [command(config, in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]

cpp_config = hancho.Config(
toolchain = "x86_64-linux-gnu",
Expand Down Expand Up @@ -107,7 +103,7 @@ exports.link_cpp_lib = hancho.Command(
desc = "Bundling C++ lib {rel(out_lib)}",
command = "ar rcs {rel(out_lib)} {rel(in_objs)}",
in_objs = None,
out_lib = "{name}",
out_lib = "{name}.a",
)

#----------------------------------------
Expand All @@ -132,25 +128,23 @@ exports.link_cpp_bin = hancho.Command(

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

def cpp_bin(*, name, in_srcs = [], in_objs = [], in_libs = [], out_bin = "{name}", **kwargs):
objs = [compile_cpp(in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]
return link_cpp_bin(
def cpp_bin(*, name, in_srcs = [], in_objs = [], in_libs = [], **kwargs):
objs = [exports.compile_cpp(in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]
return exports.link_cpp_bin(
name = name,
in_objs = [objs, in_objs, in_libs],
out_bin = out_bin,
**kwargs,
)

exports.cpp_bin = hancho.Command(cpp_bin)

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

def cpp_lib(*, name, in_srcs = [], in_objs = [], in_libs = [], out_lib = "{name}", **kwargs):
objs = [compile_cpp(in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]
return link_cpp_lib(
def cpp_lib(*, name, in_srcs = [], in_objs = [], in_libs = [], **kwargs):
objs = [exports.compile_cpp(in_src = file, **kwargs) for file in hancho.flatten(in_srcs)]
return exports.link_cpp_lib(
name = name,
in_objs = [objs, in_objs, in_libs],
out_lib = out_lib,
**kwargs,
)

Expand Down Expand Up @@ -188,23 +182,23 @@ exports.make = hancho.Command(
# Tests

run_test = hancho.Command(
desc = "Running test {rel(in_test)}",
command = "{in_test} {args}",
in_test = None,
out_log = "{in_test}.test",
args = "",
is_test = True,
desc = "Running test {rel(in_test)}",
command = "{in_test} {args} && touch {out_pass}",
in_test = None,
args = "",
out_pass = "{in_test}.pass",
save_log = True,
out_log = "{in_test}.log",
)

def c_test(*, name, in_srcs = [], in_objs = [], in_libs = [], out_bin = "{name}", **kwargs):
objs = [compile_cpp(in_src = src, **kwargs) for src in hancho.flatten(in_srcs)]
bin = link_cpp_bin(
def c_test(*, name, in_srcs = [], in_objs = [], in_libs = [], **kwargs):
objs = [exports.compile_cpp(kwargs, in_src = src) for src in hancho.flatten(in_srcs)]
bin = exports.link_cpp_bin(
kwargs,
name = name,
in_objs = [objs, in_objs, in_libs],
out_bin = out_bin,
**kwargs
)
return run_test(in_test = bin)
return run_test(kwargs, in_test = bin)

exports.c_test = hancho.Command(c_test)

Expand Down

0 comments on commit cb597c5

Please sign in to comment.