From c2bb9890e9fab848ed7336b8295662204623f5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 4 Aug 2017 15:10:27 +0200 Subject: [PATCH] GUI: add clang-tidy --- gui/checkthread.cpp | 40 ++++++-- gui/projectfiledialog.cpp | 9 +- gui/projectfiledialog.ui | 193 ++++++++++++++++++++++---------------- 3 files changed, 146 insertions(+), 96 deletions(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index ff914b92f..ab14d9c81 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -25,6 +25,9 @@ #include "threadresult.h" #include "cppcheck.h" +static const char CLANG[] = "clang"; +static const char CLANGTIDY[] = "clang-tidy"; + CheckThread::CheckThread(ThreadResult &result) : mState(Ready), mResult(result), @@ -110,26 +113,35 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS QString dumpFile; foreach (const QString addon, mAddons) { - if (addon == "clang") { + if (addon == CLANG || addon == CLANGTIDY) { if (!fileSettings) continue; - QString cmd("clang --analyze"); + + QString args; for (std::list::const_iterator I = fileSettings->includePaths.begin(); I != fileSettings->includePaths.end(); ++I) - cmd += " -I" + QString::fromStdString(*I); + args += " -I" + QString::fromStdString(*I); for (std::list::const_iterator i = fileSettings->systemIncludePaths.begin(); i != fileSettings->systemIncludePaths.end(); ++i) - cmd += " -isystem " + QString::fromStdString(*i); + args += " -isystem " + QString::fromStdString(*i); foreach (QString D, QString::fromStdString(fileSettings->defines).split(";")) { - cmd += " -D" + D; + args += " -D" + D; } if (!fileSettings->standard.empty()) - cmd += " -std=" + QString::fromStdString(fileSettings->standard); - cmd += ' ' + fileName; + args += " -std=" + QString::fromStdString(fileSettings->standard); + + QString cmd; + if (addon == CLANG) + cmd = addon + " --analyze" + args + ' ' + fileName; + else + cmd = addon + " -checks=*,-clang*,-llvm* " + fileName + " -- " + args; qDebug() << cmd; QProcess process; process.start(cmd); process.waitForFinished(600*1000); - parseClangErrors(process.readAllStandardError()); + if (addon == CLANG) + parseClangErrors(process.readAllStandardError()); + else + parseClangErrors(process.readAllStandardOutput()); } else { QString a; if (QFileInfo(addonPath + '/' + addon + ".py").exists()) @@ -225,8 +237,16 @@ void CheckThread::parseClangErrors(QString err) const std::string filename = r.cap(1).toStdString(); const int lineNumber = r.cap(2).toInt(); Severity::SeverityType severity = (r.cap(3) == "warning") ? Severity::warning : Severity::error; - const std::string message = r.cap(4).toStdString(); - const std::string id = "clang"; + std::string message, id; + QRegExp r2("(.*)\\[([a-zA-Z0-9\\-_\\.]+)\\]"); + if (r2.exactMatch(r.cap(4))) { + message = r2.cap(1).toStdString(); + id = r2.cap(2).toStdString(); + } else { + message = r.cap(4).toStdString(); + id = CLANG; + } + std::list callstack; callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber)); ErrorLogger::ErrorMessage errmsg(callstack, filename, severity, message, id, false); diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index 7f669a1e7..b5701492e 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -132,6 +132,8 @@ void ProjectFileDialog::saveSettings() const void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile) { + mUI.mToolClang->setChecked(projectFile->getAddons().contains("clang")); + mUI.mToolClangTidy->setChecked(projectFile->getAddons().contains("clang-tidy")); setRootPath(projectFile->getRootPath()); setBuildDir(projectFile->getBuildDir()); setIncludepaths(projectFile->getIncludeDirs()); @@ -145,7 +147,6 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile) mUI.mAddonY2038->setChecked(projectFile->getAddons().contains("y2038")); mUI.mAddonCert->setChecked(projectFile->getAddons().contains("cert")); mUI.mAddonMisra->setChecked(projectFile->getAddons().contains("misra")); - mUI.mClang->setChecked(projectFile->getAddons().contains("clang")); updatePathsAndDefines(); } @@ -161,6 +162,10 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const projectFile->setLibraries(getLibraries()); projectFile->setSuppressions(getSuppressions()); QStringList list; + if (mUI.mToolClang->isChecked()) + list << "clang"; + if (mUI.mToolClangTidy->isChecked()) + list << "clang-tidy"; if (mUI.mAddonThreadSafety->isChecked()) list << "threadsafety"; if (mUI.mAddonY2038->isChecked()) @@ -169,8 +174,6 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const list << "cert"; if (mUI.mAddonMisra->isChecked()) list << "misra"; - if (mUI.mClang->isChecked()) - list << "clang"; projectFile->setAddons(list); } diff --git a/gui/projectfiledialog.ui b/gui/projectfiledialog.ui index 68716f080..822cb5b20 100644 --- a/gui/projectfiledialog.ui +++ b/gui/projectfiledialog.ui @@ -19,93 +19,48 @@ 0 - + - Project + Tools - + - - - - - &Root: - - - mEditProjectRoot - - - - - - - - - - - - - - <html><head/><body><p>In the build dir, cppcheck stores data about each translation unit.</p><p>With a build dir you get whole program analysis.</p><p>Unchanged files will be analyzed much faster; Cppcheck skip the analysis of these files and reuse their old data.</p></body></html> - - - Cppcheck build dir (whole program analysis, faster analysis for unchanged files) - - - - - - - - - - - - ... - - - - - - - - - - - - - Libraries: - - - - - - - + - Note: Put your own custom .cfg files in the same folder as the project file. You should see them above. - - - true + It is common best practice to use several tools. - + + + Clang + + + + + + + Clang-tidy + + + + + Qt::Vertical 20 - 96 + 310 - + Paths and Defines @@ -356,6 +311,92 @@ + + + Project + + + + + + + + &Root: + + + mEditProjectRoot + + + + + + + + + + + + + + <html><head/><body><p>In the build dir, cppcheck stores data about each translation unit.</p><p>With a build dir you get whole program analysis.</p><p>Unchanged files will be analyzed much faster; Cppcheck skip the analysis of these files and reuse their old data.</p></body></html> + + + Cppcheck build dir (whole program analysis, faster analysis for unchanged files) + + + + + + + + + + + + ... + + + + + + + + + + + + + Libraries: + + + + + + + + + Note: Put your own custom .cfg files in the same folder as the project file. You should see them above. + + + true + + + + + + + Qt::Vertical + + + + 20 + 96 + + + + + + Exclude @@ -415,7 +456,7 @@ - + Suppressions @@ -463,7 +504,7 @@ - + Addons @@ -503,20 +544,6 @@ - - - - Other - - - - - - - clang (experimental) - - -