Skip to content

Commit

Permalink
macdeployqt: port away from Q_FOREACH and mark the tool free of it
Browse files Browse the repository at this point in the history
As a drive-by, fix a detach attempt in an existing ranged for-loop by
making the container const, and don't re-construct the same QDir three
times, just once, at beginning of the function.

Change-Id: I5031c4b63dd939ae93dd119b01d1cad5e655f733
Reviewed-by: Fabian Kosmale <[email protected]>
  • Loading branch information
marcmutz committed Aug 5, 2023
1 parent a631fef commit d7dc4d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/tools/macdeployqt/macdeployqt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ qt_internal_add_tool(${target_name}
SOURCES
../shared/shared.cpp
main.cpp
DEFINES
QT_NO_FOREACH
LIBRARIES
${FWCoreFoundation}
)
Expand Down
17 changes: 10 additions & 7 deletions src/tools/macdeployqt/shared/shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ QStringList getBinaryDependencies(const QString executablePath,
} else if (trimmedLine.startsWith("@rpath/")) {
if (!rpathsLoaded) {
rpaths = getBinaryRPaths(path, true, executablePath);
foreach (const QString &binaryPath, additionalBinariesContainingRpaths)
for (const QString &binaryPath : additionalBinariesContainingRpaths)
rpaths += getBinaryRPaths(binaryPath, true);
rpaths.removeDuplicates();
rpathsLoaded = true;
Expand Down Expand Up @@ -630,23 +630,24 @@ QStringList getBinaryDependencies(const QString executablePath,
bool recursiveCopy(const QString &sourcePath, const QString &destinationPath,
const QRegularExpression &ignoreRegExp = QRegularExpression())
{
if (!QDir(sourcePath).exists())
const QDir sourceDir(sourcePath);
if (!sourceDir.exists())
return false;
QDir().mkpath(destinationPath);

LogNormal() << "copy:" << sourcePath << destinationPath;

QStringList files = QDir(sourcePath).entryList(QStringList() << "*", QDir::Files | QDir::NoDotAndDotDot);
const QStringList files = sourceDir.entryList(QStringList() << "*", QDir::Files | QDir::NoDotAndDotDot);
const bool hasValidRegExp = ignoreRegExp.isValid() && ignoreRegExp.pattern().length() > 0;
foreach (QString file, files) {
for (const QString &file : files) {
if (hasValidRegExp && ignoreRegExp.match(file).hasMatch())
continue;
const QString fileSourcePath = sourcePath + "/" + file;
const QString fileDestinationPath = destinationPath + "/" + file;
copyFilePrintStatus(fileSourcePath, fileDestinationPath);
}

QStringList subdirs = QDir(sourcePath).entryList(QStringList() << "*", QDir::Dirs | QDir::NoDotAndDotDot);
const QStringList subdirs = sourceDir.entryList(QStringList() << "*", QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &dir : subdirs) {
recursiveCopy(sourcePath + "/" + dir, destinationPath + "/" + dir);
}
Expand All @@ -660,7 +661,9 @@ void recursiveCopyAndDeploy(const QString &appBundlePath, const QList<QString> &
LogNormal() << "copy:" << sourcePath << destinationPath;
const bool isDwarfPath = sourcePath.endsWith("DWARF");

QStringList files = QDir(sourcePath).entryList(QStringList() << QStringLiteral("*"), QDir::Files | QDir::NoDotAndDotDot);
const QDir sourceDir(sourcePath);

const QStringList files = sourceDir.entryList(QStringList() << QStringLiteral("*"), QDir::Files | QDir::NoDotAndDotDot);
for (const QString &file : files) {
const QString fileSourcePath = sourcePath + u'/' + file;

Expand Down Expand Up @@ -706,7 +709,7 @@ void recursiveCopyAndDeploy(const QString &appBundlePath, const QList<QString> &
}
}

QStringList subdirs = QDir(sourcePath).entryList(QStringList() << QStringLiteral("*"), QDir::Dirs | QDir::NoDotAndDotDot);
const QStringList subdirs = sourceDir.entryList(QStringList() << QStringLiteral("*"), QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &dir : subdirs) {
recursiveCopyAndDeploy(appBundlePath, rpaths, sourcePath + u'/' + dir, destinationPath + u'/' + dir);
}
Expand Down

0 comments on commit d7dc4d3

Please sign in to comment.