Add pcb export-kicad subcommand#771
Open
jeanmw wants to merge 6 commits into
Open
Conversation
process_layout(use_temp_dir=true) previously called TempDir::keep(), leaving an orphaned pcb-layout-* directory under $TMPDIR after every export. Move ownership of the TempDir onto the returned LayoutResult so it cleans up when the caller drops the result, and remove the workaround in export_kicad. Adds a hermetic test exercising --offline --locked.
Collapse two-line with_context() and trim a stray double-space comment flagged by `cargo fmt --all -- --check`.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 200426f. Configure here.
`pcb layout --temp` runs `process_layout(use_temp_dir=true)` and then spawns KiCad asynchronously via `pcb_kicad::open_pcbnew`. With the previous commit moving TempDir ownership onto LayoutResult, the temp directory was being removed at function exit while pcbnew was still loading the .kicad_pcb / .kicad_pro files from it. Add `LayoutResult::persist_temp_dir(&mut self)` to opt out of cleanup on drop, and call it in the `pcb layout --temp` path before spawning KiCad. `pcb export-kicad` does not call it — it copies the project out and lets the temp dir clean up normally. Includes unit tests covering both branches (drop cleans, persist keeps).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Implements
pcb export-kicad, a new CLI subcommand that takes a.zenfile and writes a standalone, self-contained KiCad project directory.
pcb export-kicad <file.zen> -o <dir> [--offline] [--locked]--offlineand--lockedplumb through to the sharedresolve::resolve(...)pipeline used by
pcb build/pcb bom/etc..zeninputs with a clear error.pcb_layout::process_layout(use_temp_dir=true):the
TempDiris now owned by the returnedLayoutResultand is removedwhen the result drops, instead of being kept via
TempDir::keep().Closes #682.
Notes for reviewers
layout.kicad_pro+layout.kicad_pcb(+
.kicad_prl). KiCad creates the.kicad_schfile itself the firsttime eeschema opens the project — same behavior as
crates/pcb-layout/tests/layout_generation.rs.LayoutResultgained a private_temp_dir: Option<TempDir>field. Allexisting callers pass
use_temp_dir=falseso they getNoneandbehavior is unchanged. Only the new
export_kicadpath passestrue.Test plan
cargo test --workspace --locked --no-fail-fastcargo clippy --workspace --all-targets -- -D warningscargo fmt --all -- --checkcargo run -p pcb -- fmt --check stdlibcrates/pcb/tests/export_kicad.rs:test_export_kicad_rejects_missing_filetest_export_kicad_writes_project_directorytest_export_kicad_offline_locked_writes_project_directory(hermetic,seeded sandbox cache, network egress blocked)
pcb-layout-*directories leak into$TMPDIRafterrunning the export tests.
layout.kicad_proin KiCadand confirmed it loads cleanly.
Note
Medium Risk
Adds a new CLI command that generates and copies full KiCad projects, and changes
process_layout(use_temp_dir=true)to manage temp directory cleanup viaLayoutResult, which could affect workflows that relied on the previous temp dir persistence unlesspersist_temp_dir()is used.Overview
Adds a new
pcb export-kicadsubcommand that builds a.zendesign, runsprocess_layoutin a fresh temp layout, then copies the generated KiCad project files into a user-specified output directory (with--offline/--lockedwired through resolution) and reports diagnostics.Fixes a temp-dir leak/behavior in
pcb_layout::process_layout(use_temp_dir=true)by havingLayoutResultown the backingTempDirand delete it on drop, plus introducesLayoutResult::persist_temp_dir()and updatespcb layout --tempto call it before launching KiCad asynchronously.Adds tests and snapshots covering
export-kicadsuccess, missing input handling, and offline/locked execution, and updates the CLI help snapshot to include the new command.Reviewed by Cursor Bugbot for commit 05f5a8c. Bugbot is set up for automated code reviews on this repo. Configure here.