Skip to content

Commit

Permalink
GUI: Add check level choice in project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jun 28, 2023
1 parent 4f71bbe commit 4fe04bc
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,10 @@ Settings MainWindow::getCppcheckSettings()

result.maxCtuDepth = mProjectFile->getMaxCtuDepth();
result.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
if (mProjectFile->isCheckLevelExhaustive())
result.setCheckLevelExhaustive();
else
result.setCheckLevelNormal();
result.checkHeaders = mProjectFile->getCheckHeaders();
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
result.safeChecks.classes = mProjectFile->safeChecks.classes;
Expand Down
19 changes: 19 additions & 0 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void ProjectFile::clear()
{
const Settings settings;
clangParser = false;
mCheckLevel = CheckLevel::normal;
mRootPath.clear();
mBuildDir.clear();
mImportProject.clear();
Expand Down Expand Up @@ -141,6 +142,9 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
mCheckUnusedTemplates = readBool(xmlReader);

if (xmlReader.name() == QString(CppcheckXml::CheckLevelExhaustiveElementName))
mCheckLevel = CheckLevel::exhaustive;

// Find include directory from inside project element
if (xmlReader.name() == QString(CppcheckXml::IncludeDirElementName))
readIncludeDirs(xmlReader);
Expand Down Expand Up @@ -780,6 +784,16 @@ void ProjectFile::setVSConfigurations(const QStringList &vsConfigs)
mVsConfigurations = vsConfigs;
}

void ProjectFile::setCheckLevel(ProjectFile::CheckLevel checkLevel)
{
mCheckLevel = checkLevel;
}

bool ProjectFile::isCheckLevelExhaustive() const
{
return mCheckLevel == CheckLevel::exhaustive;
}

void ProjectFile::setWarningTags(std::size_t hash, const QString& tags)
{
if (tags.isEmpty())
Expand Down Expand Up @@ -978,6 +992,11 @@ bool ProjectFile::write(const QString &filename)
}
}

if (mCheckLevel == CheckLevel::exhaustive) {
xmlWriter.writeStartElement(CppcheckXml::CheckLevelExhaustiveElementName);
xmlWriter.writeEndElement();
}

// Cppcheck Premium
if (mBughunting) {
xmlWriter.writeStartElement(CppcheckXml::BughuntingElementName);
Expand Down
15 changes: 14 additions & 1 deletion gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class ProjectFile : public QObject {
if (this == mActiveProject) mActiveProject = nullptr;
}

enum class CheckLevel {
normal,
exhaustive
};

static ProjectFile* getActiveProject() {
return mActiveProject;
}
Expand Down Expand Up @@ -329,6 +334,10 @@ class ProjectFile : public QObject {
*/
void setVSConfigurations(const QStringList &vsConfigs);

/** CheckLevel: normal/exhaustive */
void setCheckLevel(CheckLevel checkLevel);
bool isCheckLevelExhaustive() const;

/**
* @brief Set tags.
* @param tags tag list
Expand Down Expand Up @@ -587,7 +596,10 @@ class ProjectFile : public QObject {
*/
QStringList mAddons;

bool mBughunting;
bool mBughunting = false;

/** @brief Should Cppcheck run normal or exhaustive analysis? */
CheckLevel mCheckLevel = CheckLevel::normal;

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

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

/** @brief Execute clang analyzer? */
Expand Down
25 changes: 24 additions & 1 deletion gui/projectfile.ui
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
<attribute name="title">
<string>Analysis</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_18">
<layout class="QVBoxLayout" name="verticalLayout_22">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
Expand Down Expand Up @@ -452,6 +452,29 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_13">
<property name="title">
<string>Check level</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QRadioButton" name="mCheckLevelNormal">
<property name="text">
<string>Normal : meant for normal analysis in CI. Analysis should finish in reasonable time.</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mCheckLevelExhaustive">
<property name="text">
<string>Exhaustive -- meant for nightly builds etc. Analysis time can be longer (10x slower than compilation is OK).</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_11">
<property name="title">
Expand Down
5 changes: 5 additions & 0 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
else
item->setCheckState(Qt::Unchecked);
}
if (projectFile->isCheckLevelExhaustive())
mUI->mCheckLevelExhaustive->setChecked(true);
else
mUI->mCheckLevelNormal->setChecked(true);
mUI->mCheckHeaders->setChecked(projectFile->getCheckHeaders());
mUI->mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
mUI->mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
Expand Down Expand Up @@ -428,6 +432,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setCheckPaths(getCheckPaths());
projectFile->setExcludedPaths(getExcludedPaths());
projectFile->setLibraries(getLibraries());
projectFile->setCheckLevel(mUI->mCheckLevelExhaustive->isChecked() ? ProjectFile::CheckLevel::exhaustive : ProjectFile::CheckLevel::normal);
projectFile->clangParser = mUI->mBtnClangParser->isChecked();
projectFile->safeChecks.classes = mUI->mBtnSafeClasses->isChecked();
if (mUI->mComboBoxPlatform->currentText().endsWith(".xml"))
Expand Down
9 changes: 9 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti

guiProject.analyzeAllVsConfigs.clear();

bool checkLevelExhaustive = false;

// TODO: this should support all available command-line options
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(), CppcheckXml::RootPathName) == 0) {
Expand Down Expand Up @@ -1216,6 +1218,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
}
} else if (strcmp(node->Name(), CppcheckXml::CheckHeadersElementName) == 0)
temp.checkHeaders = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
else if (strcmp(node->Name(), CppcheckXml::CheckLevelExhaustiveElementName) == 0)
checkLevelExhaustive = true;
else if (strcmp(node->Name(), CppcheckXml::CheckUnusedTemplatesElementName) == 0)
temp.checkUnusedTemplates = (strcmp(readSafe(node->GetText(), ""), "true") == 0);
else if (strcmp(node->Name(), CppcheckXml::MaxCtuDepthElementName) == 0)
Expand Down Expand Up @@ -1281,6 +1285,11 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
settings->maxTemplateRecursion = temp.maxTemplateRecursion;
settings->safeChecks = temp.safeChecks;

if (checkLevelExhaustive)
settings->setCheckLevelExhaustive();
else
settings->setCheckLevelNormal();

return true;
}

Expand Down
1 change: 1 addition & 0 deletions lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ namespace CppcheckXml {
const char TagAttributeName[] = "tag";
const char WarningElementName[] = "warning";
const char HashAttributeName[] = "hash";
const char CheckLevelExhaustiveElementName[] = "check-level-exhaustive";
const char CheckHeadersElementName[] = "check-headers";
const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
const char MaxCtuDepthElementName[] = "max-ctu-depth";
Expand Down

0 comments on commit 4fe04bc

Please sign in to comment.