Make it possible to configure default addons in a cppcheck.cfg file.

Example:
{
    "addons":["cert"]
}

With that cppcheck.cfg file cppcheck will always run the "cert" addon. Explicit options such as --addon=cert will not be needed.
This commit is contained in:
Daniel Marjamäki 2021-10-13 20:02:48 +02:00
parent 935c9349f3
commit d053f8ba23
5 changed files with 47 additions and 1 deletions

View File

@ -121,6 +121,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mSettings->exename = argv[0];
mSettings->loadCppcheckCfg(Path::getPathFromFilename(argv[0]) + "cppcheck.cfg");
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
// User define

View File

@ -508,6 +508,10 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
checkSettings.checkLibrary = checkLibrary;
checkSettings.checkConfiguration = checkConfiguration;
const QString applicationFilePath = QCoreApplication::applicationFilePath();
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
checkSettings.loadCppcheckCfg(appPath.toStdString() + "/cppcheck.cfg");
if (mProjectFile)
qDebug() << "Checking project file" << mProjectFile->getFilename();

View File

@ -92,8 +92,15 @@ void ThreadHandler::check(const Settings &settings)
mRunningThreadCount = mResults.getFileCount();
}
QStringList addonsAndTools = mAddonsAndTools;
for (const std::string& addon: settings.addons) {
QString s = QString::fromStdString(addon);
if (!addonsAndTools.contains(s))
addonsAndTools << s;
}
for (int i = 0; i < mRunningThreadCount; i++) {
mThreads[i]->setAddonsAndTools(mAddonsAndTools);
mThreads[i]->setAddonsAndTools(addonsAndTools);
mThreads[i]->setSuppressions(mSuppressions);
mThreads[i]->setClangIncludePaths(mClangIncludePaths);
mThreads[i]->setDataDir(mDataDir);

View File

@ -17,9 +17,15 @@
*/
#include "settings.h"
#include "path.h"
#include "summaries.h"
#include "valueflow.h"
#include <fstream>
#define PICOJSON_USE_INT64
#include <picojson.h>
std::atomic<bool> Settings::mTerminated;
const char Settings::SafeChecks::XmlRootName[] = "safe-checks";
@ -70,6 +76,31 @@ Settings::Settings()
certainty.setEnabled(Certainty::normal, true);
}
void Settings::loadCppcheckCfg(const std::string &filename)
{
std::ifstream fin(filename);
if (!fin.is_open())
return;
picojson::value json;
fin >> json;
if (!picojson::get_last_error().empty())
return;
picojson::object obj = json.get<picojson::object>();
if (obj.count("addons") && obj["addons"].is<picojson::array>()) {
for (const picojson::value &v : obj["addons"].get<picojson::array>()) {
const std::string &s = v.get<std::string>();
if (!Path::isAbsolute(s))
addons.push_back(Path::getPathFromFilename(filename) + s);
else
addons.push_back(s);
}
}
if (obj.count("suppressions") && obj["suppressions"].is<picojson::array>()) {
for (const picojson::value &v : obj["suppressions"].get<picojson::array>())
nomsg.addSuppressionLine(v.get<std::string>());
}
}
std::string Settings::addEnabled(const std::string &str)
{
// Enable parameters may be comma separated...

View File

@ -95,6 +95,8 @@ private:
public:
Settings();
void loadCppcheckCfg(const std::string &filename);
/** @brief addons, either filename of python/json file or json data */
std::list<std::string> addons;