diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-26 10:42:16 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-05-09 13:54:51 +0200 |
commit | 324fd7d58f88e814abf347eb43d5ed628318f9b7 (patch) | |
tree | 49f0c14c88ab7ce0ad78fa77444baf6858ee11e3 /tools/qmltc | |
parent | 7b771c756aef91a90d40fdb51944a860c67e3f53 (diff) |
qmltc: Uniquely name internal method that provides QML document URL
To enable unity builds of the generated code we have to name our static
methods in a unique way, so make URL method use QML document url as part
of the name. This should be unique enough since we don't have two
exactly named QML files within a module
Fixes: QTBUG-102765
Change-Id: I2618b19709e63149d68efc45b6726e84ba64981f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit b497eaf8914ec5690692d108af4babcb9f70f2d0)
Diffstat (limited to 'tools/qmltc')
-rw-r--r-- | tools/qmltc/prototype/codegenerator.cpp | 4 | ||||
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 16 | ||||
-rw-r--r-- | tools/qmltc/qmltccompiler.h | 2 | ||||
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.h | 12 |
4 files changed, 22 insertions, 12 deletions
diff --git a/tools/qmltc/prototype/codegenerator.cpp b/tools/qmltc/prototype/codegenerator.cpp index f0e2ca2993..84f49cd3f7 100644 --- a/tools/qmltc/prototype/codegenerator.cpp +++ b/tools/qmltc/prototype/codegenerator.cpp @@ -1915,8 +1915,10 @@ void CodeGenerator::compileScriptBindingOfComponent(QQmlJSAotObject ¤t, void CodeGenerator::compileUrlMethod() { + QFileInfo fi(m_url); m_urlMethod.returnType = u"const QUrl &"_qs; - m_urlMethod.name = u"q_qmltc_docUrl"_qs; + m_urlMethod.name = + u"q_qmltc_docUrl_" + fi.fileName().replace(u".qml"_qs, u""_qs).replace(u'.', u'_'); m_urlMethod.body << u"static QUrl docUrl = %1;"_qs.arg( CodeGeneratorUtility::toResourcePath(m_options.resourcePath)); m_urlMethod.body << u"return docUrl;"_qs; diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp index 33fffcad62..e15b397f13 100644 --- a/tools/qmltc/qmltccompiler.cpp +++ b/tools/qmltc/qmltccompiler.cpp @@ -42,7 +42,6 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcQmltcCompiler, "qml.qmltc.compiler", QtWarningMsg); const QString QmltcCodeGenerator::privateEngineName = u"ePriv"_qs; -const QString QmltcCodeGenerator::urlMethodName = u"q_qmltc_docUrl"_qs; QmltcCompiler::QmltcCompiler(const QString &url, QmltcTypeResolver *resolver, QmltcVisitor *visitor, QQmlJSLogger *logger) @@ -63,8 +62,10 @@ void QmltcCompiler::compile(const QmltcCompilerInfo &info) QList<QmltcType> compiledTypes; compiledTypes.reserve(types.size()); + QmltcCodeGenerator generator { m_url, QQmlJSScope::ConstPtr() }; + QmltcMethod urlMethod; - compileUrlMethod(urlMethod); + compileUrlMethod(urlMethod, generator.urlMethodName()); for (const QQmlJSScope::ConstPtr &type : types) { compiledTypes.emplaceBack(); // creates empty type @@ -87,9 +88,9 @@ void QmltcCompiler::compile(const QmltcCompilerInfo &info) QmltcCodeWriter::write(code, program); } -void QmltcCompiler::compileUrlMethod(QmltcMethod &urlMethod) +void QmltcCompiler::compileUrlMethod(QmltcMethod &urlMethod, const QString &urlMethodName) { - urlMethod.name = QmltcCodeGenerator::urlMethodName; + urlMethod.name = urlMethodName; urlMethod.returnType = u"const QUrl&"_qs; urlMethod.body << u"static QUrl url {QStringLiteral(\"qrc:%1\")};"_qs.arg(m_info.resourcePath); urlMethod.body << u"return url;"_qs; @@ -186,7 +187,7 @@ void QmltcCompiler::compileType(QmltcType ¤t, const QQmlJSScope::ConstPtr current.basicCtor.body << u"QQml_setParent_noEvent(this, " + parent.name + u");"; } - QmltcCodeGenerator generator { rootType }; + QmltcCodeGenerator generator { m_url, rootType }; // compilation stub: current.fullCtor.body << u"Q_UNUSED(engine);"_qs; @@ -435,8 +436,9 @@ void QmltcCompiler::compileBinding(QmltcType ¤t, const QQmlJSMetaPropertyB // without if-checking every type QmltcCodeGenerator generator { - QQmlJSScope::ConstPtr() - }; // NB: we don't need document root here + m_url, + QQmlJSScope::ConstPtr() // NB: we don't need document root here + }; switch (binding.bindingType()) { case QQmlJSMetaPropertyBinding::BoolLiteral: { diff --git a/tools/qmltc/qmltccompiler.h b/tools/qmltc/qmltccompiler.h index 0574b03088..e55ee47538 100644 --- a/tools/qmltc/qmltccompiler.h +++ b/tools/qmltc/qmltccompiler.h @@ -63,7 +63,7 @@ private: QQmlJSLogger *m_logger = nullptr; QmltcCompilerInfo m_info {}; // miscellaneous input/output information - void compileUrlMethod(QmltcMethod &urlMethod); + void compileUrlMethod(QmltcMethod &urlMethod, const QString &urlMethodName); void compileType(QmltcType ¤t, const QQmlJSScope::ConstPtr &type); void compileEnum(QmltcType ¤t, const QQmlJSMetaEnum &e); void compileMethod(QmltcType ¤t, const QQmlJSMetaMethod &m); diff --git a/tools/qmltc/qmltccompilerpieces.h b/tools/qmltc/qmltccompilerpieces.h index e0c587b5f3..60b6c5c5ba 100644 --- a/tools/qmltc/qmltccompilerpieces.h +++ b/tools/qmltc/qmltccompilerpieces.h @@ -31,6 +31,7 @@ #include <QtCore/qscopeguard.h> #include <QtCore/qstringbuilder.h> +#include <QtCore/qfileinfo.h> #include "qmltcoutputir.h" #include "qmltcvisitor.h" @@ -47,8 +48,7 @@ QT_BEGIN_NAMESPACE struct QmltcCodeGenerator { static const QString privateEngineName; - static const QString urlMethodName; - + QString documentUrl; QQmlJSScope::ConstPtr documentRoot; /*! @@ -65,6 +65,12 @@ struct QmltcCodeGenerator inline void generate_assignToProperty(QmltcType ¤t, const QQmlJSScope::ConstPtr &type, const QQmlJSMetaProperty &p, const QString &value, const QString &accessor); + + QString urlMethodName() const + { + QFileInfo fi(documentUrl); + return u"q_qmltc_docUrl_" + fi.fileName().replace(u".qml"_qs, u""_qs).replace(u'.', u'_'); + } }; inline decltype(auto) @@ -118,7 +124,7 @@ QmltcCodeGenerator::generate_qmlContextSetup(QmltcType ¤t, const QQmlJSSco << QStringLiteral( "context = %1->createInternalContext(%1->compilationUnitFromUrl(%2()), " "context, 0, true);") - .arg(privateEngineName, urlMethodName); + .arg(privateEngineName, urlMethodName()); } else { current.init.body << u"// 1. use current context as this object's context"_qs; current.init.body << u"// context = context;"_qs; |