Improved build api.

This commit is contained in:
Sleepy Monax 2024-01-17 09:18:27 +01:00
parent 9c9db6c36b
commit f134c5752b
2 changed files with 5 additions and 5 deletions

View file

@ -3,7 +3,7 @@ import logging
import dataclasses as dt
from pathlib import Path
from typing import Callable, TextIO, Union
from typing import Callable, Literal, TextIO, Union
from . import shell, rules, model, ninja, const, cli
@ -300,17 +300,16 @@ def gen(out: TextIO, scope: TargetScope):
def build(
scope: TargetScope,
components: Union[list[model.Component], model.Component, None] = None,
components: Union[list[model.Component], model.Component, Literal["all"]] = "all",
) -> list[ProductScope]:
all = False
shell.mkdir(scope.target.builddir)
ninjaPath = os.path.join(scope.target.builddir, "build.ninja")
# if not os.path.exists(ninjaPath):
with open(ninjaPath, "w") as f:
gen(f, scope)
if components is None:
if components == "all":
all = True
components = list(scope.registry.iterEnabled(scope.target))
@ -348,7 +347,7 @@ def _(args: cli.Args):
component = None
if componentSpec is not None:
component = scope.registry.lookup(componentSpec, model.Component)
build(scope, component)[0]
build(scope, component if component is not None else "all")[0]
@cli.command("r", "builder/run", "Run a component")

View file

@ -15,6 +15,7 @@ def load(path: str):
if not spec or not spec.loader:
_logger.error(f"Failed to load plugin {path}")
return
module = importlib.module_from_spec(spec)
sys.modules["plugin"] = module