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 <oswald.buddenhagen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Ville Nummela
2018-11-30 10:31:56 +02:00
parent 85a02fe8aa
commit 76262814b6
4 changed files with 43 additions and 5 deletions

View File

@@ -42,6 +42,7 @@
#include <qtsupport/profilereader.h> #include <qtsupport/profilereader.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/filesystemwatcher.h>
#include <utils/qtcprocess.h> #include <utils/qtcprocess.h>
#include <utils/mimetypes/mimedatabase.h> #include <utils/mimetypes/mimedatabase.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
@@ -151,6 +152,7 @@ public:
InstallsList installsList; InstallsList installsList;
QHash<Variable, QStringList> newVarValues; QHash<Variable, QStringList> newVarValues;
QStringList errors; QStringList errors;
QSet<QString> directoriesWithWildcards;
}; };
} // namespace Internal } // namespace Internal
@@ -1366,14 +1368,14 @@ QmakeEvalResult *QmakeProFile::evaluate(const QmakeEvalInput &input)
const QStringList vPathsExact = fullVPaths( const QStringList vPathsExact = fullVPaths(
baseVPathsExact, exactReader, qmakeVariable, input.projectDir); baseVPathsExact, exactReader, qmakeVariable, input.projectDir);
auto sourceFiles = exactReader->absoluteFileValues( auto sourceFiles = exactReader->absoluteFileValues(
qmakeVariable, input.projectDir, vPathsExact, &handled); qmakeVariable, input.projectDir, vPathsExact, &handled, result->directoriesWithWildcards);
exactSourceFiles[qmakeVariable] = sourceFiles; exactSourceFiles[qmakeVariable] = sourceFiles;
extractSources(proToResult, &result->includedFiles.result, sourceFiles, type); extractSources(proToResult, &result->includedFiles.result, sourceFiles, type);
} }
const QStringList vPathsCumulative = fullVPaths( const QStringList vPathsCumulative = fullVPaths(
baseVPathsCumulative, cumulativeReader, qmakeVariable, input.projectDir); baseVPathsCumulative, cumulativeReader, qmakeVariable, input.projectDir);
auto sourceFiles = cumulativeReader->absoluteFileValues( auto sourceFiles = cumulativeReader->absoluteFileValues(
qmakeVariable, input.projectDir, vPathsCumulative, &handled); qmakeVariable, input.projectDir, vPathsCumulative, &handled, result->directoriesWithWildcards);
cumulativeSourceFiles[qmakeVariable] = sourceFiles; cumulativeSourceFiles[qmakeVariable] = sourceFiles;
extractSources(proToResult, &result->includedFiles.result, sourceFiles, type); extractSources(proToResult, &result->includedFiles.result, sourceFiles, type);
} }
@@ -1594,6 +1596,33 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult)
m_displayName = singleVariableValue(Variable::QmakeProjectName); m_displayName = singleVariableValue(Variable::QmakeProjectName);
} // result == EvalOk } // result == EvalOk
if (!result->directoriesWithWildcards.isEmpty()) {
if (!m_wildcardWatcher) {
m_wildcardWatcher = std::make_unique<Utils::FileSystemWatcher>();
QObject::connect(
m_wildcardWatcher.get(), &Utils::FileSystemWatcher::directoryChanged,
[this]() {
scheduleUpdate();
});
}
m_wildcardWatcher->addDirectories(
Utils::filtered<QStringList>(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<QStringList>(m_wildcardWatcher->directories(),
[&result](const QString &path) {
return !result->directoriesWithWildcards.contains(path);
}));
}
}
setParseInProgress(false); setParseInProgress(false);
updateGeneratedFiles(buildDirectory); updateGeneratedFiles(buildDirectory);

View File

@@ -39,7 +39,11 @@
#include <memory> #include <memory>
namespace Utils { class FileName; } namespace Utils {
class FileName;
class FileSystemWatcher;
} // namespace Utils;
namespace QtSupport { class ProFileReader; } namespace QtSupport { class ProFileReader; }
namespace ProjectExplorer { class RunConfiguration; } namespace ProjectExplorer { class RunConfiguration; }
@@ -362,6 +366,8 @@ private:
Utils::FileNameList m_subProjectsNotToDeploy; Utils::FileNameList m_subProjectsNotToDeploy;
InstallsList m_installsList; InstallsList m_installsList;
std::unique_ptr<Utils::FileSystemWatcher> m_wildcardWatcher;
// Async stuff // Async stuff
QFutureWatcher<Internal::QmakeEvalResult *> m_parseFutureWatcher; QFutureWatcher<Internal::QmakeEvalResult *> m_parseFutureWatcher;
QtSupport::ProFileReader *m_readerExact = nullptr; QtSupport::ProFileReader *m_readerExact = nullptr;

View File

@@ -139,7 +139,7 @@ QStringList ProFileEvaluator::absolutePathValues(
QVector<ProFileEvaluator::SourceFile> ProFileEvaluator::absoluteFileValues( QVector<ProFileEvaluator::SourceFile> ProFileEvaluator::absoluteFileValues(
const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
QHash<ProString, bool> *handled) const QHash<ProString, bool> *handled, QSet<QString> &directoriesWithWildcards) const
{ {
QMakeVfs::VfsFlags flags = (d->m_cumulative ? QMakeVfs::VfsCumulative : QMakeVfs::VfsExact); QMakeVfs::VfsFlags flags = (d->m_cumulative ? QMakeVfs::VfsCumulative : QMakeVfs::VfsExact);
QVector<SourceFile> result; QVector<SourceFile> result;
@@ -186,6 +186,9 @@ QVector<ProFileEvaluator::SourceFile> ProFileEvaluator::absoluteFileValues(
foreach (const QString &fn, theDir.entryList(QStringList(wildcard))) foreach (const QString &fn, theDir.entryList(QStringList(wildcard)))
if (fn != QLatin1String(".") && fn != QLatin1String("..")) if (fn != QLatin1String(".") && fn != QLatin1String(".."))
result << SourceFile{absDir + QLatin1Char('/') + fn, str.sourceFile()}; result << SourceFile{absDir + QLatin1Char('/') + fn, str.sourceFile()};
QString directoryWithWildcard(absDir);
directoryWithWildcard.detach();
directoriesWithWildcards.insert(directoryWithWildcard);
} // else if (acceptMissing) } // else if (acceptMissing)
} }
} }

View File

@@ -86,7 +86,7 @@ public:
QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const; QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const;
QVector<SourceFile> absoluteFileValues( QVector<SourceFile> absoluteFileValues(
const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
QHash<ProString, bool> *handled) const; QHash<ProString, bool> *handled, QSet<QString> &directoriesWithWildcards) const;
QString propertyValue(const QString &val) const; QString propertyValue(const QString &val) const;
static QStringList sourcesToFiles(const QVector<SourceFile> &sources); static QStringList sourcesToFiles(const QVector<SourceFile> &sources);