Context caching

This commit is contained in:
Sleepy Monax 2023-02-08 23:37:28 +01:00
parent 120f4ee152
commit e620d8e1cf
3 changed files with 15 additions and 7 deletions

View file

@ -76,8 +76,8 @@ def gen(out: TextIO, context: Context):
writer.newline()
def build(componentSpec: str, targetSpec: str, props: Props = {}) -> str:
context = contextFor(targetSpec, props)
def build(componentSpec: str, targetSpec: str) -> str:
context = contextFor(targetSpec)
target = context.target
shell.mkdir(context.builddir())
@ -107,8 +107,8 @@ class Paths:
self.obj = obj
def buildAll(targetSpec: str, props: Props = {}) -> Paths:
context = contextFor(targetSpec, props)
def buildAll(targetSpec: str) -> Paths:
context = contextFor(targetSpec)
target = context.target
shell.mkdir(context.builddir())

View file

@ -156,7 +156,7 @@ def graphCmd(args: Args):
scope: str | None = cast(str | None, args.tryConsumeOpt("scope"))
onlyLibs: bool = args.consumeOpt("only-libs", False) == True
context = contextFor(targetSpec, {})
context = contextFor(targetSpec)
graph.view(context, scope=scope, showExe=not onlyLibs)

View file

@ -183,7 +183,13 @@ def instanciate(componentSpec: str, components: list[ComponentManifest], target:
return ComponentInstance(manifest, sources, resolved[1:])
def contextFor(targetSpec: str, props: Props) -> Context:
context: dict = {}
def contextFor(targetSpec: str) -> Context:
if targetSpec in context:
return context[targetSpec]
logger.log(f"Loading context for {targetSpec}")
targetEls = targetSpec.split(":")
@ -221,8 +227,10 @@ def contextFor(targetSpec: str, props: Props) -> Context:
instances = cast(list[ComponentInstance], list(filter(lambda e: e != None, map(lambda c: instanciate(
c.id, components, target), components))))
return Context(
context[targetSpec] = Context(
target,
instances,
tools,
)
return context[targetSpec]