refactor(cpp-generator): merge legacy/ into the generator, dropping its dead half

`legacy/` was never a library with an API surface. Two files, 475 lines, exactly
one exported symbol — `int legacy_main(int, char**)` — with every other
definition `static`, compiled INTO logos-cpp-generator and reached by fallthrough
at the end of main(). So there was nothing to keep separate: it is one mode of
this binary, and it now lives beside the others as plugin_introspect.{cpp,h}
behind `runPluginIntrospectMode()`, named for what it does.

Deleting it was never an option — that premise was checked and refused earlier.
`--general-only` alone has ~10 live callers across 7 repos including the central
module path (buildPlugin.nix:206,211, buildHeaders.nix:221,
LogosModule.cmake:423). The mode is load-bearing; only its packaging was wrong.

110 lines go with the move, all genuinely unreferenced:

  * cppStringEscape — zero callers anywhere.
  * writeUmbrellaHeader / writeUmbrellaSource and the `if (!moduleOnly)` block
    that called them. This is the real prize: a SECOND, directory-SCRAPING
    implementation of logos_sdk.{h,cpp}, unreachable in practice because
    generate-module-headers.sh:60 always passes --module-only. generator_lib's
    deps-driven makeUmbrella*FromDeps is now the only umbrella emitter, so the
    two cannot drift.
  * a dead `QJsonDocument doc(methods);` and its commented-out use.

With the block gone, `--module-only` suppresses nothing, so the parameter and
its plumbing go too. The FLAG stays tolerated rather than rejected, because
generate-module-headers.sh passes it unconditionally — a comment at the old
parse site says so.

Verified: #default builds, and both checks pass — `generator-cli` (which
exercises the CLI surface, including --general-only) and `tests`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Dario Gabriel Lipicar
2026-08-18 16:46:09 -03:00
co-authored by Claude Opus 5
parent d27927aba5
commit 1afcf46f4d
6 changed files with 37 additions and 140 deletions
+9 -9
View File
@@ -1,4 +1,4 @@
#include "legacy/legacy_main.h"
#include "plugin_introspect.h"
#include "generator_lib.h"
#include "lidl_to_json.h"
#include "experimental/lidl_gen_client.h"
@@ -26,11 +26,11 @@
// its interface dependencies, and the per-dependency / per-interface wrappers
// those aggregate.
//
// This is NOT a legacy mode, despite having lived in `legacy/main.cpp` until
// This is NOT a legacy mode, despite having lived in `plugin_introspect.cpp` until
// now: `LogosModuleContext::modules()` returns `LogosModules&`, so every
// `interface: "universal"` module that calls a declared dependency goes
// through it, and LogosModule.cmake runs it for every module build. Only the
// QPluginLoader-introspection path in `legacy/main.cpp` is legacy.
// QPluginLoader-introspection path in `plugin_introspect.cpp` is legacy.
//
// `--general-only` is kept as an exact alias — it is what LogosModule.cmake,
// buildPlugin.nix and buildHeaders.nix all pass today — so there is ONE
@@ -217,7 +217,7 @@ static int runUmbrellaMode(const QStringList& args, const QString& progName,
outputDir = stripAt(args.at(outDirIdx + 1));
}
// `--api-style qt|lp` — the one parser, shared with legacy_main's plugin
// `--api-style qt|lp` — the one parser, shared with runPluginIntrospectMode's plugin
// path (generator_lib.h, next to the ApiStyle enum).
ApiStyle apiStyle = ApiStyle::Qt;
if (!parseApiStyleFlag(args, apiStyle, err)) return 1;
@@ -428,7 +428,7 @@ static int runUmbrellaMode(const QStringList& args, const QString& progName,
int main(int argc, char* argv[])
{
// Check for --lidl / --from-header / --header-to-lidl mode before
// initializing QCoreApplication, since legacy_main creates its own.
// initializing QCoreApplication, since runPluginIntrospectMode creates its own.
bool hasLidl = false;
bool hasFromHeader = false;
bool hasHeaderToLidl = false;
@@ -446,8 +446,8 @@ int main(int argc, char* argv[])
}
// Umbrella mode. `--general-only` routes here too — ONE implementation,
// no second copy in legacy/main.cpp to drift — but only in the shape
// legacy_main ever honoured it: inside the `--metadata` branch. Without
// no second copy in plugin_introspect.cpp to drift — but only in the shape
// runPluginIntrospectMode ever honoured it: inside the `--metadata` branch. Without
// `--metadata` the flag was never a mode at all (it fell through to the
// plugin path and reported the flag itself as a missing plugin file), so
// that case still falls through, unchanged.
@@ -471,7 +471,7 @@ int main(int argc, char* argv[])
const QStringList args = app.arguments();
// Strip a leading '@' from path arguments — some build drivers pass
// `@/abs/path`. Matches the legacy_main path handling.
// `@/abs/path`. Matches the runPluginIntrospectMode path handling.
auto stripAt = [](QString p) { if (p.startsWith('@')) p.remove(0, 1); return p; };
const int idx = args.indexOf("--header-to-lidl");
@@ -769,5 +769,5 @@ int main(int argc, char* argv[])
return lidlGenerateClientStubs(lidlPath, outputDir, moduleOnly, out, err);
}
return legacy_main(argc, argv);
return runPluginIntrospectMode(argc, argv);
}