Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Common/CodeGen/main_grantlee.cpp
T
berrux-dev cfe15c72c4 Merge story/release-validation-scope
Bring the validation-scope line (in-tree Jenkins CI copy, lcov coverage
wiring, step-by-step release-scope README, TetraIF unit tests, the
LogView runtime icon/resource fix, Dockerfile, rpmbuild and the
new_docker_build.sh driver with the DEB output path) on top of the
XmlPatterns branch pruned to the Release 2 scope.

Conflict policy:
- Out-of-scope targets/modules: keep the prune (deletion wins).
- In-scope files that validation had deleted: restored from
  story/release-2-cleanup (the Release 2 closure, with the
  pruned-module guards).
- In-scope sources carrying migration work: XmlPatterns versions
  (Qt XmlPatterns rework on QDomDocument, DDS member and logger
  fixes, first-build fixes).
- Scope-aware CMakeLists (top level, PluginInterfaces, LtsWidgets)
  and .envrc: story/release-2-cleanup / ours versions.
2026-11-16 18:49:14 +01:00

174 lines
5.5 KiB
C++

/**
* @RDE_HEADER@
* main for ExerciseManagement
* $Id$
* $HeadURL$
* $Author$
*/
#include "CppTopicGeneratorGrantlee.h"
#include "DaoGeneratorGrantlee.h"
#include "DatabaseGeneratorGrantlee.h"
#include "SqlGenerator.h"
#include "StructBuilder.h"
#include "XmlReader.h"
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <NGLLogger/INGLLogger.h>
#include <QtCore/QDir>
#include <nglapplication/nglcoreapplication.h>
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
{
public:
CmdLineParser() : LtsCommandLineParser(LtsCommandLineParser::LtsCommandLineParser::None)
{
addOption({QStringList() << QStringLiteral("s") << QStringLiteral("servicefile"),
QStringLiteral("full path to the service xml-file"), QStringLiteral("service xml-file"),
QStringLiteral("/home")});
addOption({QStringList() << QStringLiteral("a") << QStringLiteral("action"),
QStringLiteral("the action to execute"), QStringLiteral("DATABASE|DATABASE_SERVER|IDL|DDS_TOPICS"),
QStringLiteral("/0")});
addOption({QStringList() << QStringLiteral("o") << QStringLiteral("outdir"),
QStringLiteral("the output directory where to put the generated files"),
QStringLiteral("output directory"), QStringLiteral("/home")});
addOption({QStringList() << QStringLiteral("i") << QStringLiteral("idlinfo"),
QStringLiteral("the info file with all available idl service files"),
QStringLiteral("info file for idl"), QStringLiteral("/0")});
}
bool init()
{
if (!LtsCommandLineParser::init())
return false;
if (serviceFile().isEmpty() || action().isEmpty() || outDir().isEmpty())
{
showHelp();
return false;
}
return true;
}
QString serviceFile() const
{
return value(QStringLiteral("s"));
}
QString action() const
{
return value(QStringLiteral("a"));
}
QString outDir() const
{
return value(QStringLiteral("o"));
}
QString idlInfoFile() const
{
return value(QStringLiteral("i"));
}
};
int main(int argc, char** argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("CodeGen", "codegen_log4cxx.props", true);
NGL::INGLLogger& m_logger = app.baseLogger();
CmdLineParser options;
if (!options.init())
return -1;
QScopedPointer<CodeGen::XmlReader> reader(new CodeGen::XmlReader);
DEBUG_LOG(m_logger) << "ServiceFile: " << options.serviceFile();
DEBUG_LOG(m_logger) << "IdlInfoFile: " << options.idlInfoFile();
if (!reader->readServiceFile(options.serviceFile(), options.idlInfoFile()))
{
ERROR_LOG(m_logger) << "Error parsing service file '" << options.serviceFile() << ": " << reader->errorString();
return 2;
}
QDir dir(options.outDir());
DEBUG_LOG(m_logger) << "Directory: " << options.outDir();
if (!dir.exists() && !dir.mkpath(options.outDir()))
{
ERROR_LOG(m_logger) << "Directory '" << options.outDir() << "' does not exist and can not be created!";
return 3;
}
QScopedPointer<CodeGen::StructBuilder> structBuilder(new CodeGen::StructBuilder(reader.data()));
if (!structBuilder->buildStructures())
{
ERROR_LOG(m_logger) << "Error building up structures";
return 4;
}
const QString action = options.action().toLower();
QScopedPointer<CodeGen::GeneratorGrantleeBase> generator;
if (action == QStringLiteral("dao"))
generator.reset(new CodeGen::DaoGeneratorGrantlee);
else if (action == QStringLiteral("database"))
generator.reset(new CodeGen::DatabaseGeneratorGrantlee(false));
else if (action == QStringLiteral("database_server"))
generator.reset(new CodeGen::DatabaseGeneratorGrantlee(true));
else if (action == QStringLiteral("dds_topics"))
generator.reset(new CodeGen::CppTopicGeneratorGrantlee);
else if (action == QStringLiteral("sql"))
{
CodeGen::SqlGenerator sql(reader.data(), structBuilder.data());
if (!sql.generateData(35))
return 8;
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
{
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
return 10;
}
if (!sql.generateData(42))
return 8;
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Exercise))
{
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
return 10;
}
sql.generateData(0);
if (!sql.writeSql(dir.absolutePath() + QLatin1Char('/'), CodeGen::ExerciseDependency::Global))
{
ERROR_LOG(m_logger) << "Error while writing sql information for service " << sql.getServiceAbbr();
return 10;
}
return 0;
}
else
{
ERROR_LOG(m_logger) << "Invalid action '" << options.action() << "' given!";
return 5;
}
if (!generator->init(reader.data(), structBuilder.data()))
{
ERROR_LOG(m_logger) << "Error initializing generator!";
return 6;
}
const auto posArgs = options.positionalArguments();
for (const QString& file : posArgs)
{
if (!generator->generateData(file, dir.absolutePath()))
return 7;
}
return 0;
}