28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
# build/build_targets/tests.py
|
|
from .base import BuildTarget
|
|
from ..utils import mkdir
|
|
|
|
class TestBuild(BuildTarget):
|
|
def sources(self):
|
|
tests = list(self.config.TEST_DIR.glob("*.c"))
|
|
main_sources = [s for s in self.config.SRC_DIR.glob("*.c") if s.name not in ["main.c", "pico_main.c"]]
|
|
return tests + main_sources
|
|
|
|
def output(self):
|
|
return self.config.TEST_TARGET
|
|
|
|
def build(self):
|
|
self.utils.mkdir(self.config.OBJ_DIR)
|
|
compiler = self.platform.compiler()
|
|
objects = []
|
|
for s in self.sources():
|
|
obj = self.config.OBJ_DIR / (s.stem + ".o")
|
|
deps = self.config.OBJ_DIR / (s.stem + ".d")
|
|
is_test = s.parent == self.config.TEST_DIR
|
|
flags = self.platform.cflags(test=is_test)
|
|
extra = [f'-DGIT_COMMIT_HASH="{self.utils.git_commit_hash()}"']
|
|
compiler.compile(s, obj, flags, extra_defines=extra, deps_out=deps)
|
|
objects.append(obj)
|
|
self.utils.mkdir(self.config.BIN_DIR)
|
|
compiler.link(objects, self.output(), libs=["-lm"])
|