Inserts ktexttemplate ported idl files parser
This commit is contained in:
10 files changed
+217
-38
No files matched your search
@@ -0,0 +1,188 @@
|
||||
# Grantlee5 to KTextTemplate Porting Summary
|
||||
|
||||
## Overview
|
||||
Successfully ported the CodeGen module from Grantlee5 (Qt5) to KTextTemplate (Qt6/KF6).
|
||||
|
||||
## Date
|
||||
2026-01-07
|
||||
|
||||
## Changes Made
|
||||
|
||||
### Files Modified (9 files, 29 insertions, 38 deletions)
|
||||
|
||||
1. **CMakeLists.txt**
|
||||
- Changed `FIND_PACKAGE(Grantlee5 REQUIRED COMPONENTS Templates)` → `FIND_PACKAGE(KF6TextTemplate REQUIRED)`
|
||||
- Changed `TARGET Grantlee5::Templates` → `TARGET KF6::TextTemplate` (3 occurrences)
|
||||
- Updated comments to reference KTextTemplate
|
||||
|
||||
2. **GeneratorGrantleeBase.h**
|
||||
- Removed forward declarations: `namespace Grantlee { class Engine; class Context; class Template; }`
|
||||
- Added includes: `<ktexttemplate/template.h>`, `<ktexttemplate/context.h>`, `<ktexttemplate/engine.h>`
|
||||
- Changed all `Grantlee::` → `KTextTemplate::` (Engine, Context, Template)
|
||||
|
||||
3. **GeneratorGrantleeBase.cpp**
|
||||
- Removed `#include <grantlee/engine.h>` and `<grantlee/context.h>`
|
||||
- Added `#include <ktexttemplate/engine.h>` and `<ktexttemplate/context.h>`
|
||||
- Changed `Grantlee::Engine` → `KTextTemplate::Engine`
|
||||
- Changed `Grantlee::Context` → `KTextTemplate::Context`
|
||||
|
||||
4. **DaoGeneratorGrantlee.cpp**
|
||||
- Changed `#include <grantlee/context.h>` → `#include <ktexttemplate/context.h>`
|
||||
|
||||
5. **DatabaseGeneratorGrantlee.cpp**
|
||||
- Changed `#include <grantlee/context.h>` → `#include <ktexttemplate/context.h>`
|
||||
|
||||
6. **CppTopicGeneratorGrantlee.cpp**
|
||||
- Changed `#include <grantlee/context.h>` → `#include <ktexttemplate/context.h>`
|
||||
|
||||
7. **main_grantlee_gui.h**
|
||||
- Changed forward declaration: `namespace Grantlee { class Engine; }` → `namespace KTextTemplate { class Engine; }`
|
||||
- Changed member: `Grantlee::Engine*` → `KTextTemplate::Engine*`
|
||||
|
||||
8. **main_grantlee_gui.cpp**
|
||||
- Removed `#include <grantlee/engine.h>`
|
||||
- Changed `new Grantlee::Engine` → `new KTextTemplate::Engine`
|
||||
|
||||
9. **tests/GrantleeParserSmoke.cpp**
|
||||
- Changed all includes from `<grantlee/*.h>` → `<ktexttemplate/*.h>`
|
||||
- Changed `Grantlee::Engine` → `KTextTemplate::Engine`
|
||||
- Changed `Grantlee::FileSystemTemplateLoader` → `KTextTemplate::FileSystemTemplateLoader`
|
||||
- Changed `Grantlee::Template` → `KTextTemplate::Template`
|
||||
- Changed `Grantlee::NoError` → `KTextTemplate::NoError`
|
||||
- Changed `Grantlee::Context` → `KTextTemplate::Context`
|
||||
|
||||
### Files NOT Modified (No Changes Needed)
|
||||
|
||||
- **GrantleeWrappers.h/.cpp**: Pure QObject-derived wrapper classes with Q_PROPERTY, no direct Grantlee dependencies
|
||||
- **main_grantlee.cpp**: No direct Grantlee usage
|
||||
- **All .grantlee template files**: Template syntax is compatible between Grantlee5 and KTextTemplate
|
||||
|
||||
## API Compatibility
|
||||
|
||||
KTextTemplate API is nearly identical to Grantlee5:
|
||||
- `Grantlee::Engine` → `KTextTemplate::Engine`
|
||||
- `Grantlee::Context` → `KTextTemplate::Context`
|
||||
- `Grantlee::Template` → `KTextTemplate::Template` (typedef for `QSharedPointer<TemplateImpl>`)
|
||||
- `Grantlee::FileSystemTemplateLoader` → `KTextTemplate::FileSystemTemplateLoader`
|
||||
- `Grantlee::NoError` → `KTextTemplate::NoError`
|
||||
|
||||
## Build Requirements
|
||||
|
||||
### Runtime Dependencies
|
||||
- **Ubuntu 26.04** (or other distro with KF6 packages)
|
||||
- **libkf6texttemplate-dev** package
|
||||
- Qt6 (KF6)
|
||||
|
||||
### CMake Configuration
|
||||
```cmake
|
||||
FIND_PACKAGE(KF6TextTemplate REQUIRED)
|
||||
TARGET_LINK_LIBRARIES(your_target PRIVATE KF6::TextTemplate)
|
||||
```
|
||||
|
||||
## Build Instructions
|
||||
|
||||
### Using Docker (Required on Ubuntu 22.04)
|
||||
Since Ubuntu 22.04 doesn't have KTextTemplate, build must be done in Docker with Ubuntu 26.04:
|
||||
|
||||
```bash
|
||||
# Create Docker container with Ubuntu 26.04
|
||||
docker run -it --rm -v $(pwd):/workspace ubuntu:26.04 bash
|
||||
|
||||
# Inside container:
|
||||
apt-get update
|
||||
apt-get install -y libkf6texttemplate-dev qt6-base-dev cmake build-essential
|
||||
|
||||
cd /workspace/qt6-after/qt6-migrated-legatus
|
||||
cmake -B build-qt6 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_GRANTLEE=ON
|
||||
cmake --build build-qt6 --target codegen_grantlee
|
||||
```
|
||||
|
||||
### Native Build (Ubuntu 26.04+)
|
||||
```bash
|
||||
cd qt6-after/qt6-migrated-legatus
|
||||
cmake -B build-qt6 -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_GRANTLEE=ON
|
||||
cmake --build build-qt6 --target codegen_grantlee
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
### Smoke Test
|
||||
The `GrantleeParserSmoke` test validates all .grantlee template files:
|
||||
|
||||
```bash
|
||||
# After building
|
||||
cd build-qt6/Lts/Common/CodeGen
|
||||
ctest -R GrantleeParserSmoke -V
|
||||
# Or run directly:
|
||||
./grantlee_parser_smoke /path/to/Lts/Common/CodeGen
|
||||
```
|
||||
|
||||
The smoke test:
|
||||
- Scans for all `.grantlee` files in the CodeGen directory
|
||||
- Attempts to parse each template file
|
||||
- Reports any parse or render errors
|
||||
- Tests 58 template files (29 Qt5 legacy + 29 Qt6 migrated)
|
||||
|
||||
### Template Files Tested
|
||||
- svc.idl.grantlee
|
||||
- svc_enums.idl.grantlee
|
||||
- svc_translation.cpp.grantlee
|
||||
- svc_translation.h.grantlee
|
||||
- svc_dao.cpp.grantlee
|
||||
- svc_dao.h.grantlee
|
||||
- svc_db.h.grantlee
|
||||
- svc_db_impl.h.grantlee
|
||||
- svc_db_impl.cpp.grantlee
|
||||
- svc_dtc.h.grantlee
|
||||
- svc_dtc_impl.cpp.grantlee
|
||||
- svc_dtc_impl.h.grantlee
|
||||
- svc_dts.h.grantlee
|
||||
- svc_dts_impl.cpp.grantlee
|
||||
- svc_dts_impl.h.grantlee
|
||||
- svc_ftc.h.grantlee
|
||||
- svc_ftc_impl.cpp.grantlee
|
||||
- svc_ftc_impl.h.grantlee
|
||||
- svc_fts.h.grantlee
|
||||
- svc_fts_impl.cpp.grantlee
|
||||
- svc_fts_impl.h.grantlee
|
||||
- svc_json.cpp.grantlee
|
||||
- svc_json.h.grantlee
|
||||
- svc_topic_type_plugin.cpp.grantlee
|
||||
- svc_topic_type_plugin.h.grantlee
|
||||
- svc_record_replay_plugin.cpp.grantlee
|
||||
- svc_record_replay_plugin.h.grantlee
|
||||
- (Plus Qt5 legacy versions)
|
||||
|
||||
## Verification Checklist
|
||||
|
||||
- [x] All `Grantlee::` namespace references replaced with `KTextTemplate::`
|
||||
- [x] All `#include <grantlee/...>` changed to `#include <ktexttemplate/...>`
|
||||
- [x] CMakeLists.txt updated to use `KF6TextTemplate` and `KF6::TextTemplate`
|
||||
- [x] No remaining Grantlee5 dependencies in source code
|
||||
- [ ] Build successful with KTextTemplate (requires Ubuntu 26.04 or Docker)
|
||||
- [ ] Smoke test passes against all 58 .grantlee files
|
||||
- [ ] Code generation works correctly for all actions (dao, database, idl, dds_topics, etc.)
|
||||
- [ ] Generated code compiles and functions correctly
|
||||
|
||||
## Known Issues / Notes
|
||||
|
||||
1. **Build Environment**: Host system (Ubuntu 22.04) lacks KTextTemplate; Docker or Ubuntu 26.04 required
|
||||
2. **API Compatibility**: KTextTemplate API appears 100% compatible with Grantlee5 for the used features
|
||||
3. **Template Syntax**: .grantlee template files require no changes - syntax is identical
|
||||
4. **Wrapper Classes**: GrantleeWrappers.h/.cpp are pure QObject classes with no Grantlee dependencies
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Build in Docker**: Create/run Docker container with Ubuntu 26.04 and libkf6texttemplate-dev
|
||||
2. **Compile CodeGen module**: Build `codegen_grantlee` target
|
||||
3. **Run smoke test**: Execute `GrantleeParserSmoke` to validate all templates
|
||||
4. **Test code generation**: Run `ngl_codegen` with various actions against real IDL/XML files
|
||||
5. **Verify generated code**: Ensure generated C++ code compiles and works correctly
|
||||
6. **Integration**: Verify CodeGen integrates properly with Qt6 build system
|
||||
|
||||
## References
|
||||
|
||||
- Original task: `grantlee-parser-toktexttemplate-porting.prompt.md`
|
||||
- KTextTemplate docs: https://api.kde.org/frameworks/ktexttemplate/html/
|
||||
- Grantlee5 docs: https://www.grantlee.org/
|
||||
- Docker reference: `Lts/Tools/Niklas-Excon-Helper/Dockerfile` (shows Ubuntu 26.04 base)
|
||||
@@ -14,9 +14,9 @@ endif()
|
||||
|
||||
FIND_PACKAGE(RTI)
|
||||
|
||||
# Grantlee5 is Qt5-based and optional for Qt6 migration
|
||||
# KTextTemplate is Qt6-compatible replacement for Grantlee5
|
||||
IF(BUILD_GRANTLEE)
|
||||
FIND_PACKAGE(Grantlee5 REQUIRED COMPONENTS Templates)
|
||||
FIND_PACKAGE(KF6TextTemplate REQUIRED)
|
||||
ENDIF()
|
||||
|
||||
NGL_ADD_LIBRARY2(ALL codegen_base SHARED
|
||||
@@ -57,8 +57,8 @@ else()
|
||||
endif()
|
||||
NGL_INSTALL_TARGET(codegen_base)
|
||||
|
||||
# Grantlee5 is Qt5-based and optional for Qt6 migration
|
||||
IF(BUILD_GRANTLEE AND TARGET Grantlee5::Templates)
|
||||
# KTextTemplate is Qt6-compatible replacement for Grantlee5
|
||||
IF(BUILD_GRANTLEE AND TARGET KF6::TextTemplate)
|
||||
NGL_ADD_LIBRARY(ALL codegen_grantlee STATIC
|
||||
CppTopicGeneratorGrantlee.cpp
|
||||
CppTopicGeneratorGrantlee.h
|
||||
@@ -114,7 +114,7 @@ IF(BUILD_GRANTLEE AND TARGET Grantlee5::Templates)
|
||||
|
||||
NGL_TARGET_LINK_LIBRARIES(codegen_grantlee
|
||||
PRIVATE
|
||||
Grantlee5::Templates
|
||||
KF6::TextTemplate
|
||||
NGLLogger
|
||||
ProjectConfig
|
||||
PUBLIC
|
||||
@@ -135,7 +135,7 @@ IF(BUILD_GRANTLEE AND TARGET Grantlee5::Templates)
|
||||
endif()
|
||||
|
||||
add_executable(grantlee_parser_smoke tests/GrantleeParserSmoke.cpp)
|
||||
target_link_libraries(grantlee_parser_smoke PRIVATE Grantlee5::Templates ${QTCORE_TARGET})
|
||||
target_link_libraries(grantlee_parser_smoke PRIVATE KF6::TextTemplate ${QTCORE_TARGET})
|
||||
add_test(NAME GrantleeParserSmoke COMMAND grantlee_parser_smoke ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
NGL_ADD_EXECUTABLE(ALL ngl_codegen
|
||||
@@ -162,7 +162,7 @@ if(QT6_GUI_AVAILABLE)
|
||||
LtsCommandLineParser
|
||||
nglapplication
|
||||
${Qt6_Widgets}
|
||||
Grantlee5::Templates
|
||||
KF6::TextTemplate
|
||||
)
|
||||
endif()
|
||||
ELSE()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QtCore/QCryptographicHash>
|
||||
#include <grantlee/context.h>
|
||||
#include <ktexttemplate/context.h>
|
||||
|
||||
#ifdef RTI_HEADER_AVAILABLE
|
||||
#include <dds/core/xtypes/EnumType.hpp>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <grantlee/context.h>
|
||||
#include <ktexttemplate/context.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "StructBuilder.h"
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <grantlee/context.h>
|
||||
#include <ktexttemplate/context.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <grantlee/context.h>
|
||||
#include <grantlee/engine.h>
|
||||
|
||||
using namespace CodeGen;
|
||||
|
||||
GeneratorGrantleeBase::GeneratorGrantleeBase(const char* loggerName)
|
||||
: m_engine(new Grantlee::Engine)
|
||||
, m_ctx(new Grantlee::Context)
|
||||
: m_engine(new KTextTemplate::Engine)
|
||||
, m_ctx(new KTextTemplate::Context)
|
||||
, m_structBuilder(nullptr)
|
||||
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName))
|
||||
{
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "XmlReader.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedPointer>
|
||||
|
||||
#include <ktexttemplate/template.h>
|
||||
#include <ktexttemplate/context.h>
|
||||
#include <ktexttemplate/engine.h>
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace Grantlee
|
||||
{
|
||||
class Context;
|
||||
class Engine;
|
||||
class TemplateImpl;
|
||||
using Template = QSharedPointer<TemplateImpl>;
|
||||
} // namespace Grantlee
|
||||
|
||||
namespace CodeGen
|
||||
{
|
||||
class StructBuilder;
|
||||
@@ -45,9 +39,9 @@ class GeneratorGrantleeBase : public QObject
|
||||
void exportUsedServices(const XmlReader* reader);
|
||||
|
||||
protected:
|
||||
Grantlee::Engine* m_engine;
|
||||
Grantlee::Context* m_ctx;
|
||||
Grantlee::Template m_template;
|
||||
KTextTemplate::Engine* m_engine;
|
||||
KTextTemplate::Context* m_ctx;
|
||||
KTextTemplate::Template m_template;
|
||||
StructBuilder* m_structBuilder;
|
||||
NGL::INGLLogger& m_logger;
|
||||
};
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <grantlee/engine.h>
|
||||
#include <nglapplication/nglapplication.h>
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent), m_xmlReader(nullptr), m_structBuilder(nullptr),
|
||||
m_generator(new CodeGen::CppTopicGeneratorGrantlee), m_engine(new Grantlee::Engine), m_ui(new Ui_MainGrantleeGui)
|
||||
m_generator(new CodeGen::CppTopicGeneratorGrantlee), m_engine(new KTextTemplate::Engine), m_ui(new Ui_MainGrantleeGui)
|
||||
{
|
||||
m_idlServiceInfoFile = QStringLiteral("/home/chehrlic/TDS/TDS-build-product-clang/service_idl_files.txt");
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@@ -11,7 +11,7 @@ class StructBuilder;
|
||||
class GeneratorGrantleeBase;
|
||||
} // namespace CodeGen
|
||||
|
||||
namespace Grantlee
|
||||
namespace KTextTemplate
|
||||
{
|
||||
class Engine;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class MainWindow : public QMainWindow
|
||||
CodeGen::XmlReader* m_xmlReader;
|
||||
CodeGen::StructBuilder* m_structBuilder;
|
||||
CodeGen::GeneratorGrantleeBase* m_generator;
|
||||
Grantlee::Engine* m_engine;
|
||||
KTextTemplate::Engine* m_engine;
|
||||
QString m_idlServiceInfoFile;
|
||||
QString m_templateFile;
|
||||
Ui_MainGrantleeGui* m_ui;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QDir>
|
||||
#include <grantlee/engine.h>
|
||||
#include <grantlee/templateloader.h>
|
||||
#include <ktexttemplate/engine.h>
|
||||
#include <ktexttemplate/templateloader.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@@ -14,8 +14,8 @@ int main(int argc, char** argv)
|
||||
templatesDir = QString::fromLocal8Bit(argv[1]);
|
||||
}
|
||||
|
||||
Grantlee::Engine engine;
|
||||
auto loader = QSharedPointer<Grantlee::FileSystemTemplateLoader>::create();
|
||||
KTextTemplate::Engine engine;
|
||||
auto loader = QSharedPointer<KTextTemplate::FileSystemTemplateLoader>::create();
|
||||
loader->setTemplateDirs(QStringList() << templatesDir);
|
||||
engine.addTemplateLoader(loader);
|
||||
|
||||
@@ -32,7 +32,7 @@ int main(int argc, char** argv)
|
||||
bool ok = true;
|
||||
for (const QString& f : files)
|
||||
{
|
||||
Grantlee::Template t;
|
||||
KTextTemplate::Template t;
|
||||
try
|
||||
{
|
||||
t = engine.loadByName(f);
|
||||
@@ -49,14 +49,14 @@ int main(int argc, char** argv)
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
if (t->error() != Grantlee::NoError)
|
||||
if (t->error() != KTextTemplate::NoError)
|
||||
{
|
||||
qDebug() << "Parse error in" << f << ":" << t->errorString();
|
||||
ok = false;
|
||||
continue;
|
||||
}
|
||||
// Render with empty context to ensure rendering path also works.
|
||||
Grantlee::Context ctx;
|
||||
KTextTemplate::Context ctx;
|
||||
QString out = t->render(&ctx);
|
||||
if (out.isNull())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user