forked from qt-creator/qt-creator
ClangTools: Extract filtering in readSerializedDiagnostics()
Change-Id: I07a4339af72d1e232eb7fe152a6af133a6a94436 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -468,9 +468,13 @@ Diagnostics ClangTidyClazyTool::read(const QString &logFilePath,
|
|||||||
const QSet<Utils::FilePath> &projectFiles,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
QString *errorMessage) const
|
QString *errorMessage) const
|
||||||
{
|
{
|
||||||
|
const auto acceptFromFilePath = [projectFiles](const Utils::FilePath &filePath) {
|
||||||
|
return projectFiles.contains(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
return readSerializedDiagnostics(Utils::FilePath::fromString(logFilePath),
|
return readSerializedDiagnostics(Utils::FilePath::fromString(logFilePath),
|
||||||
Utils::FilePath::fromString(mainFilePath),
|
Utils::FilePath::fromString(mainFilePath),
|
||||||
projectFiles,
|
acceptFromFilePath,
|
||||||
errorMessage);
|
errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ static ExplainingStep buildFixIt(const CXDiagnostic cxDiagnostic, unsigned index
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Diagnostic buildDiagnostic(const CXDiagnostic cxDiagnostic,
|
static Diagnostic buildDiagnostic(const CXDiagnostic cxDiagnostic,
|
||||||
const QSet<Utils::FilePath> &projectFiles,
|
const AcceptDiagsFromFilePath &acceptFromFilePath,
|
||||||
const QString &nativeFilePath)
|
const QString &nativeFilePath)
|
||||||
{
|
{
|
||||||
Diagnostic diagnostic;
|
Diagnostic diagnostic;
|
||||||
@@ -136,7 +136,7 @@ static Diagnostic buildDiagnostic(const CXDiagnostic cxDiagnostic,
|
|||||||
|
|
||||||
diagnostic.location = diagLocationFromSourceLocation(cxLocation);
|
diagnostic.location = diagLocationFromSourceLocation(cxLocation);
|
||||||
const auto diagnosticFilePath = Utils::FilePath::fromString(diagnostic.location.filePath);
|
const auto diagnosticFilePath = Utils::FilePath::fromString(diagnostic.location.filePath);
|
||||||
if (!projectFiles.contains(diagnosticFilePath))
|
if (acceptFromFilePath && !acceptFromFilePath(diagnosticFilePath))
|
||||||
return diagnostic;
|
return diagnostic;
|
||||||
|
|
||||||
// TODO: Introduce CppTools::ProjectFile::isGenerated to filter these out properly
|
// TODO: Introduce CppTools::ProjectFile::isGenerated to filter these out properly
|
||||||
@@ -184,7 +184,7 @@ static Diagnostic buildDiagnostic(const CXDiagnostic cxDiagnostic,
|
|||||||
|
|
||||||
static Diagnostics readSerializedDiagnostics_helper(const Utils::FilePath &logFilePath,
|
static Diagnostics readSerializedDiagnostics_helper(const Utils::FilePath &logFilePath,
|
||||||
const Utils::FilePath &mainFilePath,
|
const Utils::FilePath &mainFilePath,
|
||||||
const QSet<Utils::FilePath> &projectFiles)
|
const AcceptDiagsFromFilePath &acceptFromFilePath)
|
||||||
{
|
{
|
||||||
Diagnostics list;
|
Diagnostics list;
|
||||||
CXLoadDiag_Error error;
|
CXLoadDiag_Error error;
|
||||||
@@ -206,7 +206,7 @@ static Diagnostics readSerializedDiagnostics_helper(const Utils::FilePath &logFi
|
|||||||
Utils::ExecuteOnDestruction cleanUpDiagnostic([&]() {
|
Utils::ExecuteOnDestruction cleanUpDiagnostic([&]() {
|
||||||
clang_disposeDiagnostic(cxDiagnostic);
|
clang_disposeDiagnostic(cxDiagnostic);
|
||||||
});
|
});
|
||||||
const Diagnostic diagnostic = buildDiagnostic(cxDiagnostic, projectFiles, nativeFilePath);
|
const Diagnostic diagnostic = buildDiagnostic(cxDiagnostic, acceptFromFilePath, nativeFilePath);
|
||||||
if (!diagnostic.isValid())
|
if (!diagnostic.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -233,13 +233,13 @@ static bool checkFilePath(const Utils::FilePath &filePath, QString *errorMessage
|
|||||||
|
|
||||||
Diagnostics readSerializedDiagnostics(const Utils::FilePath &logFilePath,
|
Diagnostics readSerializedDiagnostics(const Utils::FilePath &logFilePath,
|
||||||
const Utils::FilePath &mainFilePath,
|
const Utils::FilePath &mainFilePath,
|
||||||
const QSet<Utils::FilePath> &projectFiles,
|
const AcceptDiagsFromFilePath &acceptFromFilePath,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (!checkFilePath(logFilePath, errorMessage))
|
if (!checkFilePath(logFilePath, errorMessage))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return readSerializedDiagnostics_helper(logFilePath, mainFilePath, projectFiles);
|
return readSerializedDiagnostics_helper(logFilePath, mainFilePath, acceptFromFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -27,16 +27,16 @@
|
|||||||
|
|
||||||
#include "clangtoolsdiagnostic.h"
|
#include "clangtoolsdiagnostic.h"
|
||||||
|
|
||||||
#include <QSet>
|
|
||||||
|
|
||||||
namespace Utils { class FilePath; }
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace ClangTools {
|
namespace ClangTools {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
using AcceptDiagsFromFilePath = std::function<bool(const Utils::FilePath &)>;
|
||||||
|
|
||||||
Diagnostics readSerializedDiagnostics(const Utils::FilePath &logFilePath,
|
Diagnostics readSerializedDiagnostics(const Utils::FilePath &logFilePath,
|
||||||
const Utils::FilePath &mainFilePath,
|
const Utils::FilePath &mainFilePath,
|
||||||
const QSet<Utils::FilePath> &projectFiles,
|
const AcceptDiagsFromFilePath &acceptFromFilePath,
|
||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user