aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-08-31 16:46:39 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-09-04 08:45:58 +0200
commitb512d167148da14c670a4cc09ce1d3670839fdc8 (patch)
tree1b21986968ab8e08480b3538eded88fdcdc12598
parenta5bb7038e56969f41646ab499815d8072ed1457b (diff)
qmltyperegistrar: Properly resolve includes for foreign types
When we add them to the qmltypes files, they need the same preprocessing as the own types. Change-Id: I3c8e946609b8a0a8f739812508b75e4f085feddc Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 226b728d92975668d1ff864ab1f3f107477aef27) Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
-rw-r--r--src/qmltyperegistrar/metatypesjsonprocessor.cpp2
-rw-r--r--tests/auto/qml/qmltyperegistrar/CMakeLists.txt11
-rw-r--r--tests/auto/qml/qmltyperegistrar/dummy.cpp2
-rw-r--r--tests/auto/qml/qmltyperegistrar/dummy_p.h2
-rw-r--r--tests/auto/qml/qmltyperegistrar/foreign/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmltyperegistrar/foreign/foreign_p.h44
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp5
-rw-r--r--tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h8
8 files changed, 74 insertions, 2 deletions
diff --git a/src/qmltyperegistrar/metatypesjsonprocessor.cpp b/src/qmltyperegistrar/metatypesjsonprocessor.cpp
index 4d6f97e874..d96f75f109 100644
--- a/src/qmltyperegistrar/metatypesjsonprocessor.cpp
+++ b/src/qmltyperegistrar/metatypesjsonprocessor.cpp
@@ -317,7 +317,7 @@ void MetaTypesJsonProcessor::processTypes(const QJsonObject &types)
void MetaTypesJsonProcessor::processForeignTypes(const QJsonObject &types)
{
- const QString include = types[QLatin1String("inputFile")].toString();
+ const QString include = resolvedInclude(types[QLatin1String("inputFile")].toString());
const QJsonArray classes = types[QLatin1String("classes")].toArray();
for (const QJsonValue cls : classes) {
QJsonObject classDef = cls.toObject();
diff --git a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
index 101b13cbb0..9dd38ce506 100644
--- a/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
+++ b/tests/auto/qml/qmltyperegistrar/CMakeLists.txt
@@ -7,6 +7,16 @@
qt_manual_moc(moc_files OUTPUT_MOC_JSON_FILES json_list noextheader
INCLUDE_DIRECTORY_TARGETS Qt::Qml)
+# Dummy target to pass --private-includes to qmltyperegistrar for tst_qmltyperegistrar.
+# We want to test that it expects files named foo_p.h appearing in foreign metatypes
+# to be in a private/ subdirectory. In particular, we have a foreign_p.h to exercise this.
+# TODO: There should be more fine grained control over this.
+qt_add_library(tst_qmltyperegistrarPrivate STATIC
+ dummy.cpp dummy_p.h
+)
+
+target_link_libraries(tst_qmltyperegistrarPrivate PRIVATE Qt::Core)
+
qt_internal_add_test(tst_qmltyperegistrar
SOURCES
hppheader.hpp
@@ -20,6 +30,7 @@ qt_internal_add_test(tst_qmltyperegistrar
# Remove: Lforeign
Qt::Qml
foreign
+ tst_qmltyperegistrarPrivate
)
#### Keys ignored in scope 2:.:.:tst_qmltyperegistrar.pro:<TRUE>:
diff --git a/tests/auto/qml/qmltyperegistrar/dummy.cpp b/tests/auto/qml/qmltyperegistrar/dummy.cpp
new file mode 100644
index 0000000000..1959bc3816
--- /dev/null
+++ b/tests/auto/qml/qmltyperegistrar/dummy.cpp
@@ -0,0 +1,2 @@
+#include "dummy_p.h"
+int foo() { return 1; }
diff --git a/tests/auto/qml/qmltyperegistrar/dummy_p.h b/tests/auto/qml/qmltyperegistrar/dummy_p.h
new file mode 100644
index 0000000000..e564d3b549
--- /dev/null
+++ b/tests/auto/qml/qmltyperegistrar/dummy_p.h
@@ -0,0 +1,2 @@
+#include <QtCore/qglobal.h>
+Q_DECL_EXPORT int foo();
diff --git a/tests/auto/qml/qmltyperegistrar/foreign/CMakeLists.txt b/tests/auto/qml/qmltyperegistrar/foreign/CMakeLists.txt
index ad967cdbf0..81d4b00aa3 100644
--- a/tests/auto/qml/qmltyperegistrar/foreign/CMakeLists.txt
+++ b/tests/auto/qml/qmltyperegistrar/foreign/CMakeLists.txt
@@ -7,7 +7,7 @@
qt_internal_add_cmake_library(foreign
STATIC
SOURCES
- foreign.cpp foreign.h
+ foreign.cpp foreign.h foreign_p.h
PUBLIC_LIBRARIES
Qt::Core
)
diff --git a/tests/auto/qml/qmltyperegistrar/foreign/foreign_p.h b/tests/auto/qml/qmltyperegistrar/foreign/foreign_p.h
new file mode 100644
index 0000000000..8ea292c015
--- /dev/null
+++ b/tests/auto/qml/qmltyperegistrar/foreign/foreign_p.h
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef FOREIGN_P_H
+#define FOREIGN_P_H
+
+#include <QtCore/qobject.h>
+
+// qmltyperegistrar will assume this file is reachable under <private/foreign_p.h>
+// It's not true, but this is how it works on actual private headers in Qt.
+// See the trick in tst_qmltyperegistrar's CMakeLists.txt to turn on the --private-includes option.
+class ForeignPrivate : public QObject
+{
+ Q_OBJECT
+Q_SIGNALS:
+ void happens();
+};
+
+#endif // FOREIGN_P_H
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
index f11f5d6404..0ddadb5b16 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp
@@ -288,4 +288,9 @@ void tst_qmltyperegistrar::namespacesAndValueTypes()
check(QMetaType::fromName("ValueTypeWithEnum2"), QMetaType::fromType<ValueTypeWithEnum2>());
}
+void tst_qmltyperegistrar::derivedFromForeignPrivate()
+{
+ QVERIFY(qmltypesData.contains("file: \"private/foreign_p.h\""));
+}
+
QTEST_MAIN(tst_qmltyperegistrar)
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
index 2a8423c682..d0c0d175e3 100644
--- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
+++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h
@@ -30,6 +30,7 @@
#define TST_QMLTYPEREGISTRAR_H
#include "foreign.h"
+#include "foreign_p.h"
#include <QtQml/qqml.h>
#include <QtCore/qproperty.h>
@@ -382,6 +383,12 @@ struct BValueTypeWithEnumForeign2
QML_NAMED_ELEMENT(valueTypeWithEnum2)
};
+class DerivedFromForeignPrivate : public ForeignPrivate
+{
+ Q_OBJECT
+ QML_ELEMENT
+};
+
class tst_qmltyperegistrar : public QObject
{
Q_OBJECT
@@ -411,6 +418,7 @@ private slots:
void finalProperty();
void parentProperty();
void namespacesAndValueTypes();
+ void derivedFromForeignPrivate();
private:
QByteArray qmltypesData;