From 75fd5c16d1cf0bb6756d4dedd073fed2ef6ee325 Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Tue, 17 Jun 2025 18:42:57 +0200 Subject: [PATCH] use big resource variant, else we OOM on 32 bit machines this has issues with LTO, we have a unit test that tells if stuff got lost in the DLL fix the resource loading for static library building, uncovered by the new unit test BUG: 487452 BUG: 499674 --- .gitignore | 1 + autotests/CMakeLists.txt | 6 +++- autotests/resourcetest.cpp | 68 ++++++++++++++++++++++++++++++++++++++ src/lib/CMakeLists.txt | 5 +-- src/lib/breezeicons.cpp | 9 +++++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 autotests/resourcetest.cpp diff --git a/.gitignore b/.gitignore index d9e5e3d0d..470c5b78e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ dist node_modules /.vscode/ +/.kateproject.* CMakeLists.txt.user* .cmake/ /.clang-format diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 59b5c4cfd..d52209710 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,13 +1,17 @@ include(ECMAddTests) if(BUILD_TESTING) - find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Test) + find_package(Qt6 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Gui Test) configure_file(testdata.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/testdata.h) ecm_add_test(scalabletest.cpp TEST_NAME "scalable" LINK_LIBRARIES Qt6::Test ) + ecm_add_test(resourcetest.cpp + TEST_NAME "resource" + LINK_LIBRARIES KF6BreezeIcons Qt6::Gui Qt6::Test + ) if(WITH_ICON_GENERATION) add_test(NAME "test24x24icons" COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/autotests/test24x24icons.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} diff --git a/autotests/resourcetest.cpp b/autotests/resourcetest.cpp new file mode 100644 index 000000000..95881c5a1 --- /dev/null +++ b/autotests/resourcetest.cpp @@ -0,0 +1,68 @@ +/* + This file is part of the KDE libraries + + SPDX-FileCopyrightText: 2025 Christoph Cullmann + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#include +#include +#include + +#include "breezeicons.h" +#include "testhelpers.h" + +class ResourceTest : public QObject +{ + Q_OBJECT + + void compareFileResourceWithFilesystem(const QString &name) + { + // resource location + const QString qrcLocation(QStringLiteral(":/icons/breeze/%1").arg(name)); + + // file system location + const QString fsLocation(PROJECT_SOURCE_DIR + QStringLiteral("/icons/%1").arg(name)); + + // read full data of both, must work + QFile qrcFile(qrcLocation); + QVERIFY(qrcFile.open(QFile::ReadOnly)); + QFile fsFile(fsLocation); + QVERIFY(fsFile.open(QFile::ReadOnly)); + const auto qrcData = qrcFile.readAll(); + QVERIFY(!qrcData.isEmpty()); + const auto fsData = fsFile.readAll(); + QVERIFY(!fsData.isEmpty()); + + // fully equal? + QCOMPARE(qrcData, fsData); + } + +private Q_SLOTS: + // check that not stuff got lost in the DLL + // did happen for compiling with LTO or buggy preprocessing the DLL + void test_resourceContainsTheme() + { + // ensure the DLL is linked + BreezeIcons::initIcons(); + + // we want to have the proper theme file + compareFileResourceWithFilesystem(QStringLiteral("index.theme")); + + // check some icons we know shall be there + // check no stuff that might not be generated in some config or that is a symlink + compareFileResourceWithFilesystem(QStringLiteral("actions/16/go-previous.svg")); + compareFileResourceWithFilesystem(QStringLiteral("actions/16/table.svg")); + compareFileResourceWithFilesystem(QStringLiteral("actions/22/edit-paste.svg")); + compareFileResourceWithFilesystem(QStringLiteral("actions/22/tab-new.svg")); + compareFileResourceWithFilesystem(QStringLiteral("actions/32/document-edit.svg")); + compareFileResourceWithFilesystem(QStringLiteral("actions/32/zoom.svg")); + compareFileResourceWithFilesystem(QStringLiteral("mimetypes/64/application-json.svg")); + compareFileResourceWithFilesystem(QStringLiteral("places/64/folder-favorites.svg")); + } +}; + +QTEST_GUILESS_MAIN(ResourceTest) + +#include "resourcetest.moc" diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e8c9e0ac9..600c8a8f4 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -24,8 +24,9 @@ if(BINARY_ICONS_RESOURCE) install(FILES ${RESOURCE_FILE_BINARY} DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/breeze) endif() -# use normal resource adding, big resource variant has issue with LTO -qt_add_resources(kbreezeicons_resource_SRCS +# use big resource variant, else we OOM on 32 bit machines +# this has issues with LTO, we have a unit test that tells if stuff got lost in the DLL +qt_add_big_resources(kbreezeicons_resource_SRCS ${RESOURCE_FILE} OPTIONS --root /icons/breeze ) diff --git a/src/lib/breezeicons.cpp b/src/lib/breezeicons.cpp index 36d1ca873..7657e789d 100644 --- a/src/lib/breezeicons.cpp +++ b/src/lib/breezeicons.cpp @@ -10,11 +10,20 @@ #include +static void resourceInit() +{ + // needs to be called outside of namespace + Q_INIT_RESOURCE(breeze_icons); +} + namespace BreezeIcons { void initIcons() { + // ensure the resource is there and loaded for static libs + resourceInit(); + // ensure we fallback to breeze, if no user fallback is set const QString fallbackTheme = QIcon::fallbackThemeName(); if (fallbackTheme.isEmpty() || fallbackTheme == QLatin1String("hicolor")) { -- GitLab