diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-08-31 16:46:39 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-09-02 16:17:49 +0200 |
commit | 226b728d92975668d1ff864ab1f3f107477aef27 (patch) | |
tree | 3798df07aee5f6caca242d054224e9c83f8b87d0 | |
parent | d3623d04ecceabff1a4a179079730102a804cae7 (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.
Pick-to: 6.2
Change-Id: I3c8e946609b8a0a8f739812508b75e4f085feddc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
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 33644b0788..6d6dcd0895 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -321,4 +321,9 @@ void tst_qmltyperegistrar::deferredNames() QVERIFY(qmltypesData.contains("deferredNames: [\"A\", \"B\", \"C\"]")); } +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 63766bc8bc..e144c26499 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> @@ -424,6 +425,12 @@ QML_NAMESPACE_EXTENDED(ExtensionValueType) QML_ELEMENT } +class DerivedFromForeignPrivate : public ForeignPrivate +{ + Q_OBJECT + QML_ELEMENT +}; + class tst_qmltyperegistrar : public QObject { Q_OBJECT @@ -455,6 +462,7 @@ private slots: void namespacesAndValueTypes(); void namespaceExtendedNamespace(); void deferredNames(); + void derivedFromForeignPrivate(); private: QByteArray qmltypesData; |