diff --git a/chinook/management/_load.py b/chinook/management/_load.py index c22a687..d9e3a9f 100644 --- a/chinook/management/_load.py +++ b/chinook/management/_load.py @@ -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 diff --git a/chinook/models/_project.py b/chinook/models/_project.py index 5d30ce7..4a72de7 100644 --- a/chinook/models/_project.py +++ b/chinook/models/_project.py @@ -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: diff --git a/chinook/models/_target.py b/chinook/models/_target.py index a044280..cdd2f6c 100644 --- a/chinook/models/_target.py +++ b/chinook/models/_target.py @@ -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 { diff --git a/chinook/pipeline/_build.py b/chinook/pipeline/_build.py index 684c07f..86f8771 100644 --- a/chinook/pipeline/_build.py +++ b/chinook/pipeline/_build.py @@ -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 diff --git a/chinook/pipeline/_prepare.py b/chinook/pipeline/_prepare.py index 07ae2f5..1c26252 100644 --- a/chinook/pipeline/_prepare.py +++ b/chinook/pipeline/_prepare.py @@ -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 diff --git a/chinook/pipeline/_test.py b/chinook/pipeline/_test.py index 21bf0e9..87a6383 100644 --- a/chinook/pipeline/_test.py +++ b/chinook/pipeline/_test.py @@ -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