From 77b94a1e6f3cd2b1afd6cbc7809391fe130fd0b6 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 10 Dec 2024 12:04:00 +0100 Subject: [PATCH] macdeployqt: adjust to [[nodiscard]] QFile::open() The QFile::open() method becomes [[nodiscard]] in Qt 6.10. However, macdeployqt was not adapted to this change. As a result, an attempt to bump the Qt version fails in the CI. This patch fixes the tool. Amends 7466831509fe163f3fd1e3a6bbf38f6f5a32ef00. Change-Id: I0dc0bc4c892f42e58d80da2407ddd83781ad8246 Reviewed-by: Volker Hilsheimer --- .../macdeployqt/macdeployqt/CMakeLists.txt | 1 + src/tools/macdeployqt/shared/shared.cpp | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/tools/macdeployqt/macdeployqt/CMakeLists.txt b/src/tools/macdeployqt/macdeployqt/CMakeLists.txt index 6cd66adaa7e..79ad0bc0a75 100644 --- a/src/tools/macdeployqt/macdeployqt/CMakeLists.txt +++ b/src/tools/macdeployqt/macdeployqt/CMakeLists.txt @@ -16,6 +16,7 @@ qt_internal_add_tool(${target_name} main.cpp DEFINES QT_NO_FOREACH + QT_USE_NODISCARD_FILE_OPEN LIBRARIES ${FWCoreFoundation} ) diff --git a/src/tools/macdeployqt/shared/shared.cpp b/src/tools/macdeployqt/shared/shared.cpp index 2e433b638fa..19137d15944 100644 --- a/src/tools/macdeployqt/shared/shared.cpp +++ b/src/tools/macdeployqt/shared/shared.cpp @@ -135,12 +135,18 @@ void patch_debugInInfoPlist(const QString &infoPlistPath) // Older versions of qmake may have the "_debug" binary as // the value for CFBundleExecutable. Remove it. QFile infoPlist(infoPlistPath); - infoPlist.open(QIODevice::ReadOnly); - QByteArray contents = infoPlist.readAll(); - infoPlist.close(); - infoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate); - contents.replace("_debug", ""); // surely there are no legit uses of "_debug" in an Info.plist - infoPlist.write(contents); + if (infoPlist.open(QIODevice::ReadOnly)) { + QByteArray contents = infoPlist.readAll(); + infoPlist.close(); + if (infoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + contents.replace("_debug", ""); // surely there are no legit uses of "_debug" in an Info.plist + infoPlist.write(contents); + } else { + LogError() << "failed to write Info.plist file" << infoPlistPath; + } + } else { + LogError() << "failed to read Info.plist file" << infoPlistPath; + } } OtoolInfo findDependencyInfo(const QString &binaryPath) @@ -1233,8 +1239,7 @@ void createQtConf(const QString &appBundlePath) return; } - qtconf.open(QIODevice::WriteOnly); - if (qtconf.write(contents) != -1) { + if (qtconf.open(QIODevice::WriteOnly) && qtconf.write(contents) != -1) { LogNormal() << "Created configuration file:" << fileName; LogNormal() << "This file sets the plugin search path to" << appBundlePath + "/Contents/PlugIns"; }