Fix #11787 (GUI: configure check level) (#5206)

This commit is contained in:
Daniel Marjamäki 2023-06-28 19:55:57 +02:00 committed by GitHub
parent 55af68aaf7
commit 1b4ec0def4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 3 deletions

View File

@ -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;

View File

@ -58,6 +58,7 @@ void ProjectFile::clear()
{
const Settings settings;
clangParser = false;
mCheckLevel = CheckLevel::normal;
mRootPath.clear();
mBuildDir.clear();
mImportProject.clear();
@ -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);
@ -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())
@ -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);

View File

@ -53,6 +53,11 @@ public:
if (this == mActiveProject) mActiveProject = nullptr;
}
enum class CheckLevel {
normal,
exhaustive
};
static ProjectFile* getActiveProject() {
return mActiveProject;
}
@ -329,6 +334,10 @@ public:
*/
void setVSConfigurations(const QStringList &vsConfigs);
/** CheckLevel: normal/exhaustive */
void setCheckLevel(CheckLevel checkLevel);
bool isCheckLevelExhaustive() const;
/**
* @brief Set tags.
* @param tags tag list
@ -587,7 +596,10 @@ private:
*/
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.
@ -597,6 +609,7 @@ private:
/** @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? */

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>940</width>
<height>617</height>
<height>701</height>
</rect>
</property>
<property name="windowTitle">
@ -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">
@ -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">

View File

@ -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());
@ -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"))

View File

@ -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) {
@ -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)
@ -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;
}

View File

@ -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";