From 76262814b6a10604cf84c3ecc85b2792af1b942d Mon Sep 17 00:00:00 2001 From: Ville Nummela Date: Fri, 30 Nov 2018 10:31:56 +0200 Subject: [PATCH] QmakeProjectManager: Watch wildcard directories for changes If e.g. DISTFILES contains wildcards, watch the directory for changes. Fixes: QTCREATORBUG-21603 Change-Id: Ia6e8c94ab7b74e0404776ba1d7d9b10eb3b643de Reviewed-by: Oswald Buddenhagen Reviewed-by: Tobias Hunger Reviewed-by: Orgad Shaneh --- .../qmakeprojectmanager/qmakeparsernodes.cpp | 33 +++++++++++++++++-- .../qmakeprojectmanager/qmakeparsernodes.h | 8 ++++- src/shared/proparser/profileevaluator.cpp | 5 ++- src/shared/proparser/profileevaluator.h | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index 246cd05a78a..907bcfa6a55 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -151,6 +152,7 @@ public: InstallsList installsList; QHash newVarValues; QStringList errors; + QSet directoriesWithWildcards; }; } // namespace Internal @@ -1366,14 +1368,14 @@ QmakeEvalResult *QmakeProFile::evaluate(const QmakeEvalInput &input) const QStringList vPathsExact = fullVPaths( baseVPathsExact, exactReader, qmakeVariable, input.projectDir); auto sourceFiles = exactReader->absoluteFileValues( - qmakeVariable, input.projectDir, vPathsExact, &handled); + qmakeVariable, input.projectDir, vPathsExact, &handled, result->directoriesWithWildcards); exactSourceFiles[qmakeVariable] = sourceFiles; extractSources(proToResult, &result->includedFiles.result, sourceFiles, type); } const QStringList vPathsCumulative = fullVPaths( baseVPathsCumulative, cumulativeReader, qmakeVariable, input.projectDir); auto sourceFiles = cumulativeReader->absoluteFileValues( - qmakeVariable, input.projectDir, vPathsCumulative, &handled); + qmakeVariable, input.projectDir, vPathsCumulative, &handled, result->directoriesWithWildcards); cumulativeSourceFiles[qmakeVariable] = sourceFiles; extractSources(proToResult, &result->includedFiles.result, sourceFiles, type); } @@ -1594,6 +1596,33 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult) m_displayName = singleVariableValue(Variable::QmakeProjectName); } // result == EvalOk + if (!result->directoriesWithWildcards.isEmpty()) { + if (!m_wildcardWatcher) { + m_wildcardWatcher = std::make_unique(); + QObject::connect( + m_wildcardWatcher.get(), &Utils::FileSystemWatcher::directoryChanged, + [this]() { + scheduleUpdate(); + }); + } + m_wildcardWatcher->addDirectories( + Utils::filtered(result->directoriesWithWildcards.toList(), + [this](const QString &path) { + return !m_wildcardWatcher->watchesDirectory(path); + }), Utils::FileSystemWatcher::WatchAllChanges); + } + if (m_wildcardWatcher) { + if (result->directoriesWithWildcards.isEmpty()) { + m_wildcardWatcher.reset(); + } else { + m_wildcardWatcher->removeDirectories( + Utils::filtered(m_wildcardWatcher->directories(), + [&result](const QString &path) { + return !result->directoriesWithWildcards.contains(path); + })); + } + } + setParseInProgress(false); updateGeneratedFiles(buildDirectory); diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h index 7b09fbc7024..066a7558d4a 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h @@ -39,7 +39,11 @@ #include -namespace Utils { class FileName; } +namespace Utils { +class FileName; +class FileSystemWatcher; +} // namespace Utils; + namespace QtSupport { class ProFileReader; } namespace ProjectExplorer { class RunConfiguration; } @@ -362,6 +366,8 @@ private: Utils::FileNameList m_subProjectsNotToDeploy; InstallsList m_installsList; + std::unique_ptr m_wildcardWatcher; + // Async stuff QFutureWatcher m_parseFutureWatcher; QtSupport::ProFileReader *m_readerExact = nullptr; diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index 0cb1f2ca041..22f3ee5b4e1 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -139,7 +139,7 @@ QStringList ProFileEvaluator::absolutePathValues( QVector ProFileEvaluator::absoluteFileValues( const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, - QHash *handled) const + QHash *handled, QSet &directoriesWithWildcards) const { QMakeVfs::VfsFlags flags = (d->m_cumulative ? QMakeVfs::VfsCumulative : QMakeVfs::VfsExact); QVector result; @@ -186,6 +186,9 @@ QVector ProFileEvaluator::absoluteFileValues( foreach (const QString &fn, theDir.entryList(QStringList(wildcard))) if (fn != QLatin1String(".") && fn != QLatin1String("..")) result << SourceFile{absDir + QLatin1Char('/') + fn, str.sourceFile()}; + QString directoryWithWildcard(absDir); + directoryWithWildcard.detach(); + directoriesWithWildcards.insert(directoryWithWildcard); } // else if (acceptMissing) } } diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h index ce1675dd4b4..a67d4b5a74f 100644 --- a/src/shared/proparser/profileevaluator.h +++ b/src/shared/proparser/profileevaluator.h @@ -86,7 +86,7 @@ public: QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const; QVector absoluteFileValues( const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, - QHash *handled) const; + QHash *handled, QSet &directoriesWithWildcards) const; QString propertyValue(const QString &val) const; static QStringList sourcesToFiles(const QVector &sources);