pcbjam/wasm/cli/kicad_tools_main.cpp
Gergő Törcsvári fb2aa2759d
kicad-validity B3+C+S: revert toast, corpus lint, .kicad_mod tier
B3 (editor): kicad-binding observes kdoc_meta.revertNonce (deduped, like
seedNonce) → DOC_REVERTED_EVENT → WasmTool doc-reverted-toast (15 s,
data-testid for the deferred e2e check).
C: tests/tools/corpus-lint.ts (npm run corpus:lint) — kicad_tools --lint
over the fixture corpora raw + shared-codec round-trips
(docToFile(fileToDoc(x))); the E3/wrapInBoardEnvelope-class gate. Skips
when output/kicad_tools.js isn't built; CI step lands when kicad_tools
joins the CI app set. 7 fixtures / 7 round-trips green.
S: --lint + --resave gain the .kicad_mod tier (pcbToolsLintFootprint /
pcbToolsResaveFootprint; writer needs CTL_FOR_LIBRARY or the board flags
strip the (version) header). Verified: qa footprint round-trip lints
clean, resave stamps 20260206, garbage exits 1. Also bumps pcbjam-shared
(mergeYUpdates for the bisect pass).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLua64PCVwkQ1hpWdaf1Gm
2026-07-14 19:02:13 +02:00

66 lines
2.7 KiB
C++

/*
* kicad_tools — merged headless KiCad CLI, built as ONE WebAssembly module
* linking both dieted kifaces (pcbjam-mcp 0001 tier 3a).
*
* Thin dispatcher over the two per-app entry points (compiled into this image
* with KICAD_TOOLS_COMBINED, which strips their standalone main()s):
*
* pcbnew side (pcb_convert_main.cpp):
* kicad_tools --drc [--json] [--strict] <file.kicad_pcb> [<out>]
* kicad_tools --gerbers <file.kicad_pcb> [<outdir>]
* kicad_tools --drill <file.kicad_pcb> [<outdir>]
* kicad_tools --plot-board [--pdf] [--layers <a,b,...>] <file.kicad_pcb> [<out>]
*
* eeschema side (sym_convert_main.cpp) — everything else:
* kicad_tools --convert-lib <input.lib> <output.kicad_sym>
* kicad_tools --lint [--strict] <file> [<file>...]
* (.kicad_pcb/.kicad_mod get a FULL parse here — the
* pcbnew parser is linked; the lint driver calls back
* into pcbToolsLintBoard/pcbToolsLintFootprint)
* kicad_tools --resave <file> <outdir>
* (full parse + rewrite in the current file-format
* version — kicad-validity 0001; .kicad_pcb via the
* pcbToolsResaveBoard callback, .kicad_sch one file per
* sheet, .kicad_sym/.lib via ConvertLibrary. Exit 4 =
* input invalid, 5 = write failed)
* kicad_tools --erc [--json] [--strict] <file.kicad_sch> [<out>]
* kicad_tools --netlist [--xml] <file.kicad_sch> [<out>]
* kicad_tools --bom <file.kicad_sch> [<out>]
* kicad_tools --plot [--pdf] <file.kicad_sch> [<out>]
*
* Each side brings up its own minimal PGM runtime on first use; dispatch is
* exclusive per process, so the two runtimes never coexist.
*/
#include <cstdio>
#include <cstring>
#include <unistd.h>
int symConvertMain( int argc, char** argv );
int pcbConvertMain( int argc, char** argv );
int main( int argc, char** argv )
{
int rc;
if( argc >= 2
&& ( std::strcmp( argv[1], "--drc" ) == 0 || std::strcmp( argv[1], "--gerbers" ) == 0
|| std::strcmp( argv[1], "--drill" ) == 0
|| std::strcmp( argv[1], "--plot-board" ) == 0 ) )
{
rc = pcbConvertMain( argc, argv );
}
else
{
rc = symConvertMain( argc, argv );
}
// Skip the EXIT_RUNTIME static-dtor pass (same rationale as
// pcb_convert_main.cpp, which already does this on its --drc path): with
// the pcbnew kiface in the image, some dieted-out teardown is reachable
// through vtable slots from static dtors and traps ("table index is out
// of bounds") AFTER the subcommand finished, clobbering the exit code.
std::fflush( nullptr );
_exit( rc );
}