Better target preparation

This commit is contained in:
2026-06-26 06:57:14 +00:00
parent b7b99783c8
commit 3fa98a4e26
6 changed files with 68 additions and 21 deletions
+4 -2
View File
@@ -41,6 +41,8 @@ def load(path: Path) -> Project:
raise rethrowme
def _collect_profiles(project: Project) -> None:
assert False, "Not Implemented Yet"
# TODO: Determine what profile is supposed to be active and load the targets
# so that they will be compiled.
for profile in project.profiles:
@@ -115,11 +117,11 @@ def _clone_required(
reqpath: Path
) -> None:
# TODO: Clean this up.
def handle_success(cmdstr: str, stdout: str, stderr: str) -> None:
def handle_success(retcode: int, cmdstr: str, stdout: str) -> None:
return
errstr = None
def handle_error(cmdstr: str, stdout: str, stderr: str) -> None:
def handle_error(retcode: int, cmdstr: str, stderr: str) -> None:
global errstr
errstr = stderr
+2 -2
View File
@@ -25,8 +25,8 @@ class Project(Identity):
tests: list[Target] = field(default_factory=list)
exports: list[str] = field(default_factory=list)
origination: Origination = field(default=Origination.cwd())
destination: Destination = field(default=Destination.cwd())
origination: Origination = field(default=Origination.cwd())
destination: Destination = field(default=Destination.cwd())
@classmethod
def to_dict(cls, data: Self) -> dict:
+3
View File
@@ -27,6 +27,9 @@ class Target(yaml.YAMLObject):
libs: set[Accessor] = field(default_factory=set)
srcs: set[Accessor] = field(default_factory=set)
# Internal to the tool.
_prepared: bool = field(init=False,default=False)
@classmethod
def to_dict(cls, data: Self) -> dict:
return {
+19
View File
@@ -22,5 +22,24 @@ def build(
commands: list[Command] = []
for target in project.targets:
commands.extend(_prepare_dependencies(appcfg, target, logger))
commands.extend(prepare(appcfg, project, target, logger))
return execute(commands, "Building")
def _prepare_dependencies(
appcfg: Config,
target: Target,
logger: Logger = _logger
) -> list[Command]:
from ..management import find_target_by_name
from ..management import find_project_by_target
commands: list[Command] = []
for required in target.deps:
dependency = find_target_by_name(required)
if dependency._prepared:
continue
project = find_project_by_target(required)
commands.extend(prepare(appcfg, project, target, logger))
return commands
+21 -17
View File
@@ -26,10 +26,19 @@ def prepare(
target: Target,
logger: Logger = _logger
) -> list[Command]:
objects: list[Path] = []
commands: list[Command] = []
if target.type == Output.IMP or \
target.type == Output.INT:
return commands
match target.type:
case Output.EXE: outfile = project.destination.bin(target.name)
case Output.LIB: outfile = project.destination.lib(target.name)
case Output.DLL: outfile = project.destination.dll(target.name)
case Output.OBJ: assert False, "Not Implemented"
objects: list[Path] = []
# TODO: clean this up.
compiler = Compiler(appcfg.native_tooling, logger)
defopts = CompilerOptions()
@@ -40,10 +49,10 @@ def prepare(
for file in target.srcs:
srcfile = project.origination.src(file.value)
dstfile = project.destination.obj(file.value)
if latest(srcfile, dstfile):
continue
commands.append(CompileObject(compiler, defopts, logger, srcfile, dstfile))
objects.append(dstfile)
if not latest(srcfile, dstfile):
commands.append(CompileObject(compiler, defopts, logger, srcfile, dstfile))
if not latest(srcfile, outfile):
objects.append(dstfile)
defopts.objfiles.update(objects)
del objects
@@ -65,16 +74,11 @@ def prepare(
command: Command
match target.type:
case Output.EXE:
outfile = project.destination.bin(target.name)
command = CompileProgram(compiler, defopts, logger, outfile)
case Output.LIB:
outfile = project.destination.lib(target.name)
command = CompileArchive(compiler, defopts, logger, outfile)
case Output.DLL:
outfile = project.destination.dll(target.name)
command = CompileDynlib(compiler, defopts, logger, outfile)
case Output.OBJ:
assert False, "Not Implemented"
case Output.EXE: command = CompileProgram(compiler, defopts, logger, outfile)
case Output.LIB: command = CompileArchive(compiler, defopts, logger, outfile)
case Output.DLL: command = CompileDynlib(compiler, defopts, logger, outfile)
case Output.OBJ: assert False, "Not Implemented"
target._prepared = True
commands.append(command)
return commands
+19
View File
@@ -23,6 +23,7 @@ def test(
commands: list[Command] = []
for target in project.tests:
commands.extend(_prepare_dependencies(appcfg, target, logger))
commands.extend(prepare(appcfg, project, target, logger))
results = execute(commands, "Building")
@@ -32,3 +33,21 @@ def test(
commands.append(ExecuteTest(None, None, logger, testfile))
results.extend(execute(commands, "Testing"))
return results
def _prepare_dependencies(
appcfg: Config,
target: Target,
logger: Logger = _logger
) -> list[Command]:
from ..management import find_target_by_name
from ..management import find_project_by_target
commands: list[Command] = []
for required in target.deps:
dependency = find_target_by_name(required)
if dependency._prepared:
continue
project = find_project_by_target(required)
commands.extend(prepare(appcfg, project, target, logger))
return commands