Load cppcheck.cfg in FILESDIR if that is specified

This commit is contained in:
Daniel Marjamäki 2021-11-05 20:37:48 +01:00
parent b2f1a0aaa9
commit ed4d2c21e6
4 changed files with 12 additions and 8 deletions

View File

@ -917,7 +917,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
}
mSettings->loadCppcheckCfg(Path::getPathFromFilename(argv[0]) + "cppcheck.cfg");
mSettings->loadCppcheckCfg(argv[0]);
// Default template format..
if (mSettings->templateFormat.empty()) {

View File

@ -508,9 +508,7 @@ 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");
checkSettings.loadCppcheckCfg(QCoreApplication::applicationFilePath().toStdString());
if (mProjectFile)
qDebug() << "Checking project file" << mProjectFile->getFilename();

View File

@ -76,9 +76,15 @@ Settings::Settings()
certainty.setEnabled(Certainty::normal, true);
}
void Settings::loadCppcheckCfg(const std::string &filename)
void Settings::loadCppcheckCfg(const std::string &exename)
{
std::ifstream fin(filename);
std::string fileName = Path::getPathFromFilename(exename) + "cppcheck.cfg";
#ifdef FILESDIR
if (Path::fileExists(FILESDIR "/cppcheck.cfg"))
fileName = FILESDIR "/cppcheck.cfg";
#endif
std::ifstream fin(fileName);
if (!fin.is_open())
return;
picojson::value json;
@ -90,7 +96,7 @@ void Settings::loadCppcheckCfg(const std::string &filename)
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);
addons.push_back(Path::getPathFromFilename(fileName) + s);
else
addons.push_back(s);
}

View File

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