ClangTools: Cache information about the clazy executable

Fixes: QTCREATORBUG-26237
Change-Id: I43203d58b8ed278664427e3b4112a7c7848354b9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-09-08 12:08:55 +02:00
parent 2d77922856
commit bf275331dd
5 changed files with 32 additions and 5 deletions

View File

@@ -227,7 +227,7 @@ QVersionNumber ClangToolsSettings::clangTidyVersion()
QVersionNumber ClangToolsSettings::clazyVersion() QVersionNumber ClangToolsSettings::clazyVersion()
{ {
return ClazyStandaloneInfo(ClangTools::Internal::clazyStandaloneExecutable()).version; return ClazyStandaloneInfo::getInfo(ClangTools::Internal::clazyStandaloneExecutable()).version;
} }
} // namespace Internal } // namespace Internal

View File

@@ -1140,7 +1140,7 @@ QString removeClangTidyCheck(const QString &checks, const QString &check)
QString removeClazyCheck(const QString &checks, const QString &check) QString removeClazyCheck(const QString &checks, const QString &check)
{ {
const ClazyStandaloneInfo clazyInfo(clazyStandaloneExecutable()); const ClazyStandaloneInfo clazyInfo = ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable());
ClazyChecksTreeModel model(clazyInfo.supportedChecks); ClazyChecksTreeModel model(clazyInfo.supportedChecks);
model.enableChecks(checks.split(',', Qt::SkipEmptyParts)); model.enableChecks(checks.split(',', Qt::SkipEmptyParts));
const QModelIndex index = model.indexForName(check.mid(QString("clazy-").length())); const QModelIndex index = model.indexForName(check.mid(QString("clazy-").length()));
@@ -1190,7 +1190,8 @@ void disableChecks(const QList<Diagnostic> &diagnostics)
if (diag.name.startsWith("clazy-")) { if (diag.name.startsWith("clazy-")) {
if (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) { if (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) {
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks); config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
const ClazyStandaloneInfo clazyInfo(clazyStandaloneExecutable()); const ClazyStandaloneInfo clazyInfo
= ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable());
config.setClazyChecks(clazyInfo.defaultChecks.join(',')); config.setClazyChecks(clazyInfo.defaultChecks.join(','));
} }
config.setClazyChecks(removeClazyCheck(config.clazyChecks(), diag.name)); config.setClazyChecks(removeClazyCheck(config.clazyChecks(), diag.name));

View File

@@ -163,6 +163,23 @@ ClangTidyInfo::ClangTidyInfo(const QString &executablePath)
, supportedChecks(queryClangTidyChecks(executablePath, "-checks=*")) , supportedChecks(queryClangTidyChecks(executablePath, "-checks=*"))
{} {}
ClazyStandaloneInfo ClazyStandaloneInfo::getInfo(const QString &_executablePath)
{
const FilePath executablePath = FilePath::fromString(_executablePath);
const QDateTime timeStamp = executablePath.lastModified();
const auto it = cache.find(executablePath);
if (it == cache.end()) {
const ClazyStandaloneInfo info(executablePath.toString());
cache.insert(executablePath, qMakePair(timeStamp, info));
return info;
}
if (it->first != timeStamp) {
it->first = timeStamp;
it->second = ClazyStandaloneInfo(executablePath.toString());
}
return it->second;
}
ClazyStandaloneInfo::ClazyStandaloneInfo(const QString &executablePath) ClazyStandaloneInfo::ClazyStandaloneInfo(const QString &executablePath)
: defaultChecks(queryClangTidyChecks(executablePath, {})) // Yup, behaves as clang-tidy. : defaultChecks(queryClangTidyChecks(executablePath, {})) // Yup, behaves as clang-tidy.
, supportedChecks(querySupportedClazyChecks(executablePath)) , supportedChecks(querySupportedClazyChecks(executablePath))
@@ -229,5 +246,7 @@ QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolP
return qMakePair(dynamicResourceDir + "/include", dynamicVersion); return qMakePair(dynamicResourceDir + "/include", dynamicVersion);
} }
QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache;
} // namespace Internal } // namespace Internal
} // namespace ClangTools } // namespace ClangTools

View File

@@ -27,6 +27,8 @@
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QDateTime>
#include <QHash>
#include <QPair> #include <QPair>
#include <QStringList> #include <QStringList>
#include <QVector> #include <QVector>
@@ -60,11 +62,16 @@ using ClazyChecks = QVector<ClazyCheck>;
class ClazyStandaloneInfo class ClazyStandaloneInfo
{ {
public: public:
ClazyStandaloneInfo(const QString &executablePath); static ClazyStandaloneInfo getInfo(const QString &executablePath);
QVersionNumber version; QVersionNumber version;
QStringList defaultChecks; QStringList defaultChecks;
ClazyChecks supportedChecks; ClazyChecks supportedChecks;
private:
ClazyStandaloneInfo(const QString &executablePath);
static QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> cache;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -80,7 +80,7 @@ static CppTools::ClangDiagnosticConfigsWidget *createEditWidget(
return new DiagnosticConfigsWidget(configs, return new DiagnosticConfigsWidget(configs,
configToSelect, configToSelect,
ClangTidyInfo(clangTidyPath), ClangTidyInfo(clangTidyPath),
ClazyStandaloneInfo(clazyStandalonePath)); ClazyStandaloneInfo::getInfo(clazyStandalonePath));
} }
void RunSettingsWidget::fromSettings(const RunSettings &s) void RunSettingsWidget::fromSettings(const RunSettings &s)