diff --git a/Lts/Common/CodeGen/CMakeLists.txt b/Lts/Common/CodeGen/CMakeLists.txt index 07ae22229..2fdff8411 100755 --- a/Lts/Common/CodeGen/CMakeLists.txt +++ b/Lts/Common/CodeGen/CMakeLists.txt @@ -113,6 +113,21 @@ else() message(STATUS "Grantlee5 not found; skipping codegen_grantlee target") endif() +# Smoke-test: parse all .grantlee templates in this directory to detect parse/render regressions +if (TARGET Grantlee5::Templates) + find_package(Qt6 COMPONENTS Core QUIET) + if (Qt6_FOUND) + set(QTCORE_TARGET Qt6::Core) + else() + find_package(Qt5 COMPONENTS Core REQUIRED) + set(QTCORE_TARGET Qt5::Core) + endif() + + add_executable(grantlee_parser_smoke tests/GrantleeParserSmoke.cpp) + target_link_libraries(grantlee_parser_smoke PRIVATE Grantlee5::Templates ${QTCORE_TARGET}) + add_test(NAME GrantleeParserSmoke COMMAND grantlee_parser_smoke ${CMAKE_CURRENT_SOURCE_DIR}) +endif() + NGL_ADD_EXECUTABLE(ALL codegen main_grantlee.cpp ) diff --git a/Lts/Common/CodeGen/tests/GrantleeParserSmoke.cpp b/Lts/Common/CodeGen/tests/GrantleeParserSmoke.cpp new file mode 100644 index 000000000..5af6f98aa --- /dev/null +++ b/Lts/Common/CodeGen/tests/GrantleeParserSmoke.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + QString templatesDir = QDir::currentPath(); + if (argc > 1) { + templatesDir = QString::fromLocal8Bit(argv[1]); + } + + Grantlee::Engine engine; + auto loader = QSharedPointer::create(); + loader->setTemplateDirs(QStringList() << templatesDir); + engine.addTemplateLoader(loader); + + QDir d(templatesDir); + QStringList files = d.entryList(QStringList() << "*.grantlee", QDir::Files); + if (files.isEmpty()) { + qDebug() << "No .grantlee templates found in" << templatesDir; + // Treat absence as successful parse (nothing to check) to avoid failing + // when directory is empty in different setups. + return 0; + } + + bool ok = true; + for (const QString &f : files) { + Grantlee::Template t; + try { + t = engine.loadByName(f); + } catch (...) { + qDebug() << "Exception while loading" << f; + ok = false; + continue; + } + if (!t) { + qDebug() << "Failed to load template" << f; + ok = false; + continue; + } + if (t->error() != Grantlee::TemplateImpl::Error::NoError) { + qDebug() << "Parse error in" << f << ":" << t->errorString(); + ok = false; + continue; + } + // Render with empty context to ensure rendering path also works. + Grantlee::Context ctx; + QString out = t->render(&ctx); + if (out.isNull()) { + qDebug() << "Rendering produced null for" << f; + ok = false; + continue; + } + } + + return ok ? 0 : 2; +} diff --git a/app/patches/apply_grantlee_fix.sh b/app/patches/apply_grantlee_fix.sh new file mode 100755 index 000000000..05cd16101 --- /dev/null +++ b/app/patches/apply_grantlee_fix.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Apply lightweight fix to Grantlee sources in externals to avoid duplicate +# QT_TESTCASE_BUILDDIR definition which causes compiler errors on Qt6. + +GRANTLEE_SRC_DIR="${1:-./external/grantlee-src}" + +if [ ! -d "$GRANTLEE_SRC_DIR" ]; then + echo "Grantlee source dir not found: $GRANTLEE_SRC_DIR" >&2 + exit 2 +fi + +TARGET_FILE="$GRANTLEE_SRC_DIR/textdocument/tests/CMakeLists.txt" + +if [ ! -f "$TARGET_FILE" ]; then + echo "Target CMake file not found: $TARGET_FILE" >&2 + exit 3 +fi + +# Replace the unconditional target_compile_definitions block with a commented +# explanation to avoid duplicate -D flags. + +awk ' +BEGIN{inblock=0} +/target_compile_definitions\(plainmarkupbuildertest_exec PRIVATE QT_TESTCASE_BUILDDIR/ {inblock=1; print "# QT_TESTCASE_BUILDDIR was previously defined here which could conflict with the"; print "# the definition injected by Qt\'s test configuration. Defining the macro in"; print "# multiple places leads to compiler redefinition errors. The test framework"; print "# already provides this define when needed, so omit the explicit definition"; print "# to avoid duplicate -D flags."; next} +{ if (inblock) { if (/^endif\(\)/) { inblock=0; next } else next } print } +' "$TARGET_FILE" > "$TARGET_FILE.tmp" && mv "$TARGET_FILE.tmp" "$TARGET_FILE" + +echo "Applied grantlee fix to $TARGET_FILE"