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 raise rethrowme
def _collect_profiles(project: Project) -> None: def _collect_profiles(project: Project) -> None:
assert False, "Not Implemented Yet"
# TODO: Determine what profile is supposed to be active and load the targets # TODO: Determine what profile is supposed to be active and load the targets
# so that they will be compiled. # so that they will be compiled.
for profile in project.profiles: for profile in project.profiles:
@@ -115,11 +117,11 @@ def _clone_required(
reqpath: Path reqpath: Path
) -> None: ) -> None:
# TODO: Clean this up. # 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 return
errstr = None errstr = None
def handle_error(cmdstr: str, stdout: str, stderr: str) -> None: def handle_error(retcode: int, cmdstr: str, stderr: str) -> None:
global errstr global errstr
errstr = stderr errstr = stderr
+2 -2
View File
@@ -25,8 +25,8 @@ class Project(Identity):
tests: list[Target] = field(default_factory=list) tests: list[Target] = field(default_factory=list)
exports: list[str] = field(default_factory=list) exports: list[str] = field(default_factory=list)
origination: Origination = field(default=Origination.cwd()) origination: Origination = field(default=Origination.cwd())
destination: Destination = field(default=Destination.cwd()) destination: Destination = field(default=Destination.cwd())
@classmethod @classmethod
def to_dict(cls, data: Self) -> dict: 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) libs: set[Accessor] = field(default_factory=set)
srcs: 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 @classmethod
def to_dict(cls, data: Self) -> dict: def to_dict(cls, data: Self) -> dict:
return { return {
+19
View File
@@ -22,5 +22,24 @@ def build(
commands: list[Command] = [] commands: list[Command] = []
for target in project.targets: for target in project.targets:
commands.extend(_prepare_dependencies(appcfg, target, logger))
commands.extend(prepare(appcfg, project, target, logger)) commands.extend(prepare(appcfg, project, target, logger))
return execute(commands, "Building") 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, target: Target,
logger: Logger = _logger logger: Logger = _logger
) -> list[Command]: ) -> list[Command]:
objects: list[Path] = []
commands: list[Command] = [] 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) compiler = Compiler(appcfg.native_tooling, logger)
defopts = CompilerOptions() defopts = CompilerOptions()
@@ -40,10 +49,10 @@ def prepare(
for file in target.srcs: for file in target.srcs:
srcfile = project.origination.src(file.value) srcfile = project.origination.src(file.value)
dstfile = project.destination.obj(file.value) dstfile = project.destination.obj(file.value)
if latest(srcfile, dstfile): if not latest(srcfile, dstfile):
continue commands.append(CompileObject(compiler, defopts, logger, srcfile, dstfile))
commands.append(CompileObject(compiler, defopts, logger, srcfile, dstfile)) if not latest(srcfile, outfile):
objects.append(dstfile) objects.append(dstfile)
defopts.objfiles.update(objects) defopts.objfiles.update(objects)
del objects del objects
@@ -65,16 +74,11 @@ def prepare(
command: Command command: Command
match target.type: match target.type:
case Output.EXE: case Output.EXE: command = CompileProgram(compiler, defopts, logger, outfile)
outfile = project.destination.bin(target.name) case Output.LIB: command = CompileArchive(compiler, defopts, logger, outfile)
command = CompileProgram(compiler, defopts, logger, outfile) case Output.DLL: command = CompileDynlib(compiler, defopts, logger, outfile)
case Output.LIB: case Output.OBJ: assert False, "Not Implemented"
outfile = project.destination.lib(target.name)
command = CompileArchive(compiler, defopts, logger, outfile) target._prepared = True
case Output.DLL:
outfile = project.destination.dll(target.name)
command = CompileDynlib(compiler, defopts, logger, outfile)
case Output.OBJ:
assert False, "Not Implemented"
commands.append(command) commands.append(command)
return commands return commands
+19
View File
@@ -23,6 +23,7 @@ def test(
commands: list[Command] = [] commands: list[Command] = []
for target in project.tests: for target in project.tests:
commands.extend(_prepare_dependencies(appcfg, target, logger))
commands.extend(prepare(appcfg, project, target, logger)) commands.extend(prepare(appcfg, project, target, logger))
results = execute(commands, "Building") results = execute(commands, "Building")
@@ -32,3 +33,21 @@ def test(
commands.append(ExecuteTest(None, None, logger, testfile)) commands.append(ExecuteTest(None, None, logger, testfile))
results.extend(execute(commands, "Testing")) results.extend(execute(commands, "Testing"))
return results 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