From 571cfe45857b049ad287f293b79e1e9fe925295e Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Thu, 20 Apr 2023 08:18:37 +0200 Subject: [PATCH] Fix invalid computation of hask keys. --- osdk/cmds.py | 16 ++++++++++++---- osdk/context.py | 4 +++- osdk/model.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/osdk/cmds.py b/osdk/cmds.py index d7cadda..4f2da09 100644 --- a/osdk/cmds.py +++ b/osdk/cmds.py @@ -41,9 +41,13 @@ def runCmd(args: Args): if componentSpec is None: raise Exception("Component not specified") - exe = builder.build(componentSpec, targetSpec).outfile() + component = builder.build(componentSpec, targetSpec) - shell.exec(exe, *args.args) + os.environ["OSDK_TARGET"] = component.context.target.id + os.environ["OSDK_COMPONENT"] = component.id() + os.environ["OSDK_BUILDDIR"] = component.context.builddir() + + shell.exec(component.outfile(), *args.args) cmds += [Cmd("r", "run", "Run the target", runCmd)] @@ -67,9 +71,13 @@ def debugCmd(args: Args): if componentSpec is None: raise Exception("Component not specified") - exe = builder.build(componentSpec, targetSpec).outfile() + component = builder.build(componentSpec, targetSpec) - shell.exec("lldb", "-o", "run", exe) + os.environ["OSDK_TARGET"] = component.context.target.id + os.environ["OSDK_COMPONENT"] = component.id() + os.environ["OSDK_BUILDDIR"] = component.context.builddir() + + shell.exec("lldb", "-o", "run", component.outfile(), *args.args) cmds += [Cmd("d", "debug", "Debug the target", debugCmd)] diff --git a/osdk/context.py b/osdk/context.py index f6cc9d3..95dab6d 100644 --- a/osdk/context.py +++ b/osdk/context.py @@ -12,6 +12,8 @@ logger = Logger("context") class IContext(Protocol): + target: TargetManifest + def builddir(self) -> str: ... @@ -109,7 +111,7 @@ class Context(IContext): return self.target.cdefs() def hashid(self) -> str: - return utils.hash((self.target.props, str(self.tools)))[0:8] + return utils.hash((self.target.props, [self.tools[t].toJson() for t in self.tools]))[0:8] def builddir(self) -> str: return os.path.join(const.BUILD_DIR, f"{self.target.id}-{self.hashid()[:8]}") diff --git a/osdk/model.py b/osdk/model.py index 5dc2521..2905965 100644 --- a/osdk/model.py +++ b/osdk/model.py @@ -43,6 +43,13 @@ class Manifest: for key in kwargs: setattr(self, key, kwargs[key]) + def toJson(self) -> Json: + return { + "id": self.id, + "type": self.type.value, + "path": self.path + } + def __str__(self): return f"Manifest(id={self.id}, type={self.type}, path={self.path})" @@ -74,6 +81,12 @@ class Extern: for key in kwargs: setattr(self, key, kwargs[key]) + def toJson(self) -> Json: + return { + "git": self.git, + "tag": self.tag + } + def __str__(self): return f"Extern(git={self.git}, tag={self.tag})" @@ -99,6 +112,13 @@ class ProjectManifest(Manifest): super().__init__(json, path, strict, **kwargs) + def toJson(self) -> Json: + return { + **super().toJson(), + "description": self.description, + "extern": {k: v.toJson() for k, v in self.extern.items()} + } + def __str__(self): return f"ProjectManifest(id={self.id}, type={self.type}, path={self.path}, description={self.description}, extern={self.extern})" @@ -130,6 +150,13 @@ class Tool: for key in kwargs: setattr(self, key, kwargs[key]) + def toJson(self) -> Json: + return { + "cmd": self.cmd, + "args": self.args, + "files": self.files + } + def __str__(self): return f"Tool(cmd={self.cmd}, args={self.args}, files={self.files})" @@ -161,6 +188,14 @@ class TargetManifest(Manifest): super().__init__(json, path, strict, **kwargs) + def toJson(self) -> Json: + return { + **super().toJson(), + "props": self.props, + "tools": {k: v.toJson() for k, v in self.tools.items()}, + "routing": self.routing + } + def __repr__(self): return f"TargetManifest({self.id})" @@ -206,6 +241,18 @@ class ComponentManifest(Manifest): super().__init__(json, path, strict, **kwargs) + def toJson(self) -> Json: + return { + **super().toJson(), + "description": self.decription, + "props": self.props, + "tools": {k: v.toJson() for k, v in self.tools.items()}, + "enableIf": self.enableIf, + "requires": self.requires, + "provides": self.provides, + "subdirs": self.subdirs + } + def __repr__(self): return f"ComponentManifest({self.id})"