From 15077137a460f918be2a7958f01bf73e9e6db19d Mon Sep 17 00:00:00 2001 From: Thomas Langewouters <82949801+q-thla@users.noreply.github.com> Date: Wed, 25 Jan 2023 17:09:48 +0100 Subject: [PATCH] zap/generate.py: add resolveEnvVars pathRelativity (#24482) * zap/generate.py: add resolveEnvVars pathRelativity This allows the .zap's package pathRelativity to be set to resolveEnvVars , making it perform environment variable subsitution on the path given. This allows variables like $CHIP_ROOT to be used, which is needed when the chip codebase is independent to the repository the zap file is in. * zap/generate.py: Add clarity wrt prefix_chip_root_dir --- scripts/tools/zap/generate.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/tools/zap/generate.py b/scripts/tools/zap/generate.py index e2aa324f65c7bb..d3c4283aca0f94 100755 --- a/scripts/tools/zap/generate.py +++ b/scripts/tools/zap/generate.py @@ -66,8 +66,11 @@ def checkDirExists(path): exit(1) -def getFilePath(name): - fullpath = os.path.join(CHIP_ROOT_DIR, name) +def getFilePath(name, prefix_chip_root_dir=True): + if prefix_chip_root_dir: + fullpath = os.path.join(CHIP_ROOT_DIR, name) + else: + fullpath = name checkFileExists(fullpath) return fullpath @@ -81,6 +84,7 @@ def getDirPath(name): def detectZclFile(zapFile): print(f"Searching for zcl file from {zapFile}") + prefix_chip_root_dir = True path = 'src/app/zap-templates/zcl/zcl.json' data = json.load(open(zapFile)) @@ -88,14 +92,17 @@ def detectZclFile(zapFile): if package["type"] != "zcl-properties": continue + prefix_chip_root_dir = (package["pathRelativity"] != "resolveEnvVars") # found the right path, try to figure out the actual path if package["pathRelativity"] == "relativeToZap": path = os.path.abspath(os.path.join( os.path.dirname(zapFile), package["path"])) + elif package["pathRelativity"] == "resolveEnvVars": + path = os.path.expandvars(package["path"]) else: path = package["path"] - return getFilePath(path) + return getFilePath(path, prefix_chip_root_dir) def runArgumentsParser() -> CmdLineArgs: