Skip to content

Commit 318f9ab

Browse files
[nrf toup][nrfconnect] Add --full flag to zap-generate
Add a `--full` flag that generates full data model and puts it it `app-common/zap-generated` subdirectory. Additionaly fix minor bug when equal paths have been shown as non- relative and zap file is not properly updated with zcl.json file Signed-off-by: Maciej Baczmanski <maciej.baczmanski@nordicsemi.no>
1 parent d5c7f72 commit 318f9ab

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

scripts/west/zap_common.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,15 @@ def update_zcl_in_zap(zap_file: Path, zcl_json: Path, app_templates: Path) -> bo
9595

9696
for package in packages:
9797
if package.get("type") == "zcl-properties":
98-
if not zcl_json.parent.absolute().is_relative_to(zap_file.parent.absolute()):
98+
if zcl_json.parent.absolute() == zap_file.parent.absolute() or \
99+
not zcl_json.parent.absolute().is_relative_to(zap_file.parent.absolute()):
100+
99101
package.update({"path": str(zcl_json.absolute().relative_to(zap_file.parent.absolute(), walk_up=True))})
100102
updated = True
101103
if package.get("type") == "gen-templates-json":
102-
if not app_templates.parent.absolute().is_relative_to(zap_file.parent.absolute()):
104+
if app_templates.parent.absolute() == zap_file.parent.absolute() or \
105+
not app_templates.parent.absolute().is_relative_to(zap_file.parent.absolute()):
106+
103107
package.update({"path": str(app_templates.absolute().relative_to(zap_file.parent.absolute(), walk_up=True))})
104108
updated = True
105109

scripts/west/zap_generate.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ def do_add_parser(self, parser_adder):
3636
help='Path where to store the generated files')
3737
parser.add_argument('-m', '--matter-path', type=existing_dir_path,
3838
default=DEFAULT_MATTER_PATH, help='Path to Matter SDK')
39+
parser.add_argument('-f', '--full', action='store_true', help='Generate full data model files')
3940
return parser
4041

42+
def build_command(self, zap_file_path, output_path, templates_path):
43+
cmd = [sys.executable, self.zap_generate_path, zap_file_path, "-o", output_path, "-t", templates_path]
44+
return [str(x) for x in cmd]
45+
4146
def do_run(self, args, unknown_args):
47+
self.zap_generate_path = args.matter_path / "scripts/tools/zap/generate.py"
48+
4249
if args.zap_file:
4350
zap_file_path = args.zap_file.absolute()
4451
else:
@@ -52,20 +59,25 @@ def do_run(self, args, unknown_args):
5259
else:
5360
output_path = zap_file_path.parent / "zap-generated"
5461

62+
templates_path = args.matter_path / "src/app/common/templates/templates.json"
5563
app_templates_path = args.matter_path / "src/app/zap-templates/app-templates.json"
56-
zap_generate_path = args.matter_path / "scripts/tools/zap/generate.py"
5764

5865
zap_installer = ZapInstaller(args.matter_path)
5966
zap_installer.update_zap_if_needed()
6067

6168
# make sure that the generate.py script uses the proper zap_cli binary (handled by west)
6269
os.environ["ZAP_INSTALL_PATH"] = str(zap_installer.get_zap_cli_path().parent.absolute())
6370

64-
cmd = [sys.executable, zap_generate_path]
65-
cmd += [zap_file_path]
66-
cmd += ["-t", app_templates_path]
67-
cmd += ["-o", output_path]
6871

69-
self.check_call([str(x) for x in cmd])
72+
# Make sure that output directory exists
73+
output_path.mkdir(exist_ok=True)
74+
75+
self.check_call(self.build_command(zap_file_path, output_path, app_templates_path))
76+
77+
if args.full:
78+
output_path = output_path / "app-common/zap-generated"
79+
output_path.mkdir(parents=True, exist_ok=True)
80+
81+
self.check_call(self.build_command(zap_file_path, output_path, templates_path))
7082

7183
log.inf(f"Done. Files generated in {output_path}")

0 commit comments

Comments
 (0)