diff options
author | Vadim Popov <vadim.popov@pelagicore.com> | 2017-05-11 11:11:05 +0200 |
---|---|---|
committer | Vadim Popov <vadim.popov@pelagicore.com> | 2017-06-13 14:00:44 +0000 |
commit | 45758b0387e4335b2067400efd9cc6a7f565517c (patch) | |
tree | 5efcfa3b9f4dc628334f6a503a8d8793abf19751 | |
parent | a202116603c4bcba6e5da3a90988e35ea17dd204 (diff) | |
download | qtivi-45758b0387e4335b2067400efd9cc6a7f565517c.tar.gz |
Auto-validation of the auto-generation
Add code for validating results of auto-generation
More to the auto-validation of the generation process,
I hope part of this code might be re-used in the make
integration as well
Task-number: QTAUTO-365
Change-Id: I051f593a6c3492cae4423b978b3f8ae46b708ceb
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
22 files changed, 845 insertions, 18 deletions
diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index e3c5f99..52717f2 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -43,6 +43,7 @@ import logging.config import yaml import json from path import Path +from qface.filters import jsonify from qface.generator import FileSystem, Generator from qface.helper.qtcpp import Filters @@ -242,6 +243,7 @@ def generate(tplconfig, moduleConfig, src, dst): generator.register_filter("enum_value", enum_value) generator.register_filter("tag_by_path", tag_by_path) generator.register_filter("conf_sim_tag", conf_sim_tag) + generator.register_filter('jsonify', jsonify) generator.register_filter('has_domains', has_domains) generator.register_filter('json_domain', json_domain) generator.register_filter('qml_type', qml_type) @@ -266,7 +268,9 @@ def generate(tplconfig, moduleConfig, src, dst): log.debug('generate backend code for interface %s', interface) interface.add_tag('config') ctx.update({'interface': interface}) - for rule in gen_config['generate_rules']['interface_rules']: + interface_rules = gen_config['generate_rules']['interface_rules'] + if interface_rules is None: interface_rules = [] + for rule in interface_rules: preserve = rule['preserve'] if 'preserve' in rule else False generator.write(rule['dest_file'], rule['template_file'], ctx, preserve) if 'struct_rules' in gen_config['generate_rules'] and isinstance(gen_config['generate_rules']['struct_rules'], list): @@ -284,7 +288,7 @@ def run(formats, moduleConfig, src, dst): switcher = { 'frontend': 'templates_frontend', 'backend_simulator': 'templates_backend_simulator', - 'test': 'templates_test', + 'generation_validator': 'templates_generation_validator' } tplConfig = switcher.get(f, 'unknown') if tplConfig == 'unknown': @@ -295,11 +299,12 @@ def run(formats, moduleConfig, src, dst): @click.command() @click.option('--reload/--no-reload', default=False) -@click.option('--format', '-f', multiple=True, type=click.Choice(['frontend', 'backend_simulator', 'test'])) +@click.option('--format', '-f', multiple=True, type=click.Choice(['frontend', 'backend_simulator', 'generation_validator'])) @click.option('--module', default=False) +@click.option('--validation_info', default=False) @click.argument('src', nargs=-1, type=click.Path(exists=True)) @click.argument('dst', nargs=1, type=click.Path(exists=True)) -def app(src, dst, format, reload, module): +def app(src, dst, format, reload, module, validation_info): """Takes several files or directories as src and generates the code in the given dst directory.""" if reload: @@ -307,7 +312,8 @@ def app(src, dst, format, reload, module): monitor(src, script) else: moduleConfig = { - "module": module + "module": module, + "validation_info": validation_info } run(format, moduleConfig, src, dst) diff --git a/src/tools/ivigenerator/templates_frontend/interface.h.tpl b/src/tools/ivigenerator/templates_frontend/interface.h.tpl index ac1a800..17be2e9 100644 --- a/src/tools/ivigenerator/templates_frontend/interface.h.tpl +++ b/src/tools/ivigenerator/templates_frontend/interface.h.tpl @@ -67,6 +67,9 @@ class {{exportsymbol}} {{class}} : public QIviAbstractFeature { Q_PROPERTY({{property|return_type}} {{property}} READ {{property}}{% if not property.readonly and not property.const %} WRITE set{{property|upperfirst}}{% endif %} NOTIFY {{property}}Changed) {% endfor %} Q_CLASSINFO("IviPropertyDomains", "{{ interface.properties|json_domain|replace("\"", "\\\"") }}") +{% if interface.module.tags.config.validation_info %} + Q_CLASSINFO("IviJson", "{{ module|jsonify|replace("\"", "\\\"")|replace("\n", " \\\n") }}") +{% endif %} public: {% if interface.tags.config.zoned %} explicit {{class}}(const QString &zone = QString(), QObject *parent = nullptr); diff --git a/src/tools/ivigenerator/templates_generation_validator.yaml b/src/tools/ivigenerator/templates_generation_validator.yaml new file mode 100644 index 0000000..1dbffcb --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator.yaml @@ -0,0 +1,19 @@ +generate_rules: + module_rules: + - dest_file: "main.cpp" + template_file: "main.cpp.tpl" + - dest_file: "main.qml" + template_file: "main.qml.tpl" + - dest_file: "qml.qrc" + template_file: "qml.qrc.tpl" + - dest_file: "{{module|lower|replace('.', '-')}}.pri" + template_file: "ui.pri.tpl" + - dest_file: "generationstatusitem.cpp" + template_file: "generationstatusitem.cpp.tpl" + - dest_file: "generationstatusitem.h" + template_file: "generationstatusitem.h.tpl" + - dest_file: "validationstatus.cpp" + template_file: "validationstatus.cpp.tpl" + - dest_file: "validationstatus.h" + template_file: "validationstatus.h.tpl" + interface_rules: diff --git a/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl new file mode 100644 index 0000000..b6c2e74 --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/generated_comment.cpp.tpl @@ -0,0 +1,47 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +/**************************************************************************** +** Generated from '{{module}}.qface' +** +** Created by: The QFace generator (QtAS {{qtASVersion}}) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + diff --git a/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.cpp.tpl b/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.cpp.tpl new file mode 100644 index 0000000..624f6db --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.cpp.tpl @@ -0,0 +1,59 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} +#include "generationstatusitem.h" +#include "validationstatus.h" +{% for iface in module.interfaces %} +#include "{{iface|lower}}.h" +{% endfor %} + + +GeneratorValidationStatus::GeneratorValidationStatus(QObject *parent) +: QObject(parent) +, m_errorMessage("All data has been successfully generated") +{ + QString error; +{% for iface in module.interfaces %} + {{iface}} {{iface|lowerfirst}}; + checkGeneration(error, {{iface|lowerfirst}}); +{% endfor %} + if (!error.isEmpty()) + m_errorMessage = error; +} diff --git a/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.h.tpl b/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.h.tpl new file mode 100644 index 0000000..160022c --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/generationstatusitem.h.tpl @@ -0,0 +1,56 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} +#include <QObject> + + +class GeneratorValidationStatus : public QObject { + Q_OBJECT + Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) +public: + explicit GeneratorValidationStatus(QObject *parent = nullptr); + ~GeneratorValidationStatus() = default; + + QString errorMessage() const { return m_errorMessage;} +Q_SIGNALS: + void errorMessageChanged(const QString &errorMessage); +private: + QString m_errorMessage; +}; diff --git a/src/tools/ivigenerator/templates_generation_validator/main.cpp.tpl b/src/tools/ivigenerator/templates_generation_validator/main.cpp.tpl new file mode 100644 index 0000000..9d12223 --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/main.cpp.tpl @@ -0,0 +1,73 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include "generationstatusitem.h" +#include "validationstatus.h" + +#include <{{module.module_name|lower}}module.h> +{% for iface in module.interfaces %} +#include "{{iface|lower}}.h" +{% endfor %} + + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QString error; +{% for iface in module.interfaces %} + {{iface|upperfirst}} {{iface|lowerfirst}}; + checkGeneration(error, {{iface|lowerfirst}}); +{% endfor %} + + + qmlRegisterType<GeneratorValidationStatus>("org.example.Example", 1, 0, "ValidationStatus"); + {{module.module_name}}Module::registerTypes(); +{#% for iface in module.interfaces %#} + {{module.module_name}}Module::registerQmlTypes(QLatin1String("{{module.module_name}}"), 1, 0); +{#% endfor %#} + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/src/tools/ivigenerator/templates_generation_validator/main.qml.tpl b/src/tools/ivigenerator/templates_generation_validator/main.qml.tpl new file mode 100644 index 0000000..460e08f --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/main.qml.tpl @@ -0,0 +1,87 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} + +import QtQuick 2.7 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.1 +import org.example.Example 1.0 +import {{module.module_name}} 1.0 + +Window { + visible: true + width: 640 + height: 480 + title: qsTr("QtIVI {{module.module_name}}") + + ValidationStatus { + id: validationStatus + } + + Column { + anchors.fill: parent + anchors.margins: 5 + + Text { + text: validationStatus.errorMessage + } + +{% for iface in module.interfaces %} + {{iface|qml_type}} { + id: {{iface|lowerfirst}} + } + + Text { + text: "{{iface}}" + } + + ToolSeparator { + orientation: Qt.Horizontal + } + +{% for property in iface.properties %} + Text { + text: "{{property|upperfirst}}: " + {{iface|lowerfirst}}.{{property}} + } +{% endfor %} + +{% endfor %} + } +} diff --git a/src/tools/ivigenerator/templates_generation_validator/qml.qrc.tpl b/src/tools/ivigenerator/templates_generation_validator/qml.qrc.tpl new file mode 100644 index 0000000..ea4cd6a --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/qml.qrc.tpl @@ -0,0 +1,44 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/src/tools/ivigenerator/templates_generation_validator/ui.pri.tpl b/src/tools/ivigenerator/templates_generation_validator/ui.pri.tpl new file mode 100644 index 0000000..d8a2a71 --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/ui.pri.tpl @@ -0,0 +1,15 @@ +############################################################################# +## This is an auto-generated file. +## Do not edit! All changes made to it will be lost. +############################################################################# + +SOURCES += \ + $$PWD/main.cpp \ + $$PWD/validationstatus.cpp \ + $$PWD/generationstatusitem.cpp + +HEADERS += \ + $$PWD/validationstatus.h \ + $$PWD/generationstatusitem.h + +RESOURCES += $$PWD/qml.qrc diff --git a/src/tools/ivigenerator/templates_generation_validator/validationstatus.cpp.tpl b/src/tools/ivigenerator/templates_generation_validator/validationstatus.cpp.tpl new file mode 100644 index 0000000..dcf908c --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/validationstatus.cpp.tpl @@ -0,0 +1,193 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} + +#include "validationstatus.h" + +#include <QJsonDocument> +#include <QJsonObject> +#include <QJsonArray> +#include <QDebug> +#include <QObject> +#include <QMetaProperty> + +QString idlToQtTypeName(const QString& idlTypeName) +{ + QString result = idlTypeName; + if (idlTypeName == QLatin1String("string")) + result = "QString"; + return result; +} + +bool checkProperty(const QMetaProperty& metaProp, const QJsonValue& jValProp, QString& errorMessage) +{ + bool result = true; + QJsonObject jObjProp = jValProp.toObject(); + if (metaProp.name() != jObjProp[QLatin1String("name")].toString()) + return false; + // Anyway it should be readable + if (!metaProp.isReadable()) { + errorMessage += QString("Property %1 is not readable\n").arg(metaProp.name()); + return false; + } + // Writable only if not readonly + if (metaProp.isWritable() && jObjProp[QLatin1String("readonly")].toBool()) { + errorMessage += QString("Property %1 is writable whereas it's defined as read-only\n").arg(metaProp.name()); + return false; + } + // Check the property type as well + QString metaTypeName = metaProp.typeName(); + QString propTypeName = idlToQtTypeName(jObjProp[QLatin1String("type")].toObject()[QLatin1String("name")].toString()); + if (metaTypeName != propTypeName) + return false; + return result; +} + +bool checkMethod(const QMetaMethod& metaOp, const QJsonValue& jValOp, QString& errorMessage) +{ + QJsonObject jObjOp = jValOp.toObject(); + if (metaOp.name() != jObjOp[QLatin1String("name")].toString()) + return false; + + // Check the method parameter types and return type as well + QString metaReturnType = metaOp.typeName(); + QString opReturnType = jObjOp[QLatin1String("type")].toObject()[QLatin1String("name")].toString(); + opReturnType = idlToQtTypeName(opReturnType); + if (metaReturnType != opReturnType) { + return false; + } + QJsonValue jValParams = jObjOp[QLatin1String("parameters")]; + Q_ASSERT(jValParams.isNull() || jValParams.isArray()); + QJsonArray jArrParams = jValParams.toArray(); + if (jArrParams.size() != metaOp.parameterCount()) { + errorMessage += QString("Amount of parameters in method %1 differs from its IDL definition (%2 vs %3)\n") + .arg(metaOp.name().data()) + .arg(metaOp.parameterCount()) + .arg(jArrParams.size()); + return false; + } + + for (int i = 0; i < metaOp.parameterCount(); ++i) { + QString metaParamType = jArrParams[i].toObject()[QLatin1String("type")].toObject()[QLatin1String("name")].toString(); + metaParamType = idlToQtTypeName(metaParamType); + QString genParamType = metaOp.parameterTypes().at(i); + if (genParamType != metaParamType) { + errorMessage += QString("Method %1: %2-th parameter type differs from IDL definition (%3 vs %4)\n") + .arg(metaOp.name().data()) + .arg(i) + .arg(genParamType) + .arg(metaParamType); + return false; + } + } + return true; +} + +bool checkGeneration(QString& errorMessage, QObject& obj) +{ + bool result = true; + auto* metaObj = obj.metaObject(); + int classInfoCount = metaObj->classInfoCount(); + QMetaClassInfo metaClassInfo; + const QString META_INFO_NAME = QLatin1String("IviJson"); + for (int index = 0; index < classInfoCount; ++index) { + metaClassInfo = metaObj->classInfo(index); + if (metaClassInfo.name() == META_INFO_NAME) + break; + } + if (metaClassInfo.name() != META_INFO_NAME) { + return false; + } + QJsonObject metaDoc(QJsonDocument::fromJson(metaClassInfo.value()).object()); + auto jVal = metaDoc[QLatin1String("interfaces")]; + if (jVal.isNull() || !jVal.isArray()) { + errorMessage += QString("Interfaces list is empty in the class meta info"); + return false; + } + + + QJsonArray jArrInterfaces = jVal.toArray(); + QJsonObject jInterface; + for (auto jValInterface : jArrInterfaces) { + Q_ASSERT(jValInterface.isObject()); + if (jValInterface.toObject()[QLatin1String("name")] == QLatin1String(metaObj->className())) { + jInterface = jValInterface.toObject(); + break; + } + } + if (jInterface.empty()) { + errorMessage += QString("Interface %1 is not implemented!\n").arg(metaObj->className()); + return false; + } + + // Check the properties + QJsonValue jValProps = jInterface[QLatin1String("properties")]; + auto jArrProps = jValProps.toArray(); + for (auto jValProp : jArrProps) { + auto propName = jValProp.toObject()[QLatin1String("name")].toString(); + int propIdx = metaObj->indexOfProperty(propName.toLatin1().data()); + if (propIdx == -1) { + errorMessage += QString("Property %1 has been not generated by the generator!\n").arg(propName); + result = false; + } else { + result &= checkProperty(metaObj->property(propIdx), jValProp, errorMessage); + } + } + + // Check the methods + QJsonValue jValOps = jInterface[QLatin1String("operations")]; + auto jArrOps = jValOps.toArray(); + for (auto jValOp : jArrOps) { + bool opFound = false; + QString opName = jValOp.toObject()[QLatin1String("name")].toString(); + for (int i = 0; i < metaObj->methodCount(); ++i) { + if (metaObj->method(i).name() == opName) { + opFound = true; + result &= checkMethod(metaObj->method(i), jValOp, errorMessage); + } + } + if (!opFound) { + errorMessage += QString("Method %1 has been not generated by the generator!").arg(opName); + result = false; + } + } + + return result; +} diff --git a/src/tools/ivigenerator/templates_generation_validator/validationstatus.h.tpl b/src/tools/ivigenerator/templates_generation_validator/validationstatus.h.tpl new file mode 100644 index 0000000..85579f3 --- /dev/null +++ b/src/tools/ivigenerator/templates_generation_validator/validationstatus.h.tpl @@ -0,0 +1,51 @@ +{# +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} + +#ifndef VALIDATIONSTATUS_H_ +#define VALIDATIONSTATUS_H_ + +class QMetaProperty; +class QObject; +class QString; + +bool checkGeneration(QString& errorMessage, QObject& obj); + +#endif // VALIDATIONSTATUS_H_ diff --git a/src/tools/ivigenerator/templates_ui/main.qml.tpl b/src/tools/ivigenerator/templates_ui/main.qml.tpl deleted file mode 100644 index e69de29..0000000 --- a/src/tools/ivigenerator/templates_ui/main.qml.tpl +++ /dev/null diff --git a/tests/manual/core/ivigenerator/autotest.sh b/tests/manual/core/ivigenerator/autotest.sh index 57ca6d9..18d7c63 100755 --- a/tests/manual/core/ivigenerator/autotest.sh +++ b/tests/manual/core/ivigenerator/autotest.sh @@ -65,16 +65,18 @@ fi WORKDIR=$(dirname $0) GENERATOR=${WORKDIR}/../../../../src/tools/ivigenerator/generate.py +TEST_FILES=(org.example.echo) # org.example.echo.noprivate) test -x ${GENERATOR} || die "${GENERATOR} does not exists or can't be executed" 1 -for idlfile in org.example.echo org.example.echo.noprivate +for idlfile in "${TEST_FILES[@]}" do echo "Testing '$idlfile' ================" idldir=$(echo $idlfile | tr . -) out_dir=${WORKDIR}/projects/${idldir} /bin/rm -rf ${out_dir}/frontend/*.{h,cpp,pri} /bin/rm -rf ${out_dir}/backend_simulator/*.{h,cpp,pri} - ${GENERATOR} --format=frontend ${WORKDIR}/${idlfile}.qface ${out_dir}/frontend || die "Generator failed" 1 + ${GENERATOR} --format=frontend --validation_info=True ${WORKDIR}/${idlfile}.qface ${out_dir}/frontend || die "Generator failed" 1 ${GENERATOR} --format=backend_simulator ${WORKDIR}/${idlfile}.qface ${out_dir}/backend_simulator || die "Generator for backend failed" 1 + ${GENERATOR} --format=generation_validator ${WORKDIR}/${idlfile}.qface ${out_dir}/ui || die "Generator for validator failed" 1 test -d build/${idldir} && /bin/rm -rf build/${idldir} test -d build/${idldir} && die "Cannot remove existing build folder" 1 mkdir -p build/${idldir} || die "Cannot create build folder" 1 @@ -82,11 +84,24 @@ do project_dir=../../projects/${idldir} qmake ${project_dir}/${idldir}-project.pro || die "Failed to run qmake" 1 make || die "Failed to build" 1 +if [[ "$OSTYPE" == "linux-gnu" ]]; then + OLD_LD_PATH=$LD_LIBRARY_PATH + export LD_LIBRARY_PATH=./out:$LD_LIBRARY_PATH + #./out/ui || die "Test failed" + export LD_LIBRARY_PATH=${OLD_LD_PATH} + +elif [[ "$OSTYPE" == "darwin"* ]]; then + OLD_DYLD_PATH=$DYLD_LIBRARY_PATH + export DYLD_LIBRARY_PATH=./out:$DYLD_LIBRARY_PATH + #./out/ui.app/Contents/MacOS/ui || die "Test failed" + export DYLD_LIBRARY_PATH=${OLD_DYLD_PATH} +fi + popd echo "Done '$idlfile' ================" done -for idlfile in org.example.echo org.example.echo.noprivate +for idlfile in "${TEST_FILES[@]}" do echo "Testing '$idlfile' backend_simulator ================" idldir=$(echo $idlfile | tr . -) diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro index 80a687b..98971f3 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/backend_simulator/backend_simulator.pro @@ -1,13 +1,15 @@ TEMPLATE=lib TARGET = echo_noprivate_simulator -LIBS += -L../frontend -lecho_noprivate_frontend +LIBS += -L../out -lecho_noprivate_frontend CONFIG += warn_off -INCLUDEPATH += ../frontend/org-example-echo +INCLUDEPATH += ../frontend PLUGIN_TYPE = qtivi PLUGIN_EXTENDS = qtivi PLUGIN_CLASS_NAME = QIviServiceInterface QT += core ivicore -include(org-example-echo/org-example-echo.pri) +include(org-example-echo-noprivate.pri) +DESTDIR = ../out/qtivi +INSTALLS += target diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro index ec87c1c..61516e5 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro @@ -1,7 +1,7 @@ TEMPLATE=lib TARGET=echo_noprivate_frontend - QT += ivicore ivicore-private qml quick -include(org-example-echo/org-example-echo.pri) - +include(org-example-echo-noprivate.pri) +DESTDIR = ../out +INSTALLS += target diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate-project.pro b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate-project.pro index 2a58441..b7e0ac7 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate-project.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate-project.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = frontend \ backend_simulator \ + ui \ CONFIG += ordered diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo/backend_simulator/backend_simulator.pro b/tests/manual/core/ivigenerator/projects/org-example-echo/backend_simulator/backend_simulator.pro index a5b053f..35f0fb6 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo/backend_simulator/backend_simulator.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo/backend_simulator/backend_simulator.pro @@ -1,8 +1,9 @@ TEMPLATE=lib TARGET = echo_simulator -LIBS += -L../frontend -lecho_frontend +QT = core core-private ivicore ivicore-private +LIBS += -L../out -lecho_frontend -CONFIG += warn_off +CONFIG += warn_off c++11 INCLUDEPATH += ../frontend PLUGIN_TYPE = qtivi PLUGIN_EXTENDS = qtivi @@ -11,3 +12,5 @@ PLUGIN_CLASS_NAME = QIviServiceInterface QT += core ivicore include(org-example-echo.pri) +DESTDIR = ../out/qtivi +INSTALLS += target diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro b/tests/manual/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro index c0b4be8..13385e6 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro @@ -1,7 +1,7 @@ TEMPLATE=lib TARGET=echo_frontend - QT += ivicore ivicore-private qml quick include(org-example-echo.pri) - +DESTDIR = ../out +INSTALLS += target diff --git a/tests/manual/core/ivigenerator/projects/org-example-echo/org-example-echo-project.pro b/tests/manual/core/ivigenerator/projects/org-example-echo/org-example-echo-project.pro index 2a58441..b7e0ac7 100644 --- a/tests/manual/core/ivigenerator/projects/org-example-echo/org-example-echo-project.pro +++ b/tests/manual/core/ivigenerator/projects/org-example-echo/org-example-echo-project.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = frontend \ backend_simulator \ + ui \ CONFIG += ordered diff --git a/tests/manual/qface/projects/org-example-echo-noprivate/ui/ui.pro b/tests/manual/qface/projects/org-example-echo-noprivate/ui/ui.pro new file mode 100644 index 0000000..1145a3e --- /dev/null +++ b/tests/manual/qface/projects/org-example-echo-noprivate/ui/ui.pro @@ -0,0 +1,76 @@ +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:BSD-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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. +# +# BSD License Usage +# Alternatively, you may use this file under the terms of the BSD license +# as follows: +# +# "Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of The Qt Company Ltd nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: BSD-3-Clause + +TEMPLATE = app + +QT += qml quick +CONFIG += c++11 + +LIBS += -L../out -lecho_noprivate_frontend +INCLUDEPATH += ../frontend + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +DESTDIR = ../out +INSTALLS += target +include(org-example-echo-noprivate.pri) diff --git a/tests/manual/qface/projects/org-example-echo/ui/ui.pro b/tests/manual/qface/projects/org-example-echo/ui/ui.pro new file mode 100644 index 0000000..4364b7b --- /dev/null +++ b/tests/manual/qface/projects/org-example-echo/ui/ui.pro @@ -0,0 +1,76 @@ +# Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:BSD-QTAS$ +# Commercial License Usage +# Licensees holding valid commercial Qt Automotive Suite 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. +# +# BSD License Usage +# Alternatively, you may use this file under the terms of the BSD license +# as follows: +# +# "Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of The Qt Company Ltd nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: BSD-3-Clause + +TEMPLATE = app + +QT += qml quick core +CONFIG += c++11 + +LIBS += -L../out -lecho_frontend +INCLUDEPATH += ../frontend + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +DESTDIR = ../out +INSTALLS += target +include(org-example-echo.pri) |