forked from qt-creator/qt-creator
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:
@@ -227,7 +227,7 @@ QVersionNumber ClangToolsSettings::clangTidyVersion()
|
||||
|
||||
QVersionNumber ClangToolsSettings::clazyVersion()
|
||||
{
|
||||
return ClazyStandaloneInfo(ClangTools::Internal::clazyStandaloneExecutable()).version;
|
||||
return ClazyStandaloneInfo::getInfo(ClangTools::Internal::clazyStandaloneExecutable()).version;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -1140,7 +1140,7 @@ QString removeClangTidyCheck(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);
|
||||
model.enableChecks(checks.split(',', Qt::SkipEmptyParts));
|
||||
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 (config.clazyMode() == ClangDiagnosticConfig::ClazyMode::UseDefaultChecks) {
|
||||
config.setClazyMode(ClangDiagnosticConfig::ClazyMode::UseCustomChecks);
|
||||
const ClazyStandaloneInfo clazyInfo(clazyStandaloneExecutable());
|
||||
const ClazyStandaloneInfo clazyInfo
|
||||
= ClazyStandaloneInfo::getInfo(clazyStandaloneExecutable());
|
||||
config.setClazyChecks(clazyInfo.defaultChecks.join(','));
|
||||
}
|
||||
config.setClazyChecks(removeClazyCheck(config.clazyChecks(), diag.name));
|
||||
|
||||
@@ -163,6 +163,23 @@ ClangTidyInfo::ClangTidyInfo(const QString &executablePath)
|
||||
, 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)
|
||||
: defaultChecks(queryClangTidyChecks(executablePath, {})) // Yup, behaves as clang-tidy.
|
||||
, supportedChecks(querySupportedClazyChecks(executablePath))
|
||||
@@ -229,5 +246,7 @@ QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolP
|
||||
return qMakePair(dynamicResourceDir + "/include", dynamicVersion);
|
||||
}
|
||||
|
||||
QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache;
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
@@ -60,11 +62,16 @@ using ClazyChecks = QVector<ClazyCheck>;
|
||||
class ClazyStandaloneInfo
|
||||
{
|
||||
public:
|
||||
ClazyStandaloneInfo(const QString &executablePath);
|
||||
static ClazyStandaloneInfo getInfo(const QString &executablePath);
|
||||
|
||||
QVersionNumber version;
|
||||
QStringList defaultChecks;
|
||||
ClazyChecks supportedChecks;
|
||||
|
||||
private:
|
||||
ClazyStandaloneInfo(const QString &executablePath);
|
||||
|
||||
static QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> cache;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -80,7 +80,7 @@ static CppTools::ClangDiagnosticConfigsWidget *createEditWidget(
|
||||
return new DiagnosticConfigsWidget(configs,
|
||||
configToSelect,
|
||||
ClangTidyInfo(clangTidyPath),
|
||||
ClazyStandaloneInfo(clazyStandalonePath));
|
||||
ClazyStandaloneInfo::getInfo(clazyStandalonePath));
|
||||
}
|
||||
|
||||
void RunSettingsWidget::fromSettings(const RunSettings &s)
|
||||
|
||||
Reference in New Issue
Block a user