From 4df350fd3cdfdff8c979d2788a5580e29e8321d9 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 20 Dec 2023 17:37:46 +0100 Subject: [PATCH 1/2] tools/makemanifest.py: Provide access to MICROPY_MANIFEST_xxx symbols. The new function resolve(name) returns the value of a Makefile symbol defined as MICROPY_MANIFEST_. Example: Makefile: MICROPY_MANIFEST_FROZEN_SET = "default" manifest.py: frozen_set = resolve("$FROZEN_SET") If name is not defined, resolve() returns `None`. Set the symbols MICROPY_MANIFEST_BOARD and MICROPY_MANIFEST_BOARD_VARIANT by default. Notes: - Instead of "resolve" the function may have any other appropriate name. - The "$XYZ" notation was kept for consistency with the other functions. Signed-off-by: robert-hh --- py/mkrules.mk | 3 +++ tools/manifestfile.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/py/mkrules.mk b/py/mkrules.mk index 5050935873..4addac38a6 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -206,6 +206,9 @@ MICROPY_MANIFEST_MPY_LIB_DIR = $(MPY_LIB_DIR) MICROPY_MANIFEST_PORT_DIR = $(shell pwd) MICROPY_MANIFEST_BOARD_DIR = $(BOARD_DIR) MICROPY_MANIFEST_MPY_DIR = $(TOP) +# Set variables for BOARD and BOARD_VARIANT by default +MICROPY_MANIFEST_BOARD = $(BOARD) +MICROPY_MANIFEST_BOARD_VARIANT = $(BOARD_VARIANT) # Find all MICROPY_MANIFEST_* variables and turn them into command line arguments. MANIFEST_VARIABLES = $(foreach var,$(filter MICROPY_MANIFEST_%, $(.VARIABLES)),-v "$(subst MICROPY_MANIFEST_,,$(var))=$($(var))") diff --git a/tools/manifestfile.py b/tools/manifestfile.py index c1fc836585..da4a043eb7 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -222,6 +222,7 @@ class ManifestFile: "add_library": self.add_library, "package": self.package, "module": self.module, + "resolve": self.resolve, "options": IncludeOptions(**kwargs), } @@ -572,6 +573,12 @@ class ManifestFile: """ self._freeze_internal(path, script, exts=(".mpy",), kind=KIND_FREEZE_MPY, opt=opt) + def resolve(self, name): + if name[0] == "$" and name[1:] in self._path_vars.keys(): + return self._path_vars[name[1:]] + else: + return None + # Generate a temporary file with a line appended to the end that adds __version__. @contextlib.contextmanager From 579e45a97e43fb263902d39ffbf306532f3449b4 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Thu, 21 Dec 2023 09:07:35 +0100 Subject: [PATCH 2/2] tools/makemanifest.py: Expand the path only for known directories. That imposes the least side effects and does not add a naming convention. If a manifest.py script want to expand a path, it can do so using e.g. os.path.abspath(). Signed-off-by: robert-hh --- tools/makemanifest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/makemanifest.py b/tools/makemanifest.py index a74a6934ae..92b9cfaf92 100644 --- a/tools/makemanifest.py +++ b/tools/makemanifest.py @@ -143,7 +143,7 @@ def main(): # Extract variables for substitution. for var in args.var: name, value = var.split("=", 1) - if os.path.exists(value): + if name in ("MPY_DIR", "MPY_LIB_DIR", "BOARD_DIR", "PORT_DIR") and os.path.exists(value): value = os.path.abspath(value) VARS[name] = value