Skip to content

Commit 6ddcfc3

Browse files
committed
GUI: Updated handling of clang and clang-tidy
1 parent 5993c40 commit 6ddcfc3

11 files changed

Lines changed: 96 additions & 33 deletions

gui/checkthread.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include "erroritem.h"
2626
#include "threadresult.h"
2727
#include "cppcheck.h"
28-
29-
static const char CLANG[] = "clang";
30-
static const char CLANGTIDY[] = "clang-tidy";
28+
#include "common.h"
3129

3230
CheckThread::CheckThread(ThreadResult &result) :
3331
mState(Ready),
@@ -82,7 +80,7 @@ void CheckThread::run()
8280
while (!file.isEmpty() && mState == Running) {
8381
qDebug() << "Checking file" << file;
8482
mCppcheck.check(file.toStdString());
85-
runAddons(addonPath, nullptr, file);
83+
runAddonsAndTools(addonPath, nullptr, file);
8684
emit fileChecked(file);
8785

8886
if (mState == Running)
@@ -94,7 +92,7 @@ void CheckThread::run()
9492
file = QString::fromStdString(fileSettings.filename);
9593
qDebug() << "Checking file" << file;
9694
mCppcheck.check(fileSettings);
97-
runAddons(addonPath, &fileSettings, QString::fromStdString(fileSettings.filename));
95+
runAddonsAndTools(addonPath, &fileSettings, QString::fromStdString(fileSettings.filename));
9896
emit fileChecked(file);
9997

10098
if (mState == Running)
@@ -109,12 +107,12 @@ void CheckThread::run()
109107
emit done();
110108
}
111109

112-
void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName)
110+
void CheckThread::runAddonsAndTools(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName)
113111
{
114112
QString dumpFile;
115113

116-
foreach (const QString addon, mAddons) {
117-
if (addon == CLANG || addon == CLANGTIDY) {
114+
foreach (const QString addon, mAddonsAndTools) {
115+
if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) {
118116
if (!fileSettings)
119117
continue;
120118

@@ -195,7 +193,7 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS
195193
QFile::remove(analyzerInfoFile + '.' + addon + "-results");
196194
}
197195

198-
if (addon == CLANG) {
196+
if (addon == CLANG_ANALYZER) {
199197
args.insert(0,"--analyze");
200198
args.insert(1, "-Xanalyzer");
201199
args.insert(2, "-analyzer-output=text");
@@ -206,7 +204,13 @@ void CheckThread::runAddons(const QString &addonPath, const ImportProject::FileS
206204
args.insert(2, "--");
207205
}
208206

209-
const QString cmd(mClangPath.isEmpty() ? addon : (mClangPath + '/' + addon + ".exe"));
207+
#ifdef Q_OS_WIN
208+
const QString ext = ".exe";
209+
#else
210+
const QString ext = "";
211+
#endif
212+
const QString exename(addon == CLANG_ANALYZER ? ("clang" + ext) : ("clang-tidy" + ext));
213+
const QString cmd(mClangPath.isEmpty() ? exename : (mClangPath + '/' + exename));
210214
{
211215
QString debug(cmd.contains(" ") ? ('\"' + cmd + '\"') : cmd);
212216
foreach (QString arg, args) {
@@ -383,7 +387,7 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
383387
errorItem.severity = Severity::SeverityType::style;
384388
} else {
385389
message = r1.cap(5);
386-
id = CLANG;
390+
id = CLANG_ANALYZER;
387391
}
388392

389393
if (errorItem.errorPath.size() == 1) {

gui/checkthread.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class CheckThread : public QThread {
5252
*/
5353
void analyseWholeProgram(const QStringList &files);
5454

55-
void setAddons(const QStringList &addons) {
56-
mAddons = addons;
55+
void setAddonsAndTools(const QStringList &addonsAndTools) {
56+
mAddonsAndTools = addonsAndTools;
5757
}
5858

5959
void setPythonPath(const QString &p) {
@@ -124,14 +124,14 @@ class CheckThread : public QThread {
124124
private:
125125
QString getAddonPath() const;
126126

127-
void runAddons(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName);
127+
void runAddonsAndTools(const QString &addonPath, const ImportProject::FileSettings *fileSettings, const QString &fileName);
128128

129129
void parseAddonErrors(QString err, QString tool);
130130
void parseClangErrors(const QString &tool, const QString &file0, QString err);
131131

132132
QStringList mFiles;
133133
bool mAnalyseWholeProgram;
134-
QStringList mAddons;
134+
QStringList mAddonsAndTools;
135135
QString mPythonPath;
136136
QString mDataDir;
137137
QString mClangPath;

gui/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
/// @addtogroup GUI
2525
/// @{
2626

27+
#define CLANG_ANALYZER "clang-analyzer"
28+
#define CLANG_TIDY "clang-tidy"
2729

2830
/**
2931
* QSetting value names

gui/erroritem.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "erroritem.h"
20+
#include "common.h"
2021

2122
QErrorPathItem::QErrorPathItem(const ErrorLogger::ErrorMessage::FileLocation &loc)
2223
: file(QString::fromStdString(loc.getfile(false)))
@@ -55,10 +56,10 @@ ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
5556

5657
QString ErrorItem::tool() const
5758
{
58-
if (errorId == "clang")
59-
return "clang";
60-
if (errorId.startsWith("clang-tidy"))
61-
return "clang-tidy";
59+
if (errorId == CLANG_ANALYZER)
60+
return CLANG_ANALYZER;
61+
if (errorId.startsWith(CLANG_TIDY))
62+
return CLANG_TIDY;
6263
if (errorId.startsWith("clang-"))
6364
return "clang";
6465
return "cppcheck";

gui/mainwindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void MainWindow::doAnalyzeProject(ImportProject p)
445445

446446
//mThread->SetanalyzeProject(true);
447447
if (mProjectFile) {
448-
mThread->setAddons(mProjectFile->getAddons());
448+
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools());
449449
mThread->setPythonPath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
450450
QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString();
451451
mThread->setClangIncludePaths(clangHeaders.split(";"));
@@ -1417,7 +1417,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile)
14171417
QFileInfo inf(projectFile->getFilename());
14181418
const QString rootpath = projectFile->getRootPath();
14191419

1420-
mThread->setAddons(projectFile->getAddons());
1420+
mThread->setAddonsAndTools(projectFile->getAddonsAndTools());
14211421
mUI.mResults->setTags(projectFile->getTags());
14221422

14231423
// If the root path is not given or is not "current dir", use project

gui/projectfile.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QFile>
2424
#include <QDir>
2525
#include "projectfile.h"
26+
#include "common.h"
2627

2728
static const char ProjectElementName[] = "project";
2829
static const char ProjectVersionAttrib[] = "version";
@@ -53,6 +54,8 @@ static const char SuppressionsElementName[] = "suppressions";
5354
static const char SuppressionElementName[] = "suppression";
5455
static const char AddonElementName[] = "addon";
5556
static const char AddonsElementName[] = "addons";
57+
static const char ToolElementName[] = "tool";
58+
static const char ToolsElementName[] = "tools";
5659
static const char TagsElementName[] = "tags";
5760
static const char TagElementName[] = "tag";
5861

@@ -83,6 +86,7 @@ void ProjectFile::clear()
8386
mLibraries.clear();
8487
mSuppressions.clear();
8588
mAddons.clear();
89+
mClangAnalyzer = mClangTidy = false;
8690
}
8791

8892
bool ProjectFile::read(const QString &filename)
@@ -153,6 +157,14 @@ bool ProjectFile::read(const QString &filename)
153157
if (insideProject && xmlReader.name() == AddonsElementName)
154158
readStringList(mAddons, xmlReader, AddonElementName);
155159

160+
// Tools
161+
if (insideProject && xmlReader.name() == ToolsElementName) {
162+
QStringList tools;
163+
readStringList(tools, xmlReader, ToolElementName);
164+
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
165+
mClangTidy = tools.contains(CLANG_TIDY);
166+
}
167+
156168
if (insideProject && xmlReader.name() == TagsElementName)
157169
readStringList(mTags, xmlReader, TagElementName);
158170

@@ -588,6 +600,16 @@ bool ProjectFile::write(const QString &filename)
588600
AddonsElementName,
589601
AddonElementName);
590602

603+
QStringList tools;
604+
if (mClangAnalyzer)
605+
tools << CLANG_ANALYZER;
606+
if (mClangTidy)
607+
tools << CLANG_TIDY;
608+
writeStringList(xmlWriter,
609+
tools,
610+
ToolsElementName,
611+
ToolElementName);
612+
591613
writeStringList(xmlWriter, mTags, TagsElementName, TagElementName);
592614

593615
xmlWriter.writeEndDocument();
@@ -616,3 +638,12 @@ QStringList ProjectFile::fromNativeSeparators(const QStringList &paths)
616638
ret << QDir::fromNativeSeparators(path);
617639
return ret;
618640
}
641+
642+
QStringList ProjectFile::getAddonsAndTools() const {
643+
QStringList ret(mAddons);
644+
if (mClangAnalyzer)
645+
ret << CLANG_ANALYZER;
646+
if (mClangTidy)
647+
ret << CLANG_TIDY;
648+
return ret;
649+
}

gui/projectfile.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,26 @@ class ProjectFile : public QObject {
122122
return mAddons;
123123
}
124124

125+
/**
126+
* @brief Get list of addons and tools.
127+
* @return list of addons and tools.
128+
*/
129+
QStringList getAddonsAndTools() const;
130+
125131
bool getClangAnalyzer() const {
126-
return mAddons.contains("clang-analyzer");
132+
return mClangAnalyzer;
133+
}
134+
135+
void setClangAnalyzer(bool c) {
136+
mClangAnalyzer = c;
127137
}
128138

129139
bool getClangTidy() const {
130-
return mAddons.contains("clang-tidy");
140+
return mClangTidy;
141+
}
142+
143+
void setClangTidy(bool c) {
144+
mClangTidy = c;
131145
}
132146

133147
QStringList getTags() const {
@@ -355,6 +369,12 @@ class ProjectFile : public QObject {
355369
*/
356370
QStringList mAddons;
357371

372+
/** @brief Execute clang analyzer? */
373+
bool mClangAnalyzer;
374+
375+
/** @brief Execute clang-tidy? */
376+
bool mClangTidy;
377+
358378
/**
359379
* @brief Warning tags
360380
*/

gui/projectfiledialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void ProjectFileDialog::saveSettings() const
134134

135135
void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
136136
{
137-
mUI.mToolClangTidy->setChecked(projectFile->getAddons().contains("clang-tidy"));
138137
setRootPath(projectFile->getRootPath());
139138
setBuildDir(projectFile->getBuildDir());
140139
setIncludepaths(projectFile->getIncludeDirs());
@@ -148,6 +147,8 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
148147
mUI.mAddonThreadSafety->setChecked(projectFile->getAddons().contains("threadsafety"));
149148
mUI.mAddonY2038->setChecked(projectFile->getAddons().contains("y2038"));
150149
mUI.mAddonCert->setChecked(projectFile->getAddons().contains("cert"));
150+
//mUI.mToolClangAnalyzer->setChecked(projectFile->getClangAnalyzer());
151+
mUI.mToolClangTidy->setChecked(projectFile->getClangTidy());
151152
QString tags;
152153
foreach (const QString tag, projectFile->getTags()) {
153154
if (tags.isEmpty())
@@ -172,15 +173,15 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
172173
projectFile->setLibraries(getLibraries());
173174
projectFile->setSuppressions(getSuppressions());
174175
QStringList list;
175-
if (mUI.mToolClangTidy->isChecked())
176-
list << "clang-tidy";
177176
if (mUI.mAddonThreadSafety->isChecked())
178177
list << "threadsafety";
179178
if (mUI.mAddonY2038->isChecked())
180179
list << "y2038";
181180
if (mUI.mAddonCert->isChecked())
182181
list << "cert";
183182
projectFile->setAddons(list);
183+
//projectFile->setClangAnalyzer(mUI.mToolClangAnalyzer->isChecked());
184+
projectFile->setClangTidy(mUI.mToolClangTidy->isChecked());
184185
QStringList tags(mUI.mEditTags->text().split(";"));
185186
tags.removeAll(QString());
186187
projectFile->setTags(tags);

gui/statsdialog.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
6565
QChartView *chartView;
6666
chartView = createChart(statsFile, "cppcheck");
6767
mUI.mTabHistory->layout()->addWidget(chartView);
68-
if (projectFile->getAddons().contains("clang-tidy")) {
69-
chartView = createChart(statsFile, "clang-tidy");
68+
if (projectFile->getClangAnalyzer()) {
69+
chartView = createChart(statsFile, CLANG_ANALYZER);
70+
mUI.mTabHistory->layout()->addWidget(chartView);
71+
}
72+
if (projectFile->getClangTidy()) {
73+
chartView = createChart(statsFile, CLANG_TIDY);
7074
mUI.mTabHistory->layout()->addWidget(chartView);
7175
}
7276
}

gui/threadhandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void ThreadHandler::clearFiles()
4646
mLastFiles.clear();
4747
mResults.clearFiles();
4848
mAnalyseWholeProgram = false;
49-
mAddons.clear();
49+
mAddonsAndTools.clear();
5050
mSuppressions.clear();
5151
}
5252

@@ -93,7 +93,7 @@ void ThreadHandler::check(const Settings &settings)
9393
}
9494

9595
for (int i = 0; i < mRunningThreadCount; i++) {
96-
mThreads[i]->setAddons(mAddons);
96+
mThreads[i]->setAddonsAndTools(mAddonsAndTools);
9797
mThreads[i]->setPythonPath(mPythonPath);
9898
mThreads[i]->setSuppressions(mSuppressions);
9999
mThreads[i]->setClangPath(mClangPath);

0 commit comments

Comments
 (0)