diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 78c0abb2e..0b8fd6971 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -30,7 +30,6 @@ #include "mainwindow.h" #include "cppcheck.h" -#include "path.h" #include "applicationlist.h" #include "aboutdialog.h" @@ -59,19 +58,6 @@ static QString getDataDir(const QSettings *settings) return dataDir.isEmpty() ? appPath : dataDir; } -static QList getCheckSuppressions(const ProjectFile &project) -{ - QList ret; - const std::string projectFilePath = Path::getPathFromFilename(project.getFilename().toStdString()); - foreach (Suppressions::Suppression suppression, project.getSuppressions()) { - if (!suppression.fileName.empty() && suppression.fileName[0]!='*' && !Path::isAbsolute(suppression.fileName)) - suppression.fileName = Path::simplifyPath(projectFilePath) + suppression.fileName; - - ret.append(suppression); - } - return ret; -} - MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mSettings(settings), mApplications(new ApplicationList(this)), @@ -458,7 +444,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString()); QString clangHeaders = mSettings->value(SETTINGS_VS_INCLUDE_PATHS).toString(); mThread->setClangIncludePaths(clangHeaders.split(";")); - mThread->setSuppressions(getCheckSuppressions(*mProjectFile)); + mThread->setSuppressions(mProjectFile->getCheckSuppressions()); } mThread->setProject(p); mThread->check(checkSettings); @@ -857,8 +843,7 @@ Settings MainWindow::getCppcheckSettings() tryLoadLibrary(&result.library, filename); } - - foreach (const Suppressions::Suppression &suppression, getCheckSuppressions(*mProjectFile)) { + foreach (const Suppressions::Suppression &suppression, mProjectFile->getCheckSuppressions()) { result.nomsg.addSuppression(suppression); } diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 22796f633..58a4f406b 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -25,6 +25,8 @@ #include "projectfile.h" #include "common.h" +#include "path.h" + static const char ProjectElementName[] = "project"; static const char ProjectVersionAttrib[] = "version"; static const char ProjectFileVersion[] = "1"; @@ -596,6 +598,19 @@ void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &read } while (!allRead); } +QList ProjectFile::getCheckSuppressions() const +{ + QList ret; + const std::string projectFilePath = Path::getPathFromFilename(mFilename.toStdString()); + foreach (Suppressions::Suppression suppression, getSuppressions()) { + if (!suppression.fileName.empty() && suppression.fileName[0]!='*' && !Path::isAbsolute(suppression.fileName)) + suppression.fileName = Path::simplifyPath(projectFilePath) + suppression.fileName; + + ret.append(suppression); + } + return ret; +} + void ProjectFile::setIncludes(const QStringList &includes) { mIncludeDirs = includes; diff --git a/gui/projectfile.h b/gui/projectfile.h index def99eaee..4f775beb4 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -141,13 +141,19 @@ public: } /** - * @brief Get list suppressions. + * @brief Get "raw" suppressions. * @return list of suppressions. */ QList getSuppressions() const { return mSuppressions; } + /** + * @brief Get "check" suppressions. + * @return list of suppressions. + */ + QList getCheckSuppressions() const; + /** * @brief Get list addons. * @return list of addons. diff --git a/gui/test/projectfile/projectfile.pro b/gui/test/projectfile/projectfile.pro index 5284dc969..71ab388ad 100644 --- a/gui/test/projectfile/projectfile.pro +++ b/gui/test/projectfile/projectfile.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = test-projectfile DEPENDPATH += . -INCLUDEPATH += . +INCLUDEPATH += . ../../../externals/simplecpp OBJECTS_DIR = ../build MOC_DIR = ../build @@ -11,7 +11,11 @@ DEFINES += SRCDIR=\\\"$$PWD\\\" # tests SOURCES += testprojectfile.cpp \ - ../../projectfile.cpp + ../../projectfile.cpp \ + ../../../lib/path.cpp \ + ../../../externals/simplecpp/simplecpp.cpp HEADERS += testprojectfile.h \ - ../../projectfile.h + ../../projectfile.h \ + ../../../lib/path.h \ + ../../../externals/simplecpp/simplecpp.h diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp index 4fd0c14b7..5fb11c4e1 100644 --- a/gui/test/projectfile/testprojectfile.cpp +++ b/gui/test/projectfile/testprojectfile.cpp @@ -94,4 +94,18 @@ void TestProjectFile::loadSimpleNoroot() QCOMPARE(defines[0], QString("FOO")); } +void TestProjectFile::checkSuppressions() +{ + ProjectFile projectFile("/foo/bar/test.cppcheck"); + QList suppressions; + suppressions.append(Suppressions::Suppression("id", "file.c")); + suppressions.append(Suppressions::Suppression("id", "/abc/file.c")); + projectFile.setSuppressions(suppressions); + + const QList s = projectFile.getCheckSuppressions(); + QCOMPARE(s.size(), 2); + QCOMPARE(s[0].fileName, std::string("/foo/bar/file.c")); + QCOMPARE(s[1].fileName, std::string("/abc/file.c")); +} + QTEST_MAIN(TestProjectFile) diff --git a/gui/test/projectfile/testprojectfile.h b/gui/test/projectfile/testprojectfile.h index 56a321761..356947f27 100644 --- a/gui/test/projectfile/testprojectfile.h +++ b/gui/test/projectfile/testprojectfile.h @@ -27,4 +27,5 @@ private slots: void loadSimple(); void loadSimpleWithIgnore(); void loadSimpleNoroot(); + void checkSuppressions(); };