GUI: Use --cli option when running addons to get results in json format

This commit is contained in:
Daniel Marjamäki 2019-06-25 01:22:41 +02:00
parent 5d58b14db8
commit b0e56f873f
1 changed files with 29 additions and 11 deletions

View File

@ -21,6 +21,8 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include "checkthread.h" #include "checkthread.h"
@ -295,7 +297,7 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
} }
QStringList args; QStringList args;
args << addonFilePath << dumpFile; args << addonFilePath << "--cli" << dumpFile;
if (addon == "misra" && !mMisraFile.isEmpty() && QFileInfo(mMisraFile).exists()) { if (addon == "misra" && !mMisraFile.isEmpty() && QFileInfo(mMisraFile).exists()) {
if (mMisraFile.endsWith(".pdf", Qt::CaseInsensitive)) if (mMisraFile.endsWith(".pdf", Qt::CaseInsensitive))
args << "--misra-pdf=" + mMisraFile; args << "--misra-pdf=" + mMisraFile;
@ -312,14 +314,14 @@ void CheckThread::runAddonsAndTools(const ImportProject::FileSettings *fileSetti
} }
process.start(python, args); process.start(python, args);
process.waitForFinished(); process.waitForFinished();
const QString errout(process.readAllStandardError()); const QString output(process.readAllStandardOutput());
QFile f(dumpFile + '-' + addon + "-results"); QFile f(dumpFile + '-' + addon + "-results");
if (f.open(QIODevice::WriteOnly | QIODevice::Text)) { if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&f); QTextStream out(&f);
out << errout; out << output;
f.close(); f.close();
} }
parseAddonErrors(errout, addon); parseAddonErrors(output, addon);
} }
} }
} }
@ -336,17 +338,33 @@ void CheckThread::parseAddonErrors(QString err, const QString &tool)
QTextStream in(&err, QIODevice::ReadOnly); QTextStream in(&err, QIODevice::ReadOnly);
while (!in.atEnd()) { while (!in.atEnd()) {
QString line = in.readLine(); QString line = in.readLine();
QRegExp r1("\\[([a-zA-Z]?:?[^:]+):([0-9]+)\\]:?[ ][(]([a-z]+)[)]:? (.+) \\[([a-zA-Z0-9_\\-\\.]+)\\]"); if (!line.startsWith("{"))
if (!r1.exactMatch(line))
continue; continue;
const std::string &filename = r1.cap(1).toStdString();
const int lineNumber = r1.cap(2).toInt(); const QJsonDocument doc = QJsonDocument::fromJson(line.toLocal8Bit());
const std::string severity = r1.cap(3).toStdString(); const QJsonObject obj = doc.object();
const std::string message = r1.cap(4).toStdString();
const std::string id = r1.cap(5).toStdString(); /*
msg = { 'file': location.file,
'linenr': location.linenr,
'col': location.col,
'severity': severity,
'message': message,
'addon': addon,
'errorId': errorId,
'extra': extra}
*/
const std::string &filename = obj["file"].toString().toStdString();
const int lineNumber = obj["linenr"].toInt();
const int column = obj["col"].toInt();
const std::string severity = obj["severity"].toString().toStdString();
const std::string message = obj["message"].toString().toStdString();
const std::string id = obj["errorId"].toString().toStdString();
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack; std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber)); callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(filename, lineNumber));
callstack.back().col = column;
ErrorLogger::ErrorMessage errmsg(callstack, filename, Severity::fromString(severity), message, id, false); ErrorLogger::ErrorMessage errmsg(callstack, filename, Severity::fromString(severity), message, id, false);
mResult.reportErr(errmsg); mResult.reportErr(errmsg);
} }