Open general

kicad-cli shim: --save-board doesn't bring the refilled board back (refill is silently lost)

John Lauer · 4d ago

kicad-cli pcb drc --refill-zones --save-board board.kicad_pcb run through the container shim (desktop path) refills and saves the board on the desktop, but the shim only pulls back -o/--output files, so the local board is unchanged and the refill is lost. The command still exits 0, so a caller can't tell.

Found while building adom-fields verify --refill, which has KiCad refill and DRC a fixed copy of a board before solving it.

Repro: copy any board with zones, md5sum it, run kicad-cli pcb drc --refill-zones --save-board --format json -o drc.json board.kicad_pcb through the shim on the desktop path (service-kicad doesn't take these flags), then md5sum it again: unchanged.

Fix: after the job, when --save-board is among the args, pull each .kicad_pcb input back over the local file. This patch works on Windows (AdomLapper, KiCad 10.0.5): the refilled board comes back and its hash changes.

+# --save-board writes the input board on the desktop: bring it back over the local file
+if [[ " $* " == *" --save-board "* ]]; then
+  for f in "${files[@]}"; do
+    [[ "$f" == *.kicad_pcb ]] || continue
+    [[ " $* " == *"$(basename "$f")"* ]] || continue
+    tmp=$(mktemp -d)
+    "${AB[@]}" pull_file "$(jq_py 'import json,sys;print(json.dumps({"filePaths":[sys.argv[1]],"saveTo":sys.argv[2],"reason":"bring the board saved by kicad-cli --save-board back"}))' "$dest/$(basename "$f")" "$tmp")" >/dev/null
+    if [[ -s "$tmp/$(basename "$f")" ]]; then cp "$tmp/$(basename "$f")" "$f"; else say "the saved board $(basename "$f") did not come back"; code=1; fi
+    rm -rf "$tmp"
+  done
+fi
 if [[ $WIN == 1 ]]; then rm_cmd=...

It goes just before the job-folder cleanup. My local copy of the shim has it applied; a shim update would drop it, so it'd be great to ship it upstream (and service-kicad's own pcb drc could take --refill-zones --save-board too).

0 Replies

Log in to reply.