Skip to content

Commit

Permalink
Move IDL copy logic into generate.py so we can individually update fi…
Browse files Browse the repository at this point in the history
…les (#13626)

* Move IDL copy logic into generate.py so we can individually update files

* Restyle fixes
  • Loading branch information
andy31415 authored and pull[bot] committed Jan 8, 2024
1 parent 01d182e commit 2135235
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
21 changes: 21 additions & 0 deletions scripts/tools/zap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,33 @@ def runArgumentsParser():
return (zap_file, zcl_file, templates_file, output_dir)


def extractGeneratedIdl(output_dir, zap_config_path):
"""Find a file Clusters.matter in the output directory and
place it along with the input zap file.
Intent is to make the "zap content" more humanly understandable.
"""
idl_path = os.path.join(output_dir, "Clusters.matter")
if not os.path.exists(idl_path):
return

target_path = zap_config_path.replace(".zap", ".matter")
if not target_path.endswith(".matter"):
# We expect "something.zap" and don't handle corner cases of
# multiple extensions. This is to work with existing codebase only
raise Error("Unexpected input zap file %s" % self.zap_config)

os.rename(idl_path, target_path)


def runGeneration(zap_file, zcl_file, templates_file, output_dir):
generator_dir = getDirPath('third_party/zap/repo')
os.chdir(generator_dir)
subprocess.check_call(['node', './src-script/zap-generate.js', '-z',
zcl_file, '-g', templates_file, '-i', zap_file, '-o', output_dir])

extractGeneratedIdl(output_dir, zap_file)


def runClangPrettifier(templates_file, output_dir):
listOfSupportedFileExtensions = [
Expand Down
22 changes: 0 additions & 22 deletions scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,6 @@ def generate(self):
logging.info("Generating target: %s" % " ".join(cmd))
subprocess.check_call(cmd)

def extractAnyGeneratedIDL(self):
"""Searches for Clusters.matter in the output directory and if found,
will move it to stay along with the zap file config
"""
if not self.output_dir:
# TODO: where do things get generated if no output dir?
# Assume here that IDL is not generated in such cases
return

idl_path = os.path.join(self.output_dir, "Clusters.matter")
if not os.path.exists(idl_path):
return

target_path = self.zap_config.replace(".zap", ".matter")
if not target_path.endswith(".matter"):
# We expect "something.zap" and don't handle corner cases of
# multiple extensions. This is to work with existing codebase only
raise Error("Unexpected input zap file %s" % self.zap_config)

os.rename(idl_path, target_path)


def checkPythonVersion():
if sys.version_info[0] < 3:
Expand Down Expand Up @@ -174,7 +153,6 @@ def main():
targets = getTargets()
for target in targets:
target.generate()
target.extractAnyGeneratedIDL()


if __name__ == '__main__':
Expand Down

0 comments on commit 2135235

Please sign in to comment.