Skip to content

Adopt reflect-cpp XML/JSON SSOT for Platform, Suppressions, and .cppcheck Project schemas - #3

Open
clockblocker wants to merge 3 commits into
mainfrom
adopt-rfl-xml-ssot
Open

clockblocker wants to merge 3 commits into
mainfrom
adopt-rfl-xml-ssot

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Deep Single Source of Truth (SSOT) adoption of reflect-cpp (rfl::xml, rfl::json, and rfl::json::to_schema) across three XML/JSON configuration domains in Cppcheck, unifying duplicated CLI (tinyxml2) and GUI (QXmlStreamReader/QXmlStreamWriter) schemas into a single header-only definition in lib/schemas.h.

Summary of Changes (3 commits)

  1. Platform schema (8958cc8): Replaced tinyxml2 parsing in lib/platform.{h,cpp} and test/testplatform.cpp with cppcheck::schemas::PlatformSchema. Added loadFromXml, loadFromJson, toXml, toJson, jsonSchema, and .json platform file loading in Platform::loadFromFile. Enabled REFLECTCPP_XML and marked pugixml::pugixml include directories as SYSTEM for AppleClang -Weverything.
  2. Suppressions schema (36dded6): Removed tinyxml2 (xml.h) from lib/suppressions.cpp. Migrated SuppressionList::parseXmlFile to pugixml + rfl::xml::read<SuppressEntrySchema>(node) (PR Fixed preprocessor testcases cppcheck-opensource/cppcheck#66 DOM node interop) while preserving exact legacy error messages, migrated SuppressionList::dump to rfl::xml::write<"suppressions">(schema, doc), and added parseJson, toXml, toJson, and jsonSchema.
  3. Unified CLI & GUI .cppcheck Project File schema (7a8f1ef): Replaced ImportProject::importCppcheckGuiProject's ~200-line tinyxml2 loop and gui/projectfile.{h,cpp}'s ~725 lines of duplicated QXmlStreamReader/QXmlStreamWriter code with shared cppcheck::schemas::ProjectFileSchema (all 36 child elements + version attribute). Added .cppcheck.json support in both CLI (ImportProject::import) and GUI (ProjectFile::read/write), plus ImportProject::projectFileJsonSchema().

Key Metrics

  • git diff --shortstat fork/main..HEAD: 14 files changed, 1493 insertions(+), 1293 deletions(-)
  • gui/projectfile.cpp: 1211 -> 580 LoC (-631), gui/projectfile.h: 689 -> 595 LoC (-94)
  • lib/importproject.cpp: 5977 -> 5960 LoC (-17)
  • lib/platform.cpp: 527 -> 562 LoC (+35, adds XML/JSON write, JSON read, JSON Schema)
  • lib/suppressions.cpp: 1002 -> 1086 LoC (+84, adds XML/JSON write, JSON read, JSON Schema)
  • lib/schemas.h: 0 -> 445 LoC (single shared SSOT across all 3 domains, isolated to .cpp includes with lazy function templates to avoid cross-domain template instantiation)

Verification

  • Built testrunner and cppcheck cleanly with Ninja + AppleClang -Weverything (0 warnings)
  • TestImportProject: 52/52 passed (0 failed, 1 todo)
  • TestPlatform: 21/21 passed (0 failed, 2 todos)
  • TestSuppressions: 74/74 passed (0 failed)
  • TestCmdlineParser: 363/363 passed (0 failed, 2 todos)
  • Verified CLI --platform=avr8 --xml-version=3 --suppress=foo and empty/no-root .cppcheck error strings end-to-end

Remaining reflect-cpp Gaps Observed

  • rfl::xml::read ignores the root element tag name, requiring manual root tag verification (<platform>, <project>).
  • rfl::NoExtraFields is not supported cleanly by rfl::xml::Reader, requiring manual allowlist checks for strict unknown-element diagnostics (<suppress>, <project>, <safe-checks>).
  • std::optional<rfl::Attribute<T>> is not recognized as an XML attribute (is_attribute_v only unwraps rfl::Rename), requiring inverted rfl::Attribute<std::optional<T>>.
  • XML text content requires the magic field name "xml_content", which leaks into JSON serialization and JSON Schema output.
  • Empty self-closing XML tags (<check-headers/>, <max-ctu-depth/>, <analyze-all-vs-configs/>) cannot customize empty-element defaults per type in rfl::xml::Reader, requiring DOM pre-normalization before rfl::xml::read.
  • No built-in XML formatting options on rfl::xml::write (e.g. omitting XML declaration or custom line indentation prefix), requiring manual pugi::xml_document::save(..., pugi::format_no_declaration) + line prefixing for SuppressionList::dump.
  • Eager non-template inline functions in a multi-domain schema header cause heavy redundant template instantiation for large structs (37-field ProjectFileSchema) across every including TU; lazy function templates were required to isolate compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant