From b83487e129aa4629929e879f0c7bd1d4c067ed0e Mon Sep 17 00:00:00 2001
From: Samuli Piippo <samuli.piippo@qt.io>
Date: Thu, 30 May 2019 09:24:56 +0300
Subject: [PATCH] Add QtSafeRenderer 1.1

Add recipe for the QtSafeRenderer and include it in the automotive
image and toolchain. The sources are in a private git repository,
so it's included in the build only if we know that we have access
to those (internal-build) or user has explicitly enabled it in the
local.conf (DISTRO_FEATURES_BACKFILL). The recipe also knows how to
use the sources from a Qt online SDK intallation if the variable
(QT_SDK_PATH) is setup correctly.

Neptune3 is enabled to use QSR if that is available.

Task-number: AUTOSUITE-1009
Change-Id: I2efc68a598f1e83324de40f4f0cccce9615045f7
Reviewed-by: Nikolay Zamotaev <nzamotaev@luxoft.com>
Reviewed-by: Jani Launonen <jani.launonen@qt.io>
---
 meta-boot2qt-distro/conf/local.conf.sample    |  6 ++
 ...roup-b2qt-automotive-qt5-toolchain-host.bb |  2 +
 .../packagegroup-b2qt-automotive-addons.bb    |  2 +
 ...up-b2qt-automotive-qt5-toolchain-target.bb |  3 +
 .../qt5/nativesdk-qtbase_git.bbappend         |  2 +-
 .../recipes-qt/qt5/qtbase-native_git.bbappend |  2 +
 meta-boot2qt/classes/internal-build.bbclass   |  3 +
 .../recipes-qt/automotive/neptune3-ui_git.bb  |  5 ++
 .../0001-Fix-yocto-build-issues.patch         | 72 +++++++++++++++++++
 .../automotive/qtsaferenderer_git.bb          | 59 +++++++++++++++
 10 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 meta-boot2qt/recipes-qt/automotive/qtsaferenderer/0001-Fix-yocto-build-issues.patch
 create mode 100644 meta-boot2qt/recipes-qt/automotive/qtsaferenderer_git.bb

diff --git a/meta-boot2qt-distro/conf/local.conf.sample b/meta-boot2qt-distro/conf/local.conf.sample
index 24c572e4..c6db921f 100644
--- a/meta-boot2qt-distro/conf/local.conf.sample
+++ b/meta-boot2qt-distro/conf/local.conf.sample
@@ -284,6 +284,12 @@ INHERIT += "internal-build"
 ACCEPT_FSL_EULA = "1"
 LICENSE_FLAGS_WHITELIST = "commercial"
 
+# Path to the Qt online SDK installation, used for sources that are available only from
+# the online installer.
 QT_SDK_PATH = ""
 
+# If you have access to QtSafeRenderer sources, either from git or QtSDK,
+# you can enable it by uncommenting following line
+#DISTRO_FEATURES_BACKFILL_append = " qtsaferenderer"
+
 include conf/distro/include/${MACHINE}.pre.inc
diff --git a/meta-boot2qt-distro/recipes-qt/packagegroups/nativesdk-packagegroup-b2qt-automotive-qt5-toolchain-host.bb b/meta-boot2qt-distro/recipes-qt/packagegroups/nativesdk-packagegroup-b2qt-automotive-qt5-toolchain-host.bb
index 8c4adaae..383ad07e 100644
--- a/meta-boot2qt-distro/recipes-qt/packagegroups/nativesdk-packagegroup-b2qt-automotive-qt5-toolchain-host.bb
+++ b/meta-boot2qt-distro/recipes-qt/packagegroups/nativesdk-packagegroup-b2qt-automotive-qt5-toolchain-host.bb
@@ -38,3 +38,5 @@ RDEPENDS_${PN} += "\
     nativesdk-qtapplicationmanager-tools \
     nativesdk-qtivi-tools \
     "
+
+RDEPENDS_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'qtsaferenderer', 'nativesdk-qtsaferenderer-tools', '', d)}"
diff --git a/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-addons.bb b/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-addons.bb
index 078763ae..884a5acf 100644
--- a/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-addons.bb
+++ b/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-addons.bb
@@ -44,3 +44,5 @@ RDEPENDS_${PN} += " \
     qmllive \
     qdb \
     "
+
+RDEPENDS_${PN} += "${@bb.utils.filter('DISTRO_FEATURES', 'qtsaferenderer', d)}"
diff --git a/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-qt5-toolchain-target.bb b/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-qt5-toolchain-target.bb
index 3b64622f..efdb6e63 100644
--- a/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-qt5-toolchain-target.bb
+++ b/meta-boot2qt-distro/recipes-qt/packagegroups/packagegroup-b2qt-automotive-qt5-toolchain-target.bb
@@ -41,3 +41,6 @@ RDEPENDS_${PN} += " \
     qtapplicationmanager-dev \
     qtapplicationmanager-staticdev \
     "
+
+RDEPENDS_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'qtsaferenderer', \
+                                        'qtsaferenderer-dev qtsaferenderer-staticdev', '', d)}"
diff --git a/meta-boot2qt-distro/recipes-qt/qt5/nativesdk-qtbase_git.bbappend b/meta-boot2qt-distro/recipes-qt/qt5/nativesdk-qtbase_git.bbappend
index 1296c18b..8372fbc8 100644
--- a/meta-boot2qt-distro/recipes-qt/qt5/nativesdk-qtbase_git.bbappend
+++ b/meta-boot2qt-distro/recipes-qt/qt5/nativesdk-qtbase_git.bbappend
@@ -33,7 +33,7 @@ SRC_URI += "\
     file://0001-Add-win32-g-oe-mkspec-that-uses-the-OE_-environment.patch \
     "
 
-PACKAGECONFIG += "openssl"
+PACKAGECONFIG += "openssl gui imageformats"
 PACKAGECONFIG_remove_mingw32 += "openssl"
 
 PACKAGECONFIG[openssl] = "-openssl,-no-openssl,openssl,libssl"
diff --git a/meta-boot2qt-distro/recipes-qt/qt5/qtbase-native_git.bbappend b/meta-boot2qt-distro/recipes-qt/qt5/qtbase-native_git.bbappend
index 821c6d3e..eecfa5a6 100644
--- a/meta-boot2qt-distro/recipes-qt/qt5/qtbase-native_git.bbappend
+++ b/meta-boot2qt-distro/recipes-qt/qt5/qtbase-native_git.bbappend
@@ -29,6 +29,8 @@
 
 FILESEXTRAPATHS_prepend := "${THISDIR}/qtbase:"
 
+PACKAGECONFIG += "gui imageformats"
+
 SRC_URI += "\
     file://0001-Add-win32-g-oe-mkspec-that-uses-the-OE_-environment.patch \
     "
