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: | ||||
|     target = copy.deepcopy(target) | ||||
|     target = targets.patchToolArgs(target, "cc", [m.cincludes(manifests)]) | ||||
|     target = targets.patchToolArgs(target, "cxx", [m.cincludes(manifests)]) | ||||
|     target = targets.patchToolArgs(target, "cc", [m.cinc(manifests)]) | ||||
|     target = targets.patchToolArgs(target, "cxx", [m.cinc(manifests)]) | ||||
| 
 | ||||
|     writer = ninja.Writer(out) | ||||
| 
 | ||||
|  |  | |||
|  | @ -159,7 +159,7 @@ def prepareInOut(manifests: dict, target: dict) -> dict: | |||
|     return manifests | ||||
| 
 | ||||
| 
 | ||||
| def cincludes(manifests: dict) -> str: | ||||
| def cinc(manifests: dict) -> str: | ||||
|     include_paths = [] | ||||
| 
 | ||||
|     for key in manifests: | ||||
|  |  | |||
|  | @ -20,7 +20,10 @@ def gen(out: TextIO, context: Context): | |||
|     writer.separator("Tools") | ||||
| 
 | ||||
|     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() | ||||
| 
 | ||||
|     for i in target.tools: | ||||
|  |  | |||
|  | @ -71,11 +71,14 @@ class Context: | |||
|             return None | ||||
|         return result[0] | ||||
| 
 | ||||
|     def cincludes(self) -> list[str]: | ||||
|     def cincls(self) -> list[str]: | ||||
|         includes = list( | ||||
|             map(lambda x: x.cinclude(), self.instances)) | ||||
|         return utils.uniq(includes) | ||||
| 
 | ||||
|     def cdefs(self) -> list[str]: | ||||
|         return self.target.cdefs() | ||||
| 
 | ||||
| 
 | ||||
| def loadAllTargets() -> list[TargetManifest]: | ||||
|     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: | ||||
|     manifest = next(filter(lambda c: c.id == componentSpec, components)) | ||||
|     sources = shell.find( | ||||
|         manifest.dirname(), ["*.c", "*.cpp", "*.s", "*.asm"]) | ||||
|         manifest.dirname(), ["*.c", "*.cpp", "*.s", "*.asm"], recusive=False) | ||||
|     enabled, resolved = resolveDeps(componentSpec, components, target) | ||||
| 
 | ||||
|     if not enabled: | ||||
|  |  | |||
|  | @ -3,9 +3,9 @@ from enum import Enum | |||
| from typing import Any | ||||
| from json import JSONEncoder | ||||
| 
 | ||||
| from osdk.jexpr import Json, evalRead | ||||
| from osdk.jexpr import Json | ||||
| from osdk.logger import Logger | ||||
| from osdk import shell, const, utils | ||||
| from osdk import const, utils | ||||
| 
 | ||||
| 
 | ||||
| logger = Logger("model") | ||||
|  | @ -111,6 +111,21 @@ class TargetManifest(Manifest): | |||
|     def patch(self, toolSpec: str, args: list[str]): | ||||
|         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): | ||||
|     decription: str | ||||
|  | @ -158,7 +173,7 @@ class ComponentManifest(Manifest): | |||
| 
 | ||||
| 
 | ||||
| class ModelEncoder(JSONEncoder): | ||||
|     def default(self, o): | ||||
|     def default(self, o: Any): | ||||
|         if isinstance(o, Manifest): | ||||
|             return { | ||||
|                 "id": o.id, | ||||
|  |  | |||
|  | @ -16,19 +16,19 @@ class Rule: | |||
| 
 | ||||
| 
 | ||||
| rules: dict[str, Rule] = { | ||||
|     "cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs", ["-std=gnu2x", | ||||
|                                                                                    "-Wall", | ||||
|                                                                                    "-Wextra", | ||||
|                                                                                    "-Werror"], "$out.d"), | ||||
|     "cxx": Rule("cxx", ["cpp", "cc", "cxx"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs", ["-std=gnu++2b", | ||||
|                                                                                                     "-Wall", | ||||
|                                                                                                     "-Wextra", | ||||
|                                                                                                     "-Werror", | ||||
|                                                                                                     "-fno-exceptions", | ||||
|                                                                                                     "-fno-rtti"], "$out.d"), | ||||
|     "cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs $cdefs", ["-std=gnu2x", | ||||
|                                                                                           "-Wall", | ||||
|                                                                                           "-Wextra", | ||||
|                                                                                           "-Werror"], "$out.d"), | ||||
|     "cxx": Rule("cxx", ["cpp", "cc", "cxx"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs $cdefs", ["-std=gnu++2b", | ||||
|                                                                                                            "-Wall", | ||||
|                                                                                                            "-Wextra", | ||||
|                                                                                                            "-Werror", | ||||
|                                                                                                            "-fno-exceptions", | ||||
|                                                                                                            "-fno-rtti"], "$out.d"), | ||||
|     "as": Rule("as", ["s", "asm", "S"], ["o"], "-o $out $in $flags"), | ||||
|     "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() | ||||
| 
 | ||||
| 
 | ||||
| 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}") | ||||
| 
 | ||||
|     if not os.path.isdir(path): | ||||
|  | @ -43,14 +43,24 @@ def find(path: str, wildcards: list[str] = []) -> list[str]: | |||
| 
 | ||||
|     result: list[str] = [] | ||||
| 
 | ||||
|     for root, _, files in os.walk(path): | ||||
|         for f in files: | ||||
|     if recusive: | ||||
|         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: | ||||
|                 result.append(os.path.join(root, f)) | ||||
|                 result.append(os.path.join(path, f)) | ||||
|             else: | ||||
|                 for wildcard in wildcards: | ||||
|                     if fnmatch.fnmatch(f, wildcard): | ||||
|                         result.append(os.path.join(root, f)) | ||||
|                         result.append(os.path.join(path, f)) | ||||
|                         break | ||||
| 
 | ||||
|     return result | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue