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 <volker.hilsheimer@qt.io>
This commit is contained in:
Ivan Solovev 2024-12-10 12:04:00 +01:00
parent 250117086f
commit 77b94a1e6f
2 changed files with 14 additions and 8 deletions

View File

@ -16,6 +16,7 @@ qt_internal_add_tool(${target_name}
main.cpp main.cpp
DEFINES DEFINES
QT_NO_FOREACH QT_NO_FOREACH
QT_USE_NODISCARD_FILE_OPEN
LIBRARIES LIBRARIES
${FWCoreFoundation} ${FWCoreFoundation}
) )

View File

@ -135,12 +135,18 @@ void patch_debugInInfoPlist(const QString &infoPlistPath)
// Older versions of qmake may have the "_debug" binary as // Older versions of qmake may have the "_debug" binary as
// the value for CFBundleExecutable. Remove it. // the value for CFBundleExecutable. Remove it.
QFile infoPlist(infoPlistPath); QFile infoPlist(infoPlistPath);
infoPlist.open(QIODevice::ReadOnly); if (infoPlist.open(QIODevice::ReadOnly)) {
QByteArray contents = infoPlist.readAll(); QByteArray contents = infoPlist.readAll();
infoPlist.close(); infoPlist.close();
infoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate); if (infoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
contents.replace("_debug", ""); // surely there are no legit uses of "_debug" in an Info.plist contents.replace("_debug", ""); // surely there are no legit uses of "_debug" in an Info.plist
infoPlist.write(contents); 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) OtoolInfo findDependencyInfo(const QString &binaryPath)
@ -1233,8 +1239,7 @@ void createQtConf(const QString &appBundlePath)
return; return;
} }
qtconf.open(QIODevice::WriteOnly); if (qtconf.open(QIODevice::WriteOnly) && qtconf.write(contents) != -1) {
if (qtconf.write(contents) != -1) {
LogNormal() << "Created configuration file:" << fileName; LogNormal() << "Created configuration file:" << fileName;
LogNormal() << "This file sets the plugin search path to" << appBundlePath + "/Contents/PlugIns"; LogNormal() << "This file sets the plugin search path to" << appBundlePath + "/Contents/PlugIns";
} }