aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-22 15:50:49 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-26 16:57:00 +0100
commite43a4854edbebf676c58d60716541ecc0493592f (patch)
treedf46d53f164868fc7c2ef8fbadf794a162fb6b42 /src
parent3713ca8baf6d729b86cf46511d498e5a7e78c166 (diff)
QmlCompiler: Allow AOT compiled function to specify includes
This is necessary for include directives specific to the types being used. Change-Id: I34e0e5907d795714797fbb99a75b863cc41e9ad3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljscompiler.cpp16
-rw-r--r--src/qmlcompiler/qqmljscompiler_p.h1
2 files changed, 15 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp
index ac587666d4..8f49817851 100644
--- a/src/qmlcompiler/qqmljscompiler.cpp
+++ b/src/qmlcompiler/qqmljscompiler.cpp
@@ -368,8 +368,20 @@ bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFile
return false;
if (!aotFunctions.isEmpty()) {
- if (!writeStr("#include <QtQml/qqmlcontext.h>\n#include <type_traits>\n\n"))
- return false;
+ QStringList includes = {
+ QStringLiteral("QtQml/qqmlcontext.h"),
+ QStringLiteral("type_traits")
+ };
+
+ for (const auto &function : aotFunctions)
+ includes.append(function.includes);
+
+ std::sort(includes.begin(), includes.end());
+ const auto end = std::unique(includes.begin(), includes.end());
+ for (auto it = includes.begin(); it != end; ++it) {
+ if (!writeStr(QStringLiteral("#include <%1>\n").arg(*it).toUtf8()))
+ return false;
+ }
}
if (!writeStr(QByteArrayLiteral("namespace QmlCacheGeneratedCode {\nnamespace ")))
diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h
index 6393df9724..f750fadbf4 100644
--- a/src/qmlcompiler/qqmljscompiler_p.h
+++ b/src/qmlcompiler/qqmljscompiler_p.h
@@ -63,6 +63,7 @@ struct QQmlJSCompileError
struct QQmlJSAotFunction
{
+ QStringList includes;
QString code;
QString returnType;
};