Added support for cdefs.
This commit is contained in:
parent
3706ecb183
commit
8ee6e9625d
7 changed files with 58 additions and 27 deletions
|
@ -24,8 +24,8 @@ def mergeToolsArgs(tool, layers):
|
||||||
|
|
||||||
def genNinja(out: TextIO, manifests: dict, target: dict) -> None:
|
def genNinja(out: TextIO, manifests: dict, target: dict) -> None:
|
||||||
target = copy.deepcopy(target)
|
target = copy.deepcopy(target)
|
||||||
target = targets.patchToolArgs(target, "cc", [m.cincludes(manifests)])
|
target = targets.patchToolArgs(target, "cc", [m.cinc(manifests)])
|
||||||
target = targets.patchToolArgs(target, "cxx", [m.cincludes(manifests)])
|
target = targets.patchToolArgs(target, "cxx", [m.cinc(manifests)])
|
||||||
|
|
||||||
writer = ninja.Writer(out)
|
writer = ninja.Writer(out)
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ def genNinja(out: TextIO, manifests: dict, target: dict) -> None:
|
||||||
|
|
||||||
def prepare(targetId: str, props: dict) -> Tuple[dict, dict]:
|
def prepare(targetId: str, props: dict) -> Tuple[dict, dict]:
|
||||||
target = targets.load(targetId, props)
|
target = targets.load(targetId, props)
|
||||||
|
|
||||||
includes = ["src"]
|
includes = ["src"]
|
||||||
|
|
||||||
if os.path.exists("osdk.json"):
|
if os.path.exists("osdk.json"):
|
||||||
|
@ -110,7 +110,7 @@ def prepare(targetId: str, props: dict) -> Tuple[dict, dict]:
|
||||||
osdk = json.load(f)
|
osdk = json.load(f)
|
||||||
includes = osdk["includes"]
|
includes = osdk["includes"]
|
||||||
print("includes: ", includes)
|
print("includes: ", includes)
|
||||||
|
|
||||||
manifests = m.loadAll(includes, target)
|
manifests = m.loadAll(includes, target)
|
||||||
|
|
||||||
utils.mkdirP(target["dir"])
|
utils.mkdirP(target["dir"])
|
||||||
|
|
|
@ -159,7 +159,7 @@ def prepareInOut(manifests: dict, target: dict) -> dict:
|
||||||
return manifests
|
return manifests
|
||||||
|
|
||||||
|
|
||||||
def cincludes(manifests: dict) -> str:
|
def cinc(manifests: dict) -> str:
|
||||||
include_paths = []
|
include_paths = []
|
||||||
|
|
||||||
for key in manifests:
|
for key in manifests:
|
||||||
|
|
|
@ -20,7 +20,10 @@ def gen(out: TextIO, context: Context):
|
||||||
writer.separator("Tools")
|
writer.separator("Tools")
|
||||||
|
|
||||||
writer.variable("cincs", " ".join(
|
writer.variable("cincs", " ".join(
|
||||||
map(lambda i: f"-I{i}", context.cincludes())))
|
map(lambda i: f"-I{i}", context.cincls())))
|
||||||
|
|
||||||
|
writer.variable("cdefs", " ".join(context.cdefs()))
|
||||||
|
|
||||||
writer.newline()
|
writer.newline()
|
||||||
|
|
||||||
for i in target.tools:
|
for i in target.tools:
|
||||||
|
|
|
@ -71,11 +71,14 @@ class Context:
|
||||||
return None
|
return None
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
def cincludes(self) -> list[str]:
|
def cincls(self) -> list[str]:
|
||||||
includes = list(
|
includes = list(
|
||||||
map(lambda x: x.cinclude(), self.instances))
|
map(lambda x: x.cinclude(), self.instances))
|
||||||
return utils.uniq(includes)
|
return utils.uniq(includes)
|
||||||
|
|
||||||
|
def cdefs(self) -> list[str]:
|
||||||
|
return self.target.cdefs()
|
||||||
|
|
||||||
|
|
||||||
def loadAllTargets() -> list[TargetManifest]:
|
def loadAllTargets() -> list[TargetManifest]:
|
||||||
files = shell.find(const.TARGETS_DIR, ["*.json"])
|
files = shell.find(const.TARGETS_DIR, ["*.json"])
|
||||||
|
@ -157,7 +160,7 @@ def resolveDeps(componentSpec: str, components: list[ComponentManifest], target:
|
||||||
def instanciate(componentSpec: str, components: list[ComponentManifest], target: TargetManifest) -> ComponentInstance | None:
|
def instanciate(componentSpec: str, components: list[ComponentManifest], target: TargetManifest) -> ComponentInstance | None:
|
||||||
manifest = next(filter(lambda c: c.id == componentSpec, components))
|
manifest = next(filter(lambda c: c.id == componentSpec, components))
|
||||||
sources = shell.find(
|
sources = shell.find(
|
||||||
manifest.dirname(), ["*.c", "*.cpp", "*.s", "*.asm"])
|
manifest.dirname(), ["*.c", "*.cpp", "*.s", "*.asm"], recusive=False)
|
||||||
enabled, resolved = resolveDeps(componentSpec, components, target)
|
enabled, resolved = resolveDeps(componentSpec, components, target)
|
||||||
|
|
||||||
if not enabled:
|
if not enabled:
|
||||||
|
|
|
@ -3,9 +3,9 @@ from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
|
|
||||||
from osdk.jexpr import Json, evalRead
|
from osdk.jexpr import Json
|
||||||
from osdk.logger import Logger
|
from osdk.logger import Logger
|
||||||
from osdk import shell, const, utils
|
from osdk import const, utils
|
||||||
|
|
||||||
|
|
||||||
logger = Logger("model")
|
logger = Logger("model")
|
||||||
|
@ -111,6 +111,21 @@ class TargetManifest(Manifest):
|
||||||
def patch(self, toolSpec: str, args: list[str]):
|
def patch(self, toolSpec: str, args: list[str]):
|
||||||
self.tools[toolSpec].args += args
|
self.tools[toolSpec].args += args
|
||||||
|
|
||||||
|
def cdefs(self) -> list[str]:
|
||||||
|
defines: list[str] = []
|
||||||
|
|
||||||
|
for key in self.props:
|
||||||
|
macroname = key.lower().replace("-", "_")
|
||||||
|
prop = self.props[key]
|
||||||
|
macrovalue = str(prop).lower().replace(" ", "_").replace("-", "_")
|
||||||
|
if isinstance(prop, bool):
|
||||||
|
if prop:
|
||||||
|
defines += [f"-D__osdk_{macroname}__"]
|
||||||
|
else:
|
||||||
|
defines += [f"-D__osdk_{macroname}_{macrovalue}__"]
|
||||||
|
|
||||||
|
return defines
|
||||||
|
|
||||||
|
|
||||||
class ComponentManifest(Manifest):
|
class ComponentManifest(Manifest):
|
||||||
decription: str
|
decription: str
|
||||||
|
@ -158,7 +173,7 @@ class ComponentManifest(Manifest):
|
||||||
|
|
||||||
|
|
||||||
class ModelEncoder(JSONEncoder):
|
class ModelEncoder(JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o: Any):
|
||||||
if isinstance(o, Manifest):
|
if isinstance(o, Manifest):
|
||||||
return {
|
return {
|
||||||
"id": o.id,
|
"id": o.id,
|
||||||
|
|
|
@ -16,19 +16,19 @@ class Rule:
|
||||||
|
|
||||||
|
|
||||||
rules: dict[str, Rule] = {
|
rules: dict[str, Rule] = {
|
||||||
"cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs", ["-std=gnu2x",
|
"cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs $cdefs", ["-std=gnu2x",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Werror"], "$out.d"),
|
"-Werror"], "$out.d"),
|
||||||
"cxx": Rule("cxx", ["cpp", "cc", "cxx"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs", ["-std=gnu++2b",
|
"cxx": Rule("cxx", ["cpp", "cc", "cxx"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs $cdefs", ["-std=gnu++2b",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
"-Werror",
|
"-Werror",
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fno-rtti"], "$out.d"),
|
"-fno-rtti"], "$out.d"),
|
||||||
"as": Rule("as", ["s", "asm", "S"], ["o"], "-o $out $in $flags"),
|
"as": Rule("as", ["s", "asm", "S"], ["o"], "-o $out $in $flags"),
|
||||||
"ar": Rule("ar", ["o"], ["a"], "$flags $out $in"),
|
"ar": Rule("ar", ["o"], ["a"], "$flags $out $in"),
|
||||||
"ld": Rule("ld", ["o", "a"], ["out"], "$flags $out $in"),
|
"ld": Rule("ld", ["o", "a"], ["out"], "-o $out $in $flags"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ def sha256sum(path: str) -> str:
|
||||||
return hashlib.sha256(f.read()).hexdigest()
|
return hashlib.sha256(f.read()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def find(path: str, wildcards: list[str] = []) -> list[str]:
|
def find(path: str, wildcards: list[str] = [], recusive: bool = True) -> list[str]:
|
||||||
logger.log(f"Looking for files in {path} matching {wildcards}")
|
logger.log(f"Looking for files in {path} matching {wildcards}")
|
||||||
|
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
@ -43,14 +43,24 @@ def find(path: str, wildcards: list[str] = []) -> list[str]:
|
||||||
|
|
||||||
result: list[str] = []
|
result: list[str] = []
|
||||||
|
|
||||||
for root, _, files in os.walk(path):
|
if recusive:
|
||||||
for f in files:
|
for root, _, files in os.walk(path):
|
||||||
|
for f in files:
|
||||||
|
if len(wildcards) == 0:
|
||||||
|
result.append(os.path.join(root, f))
|
||||||
|
else:
|
||||||
|
for wildcard in wildcards:
|
||||||
|
if fnmatch.fnmatch(f, wildcard):
|
||||||
|
result.append(os.path.join(root, f))
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
for f in os.listdir(path):
|
||||||
if len(wildcards) == 0:
|
if len(wildcards) == 0:
|
||||||
result.append(os.path.join(root, f))
|
result.append(os.path.join(path, f))
|
||||||
else:
|
else:
|
||||||
for wildcard in wildcards:
|
for wildcard in wildcards:
|
||||||
if fnmatch.fnmatch(f, wildcard):
|
if fnmatch.fnmatch(f, wildcard):
|
||||||
result.append(os.path.join(root, f))
|
result.append(os.path.join(path, f))
|
||||||
break
|
break
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Reference in a new issue