Skip to content

Commit 1b4ec0d

Browse files
authored
Fix #11787 (GUI: configure check level) (#5206)
1 parent 55af68a commit 1b4ec0d

7 files changed

Lines changed: 77 additions & 3 deletions

File tree

gui/mainwindow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,10 @@ Settings MainWindow::getCppcheckSettings()
979979

980980
result.maxCtuDepth = mProjectFile->getMaxCtuDepth();
981981
result.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
982+
if (mProjectFile->isCheckLevelExhaustive())
983+
result.setCheckLevelExhaustive();
984+
else
985+
result.setCheckLevelNormal();
982986
result.checkHeaders = mProjectFile->getCheckHeaders();
983987
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
984988
result.safeChecks.classes = mProjectFile->safeChecks.classes;

gui/projectfile.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void ProjectFile::clear()
5858
{
5959
const Settings settings;
6060
clangParser = false;
61+
mCheckLevel = CheckLevel::normal;
6162
mRootPath.clear();
6263
mBuildDir.clear();
6364
mImportProject.clear();
@@ -141,6 +142,9 @@ bool ProjectFile::read(const QString &filename)
141142
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
142143
mCheckUnusedTemplates = readBool(xmlReader);
143144

145+
if (xmlReader.name() == QString(CppcheckXml::CheckLevelExhaustiveElementName))
146+
mCheckLevel = CheckLevel::exhaustive;
147+
144148
// Find include directory from inside project element
145149
if (xmlReader.name() == QString(CppcheckXml::IncludeDirElementName))
146150
readIncludeDirs(xmlReader);
@@ -780,6 +784,16 @@ void ProjectFile::setVSConfigurations(const QStringList &vsConfigs)
780784
mVsConfigurations = vsConfigs;
781785
}
782786

787+
void ProjectFile::setCheckLevel(ProjectFile::CheckLevel checkLevel)
788+
{
789+
mCheckLevel = checkLevel;
790+
}
791+
792+
bool ProjectFile::isCheckLevelExhaustive() const
793+
{
794+
return mCheckLevel == CheckLevel::exhaustive;
795+
}
796+
783797
void ProjectFile::setWarningTags(std::size_t hash, const QString& tags)
784798
{
785799
if (tags.isEmpty())
@@ -978,6 +992,11 @@ bool ProjectFile::write(const QString &filename)
978992
}
979993
}
980994

