kicad-validity A1: kicad_tools --resave — full-parse rewrite in current format

New --resave <file> <outdir> subcommand (root docs/features/kicad-validity/
0001): .kicad_sch one file per sheet mirroring the hierarchy layout,
.kicad_pcb via pcbToolsResaveBoard callback (mirror of the lint callback),
.kicad_sym/.lib via ConvertLibrary. Exit 0 ok / 2 usage / 4 input invalid /
5 write failed — only 4 marks the input invalid for the upload gate.
The s-expr schematic save stub is now #ifndef KICAD_TOOLS_COMBINED: the
merged image links the real writer (+65 KB), standalone sym_convert keeps
its diet. Board save needed no un-stubbing (pcb_io/ survives the CMake
prune).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HLua64PCVwkQ1hpWdaf1Gm
This commit is contained in:
Gergő Törcsvári 2026-07-14 09:31:17 +02:00
commit c51ccf82ba
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322
4 changed files with 237 additions and 3 deletions

View file

@ -679,6 +679,68 @@ int pcbToolsLintBoard( const char* aInPath, std::string& aError )
return -1;
}
}
// Full-parse board resave for the merged image's --resave driver (also on the
// eeschema side): a bare load like pcbToolsLintBoard, then the s-expr writer
// rewrites the board in the current format version. Zones are written
// as-saved (no refill) — a format upgrade must not change geometry. Returns
// 0 resaved / 4 load or parse failed / 5 write failed, with aError filled.
int pcbToolsResaveBoard( const char* aInPath, const char* aOutPath, std::string& aError )
{
wxFileName fn( wxString::FromUTF8( aInPath ) );
fn.MakeAbsolute();
kiRuntime();
std::unique_ptr<BOARD> brd;
try
{
brd.reset( PCB_IO_MGR::Load( PCB_IO_MGR::KICAD_SEXP, fn.GetFullPath() ) );
if( !brd )
{
aError = std::string( aInPath ) + ": error: failed to load board";
return 4;
}
}
catch( PARSE_ERROR& pe )
{
char buf[1024];
std::snprintf( buf, sizeof( buf ), "%s:%d:%d: error: %s", aInPath, pe.lineNumber,
pe.byteIndex, (const char*) pe.ParseProblem().ToUTF8() );
aError = buf;
return 4;
}
catch( const IO_ERROR& ioe )
{
aError = std::string( aInPath ) + ": error: " + std::string( ioe.Problem().ToUTF8() );
return 4;
}
catch( const std::exception& e )
{
aError = std::string( aInPath ) + ": error: " + e.what();
return 4;
}
try
{
PCB_IO_MGR::Save( PCB_IO_MGR::KICAD_SEXP, wxString::FromUTF8( aOutPath ), brd.get() );
}
catch( const IO_ERROR& ioe )
{
aError = std::string( aOutPath ) + ": error: " + std::string( ioe.Problem().ToUTF8() );
return 5;
}
catch( const std::exception& e )
{
aError = std::string( aOutPath ) + ": error: " + e.what();
return 5;
}
return 0;
}
#endif // KICAD_TOOLS_COMBINED