Disable targets that can't be built.

This commit is contained in:
Sleepy Monax 2022-07-12 17:12:00 +02:00
parent 44a34b826c
commit a82f74ee68
3 changed files with 51 additions and 36 deletions

View file

@ -84,7 +84,8 @@ def listCmd(opts: dict, args: list[str]) -> None:
componentsNames = list(components.keys())
componentsNames.sort()
for component in componentsNames:
print(" " + component)
if components[component]["enabled"]:
print(" " + component)
print("")

View file

@ -11,6 +11,9 @@ from . import utils
def mergeToolsArgs(tool, layers):
args = []
for layer in layers:
if not layer.get("enabled", True):
continue
args.extend(layer
.get("tools", {})
.get(tool, {})
@ -60,6 +63,9 @@ def genNinja(out: TextIO, manifests: dict, target: dict) -> None:
for key in manifests:
item = manifests[key]
if not item["enabled"]:
continue
writer.comment("Project: " + item["id"])
for obj in item["objs"]:
@ -133,6 +139,10 @@ def buildOne(targetId: str, componentId: str, props: dict = {}) -> str:
if not componentId in manifests:
raise utils.CliException("Unknown component: " + componentId)
if not manifests[componentId]["enabled"]:
raise utils.CliException(
f"{componentId} is not enabled for the {targetId} target")
try:
utils.runCmd("ninja", "-v", "-j", "1", "-f",
target["ninjafile"], manifests[componentId]["out"])

View file

@ -1,7 +1,5 @@
import os
import json
import copy
from . import utils
@ -18,7 +16,7 @@ def loadJsons(basedir: str) -> dict:
def filter(manifests: dict, target: dict) -> dict:
result = {}
manifests = copy.deepcopy(manifests)
for id in manifests:
manifest = manifests[id]
accepted = True
@ -30,67 +28,73 @@ def filter(manifests: dict, target: dict) -> dict:
accepted = False
break
if accepted:
result[id] = manifest
manifest["enabled"] = accepted
return result
return manifests
def doInjects(manifests: dict) -> dict:
manifests = copy.deepcopy(manifests)
for key in manifests:
item = manifests[key]
if "inject" in item:
if item["enabled"] and "inject" in item:
for inject in item["inject"]:
if inject in manifests:
manifests[inject]["deps"].append(key)
return manifests
def providersFor(key: str, manifests: dict) -> dict:
result = []
for k in manifests:
if manifests[k]["enabled"] and key in manifests[k].get("provide", []):
result.append(k)
return result
def resolveDeps(manifests: dict) -> dict:
manifests = copy.deepcopy(manifests)
def findProvide(key: str) -> str:
if key in manifests:
return key
result = []
for pkg in manifests:
if key in manifests[pkg].get("provide", []):
result.append(pkg)
if len(result) == 0:
raise utils.CliException(f"Failed to resolve dependency {key}")
if len(result) == 1:
return result[0]
raise utils.CliException(f"Multiple providers for {key}: {result}")
def resolve(key: str, stack: list[str] = []) -> list[str]:
result: list[str] = []
if not key in manifests:
providers = providersFor(key, manifests)
if len(providers) == 0:
return False, "", []
if len(providers) > 1:
raise utils.CliException(
f"Multiple providers for {key}: {providers}")
key = providers[0]
if key in stack:
raise utils.CliException("Circular dependency detected: " +
str(stack) + " -> " + key)
if not key in manifests:
raise utils.CliException("Unknown dependency: " + key)
stack.append(key)
if "deps" in manifests[key]:
stack.append(key)
for dep in manifests[key]["deps"]:
dep = findProvide(dep)
keep, dep, res = resolve(dep, stack)
if not keep:
stack.pop()
return False, "", []
result.append(dep)
result += resolve(dep, stack)
result += res
stack.pop()
return result
stack.pop()
return True, key, result
for key in manifests:
manifests[key]["deps"] = utils.stripDups(resolve(key))
keep, _, deps = resolve(key)
if not keep:
print(f"Disabling {key} because we are missing a deps")
manifests[key]["enabled"] = False
manifests[key]["deps"] = utils.stripDups(deps)
return manifests
@ -154,7 +158,7 @@ def cincludes(manifests: dict) -> str:
for key in manifests:
item = manifests[key]
if "root-include" in item:
if item["enabled"] and "root-include" in item:
include_paths.append(item["dir"])
if len(include_paths) == 0: