Better target preparation
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,9 +49,9 @@ def prepare(
|
||||
for file in target.srcs:
|
||||
srcfile = project.origination.src(file.value)
|
||||
dstfile = project.destination.obj(file.value)
|
||||
if latest(srcfile, dstfile):
|
||||
continue
|
||||
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)
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user