Skip to content

Commit

Permalink
Fix #12456 (GUI: unable to suppress warnings in "externals/*" headers)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Apr 8, 2024
1 parent bd8cb94 commit 57d5d1a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
mThread->setFiles(fileNames);
if (mProjectFile && !checkConfiguration)
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools());
mThread->setSuppressions(mProjectFile ? mProjectFile->getSuppressions() : QList<SuppressionList::Suppression>());
mThread->setSuppressions(mProjectFile ? mProjectFile->getCheckingSuppressions() : QList<SuppressionList::Suppression>());
QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath();
setPath(SETTINGS_LAST_CHECK_PATH, checkPath);
Expand Down Expand Up @@ -1022,7 +1022,7 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
tryLoadLibrary(&result.library, filename);
}

for (const SuppressionList::Suppression &suppression : mProjectFile->getSuppressions()) {
for (const SuppressionList::Suppression &suppression : mProjectFile->getCheckingSuppressions()) {
result.supprs.nomsg.addSuppression(suppression);
}

Expand Down
14 changes: 14 additions & 0 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QDir>
#include <QIODevice>
#include <QLatin1String>
#include <QRegularExpression>
#include <QXmlStreamAttributes>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
Expand Down Expand Up @@ -756,6 +757,19 @@ void ProjectFile::setPlatform(const QString &platform)
mPlatform = platform;
}

QList<SuppressionList::Suppression> ProjectFile::getCheckingSuppressions() const
{
QRegularExpression re("^[^:]+/.*");
QList<SuppressionList::Suppression> result;
for (SuppressionList::Suppression suppression : mSuppressions) {
if (re.match(suppression.fileName.c_str()).hasMatch()) {
suppression.fileName = QFileInfo(mFilename).absolutePath().toStdString() + "/" + suppression.fileName;
}
result << suppression;
}
return result;
}

void ProjectFile::setSuppressions(const QList<SuppressionList::Suppression> &suppressions)
{
mSuppressions = suppressions;
Expand Down
6 changes: 6 additions & 0 deletions gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ class ProjectFile : public QObject {
return mSuppressions;
}

/**
* @brief Get "checking" suppressions. Relative paths are converted to absolute paths.
* @return list of suppressions.
*/
QList<SuppressionList::Suppression> getCheckingSuppressions() const;

/**
* @brief Get list addons.
* @return list of addons.
Expand Down
12 changes: 12 additions & 0 deletions gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <string>

#include <QDir>
#include <QFile>
#include <QIODevice>
#include <QList>
Expand Down Expand Up @@ -138,4 +139,15 @@ void TestProjectFile::getAddonFilePath() const
QCOMPARE(ProjectFile::getAddonFilePath(tempdir.path(), filepath), filepath);
}

void TestProjectFile::getCheckingSuppressions() const
{
const SuppressionList::Suppression suppression("*", "externals/*");
const QList<SuppressionList::Suppression> suppressions{suppression};
ProjectFile projectFile;
projectFile.setFilename("/some/path/123.cppcheck");
projectFile.setSuppressions(suppressions);
QCOMPARE(projectFile.getCheckingSuppressions()[0].fileName, "/some/path/externals/*");
}

QTEST_MAIN(TestProjectFile)

2 changes: 2 additions & 0 deletions gui/test/projectfile/testprojectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ private slots:
void loadSimpleNoroot() const;

void getAddonFilePath() const;

void getCheckingSuppressions() const;
};

0 comments on commit 57d5d1a

Please sign in to comment.