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:
parent
48d5f47e73
commit
0a5b7b2af5
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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...
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue