Skip to content

Commit 3937160

Browse files
q-thlapull[bot]
authored andcommitted
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
1 parent 3c6801c commit 3937160

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/tools/zap/generate.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ def checkDirExists(path):
6666
exit(1)
6767

6868

69-
def getFilePath(name):
70-
fullpath = os.path.join(CHIP_ROOT_DIR, name)
69+
def getFilePath(name, prefix_chip_root_dir=True):
70+
if prefix_chip_root_dir:
71+
fullpath = os.path.join(CHIP_ROOT_DIR, name)
72+
else:
73+
fullpath = name
7174
checkFileExists(fullpath)
7275
return fullpath
7376

@@ -81,21 +84,25 @@ def getDirPath(name):
8184
def detectZclFile(zapFile):
8285
print(f"Searching for zcl file from {zapFile}")
8386

87+
prefix_chip_root_dir = True
8488
path = 'src/app/zap-templates/zcl/zcl.json'
8589

8690
data = json.load(open(zapFile))
8791
for package in data["package"]:
8892
if package["type"] != "zcl-properties":
8993
continue
9094

95+
prefix_chip_root_dir = (package["pathRelativity"] != "resolveEnvVars")
9196
# found the right path, try to figure out the actual path
9297
if package["pathRelativity"] == "relativeToZap":
9398
path = os.path.abspath(os.path.join(
9499
os.path.dirname(zapFile), package["path"]))
100+
elif package["pathRelativity"] == "resolveEnvVars":
101+
path = os.path.expandvars(package["path"])
95102
else:
96103
path = package["path"]
97104

98-
return getFilePath(path)
105+
return getFilePath(path, prefix_chip_root_dir)
99106

100107

101108
def runArgumentsParser() -> CmdLineArgs:

0 commit comments

Comments
 (0)