Skip to content

Commit

Permalink
zap/generate.py: add resolveEnvVars pathRelativity (#24482)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
q-thla authored and pull[bot] committed Nov 15, 2023
1 parent 567d93c commit 4653443
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -81,21 +84,25 @@ 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))
for package in data["package"]:
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:
Expand Down

0 comments on commit 4653443

Please sign in to comment.