forked from qt-creator/qt-creator
ClangTools: Fix showing diagnostics outside the project root dir
Accept diagnostics from files that are known to the project (Project::files()) instead of checking whether they are below the project root directory (Project::projectDirectory()). Fixes: QTCREATORBUG-22213 Change-Id: I2f96374d6de3f53b1bd42be875dfe44b25a55fb1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -464,11 +464,11 @@ void ClangTidyClazyTool::handleStateUpdate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<Diagnostic> ClangTidyClazyTool::read(const QString &filePath,
|
QList<Diagnostic> ClangTidyClazyTool::read(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath,
|
const QString &logFilePath,
|
||||||
QString *errorMessage) const
|
QString *errorMessage) const
|
||||||
{
|
{
|
||||||
return readSerializedDiagnostics(filePath, projectRootDir, logFilePath, errorMessage);
|
return readSerializedDiagnostics(filePath, projectFiles, logFilePath, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangTidyClazyTool::onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics)
|
void ClangTidyClazyTool::onNewDiagnosticsAvailable(const QList<Diagnostic> &diagnostics)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
void startTool(bool askUserForFileSelection) final;
|
void startTool(bool askUserForFileSelection) final;
|
||||||
|
|
||||||
QList<Diagnostic> read(const QString &filePath,
|
QList<Diagnostic> read(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath,
|
const QString &logFilePath,
|
||||||
QString *errorMessage) const final;
|
QString *errorMessage) const final;
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
virtual void startTool(bool askUserForFileSelection) = 0;
|
virtual void startTool(bool askUserForFileSelection) = 0;
|
||||||
|
|
||||||
virtual QList<Diagnostic> read(const QString &filePath,
|
virtual QList<Diagnostic> read(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath,
|
const QString &logFilePath,
|
||||||
QString *errorMessage) const = 0;
|
QString *errorMessage) const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ void ClangToolRunControl::start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_projectInfo = CppTools::CppModelManager::instance()->projectInfo(m_target->project());
|
m_projectInfo = CppTools::CppModelManager::instance()->projectInfo(m_target->project());
|
||||||
|
m_projectFiles = Utils::toSet(m_target->project()->files(Project::AllFiles));
|
||||||
|
|
||||||
// Some projects provides CompilerCallData once a build is finished,
|
// Some projects provides CompilerCallData once a build is finished,
|
||||||
if (m_projectInfo.configurationOrFilesChanged(m_projectInfoBeforeBuild)) {
|
if (m_projectInfo.configurationOrFilesChanged(m_projectInfoBeforeBuild)) {
|
||||||
@@ -360,6 +361,7 @@ void ClangToolRunControl::stop()
|
|||||||
QObject::disconnect(runner, nullptr, this, nullptr);
|
QObject::disconnect(runner, nullptr, this, nullptr);
|
||||||
delete runner;
|
delete runner;
|
||||||
}
|
}
|
||||||
|
m_projectFiles.clear();
|
||||||
m_runners.clear();
|
m_runners.clear();
|
||||||
m_unitsToProcess.clear();
|
m_unitsToProcess.clear();
|
||||||
m_progress.reportFinished();
|
m_progress.reportFinished();
|
||||||
@@ -390,22 +392,14 @@ void ClangToolRunControl::analyzeNextFile()
|
|||||||
Utils::StdOutFormat);
|
Utils::StdOutFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::FilePath cleanPath(const Utils::FilePath &filePath)
|
|
||||||
{
|
|
||||||
return Utils::FilePath::fromString(QDir::cleanPath(filePath.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClangToolRunControl::onRunnerFinishedWithSuccess(const QString &filePath)
|
void ClangToolRunControl::onRunnerFinishedWithSuccess(const QString &filePath)
|
||||||
{
|
{
|
||||||
const QString logFilePath = qobject_cast<ClangToolRunner *>(sender())->logFilePath();
|
const QString logFilePath = qobject_cast<ClangToolRunner *>(sender())->logFilePath();
|
||||||
qCDebug(LOG) << "onRunnerFinishedWithSuccess:" << logFilePath;
|
qCDebug(LOG) << "onRunnerFinishedWithSuccess:" << logFilePath;
|
||||||
|
|
||||||
QTC_ASSERT(m_projectInfo.project(), return);
|
|
||||||
const Utils::FilePath projectRootDir = cleanPath(m_projectInfo.project()->projectDirectory());
|
|
||||||
|
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
const QList<Diagnostic> diagnostics = tool()->read(filePath,
|
const QList<Diagnostic> diagnostics = tool()->read(filePath,
|
||||||
projectRootDir,
|
m_projectFiles,
|
||||||
logFilePath,
|
logFilePath,
|
||||||
&errorMessage);
|
&errorMessage);
|
||||||
QFile::remove(logFilePath); // Clean-up.
|
QFile::remove(logFilePath); // Clean-up.
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ private:
|
|||||||
|
|
||||||
QFutureInterface<void> m_progress;
|
QFutureInterface<void> m_progress;
|
||||||
AnalyzeUnits m_unitsToProcess;
|
AnalyzeUnits m_unitsToProcess;
|
||||||
|
QSet<Utils::FilePath> m_projectFiles;
|
||||||
QSet<ClangToolRunner *> m_runners;
|
QSet<ClangToolRunner *> m_runners;
|
||||||
int m_initialFilesToProcessSize = 0;
|
int m_initialFilesToProcessSize = 0;
|
||||||
int m_filesAnalyzed = 0;
|
int m_filesAnalyzed = 0;
|
||||||
|
|||||||
@@ -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 Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
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 (!diagnosticFilePath.isChildOf(projectRootDir))
|
if (!projectFiles.contains(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
|
||||||
@@ -183,7 +183,7 @@ static Diagnostic buildDiagnostic(const CXDiagnostic cxDiagnostic,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static QList<Diagnostic> readSerializedDiagnostics_helper(const QString &filePath,
|
static QList<Diagnostic> readSerializedDiagnostics_helper(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath)
|
const QString &logFilePath)
|
||||||
{
|
{
|
||||||
QList<Diagnostic> list;
|
QList<Diagnostic> list;
|
||||||
@@ -206,7 +206,7 @@ static QList<Diagnostic> readSerializedDiagnostics_helper(const QString &filePat
|
|||||||
Utils::ExecuteOnDestruction cleanUpDiagnostic([&]() {
|
Utils::ExecuteOnDestruction cleanUpDiagnostic([&]() {
|
||||||
clang_disposeDiagnostic(cxDiagnostic);
|
clang_disposeDiagnostic(cxDiagnostic);
|
||||||
});
|
});
|
||||||
const Diagnostic diagnostic = buildDiagnostic(cxDiagnostic, projectRootDir, nativeFilePath);
|
const Diagnostic diagnostic = buildDiagnostic(cxDiagnostic, projectFiles, nativeFilePath);
|
||||||
if (!diagnostic.isValid())
|
if (!diagnostic.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -232,14 +232,14 @@ static bool checkFilePath(const QString &filePath, QString *errorMessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QList<Diagnostic> readSerializedDiagnostics(const QString &filePath,
|
QList<Diagnostic> readSerializedDiagnostics(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath,
|
const QString &logFilePath,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (!checkFilePath(logFilePath, errorMessage))
|
if (!checkFilePath(logFilePath, errorMessage))
|
||||||
return QList<Diagnostic>();
|
return QList<Diagnostic>();
|
||||||
|
|
||||||
return readSerializedDiagnostics_helper(filePath, projectRootDir, logFilePath);
|
return readSerializedDiagnostics_helper(filePath, projectFiles, logFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace ClangTools {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
QList<Diagnostic> readSerializedDiagnostics(const QString &filePath,
|
QList<Diagnostic> readSerializedDiagnostics(const QString &filePath,
|
||||||
const Utils::FilePath &projectRootDir,
|
const QSet<Utils::FilePath> &projectFiles,
|
||||||
const QString &logFilePath,
|
const QString &logFilePath,
|
||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user