Skip to content

Commit 19518c5

Browse files
committed
[nrf noup] [west zap-sync] Handle overwriting of the default zcl file
Fixed the handling of the case when the default cluster definition file (zcl.json) is used as both input and output to the command. Without the fix, the script removes the zcl.json and exits, because the removed file cannot be copied. Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
1 parent dc5063b commit 19518c5

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎scripts/west/zap_sync.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ def do_run(self, args, unknown_args):
5656
zap_installer.update_zap_if_needed()
5757

5858
if args.zcl_json:
59-
# Provided zcl.json file exists, so we need to remove it and create a copy of the default zcl.json file.
60-
zcl_file_path = Path(args.zcl_json).absolute()
61-
if zcl_file_path.exists():
62-
zcl_file_path.unlink()
63-
shutil.copy(default_zcl_path, zcl_file_path)
59+
zcl_candidate = Path(args.zcl_json).absolute()
60+
# Reset project zcl.json from the SDK default. If -j is the default path itself,
61+
# do not unlink/copy (to avoid deleting the source then failing to copy if the path is the same).
62+
if zcl_candidate.resolve() == default_zcl_path.resolve():
63+
zcl_file_path = default_zcl_path
64+
else:
65+
if zcl_candidate.exists():
66+
zcl_candidate.unlink()
67+
shutil.copy(default_zcl_path, zcl_candidate)
68+
zcl_file_path = zcl_candidate
6469
else:
65-
# No zcl.json file provided, so we need to create a new one because a path was provided.
6670
zcl_file_path = default_zcl_path
6771

6872
log.inf(f"Synchronizing zcl.json file ({zcl_file_path.resolve()})...")
@@ -91,6 +95,10 @@ def run_zap():
9195
cmd += ["--tempState"]
9296

9397
output = subprocess.run([str(x) for x in cmd], capture_output=True, text=True)
98+
# Chromium often prints nothing to stdout when the sandbox aborts early.
99+
# returncode -5 is a sentinel consumed by fix_sandbox_permissions().
100+
if not output.stdout:
101+
raise subprocess.CalledProcessError(-5, cmd)
94102
display_zap_message(output)
95103
return output
96104

0 commit comments

Comments
 (0)