Generated cflags.
This commit is contained in:
		
							parent
							
								
									51f4f2ebd0
								
							
						
					
					
						commit
						3706ecb183
					
				
					 4 changed files with 38 additions and 12 deletions
				
			
		|  | @ -18,19 +18,19 @@ def gen(out: TextIO, context: Context): | ||||||
|     writer.newline() |     writer.newline() | ||||||
| 
 | 
 | ||||||
|     writer.separator("Tools") |     writer.separator("Tools") | ||||||
|  | 
 | ||||||
|  |     writer.variable("cincs", " ".join( | ||||||
|  |         map(lambda i: f"-I{i}", context.cincludes()))) | ||||||
|  |     writer.newline() | ||||||
|  | 
 | ||||||
|     for i in target.tools: |     for i in target.tools: | ||||||
|         tool = target.tools[i] |         tool = target.tools[i] | ||||||
|  |         rule = rules.rules[i] | ||||||
|         writer.variable(i, tool.cmd) |         writer.variable(i, tool.cmd) | ||||||
|         writer.variable( |         writer.variable( | ||||||
|             i + "flags", " ".join(tool.args)) |             i + "flags", " ".join(rule.args + tool.args)) | ||||||
|         writer.newline() |  | ||||||
| 
 |  | ||||||
|     writer.separator("Rules") |  | ||||||
|     for i in rules.rules: |  | ||||||
|         tool = target.tools[i] |  | ||||||
|         rule = rules.rules[i] |  | ||||||
|         writer.rule( |         writer.rule( | ||||||
|             i, f"{tool.cmd} {rule.rule.replace('$flags',f'${i}flags')}", deps=rule.deps) |             i, f"{tool.cmd} {rule.rule.replace('$flags',f'${i}flags')}", depfile=rule.deps) | ||||||
|         writer.newline() |         writer.newline() | ||||||
| 
 | 
 | ||||||
|     writer.separator("Components") |     writer.separator("Components") | ||||||
|  |  | ||||||
|  | @ -1,8 +1,10 @@ | ||||||
| from typing import cast | from typing import cast | ||||||
|  | from pathlib import Path | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| from osdk.model import TargetManifest, ComponentManifest, Props, Type | from osdk.model import TargetManifest, ComponentManifest, Props, Type | ||||||
| from osdk.logger import Logger | from osdk.logger import Logger | ||||||
| from osdk import const, shell, jexpr | from osdk import const, shell, jexpr, utils | ||||||
| 
 | 
 | ||||||
| logger = Logger("context") | logger = Logger("context") | ||||||
| 
 | 
 | ||||||
|  | @ -48,6 +50,12 @@ class ComponentInstance: | ||||||
|             return self.libfile() |             return self.libfile() | ||||||
|         return self.binfile() |         return self.binfile() | ||||||
| 
 | 
 | ||||||
|  |     def cinclude(self) -> str: | ||||||
|  |         if "cpp-root-include" in self.manifest.props: | ||||||
|  |             return self.manifest.dirname() | ||||||
|  |         else: | ||||||
|  |             return str(Path(self.manifest.dirname()).parent) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Context: | class Context: | ||||||
|     target: TargetManifest |     target: TargetManifest | ||||||
|  | @ -63,6 +71,11 @@ class Context: | ||||||
|             return None |             return None | ||||||
|         return result[0] |         return result[0] | ||||||
| 
 | 
 | ||||||
|  |     def cincludes(self) -> list[str]: | ||||||
|  |         includes = list( | ||||||
|  |             map(lambda x: x.cinclude(), self.instances)) | ||||||
|  |         return utils.uniq(includes) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def loadAllTargets() -> list[TargetManifest]: | def loadAllTargets() -> list[TargetManifest]: | ||||||
|     files = shell.find(const.TARGETS_DIR, ["*.json"]) |     files = shell.find(const.TARGETS_DIR, ["*.json"]) | ||||||
|  |  | ||||||
|  | @ -108,6 +108,9 @@ class TargetManifest(Manifest): | ||||||
|     def builddir(self) -> str: |     def builddir(self) -> str: | ||||||
|         return f"{const.BUILD_DIR}/{self.id}-{self.hashid()[:8]}" |         return f"{const.BUILD_DIR}/{self.id}-{self.hashid()[:8]}" | ||||||
| 
 | 
 | ||||||
|  |     def patch(self, toolSpec: str, args: list[str]): | ||||||
|  |         self.tools[toolSpec].args += args | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class ComponentManifest(Manifest): | class ComponentManifest(Manifest): | ||||||
|     decription: str |     decription: str | ||||||
|  |  | ||||||
|  | @ -3,19 +3,29 @@ class Rule: | ||||||
|     fileIn: list[str] |     fileIn: list[str] | ||||||
|     fileOut: list[str] |     fileOut: list[str] | ||||||
|     rule: str |     rule: str | ||||||
|  |     args: list[str] | ||||||
|     deps: str | None = None |     deps: str | None = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self, id: str, fileIn: list[str], fileOut: list[str], rule: str, deps: str | None = None): |     def __init__(self, id: str,  fileIn: list[str], fileOut: list[str], rule: str, args: list[str] = [], deps: str | None = None): | ||||||
|         self.id = id |         self.id = id | ||||||
|         self.fileIn = fileIn |         self.fileIn = fileIn | ||||||
|         self.fileOut = fileOut |         self.fileOut = fileOut | ||||||
|         self.rule = rule |         self.rule = rule | ||||||
|  |         self.args = args | ||||||
|         self.deps = deps |         self.deps = deps | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| rules: dict[str, Rule] = { | rules: dict[str, Rule] = { | ||||||
|     "cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags", "$out.d"), |     "cc": Rule("cc", ["c"], ["o"], "-c -o $out $in -MD -MF $out.d $flags $cincs", ["-std=gnu2x", | ||||||
|     "cxx": Rule("cxx", ["cpp", "cc", "cxx"], ["o"], "-c -o $out $in -MD -MF $out.d $flags", "$out.d"), |                                                                                    "-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"), | ||||||
|     "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"], "$flags $out $in"), | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue