Removed the "manifest" suffix from classes names in the model.

This commit is contained in:
Sleepy Monax 2023-11-11 16:19:14 +01:00
parent 9a962e825e
commit 3a78537dff
3 changed files with 36 additions and 43 deletions

View file

@ -5,9 +5,9 @@ import os
import logging import logging
from cutekit.model import ( from cutekit.model import (
ProjectManifest, Project,
TargetManifest, Target,
ComponentManifest, Component,
Props, Props,
Type, Type,
Tool, Tool,
@ -19,7 +19,7 @@ _logger = logging.getLogger(__name__)
class IContext(Protocol): class IContext(Protocol):
target: TargetManifest target: Target
def builddir(self) -> str: def builddir(self) -> str:
... ...
@ -28,7 +28,7 @@ class IContext(Protocol):
class ComponentInstance: class ComponentInstance:
enabled: bool = True enabled: bool = True
disableReason = "" disableReason = ""
manifest: ComponentManifest manifest: Component
sources: list[str] = [] sources: list[str] = []
res: list[str] = [] res: list[str] = []
resolved: list[str] = [] resolved: list[str] = []
@ -38,7 +38,7 @@ class ComponentInstance:
self, self,
enabled: bool, enabled: bool,
disableReason: str, disableReason: str,
manifest: ComponentManifest, manifest: Component,
sources: list[str], sources: list[str],
res: list[str], res: list[str],
resolved: list[str], resolved: list[str],
@ -103,7 +103,7 @@ class ComponentInstance:
class Context(IContext): class Context(IContext):
target: TargetManifest target: Target
instances: list[ComponentInstance] instances: list[ComponentInstance]
tools: Tools tools: Tools
@ -111,7 +111,7 @@ class Context(IContext):
return filter(lambda x: x.enabled, self.instances) return filter(lambda x: x.enabled, self.instances)
def __init__( def __init__(
self, target: TargetManifest, instances: list[ComponentInstance], tools: Tools self, target: Target, instances: list[ComponentInstance], tools: Tools
): ):
self.target = target self.target = target
self.instances = instances self.instances = instances
@ -143,7 +143,7 @@ class Context(IContext):
return os.path.join(const.BUILD_DIR, f"{self.target.id}-{self.hashid()[:8]}") return os.path.join(const.BUILD_DIR, f"{self.target.id}-{self.hashid()[:8]}")
def loadAllTargets() -> list[TargetManifest]: def loadAllTargets() -> list[Target]:
projectRoot = project.root() projectRoot = project.root()
if projectRoot is None: if projectRoot is None:
return [] return []
@ -159,42 +159,40 @@ def loadAllTargets() -> list[TargetManifest]:
ret = [] ret = []
for entry in paths: for entry in paths:
files = shell.find(entry, ["*.json"]) files = shell.find(entry, ["*.json"])
ret += list(map(lambda path: TargetManifest(jexpr.evalRead(path), path), files)) ret += list(map(lambda path: Target(jexpr.evalRead(path), path), files))
return ret return ret
def loadProject(path: str) -> ProjectManifest: def loadProject(path: str) -> Project:
path = os.path.join(path, "project.json") path = os.path.join(path, "project.json")
return ProjectManifest(jexpr.evalRead(path), path) return Project(jexpr.evalRead(path), path)
def loadTarget(id: str) -> TargetManifest: def loadTarget(id: str) -> Target:
try: try:
return next(filter(lambda t: t.id == id, loadAllTargets())) return next(filter(lambda t: t.id == id, loadAllTargets()))
except StopIteration: except StopIteration:
raise RuntimeError(f"Target '{id}' not found") raise RuntimeError(f"Target '{id}' not found")
def loadAllComponents() -> list[ComponentManifest]: def loadAllComponents() -> list[Component]:
files = shell.find(const.SRC_DIR, ["manifest.json"]) files = shell.find(const.SRC_DIR, ["manifest.json"])
files += shell.find(const.EXTERN_DIR, ["manifest.json"]) files += shell.find(const.EXTERN_DIR, ["manifest.json"])
return list(map(lambda path: ComponentManifest(jexpr.evalRead(path), path), files)) return list(map(lambda path: Component(jexpr.evalRead(path), path), files))
def filterDisabled( def filterDisabled(
components: list[ComponentManifest], target: TargetManifest components: list[Component], target: Target
) -> tuple[list[ComponentManifest], list[ComponentManifest]]: ) -> tuple[list[Component], list[Component]]:
return list(filter(lambda c: c.isEnabled(target)[0], components)), list( return list(filter(lambda c: c.isEnabled(target)[0], components)), list(
filter(lambda c: not c.isEnabled(target)[0], components) filter(lambda c: not c.isEnabled(target)[0], components)
) )
def providerFor( def providerFor(what: str, components: list[Component]) -> tuple[Optional[str], str]:
what: str, components: list[ComponentManifest] result: list[Component] = list(filter(lambda c: c.id == what, components))
) -> tuple[Optional[str], str]:
result: list[ComponentManifest] = list(filter(lambda c: c.id == what, components))
if len(result) == 0: if len(result) == 0:
# Try to find a provider # Try to find a provider
@ -213,7 +211,7 @@ def providerFor(
def resolveDeps( def resolveDeps(
componentSpec: str, components: list[ComponentManifest], target: TargetManifest componentSpec: str, components: list[Component], target: Target
) -> tuple[bool, str, list[str]]: ) -> tuple[bool, str, list[str]]:
mapping = dict(map(lambda c: (c.id, c), components)) mapping = dict(map(lambda c: (c.id, c), components))
@ -251,7 +249,7 @@ def resolveDeps(
def instanciate( def instanciate(
componentSpec: str, components: list[ComponentManifest], target: TargetManifest componentSpec: str, components: list[Component], target: Target
) -> Optional[ComponentInstance]: ) -> Optional[ComponentInstance]:
manifest = next(filter(lambda c: c.id == componentSpec, components)) manifest = next(filter(lambda c: c.id == componentSpec, components))
wildcards = set(chain(*map(lambda rule: rule.fileIn, rules.rules.values()))) wildcards = set(chain(*map(lambda rule: rule.fileIn, rules.rules.values())))
@ -266,9 +264,7 @@ def instanciate(
) )
def instanciateDisabled( def instanciateDisabled(component: Component, target: Target) -> ComponentInstance:
component: ComponentManifest, target: TargetManifest
) -> ComponentInstance:
return ComponentInstance( return ComponentInstance(
enabled=False, enabled=False,
disableReason=component.isEnabled(target)[1], disableReason=component.isEnabled(target)[1],

View file

@ -1,7 +1,7 @@
from typing import Callable from typing import Callable
from cutekit.model import TargetManifest, Tools from cutekit.model import Target, Tools
Mixin = Callable[[TargetManifest, Tools], Tools] Mixin = Callable[[Target, Tools], Tools]
def patchToolArgs(tools: Tools, toolSpec: str, args: list[str]): def patchToolArgs(tools: Tools, toolSpec: str, args: list[str]):
@ -12,20 +12,17 @@ def prefixToolCmd(tools: Tools, toolSpec: str, prefix: str):
tools[toolSpec].cmd = prefix + " " + tools[toolSpec].cmd tools[toolSpec].cmd = prefix + " " + tools[toolSpec].cmd
def mixinCache(target: TargetManifest, tools: Tools) -> Tools: def mixinCache(target: Target, tools: Tools) -> Tools:
prefixToolCmd(tools, "cc", "ccache") prefixToolCmd(tools, "cc", "ccache")
prefixToolCmd(tools, "cxx", "ccache") prefixToolCmd(tools, "cxx", "ccache")
return tools return tools
def makeMixinSan(san: str) -> Mixin: def makeMixinSan(san: str) -> Mixin:
def mixinSan(target: TargetManifest, tools: Tools) -> Tools: def mixinSan(target: Target, tools: Tools) -> Tools:
patchToolArgs( patchToolArgs(tools, "cc", [f"-fsanitize={san}"])
tools, "cc", [f"-fsanitize={san}"]) patchToolArgs(tools, "cxx", [f"-fsanitize={san}"])
patchToolArgs( patchToolArgs(tools, "ld", [f"-fsanitize={san}"])
tools, "cxx", [f"-fsanitize={san}"])
patchToolArgs(
tools, "ld", [f"-fsanitize={san}"])
return tools return tools
@ -33,7 +30,7 @@ def makeMixinSan(san: str) -> Mixin:
def makeMixinOptimize(level: str) -> Mixin: def makeMixinOptimize(level: str) -> Mixin:
def mixinOptimize(target: TargetManifest, tools: Tools) -> Tools: def mixinOptimize(target: Target, tools: Tools) -> Tools:
patchToolArgs(tools, "cc", [f"-O{level}"]) patchToolArgs(tools, "cc", [f"-O{level}"])
patchToolArgs(tools, "cxx", [f"-O{level}"]) patchToolArgs(tools, "cxx", [f"-O{level}"])
@ -42,7 +39,7 @@ def makeMixinOptimize(level: str) -> Mixin:
return mixinOptimize return mixinOptimize
def mixinDebug(target: TargetManifest, tools: Tools) -> Tools: def mixinDebug(target: Target, tools: Tools) -> Tools:
patchToolArgs(tools, "cc", ["-g", "-gdwarf-4"]) patchToolArgs(tools, "cc", ["-g", "-gdwarf-4"])
patchToolArgs(tools, "cxx", ["-g", "-gdwarf-4"]) patchToolArgs(tools, "cxx", ["-g", "-gdwarf-4"])
@ -50,7 +47,7 @@ def mixinDebug(target: TargetManifest, tools: Tools) -> Tools:
def makeMixinTune(tune: str) -> Mixin: def makeMixinTune(tune: str) -> Mixin:
def mixinTune(target: TargetManifest, tools: Tools) -> Tools: def mixinTune(target: Target, tools: Tools) -> Tools:
patchToolArgs(tools, "cc", [f"-mtune={tune}"]) patchToolArgs(tools, "cc", [f"-mtune={tune}"])
patchToolArgs(tools, "cxx", [f"-mtune={tune}"]) patchToolArgs(tools, "cxx", [f"-mtune={tune}"])

View file

@ -89,7 +89,7 @@ class Extern:
return f"Extern({self.git})" return f"Extern({self.git})"
class ProjectManifest(Manifest): class Project(Manifest):
description: str = "" description: str = ""
extern: dict[str, Extern] = {} extern: dict[str, Extern] = {}
@ -159,7 +159,7 @@ class Tool:
Tools = dict[str, Tool] Tools = dict[str, Tool]
class TargetManifest(Manifest): class Target(Manifest):
props: Props props: Props
tools: Tools tools: Tools
routing: dict[str, str] routing: dict[str, str]
@ -219,7 +219,7 @@ class TargetManifest(Manifest):
return defines return defines
class ComponentManifest(Manifest): class Component(Manifest):
decription: str = "(No description)" decription: str = "(No description)"
props: Props = {} props: Props = {}
tools: Tools = {} tools: Tools = {}
@ -264,7 +264,7 @@ class ComponentManifest(Manifest):
def __repr__(self): def __repr__(self):
return f"ComponentManifest({self.id})" return f"ComponentManifest({self.id})"
def isEnabled(self, target: TargetManifest) -> tuple[bool, str]: def isEnabled(self, target: Target) -> tuple[bool, str]:
for k, v in self.enableIf.items(): for k, v in self.enableIf.items():
if k not in target.props: if k not in target.props:
_logger.info(f"Component {self.id} disabled by missing {k} in target") _logger.info(f"Component {self.id} disabled by missing {k} in target")