diff --git a/meta-boot2qt/classes/internal-build.bbclass b/meta-boot2qt/classes/internal-build.bbclass
index d842dcb0..b56ae8be 100644
--- a/meta-boot2qt/classes/internal-build.bbclass
+++ b/meta-boot2qt/classes/internal-build.bbclass
@@ -34,6 +34,9 @@ python enable_internal_build () {
     except:
         return
 
+    # enable qtsaferenderer for internal builds
+    e.data.appendVar('DISTRO_FEATURES_BACKFILL', ' qtsaferenderer')
+
     e.data.setVar('QT_INTERNAL_BUILD', "1")
     e.data.prependVar('SSTATE_MIRRORS', "file://.* http://yocto-cache.intra.qt.io/sstate-caches/${DISTRO_CODENAME}/PATH")
     e.data.prependVar('PREMIRRORS', "\
diff --git a/meta-boot2qt/recipes-qt/automotive/neptune3-ui_git.bb b/meta-boot2qt/recipes-qt/automotive/neptune3-ui_git.bb
index a37c6e60..b97d0d55 100644
--- a/meta-boot2qt/recipes-qt/automotive/neptune3-ui_git.bb
+++ b/meta-boot2qt/recipes-qt/automotive/neptune3-ui_git.bb
@@ -69,6 +69,11 @@ RDEPENDS_${PN} = "\
     ${@bb.utils.contains('DISTRO_FEATURES', 'webengine', 'qtwebengine', '', d)} \
     "
 
+PACKAGECONFIG ?= "${@bb.utils.filter('DISTRO_FEATURES', 'qtsaferenderer', d)}"
+PACKAGECONFIG[qtsaferenderer] = "CONFIG+=use_qsr,,qtsaferenderer qtsaferenderer-native"
+
+EXTRA_QMAKEVARS_PRE += "${PACKAGECONFIG_CONFARGS}"
+
 do_install_append() {
     install -m 0755 -d ${D}${systemd_unitdir}/system
     install -m 0644 ${WORKDIR}/neptune.service ${D}${systemd_unitdir}/system/
diff --git a/meta-boot2qt/recipes-qt/automotive/qtsaferenderer/0001-Fix-yocto-build-issues.patch b/meta-boot2qt/recipes-qt/automotive/qtsaferenderer/0001-Fix-yocto-build-issues.patch
new file mode 100644
index 00000000..0f48a059
--- /dev/null
+++ b/meta-boot2qt/recipes-qt/automotive/qtsaferenderer/0001-Fix-yocto-build-issues.patch
@@ -0,0 +1,72 @@
+From d4186c1e1dec284864ba41b0d7878531320e84ea Mon Sep 17 00:00:00 2001
+From: Samuli Piippo <samuli.piippo@qt.io>
+Date: Thu, 30 May 2019 09:54:57 +0300
+Subject: [PATCH] Fix yocto build issues
+
+- add tools-only option for building qtsafelayouttool for native and
+  nativesdk targets
+- remove uncessary RPATH
+- remove host_build from the qtsafelayouttool, it depends on QtGui
+  so it cannot be bootsrapped.
+- use QT_PLUGIN_PATH for qtsafelayouttool calls. Builds are using qt.conf
+  (from OE_QMAKE_QTCONF_PATH env in yocto builds) and from QT_HOST_BINS
+  directory in the nativesdk, which has target paths for QT_INSTALL_PLUGINS
+  that causes qtsafelayouttool to fail to find any plugins.
+
+Change-Id: Ie042b7ef45c7a5e03b36008a2e2cbce1a9193139
+---
+ .qmake.conf                                 | 1 -
+ src/src.pro                                 | 2 +-
+ tools/featurespec/qtsaferenderer.prf        | 3 +++
+ tools/qtsafelayouttool/qtsafelayouttool.pro | 1 -
+ tools/tools.pro                             | 2 +-
+ 5 files changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/.qmake.conf b/.qmake.conf
+index 72e3912..e5d116f 100644
+--- a/.qmake.conf
++++ b/.qmake.conf
+@@ -2,4 +2,3 @@ load(qt_build_config)
+ CONFIG += warning_clean warnings_are_errors warn_on
+ 
+ MODULE_VERSION = 1.1.0
+-QMAKE_RPATHDIR += $$[QT_INSTALL_LIBS]
+diff --git a/src/src.pro b/src/src.pro
+index d5105c8..ee4912d 100644
+--- a/src/src.pro
++++ b/src/src.pro
+@@ -1,2 +1,2 @@
+ TEMPLATE = subdirs
+-SUBDIRS = qtsaferendererplugin messagesenderplugin saferenderer saferenderer/doc saferenderer/doc-unittests
++!tools-only:SUBDIRS = qtsaferendererplugin messagesenderplugin saferenderer saferenderer/doc saferenderer/doc-unittests
+diff --git a/tools/featurespec/qtsaferenderer.prf b/tools/featurespec/qtsaferenderer.prf
+index f133ed3..3a5c25e 100644
+--- a/tools/featurespec/qtsaferenderer.prf
++++ b/tools/featurespec/qtsaferenderer.prf
+@@ -1,3 +1,6 @@
++pluginpath.name = QT_PLUGIN_PATH
++pluginpath.value = $$[QT_HOST_LIBS/get]/plugins
++QT_TOOL_ENV += pluginpath
+ qtPrepareTool(QMAKE_SAFELAYOUT, qtsafelayouttool, _DEP)
+ qtPrepareTool(QMAKE_RCC, rcc, _DEP)
+ 
+diff --git a/tools/qtsafelayouttool/qtsafelayouttool.pro b/tools/qtsafelayouttool/qtsafelayouttool.pro
+index f3a62ea..d81e8c1 100644
+--- a/tools/qtsafelayouttool/qtsafelayouttool.pro
++++ b/tools/qtsafelayouttool/qtsafelayouttool.pro
+@@ -1,4 +1,3 @@
+-option(host_build)
+ QT += qml quick quick-private qml qml-private widgets
+ 
+ CONFIG += c++11
+diff --git a/tools/tools.pro b/tools/tools.pro
+index 7b06ef9..333f26b 100644
+--- a/tools/tools.pro
++++ b/tools/tools.pro
+@@ -1,5 +1,5 @@
+ TEMPLATE = subdirs
+ SUBDIRS = featurespec
+-!cross_compile: SUBDIRS += qtsafelayouttool
++tools-only:SUBDIRS += qtsafelayouttool
+ 
+ 
diff --git a/meta-boot2qt/recipes-qt/automotive/qtsaferenderer_git.bb b/meta-boot2qt/recipes-qt/automotive/qtsaferenderer_git.bb
new file mode 100644
index 00000000..5576860c
--- /dev/null
+++ b/meta-boot2qt/recipes-qt/automotive/qtsaferenderer_git.bb
@@ -0,0 +1,59 @@
+############################################################################
+##
+## Copyright (C) 2019 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the Boot to Qt meta layer.
+##
+## $QT_BEGIN_LICENSE:GPL$
+## 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 or (at your option) 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.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-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+############################################################################
+
+DESCRIPTION = "Qt Safe Renderer"
+
+LICENSE = "GPL-3.0 | The-Qt-Company-Commercial"
+LIC_FILES_CHKSUM = "file://${QT_LICENSE};md5=948f8877345cd66106f11031977a4625"
+
+inherit qt5-module sdk-sources distro_features_check
+
+# the sources are not generally available, support must be explicitly enabled
+REQUIRED_DISTRO_FEATURES = "qtsaferenderer"
+
+require recipes-qt/qt5/qt5-git.inc
+
+PACKAGECONFIG ?= ""
+PACKAGECONFIG_class-native = "tools-only"
+PACKAGECONFIG_class-nativesdk = "tools-only"
+PACKAGECONFIG[tools-only] = "CONFIG+=tools-only,,"
+
+EXTRA_QMAKEVARS_PRE += "${PACKAGECONFIG_CONFARGS}"
+
+PV = "1.1"
+BRANCH = "1.1"
+SRC_URI = "\
+    git://codereview.qt-project.org/tqtc-boot2qt/qtsaferenderer;branch=${BRANCH};protocol=ssh;sdk-uri=Src/QtSafeRenderer-1.1.0 \
+    file://0001-Fix-yocto-build-issues.patch \
+    "
+SRCREV = "fef1fe5cd46c51d74127ae77b67f0f296fd828c9"
+
+DEPENDS = "qtbase qtdeclarative"
+
+BBCLASSEXTEND = "nativesdk native"
-- 
GitLab