The GUI was asserting when addons were specified in the `cppcheck.cfg` since we did not generate the info for them.
This commit is contained in:
parent
6aa3478243
commit
3fc62ce10b
|
@ -905,7 +905,43 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
|
|||
return true;
|
||||
}
|
||||
|
||||
Settings MainWindow::getCppcheckSettings() {
|
||||
void MainWindow::loadAddon(Settings &settings, const QString &filesDir, const QString &pythonCmd, const QString& addon)
|
||||
{
|
||||
QString addonFilePath = ProjectFile::getAddonFilePath(filesDir, addon);
|
||||
if (addonFilePath.isEmpty())
|
||||
return; // TODO: report an error
|
||||
|
||||
addonFilePath.replace(QChar('\\'), QChar('/'));
|
||||
|
||||
picojson::object obj;
|
||||
obj["script"] = picojson::value(addonFilePath.toStdString());
|
||||
if (!pythonCmd.isEmpty())
|
||||
obj["python"] = picojson::value(pythonCmd.toStdString());
|
||||
|
||||
if (!isCppcheckPremium() && addon == "misra") {
|
||||
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
|
||||
if (!misraFile.isEmpty()) {
|
||||
QString arg;
|
||||
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
|
||||
arg = "--misra-pdf=" + misraFile;
|
||||
else
|
||||
arg = "--rule-texts=" + misraFile;
|
||||
obj["args"] = picojson::value(arg.toStdString());
|
||||
}
|
||||
}
|
||||
picojson::value json;
|
||||
json.set(std::move(obj));
|
||||
std::string json_str = json.serialize();
|
||||
|
||||
AddonInfo addonInfo;
|
||||
addonInfo.getAddonInfo(json_str, settings.exename); // TODO: handle error
|
||||
settings.addonInfos.emplace_back(std::move(addonInfo));
|
||||
|
||||
settings.addons.emplace(std::move(json_str));
|
||||
}
|
||||
|
||||
Settings MainWindow::getCppcheckSettings()
|
||||
{
|
||||
saveSettings(); // Save settings
|
||||
|
||||
Settings result;
|
||||
|
@ -916,10 +952,20 @@ Settings MainWindow::getCppcheckSettings() {
|
|||
if (!std)
|
||||
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir=<directory> at the command line to specify where this file is located. Please note that --data-dir is supposed to be used by installation scripts and therefore the GUI does not start when it is used, all that happens is that the setting is configured.").arg("std.cfg"));
|
||||
|
||||
const QString filesDir(getDataDir());
|
||||
const QString pythonCmd = fromNativePath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
|
||||
|
||||
{
|
||||
const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg());
|
||||
if (!cfgErr.isEmpty())
|
||||
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2").arg("cppcheck.cfg").arg(cfgErr));
|
||||
|
||||
const auto cfgAddons = result.addons;
|
||||
result.addons.clear();
|
||||
for (const std::string& addon : cfgAddons) {
|
||||
// TODO: support addons which are a script and not a file
|
||||
loadAddon(result, filesDir, pythonCmd, QString::fromStdString(addon));
|
||||
}
|
||||
}
|
||||
|
||||
// If project file loaded, read settings from it
|
||||
|
@ -998,40 +1044,8 @@ Settings MainWindow::getCppcheckSettings() {
|
|||
for (const QString& s : mProjectFile->getCheckUnknownFunctionReturn())
|
||||
result.checkUnknownFunctionReturn.insert(s.toStdString());
|
||||
|
||||
QString filesDir(getDataDir());
|
||||
const QString pythonCmd = fromNativePath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
|
||||
for (const QString& addon : mProjectFile->getAddons()) {
|
||||
QString addonFilePath = ProjectFile::getAddonFilePath(filesDir, addon);
|
||||
if (addonFilePath.isEmpty())
|
||||
continue;
|
||||
|
||||
addonFilePath.replace(QChar('\\'), QChar('/'));
|
||||
|
||||
picojson::object obj;
|
||||
obj["script"] = picojson::value(addonFilePath.toStdString());
|
||||
if (!pythonCmd.isEmpty())
|
||||
obj["python"] = picojson::value(pythonCmd.toStdString());
|
||||
|
||||
if (!isCppcheckPremium() && addon == "misra") {
|
||||
const QString misraFile = fromNativePath(mSettings->value(SETTINGS_MISRA_FILE).toString());
|
||||
if (!misraFile.isEmpty()) {
|
||||
QString arg;
|
||||
if (misraFile.endsWith(".pdf", Qt::CaseInsensitive))
|
||||
arg = "--misra-pdf=" + misraFile;
|
||||
else
|
||||
arg = "--rule-texts=" + misraFile;
|
||||
obj["args"] = picojson::value(arg.toStdString());
|
||||
}
|
||||
}
|
||||
picojson::value json;
|
||||
json.set(std::move(obj));
|
||||
std::string json_str = json.serialize();
|
||||
|
||||
AddonInfo addonInfo;
|
||||
addonInfo.getAddonInfo(json_str, result.exename);
|
||||
result.addonInfos.emplace_back(std::move(addonInfo));
|
||||
|
||||
result.addons.emplace(std::move(json_str));
|
||||
loadAddon(result, filesDir, pythonCmd, addon);
|
||||
}
|
||||
|
||||
if (isCppcheckPremium()) {
|
||||
|
|
|
@ -401,6 +401,8 @@ private:
|
|||
*/
|
||||
bool tryLoadLibrary(Library *library, const QString& filename);
|
||||
|
||||
void loadAddon(Settings &settings, const QString &filesDir, const QString &pythonCmd, const QString& addon);
|
||||
|
||||
/**
|
||||
* @brief Update project MRU items in File-menu.
|
||||
*/
|
||||
|
|
|
@ -33,3 +33,4 @@ Other:
|
|||
- fixed CMake build with UBSAN and GCC
|
||||
- Added command-line options "--fsigned-char" and "--funsigned-char" to control the signess of the "char" type. This overrides previously specified "--platform" options and is overrides by following ones.
|
||||
- An error is now reported when the "cppcheck.cfg" is invalid. The CLI version will also exit with a failure in that case.
|
||||
- Fixed loading of addons from "cppcheck.cfg" in the GUI application.
|
Loading…
Reference in New Issue