995+
if (mCheckLevel == CheckLevel::exhaustive) {
996+
xmlWriter.writeStartElement(CppcheckXml::CheckLevelExhaustiveElementName);
997+
xmlWriter.writeEndElement();
998+
}
999+
9811000
// Cppcheck Premium
9821001
if (mBughunting) {
9831002
xmlWriter.writeStartElement(CppcheckXml::BughuntingElementName);

gui/projectfile.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class ProjectFile : public QObject {
5353
if (this == mActiveProject) mActiveProject = nullptr;
5454
}
5555

56+
enum class CheckLevel {
57+
normal,
58+
exhaustive
59+
};
60+
5661
static ProjectFile* getActiveProject() {
5762
return mActiveProject;
5863
}
@@ -329,6 +334,10 @@ class ProjectFile : public QObject {
329334
*/
330335
void setVSConfigurations(const QStringList &vsConfigs);
331336

337+
/** CheckLevel: normal/exhaustive */
338+
void setCheckLevel(CheckLevel checkLevel);
339+
bool isCheckLevelExhaustive() const;
340+
332341
/**
333342
* @brief Set tags.
334343
* @param tags tag list
@@ -587,7 +596,10 @@ class ProjectFile : public QObject {
587596
*/
588597
QStringList mAddons;
589598

590-
bool mBughunting;
599+
bool mBughunting = false;
600+
601+
/** @brief Should Cppcheck run normal or exhaustive analysis? */
602+
CheckLevel mCheckLevel = CheckLevel::normal;
591603

592604
/**
593605
* @brief List of coding standards, checked by Cppcheck Premium.
@@ -597,6 +609,7 @@ class ProjectFile : public QObject {
597609
/** @brief Project name, used when generating compliance report */
598610
QString mProjectName;
599611

612+
/** @brief Cppcheck Premium: This value is passed to the Cert C checker if that is enabled */
600613
int mCertIntPrecision;
601614

602615
/** @brief Execute clang analyzer? */

gui/projectfile.ui

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>940</width>
10-
<height>617</height>
10+
<height>701</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -402,7 +402,7 @@
402402
<attribute name="title">
403403
<string>Analysis</string>
404404
</attribute>
405-
<layout class="QVBoxLayout" name="verticalLayout_18">
405+
<layout class="QVBoxLayout" name="verticalLayout_22">
406406
<item>
407407
<widget class="QGroupBox" name="groupBox_2">
408408
<property name="title">
@@ -452,6 +452,29 @@
452452
</layout>
453453
</widget>
454454
</item>
455+
<item>
456+
<widget class="QGroupBox" name="groupBox_13">
457+
<property name="title">
458+
<string>Check level</string>
459+
</property>
460+
<layout class="QVBoxLayout" name="verticalLayout_18">
461+
<item>
462+
<widget class="QRadioButton" name="mCheckLevelNormal">
463+
<property name="text">
464+
<string>Normal -- meant for normal analysis in CI. Analysis should finish in reasonable time.</string>
465+
</property>
466+
</widget>
467+
</item>
468+
<item>
469+
<widget class="QRadioButton" name="mCheckLevelExhaustive">
470+
<property name="text">
471+
<string>Exhaustive -- meant for nightly builds etc. Analysis time can be longer (10x slower than compilation is OK).</string>
472+
</property>
473+
</widget>
474+
</item>
475+
</layout>
476+
</widget>
477+
</item>
455478
<item>
456479
<widget class="QGroupBox" name="groupBox_11">
457480
<property name="title">

gui/projectfiledialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
307307
else
308308
item->setCheckState(Qt::Unchecked);
309309
}
310+
if (projectFile->isCheckLevelExhaustive())
311+
mUI->mCheckLevelExhaustive->setChecked(true);
312+
else
313+
mUI->mCheckLevelNormal->setChecked(true);
310314
mUI->mCheckHeaders->setChecked(projectFile->getCheckHeaders());
311315
mUI->mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
312316
mUI->mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
@@ -428,6 +432,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
428432
projectFile->setCheckPaths(getCheckPaths());
429433
projectFile->setExcludedPaths(getExcludedPaths());
430434
projectFile->setLibraries(getLibraries());
435+
projectFile->setCheckLevel(mUI->mCheckLevelExhaustive->isChecked() ? ProjectFile::CheckLevel::exhaustive : ProjectFile::CheckLevel::normal);
431436
projectFile->clangParser = mUI->mBtnClangParser->isChecked();
432437
projectFile->safeChecks.classes = mUI->mBtnSafeClasses->isChecked();
433438
if (mUI->mComboBoxPlatform->currentText().endsWith(".xml"))

lib/importproject.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
11471147

11481148
guiProject.analyzeAllVsConfigs.clear();
11491149

1150+
bool checkLevelExhaustive = false;
1151+
11501152
// TODO: this should support all available command-line options
11511153
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
11521154
if (strcmp(node->Name(), CppcheckXml::RootPathName) == 0) {
@@ -1216,6 +1218,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
12161218
}
12171219
} else if (strcmp(node->Name(), CppcheckXml::CheckHeadersElementName) == 0)
12181220
temp.checkHeaders = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
1221+
else if (strcmp(node->Name(), CppcheckXml::CheckLevelExhaustiveElementName) == 0)
1222+
checkLevelExhaustive = true;
12191223
else if (strcmp(node->Name(), CppcheckXml::CheckUnusedTemplatesElementName) == 0)
12201224
temp.checkUnusedTemplates = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
12211225
else if (strcmp(node->Name(), CppcheckXml::MaxCtuDepthElementName) == 0)
@@ -1281,6 +1285,11 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
12811285
settings->maxTemplateRecursion = temp.maxTemplateRecursion;
12821286
settings->safeChecks = temp.safeChecks;
12831287

1288+
if (checkLevelExhaustive)
1289+
settings->setCheckLevelExhaustive();
1290+
else
1291+
settings->setCheckLevelNormal();
1292+
12841293
return true;
12851294
}
12861295

lib/importproject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ namespace CppcheckXml {
172172
const char TagAttributeName[] = "tag";
173173
const char WarningElementName[] = "warning";
174174
const char HashAttributeName[] = "hash";
175+
const char CheckLevelExhaustiveElementName[] = "check-level-exhaustive";
175176
const char CheckHeadersElementName[] = "check-headers";
176177
const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
177178
const char MaxCtuDepthElementName[] = "max-ctu-depth";

0 commit comments

Comments
 (0)