Refactor load/write of cppcheck project. Reuse same string constants in cli and gui.

This commit is contained in:
Daniel Marjamäki 2019-08-09 21:15:02 +02:00
parent 16dc8a0540
commit 0fbbe2ff23
4 changed files with 165 additions and 204 deletions

View File

@ -545,10 +545,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
ImportProject::Type projType = mSettings->project.import(projectFile, mSettings);
if (projType == ImportProject::Type::CPPCHECK_GUI) {
mPathNames = mSettings->project.guiProject.pathNames;
for (const std::string &lib : mSettings->project.guiProject.libraries) {
if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], lib.c_str()))
return false;
}
for (const std::string &lib : mSettings->project.guiProject.libraries)
mSettings->libraries.push_back(lib);
for (const std::string &ignorePath : mSettings->project.guiProject.excludedPaths)
mIgnoredPaths.emplace_back(ignorePath);

View File

@ -24,52 +24,11 @@
#include <QDir>
#include "projectfile.h"
#include "common.h"
#include "importproject.h"
#include "path.h"
#include "settings.h"
static const char ProjectElementName[] = "project";
static const char ProjectVersionAttrib[] = "version";
static const char ProjectFileVersion[] = "1";
static const char BuildDirElementName[] = "builddir";
static const char ImportProjectElementName[] = "importproject";
static const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
static const char IncludeDirElementName[] = "includedir";
static const char DirElementName[] = "dir";
static const char DirNameAttrib[] = "name";
static const char DefinesElementName[] = "defines";
static const char DefineName[] = "define";
static const char DefineNameAttrib[] = "name";
static const char UndefinesElementName[] = "undefines";
static const char UndefineName[] = "undefine";
static const char PathsElementName[] = "paths";
static const char PathName[] = "dir";
static const char PathNameAttrib[] = "name";
static const char RootPathName[] = "root";
static const char RootPathNameAttrib[] = "name";
static const char IgnoreElementName[] = "ignore";
static const char IgnorePathName[] = "path";
static const char IgnorePathNameAttrib[] = "name";
static const char ExcludeElementName[] = "exclude";
static const char ExcludePathName[] = "path";
static const char ExcludePathNameAttrib[] = "name";
static const char LibrariesElementName[] = "libraries";
static const char LibraryElementName[] = "library";
static const char PlatformElementName[] = "platform";
static const char SuppressionsElementName[] = "suppressions";
static const char SuppressionElementName[] = "suppression";
static const char AddonElementName[] = "addon";
static const char AddonsElementName[] = "addons";
static const char ToolElementName[] = "tool";
static const char ToolsElementName[] = "tools";
static const char TagsElementName[] = "tags";
static const char TagElementName[] = "tag";
static const char CheckHeadersElementName[] = "check-headers";
static const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
static const char MaxCtuDepthElementName[] = "max-ctu-depth";
static const char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
static const char Name[] = "name";
ProjectFile::ProjectFile(QObject *parent) :
QObject(parent)
{
@ -125,7 +84,7 @@ bool ProjectFile::read(const QString &filename)
while (!xmlReader.atEnd()) {
switch (xmlReader.readNext()) {
case QXmlStreamReader::StartElement:
if (xmlReader.name() == ProjectElementName) {
if (xmlReader.name() == CppcheckXml::ProjectElementName) {
insideProject = true;
projectTagFound = true;
break;
@ -134,91 +93,91 @@ bool ProjectFile::read(const QString &filename)
break;
// Read root path from inside project element
if (xmlReader.name() == RootPathName)
if (xmlReader.name() == CppcheckXml::RootPathName)
readRootPath(xmlReader);
// Read root path from inside project element
if (xmlReader.name() == BuildDirElementName)
if (xmlReader.name() == CppcheckXml::BuildDirElementName)
readBuildDir(xmlReader);
// Find paths to check from inside project element
if (xmlReader.name() == PathsElementName)
if (xmlReader.name() == CppcheckXml::PathsElementName)
readCheckPaths(xmlReader);
if (xmlReader.name() == ImportProjectElementName)
if (xmlReader.name() == CppcheckXml::ImportProjectElementName)
readImportProject(xmlReader);
if (xmlReader.name() == AnalyzeAllVsConfigsElementName)
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
mAnalyzeAllVsConfigs = readBool(xmlReader);
if (xmlReader.name() == CheckHeadersElementName)
if (xmlReader.name() == CppcheckXml::CheckHeadersElementName)
mCheckHeaders = readBool(xmlReader);
if (xmlReader.name() == CheckUnusedTemplatesElementName)
if (xmlReader.name() == CppcheckXml::CheckUnusedTemplatesElementName)
mCheckUnusedTemplates = readBool(xmlReader);
// Find include directory from inside project element
if (xmlReader.name() == IncludeDirElementName)
if (xmlReader.name() == CppcheckXml::IncludeDirElementName)
readIncludeDirs(xmlReader);
// Find preprocessor define from inside project element
if (xmlReader.name() == DefinesElementName)
if (xmlReader.name() == CppcheckXml::DefinesElementName)
readDefines(xmlReader);
// Find preprocessor define from inside project element
if (xmlReader.name() == UndefinesElementName)
readStringList(mUndefines, xmlReader, UndefineName);
if (xmlReader.name() == CppcheckXml::UndefinesElementName)
readStringList(mUndefines, xmlReader, CppcheckXml::UndefineName);
// Find exclude list from inside project element
if (xmlReader.name() == ExcludeElementName)
if (xmlReader.name() == CppcheckXml::ExcludeElementName)
readExcludes(xmlReader);
// Find ignore list from inside project element
// These are read for compatibility
if (xmlReader.name() == IgnoreElementName)
if (xmlReader.name() == CppcheckXml::IgnoreElementName)
readExcludes(xmlReader);
// Find libraries list from inside project element
if (xmlReader.name() == LibrariesElementName)
readStringList(mLibraries, xmlReader,LibraryElementName);
if (xmlReader.name() == CppcheckXml::LibrariesElementName)
readStringList(mLibraries, xmlReader, CppcheckXml::LibraryElementName);
if (xmlReader.name() == PlatformElementName)
if (xmlReader.name() == CppcheckXml::PlatformElementName)
readPlatform(xmlReader);
// Find suppressions list from inside project element
if (xmlReader.name() == SuppressionsElementName)
if (xmlReader.name() == CppcheckXml::SuppressionsElementName)
readSuppressions(xmlReader);
// Unknown function return values
if (xmlReader.name() == CheckUnknownFunctionReturn)
readStringList(mCheckUnknownFunctionReturn, xmlReader, Name);
if (xmlReader.name() == CppcheckXml::CheckUnknownFunctionReturn)
readStringList(mCheckUnknownFunctionReturn, xmlReader, CppcheckXml::Name);
// check all function parameter values
if (xmlReader.name() == Settings::SafeChecks::XmlRootName)
mSafeChecks.loadFromXml(xmlReader);
// Addons
if (xmlReader.name() == AddonsElementName)
readStringList(mAddons, xmlReader, AddonElementName);
if (xmlReader.name() == CppcheckXml::AddonsElementName)
readStringList(mAddons, xmlReader, CppcheckXml::AddonElementName);
// Tools
if (xmlReader.name() == ToolsElementName) {
if (xmlReader.name() == CppcheckXml::ToolsElementName) {
QStringList tools;
readStringList(tools, xmlReader, ToolElementName);
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
mClangTidy = tools.contains(CLANG_TIDY);
}
if (insideProject && xmlReader.name() == TagsElementName)
readStringList(mTags, xmlReader, TagElementName);
if (insideProject && xmlReader.name() == CppcheckXml::TagsElementName)
readStringList(mTags, xmlReader, CppcheckXml::TagElementName);
if (insideProject && xmlReader.name() == MaxCtuDepthElementName)
if (insideProject && xmlReader.name() == CppcheckXml::MaxCtuDepthElementName)
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
break;
case QXmlStreamReader::EndElement:
if (xmlReader.name() == ProjectElementName)
if (xmlReader.name() == CppcheckXml::ProjectElementName)
insideProject = false;
break;
@ -243,7 +202,7 @@ bool ProjectFile::read(const QString &filename)
void ProjectFile::readRootPath(QXmlStreamReader &reader)
{
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), RootPathNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::RootPathNameAttrib).toString();
if (!name.isEmpty())
mRootPath = name;
}
@ -358,16 +317,16 @@ void ProjectFile::readIncludeDirs(QXmlStreamReader &reader)
case QXmlStreamReader::StartElement:
// Read dir-elements
if (reader.name().toString() == DirElementName) {
if (reader.name().toString() == CppcheckXml::DirElementName) {
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), DirNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::DirNameAttrib).toString();
if (!name.isEmpty())
mIncludeDirs << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == IncludeDirElementName)
if (reader.name().toString() == CppcheckXml::IncludeDirElementName)
allRead = true;
break;
@ -395,16 +354,16 @@ void ProjectFile::readDefines(QXmlStreamReader &reader)
switch (type) {
case QXmlStreamReader::StartElement:
// Read define-elements
if (reader.name().toString() == DefineName) {
if (reader.name().toString() == CppcheckXml::DefineName) {
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), DefineNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::DefineNameAttrib).toString();
if (!name.isEmpty())
mDefines << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == DefinesElementName)
if (reader.name().toString() == CppcheckXml::DefinesElementName)
allRead = true;
break;
@ -433,16 +392,16 @@ void ProjectFile::readCheckPaths(QXmlStreamReader &reader)
case QXmlStreamReader::StartElement:
// Read dir-elements
if (reader.name().toString() == PathName) {
if (reader.name().toString() == CppcheckXml::PathName) {
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), PathNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::PathNameAttrib).toString();
if (!name.isEmpty())
mPaths << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == PathsElementName)
if (reader.name().toString() == CppcheckXml::PathsElementName)
allRead = true;
break;
@ -470,25 +429,25 @@ void ProjectFile::readExcludes(QXmlStreamReader &reader)
switch (type) {
case QXmlStreamReader::StartElement:
// Read exclude-elements
if (reader.name().toString() == ExcludePathName) {
if (reader.name().toString() == CppcheckXml::ExcludePathName) {
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), ExcludePathNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::ExcludePathNameAttrib).toString();
if (!name.isEmpty())
mExcludedPaths << name;
}
// Read ignore-elements - deprecated but support reading them
else if (reader.name().toString() == IgnorePathName) {
else if (reader.name().toString() == CppcheckXml::IgnorePathName) {
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value(QString(), IgnorePathNameAttrib).toString();
QString name = attribs.value(QString(), CppcheckXml::IgnorePathNameAttrib).toString();
if (!name.isEmpty())
mExcludedPaths << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == IgnoreElementName)
if (reader.name().toString() == CppcheckXml::IgnoreElementName)
allRead = true;
if (reader.name().toString() == ExcludeElementName)
if (reader.name().toString() == CppcheckXml::ExcludeElementName)
allRead = true;
break;
@ -540,7 +499,7 @@ void ProjectFile::readSuppressions(QXmlStreamReader &reader)
switch (type) {
case QXmlStreamReader::StartElement:
// Read library-elements
if (reader.name().toString() == SuppressionElementName) {
if (reader.name().toString() == CppcheckXml::SuppressionElementName) {
Suppressions::Suppression suppression;
if (reader.attributes().hasAttribute(QString(),"fileName"))
suppression.fileName = reader.attributes().value(QString(),"fileName").toString().toStdString();
@ -557,7 +516,7 @@ void ProjectFile::readSuppressions(QXmlStreamReader &reader)
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() != SuppressionElementName)
if (reader.name().toString() != CppcheckXml::SuppressionElementName)
return;
break;
@ -685,64 +644,64 @@ bool ProjectFile::write(const QString &filename)
QXmlStreamWriter xmlWriter(&file);
xmlWriter.setAutoFormatting(true);
xmlWriter.writeStartDocument("1.0");
xmlWriter.writeStartElement(ProjectElementName);
xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);
xmlWriter.writeStartElement(CppcheckXml::ProjectElementName);
xmlWriter.writeAttribute(CppcheckXml::ProjectVersionAttrib, CppcheckXml::ProjectFileVersion);
if (!mRootPath.isEmpty()) {
xmlWriter.writeStartElement(RootPathName);
xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath);
xmlWriter.writeStartElement(CppcheckXml::RootPathName);
xmlWriter.writeAttribute(CppcheckXml::RootPathNameAttrib, mRootPath);
xmlWriter.writeEndElement();
}
if (!mBuildDir.isEmpty()) {
xmlWriter.writeStartElement(BuildDirElementName);
xmlWriter.writeStartElement(CppcheckXml::BuildDirElementName);
xmlWriter.writeCharacters(mBuildDir);
xmlWriter.writeEndElement();
}
if (!mPlatform.isEmpty()) {
xmlWriter.writeStartElement(PlatformElementName);
xmlWriter.writeStartElement(CppcheckXml::PlatformElementName);
xmlWriter.writeCharacters(mPlatform);
xmlWriter.writeEndElement();
}
if (!mImportProject.isEmpty()) {
xmlWriter.writeStartElement(ImportProjectElementName);
xmlWriter.writeStartElement(CppcheckXml::ImportProjectElementName);
xmlWriter.writeCharacters(mImportProject);
xmlWriter.writeEndElement();
}
xmlWriter.writeStartElement(AnalyzeAllVsConfigsElementName);
xmlWriter.writeStartElement(CppcheckXml::AnalyzeAllVsConfigsElementName);
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
xmlWriter.writeEndElement();
xmlWriter.writeStartElement(CheckHeadersElementName);
xmlWriter.writeStartElement(CppcheckXml::CheckHeadersElementName);
xmlWriter.writeCharacters(mCheckHeaders ? "true" : "false");
xmlWriter.writeEndElement();
xmlWriter.writeStartElement(CheckUnusedTemplatesElementName);
xmlWriter.writeStartElement(CppcheckXml::CheckUnusedTemplatesElementName);
xmlWriter.writeCharacters(mCheckUnusedTemplates ? "true" : "false");
xmlWriter.writeEndElement();
xmlWriter.writeStartElement(MaxCtuDepthElementName);
xmlWriter.writeStartElement(CppcheckXml::MaxCtuDepthElementName);
xmlWriter.writeCharacters(QString::number(mMaxCtuDepth));
xmlWriter.writeEndElement();
if (!mIncludeDirs.isEmpty()) {
xmlWriter.writeStartElement(IncludeDirElementName);
xmlWriter.writeStartElement(CppcheckXml::IncludeDirElementName);
foreach (QString incdir, mIncludeDirs) {
xmlWriter.writeStartElement(DirElementName);
xmlWriter.writeAttribute(DirNameAttrib, incdir);
xmlWriter.writeStartElement(CppcheckXml::DirElementName);
xmlWriter.writeAttribute(CppcheckXml::DirNameAttrib, incdir);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
if (!mDefines.isEmpty()) {
xmlWriter.writeStartElement(DefinesElementName);
xmlWriter.writeStartElement(CppcheckXml::DefinesElementName);
foreach (QString define, mDefines) {
xmlWriter.writeStartElement(DefineName);
xmlWriter.writeAttribute(DefineNameAttrib, define);
xmlWriter.writeStartElement(CppcheckXml::DefineName);
xmlWriter.writeAttribute(CppcheckXml::DefineNameAttrib, define);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
@ -750,24 +709,24 @@ bool ProjectFile::write(const QString &filename)
writeStringList(xmlWriter,
mUndefines,
UndefinesElementName,
UndefineName);
CppcheckXml::UndefinesElementName,
CppcheckXml::UndefineName);
if (!mPaths.isEmpty()) {
xmlWriter.writeStartElement(PathsElementName);
xmlWriter.writeStartElement(CppcheckXml::PathsElementName);
foreach (QString path, mPaths) {
xmlWriter.writeStartElement(PathName);
xmlWriter.writeAttribute(PathNameAttrib, path);
xmlWriter.writeStartElement(CppcheckXml::PathName);
xmlWriter.writeAttribute(CppcheckXml::PathNameAttrib, path);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
if (!mExcludedPaths.isEmpty()) {
xmlWriter.writeStartElement(ExcludeElementName);
xmlWriter.writeStartElement(CppcheckXml::ExcludeElementName);
foreach (QString path, mExcludedPaths) {
xmlWriter.writeStartElement(ExcludePathName);
xmlWriter.writeAttribute(ExcludePathNameAttrib, path);
xmlWriter.writeStartElement(CppcheckXml::ExcludePathName);
xmlWriter.writeAttribute(CppcheckXml::ExcludePathNameAttrib, path);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
@ -775,13 +734,13 @@ bool ProjectFile::write(const QString &filename)
writeStringList(xmlWriter,
mLibraries,
LibrariesElementName,
LibraryElementName);
CppcheckXml::LibrariesElementName,
CppcheckXml::LibraryElementName);
if (!mSuppressions.isEmpty()) {
xmlWriter.writeStartElement(SuppressionsElementName);
xmlWriter.writeStartElement(CppcheckXml::SuppressionsElementName);
foreach (const Suppressions::Suppression &suppression, mSuppressions) {
xmlWriter.writeStartElement(SuppressionElementName);
xmlWriter.writeStartElement(CppcheckXml::SuppressionElementName);
if (!suppression.fileName.empty())
xmlWriter.writeAttribute("fileName", QString::fromStdString(suppression.fileName));
if (suppression.lineNumber > 0)
@ -797,15 +756,15 @@ bool ProjectFile::write(const QString &filename)
writeStringList(xmlWriter,
mCheckUnknownFunctionReturn,
CheckUnknownFunctionReturn,
Name);
CppcheckXml::CheckUnknownFunctionReturn,
CppcheckXml::Name);
mSafeChecks.saveToXml(xmlWriter);
writeStringList(xmlWriter,
mAddons,
AddonsElementName,
AddonElementName);
CppcheckXml::AddonsElementName,
CppcheckXml::AddonElementName);
QStringList tools;
if (mClangAnalyzer)
@ -814,10 +773,10 @@ bool ProjectFile::write(const QString &filename)
tools << CLANG_TIDY;
writeStringList(xmlWriter,
tools,
ToolsElementName,
ToolElementName);
CppcheckXml::ToolsElementName,
CppcheckXml::ToolElementName);
writeStringList(xmlWriter, mTags, TagsElementName, TagElementName);
writeStringList(xmlWriter, mTags, CppcheckXml::TagsElementName, CppcheckXml::TagElementName);
xmlWriter.writeEndDocument();
file.close();

View File

@ -33,6 +33,7 @@
#include <utility>
#include <sstream>
void ImportProject::ignorePaths(const std::vector<std::string> &ipaths)
{
for (std::list<FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
@ -959,47 +960,6 @@ static std::string join(const std::list<std::string> &strlist, const char *sep)
return ret;
}
// These constants are copy/pasted from gui/projectfile.cpp
static const char ProjectElementName[] = "project";
static const char ProjectVersionAttrib[] = "version";
static const char ProjectFileVersion[] = "1";
static const char BuildDirElementName[] = "builddir";
static const char ImportProjectElementName[] = "importproject";
static const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
static const char IncludeDirElementName[] = "includedir";
static const char DirElementName[] = "dir";
static const char DirNameAttrib[] = "name";
static const char DefinesElementName[] = "defines";
static const char DefineName[] = "define";
static const char DefineNameAttrib[] = "name";
static const char UndefinesElementName[] = "undefines";
static const char UndefineName[] = "undefine";
static const char PathsElementName[] = "paths";
static const char PathName[] = "dir";
static const char PathNameAttrib[] = "name";
static const char RootPathName[] = "root";
static const char RootPathNameAttrib[] = "name";
static const char IgnoreElementName[] = "ignore";
static const char IgnorePathName[] = "path";
static const char IgnorePathNameAttrib[] = "name";
static const char ExcludeElementName[] = "exclude";
static const char ExcludePathName[] = "path";
static const char ExcludePathNameAttrib[] = "name";
static const char LibrariesElementName[] = "libraries";
static const char LibraryElementName[] = "library";
static const char PlatformElementName[] = "platform";
static const char SuppressionsElementName[] = "suppressions";
static const char SuppressionElementName[] = "suppression";
static const char AddonElementName[] = "addon";
static const char AddonsElementName[] = "addons";
static const char ToolElementName[] = "tool";
static const char ToolsElementName[] = "tools";
static const char TagsElementName[] = "tags";
static const char TagElementName[] = "tag";
static const char CheckHeadersElementName[] = "check-headers";
static const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
static const char MaxCtuDepthElementName[] = "max-ctu-depth";
static std::string istream_to_string(std::istream &istr)
{
std::istreambuf_iterator<char> eos;
@ -1013,12 +973,9 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
if (doc.Parse(xmldata.data(), xmldata.size()) != tinyxml2::XML_SUCCESS)
return false;
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
if (rootnode == nullptr || strcmp(rootnode->Name(), ProjectElementName) != 0)
if (rootnode == nullptr || strcmp(rootnode->Name(), CppcheckXml::ProjectElementName) != 0)
return false;
(void)ProjectFileVersion;
(void)ProjectVersionAttrib;
const std::string &path = mPath;
std::list<std::string> paths;
@ -1028,46 +985,48 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
guiProject.analyzeAllVsConfigs.clear();
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(), RootPathName) == 0 && node->Attribute(RootPathNameAttrib)) {
temp.basePaths.push_back(joinRelativePath(path, node->Attribute(RootPathNameAttrib)));
if (strcmp(node->Name(), CppcheckXml::RootPathName) == 0 && node->Attribute(CppcheckXml::RootPathNameAttrib)) {
temp.basePaths.push_back(joinRelativePath(path, node->Attribute(CppcheckXml::RootPathNameAttrib)));
temp.relativePaths = true;
} else if (strcmp(node->Name(), BuildDirElementName) == 0)
} else if (strcmp(node->Name(), CppcheckXml::BuildDirElementName) == 0)
temp.buildDir = joinRelativePath(path, node->GetText() ? node->GetText() : "");
else if (strcmp(node->Name(), IncludeDirElementName) == 0)
temp.includePaths = readXmlStringList(node, path, DirElementName, DirNameAttrib);
else if (strcmp(node->Name(), DefinesElementName) == 0)
temp.userDefines = join(readXmlStringList(node, "", DefineName, DefineNameAttrib), ";");
else if (strcmp(node->Name(), UndefinesElementName) == 0) {
for (const std::string &u : readXmlStringList(node, "", UndefineName, nullptr))
else if (strcmp(node->Name(), CppcheckXml::IncludeDirElementName) == 0)
temp.includePaths = readXmlStringList(node, path, CppcheckXml::DirElementName, CppcheckXml::DirNameAttrib);
else if (strcmp(node->Name(), CppcheckXml::DefinesElementName) == 0)
temp.userDefines = join(readXmlStringList(node, "", CppcheckXml::DefineName, CppcheckXml::DefineNameAttrib), ";");
else if (strcmp(node->Name(), CppcheckXml::UndefinesElementName) == 0) {
for (const std::string &u : readXmlStringList(node, "", CppcheckXml::UndefineName, nullptr))
temp.userUndefs.insert(u);
} else if (strcmp(node->Name(), ImportProjectElementName) == 0)
} else if (strcmp(node->Name(), CppcheckXml::ImportProjectElementName) == 0)
guiProject.projectFile = path + (node->GetText() ? node->GetText() : "");
else if (strcmp(node->Name(), PathsElementName) == 0)
paths = readXmlStringList(node, path, PathName, PathNameAttrib);
else if (strcmp(node->Name(), ExcludeElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, "", ExcludePathName, ExcludePathNameAttrib);
else if (strcmp(node->Name(), IgnoreElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, "", IgnorePathName, IgnorePathNameAttrib);
else if (strcmp(node->Name(), LibrariesElementName) == 0)
guiProject.libraries = readXmlStringList(node, "", LibraryElementName, nullptr);
else if (strcmp(node->Name(), SuppressionsElementName) == 0)
suppressions = readXmlStringList(node, "", SuppressionElementName, nullptr);
else if (strcmp(node->Name(), PlatformElementName) == 0)
else if (strcmp(node->Name(), CppcheckXml::PathsElementName) == 0)
paths = readXmlStringList(node, path, CppcheckXml::PathName, CppcheckXml::PathNameAttrib);
else if (strcmp(node->Name(), CppcheckXml::ExcludeElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::ExcludePathName, CppcheckXml::ExcludePathNameAttrib);
else if (strcmp(node->Name(), CppcheckXml::IgnoreElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib);
else if (strcmp(node->Name(), CppcheckXml::LibrariesElementName) == 0)
guiProject.libraries = readXmlStringList(node, "", CppcheckXml::LibraryElementName, nullptr);
else if (strcmp(node->Name(), CppcheckXml::SuppressionsElementName) == 0)
suppressions = readXmlStringList(node, "", CppcheckXml::SuppressionElementName, nullptr);
else if (strcmp(node->Name(), CppcheckXml::PlatformElementName) == 0)
guiProject.platform = node->GetText();
else if (strcmp(node->Name(), AnalyzeAllVsConfigsElementName) == 0)
else if (strcmp(node->Name(), CppcheckXml::AnalyzeAllVsConfigsElementName) == 0)
guiProject.analyzeAllVsConfigs = node->GetText();
else if (strcmp(node->Name(), AddonsElementName) == 0)
temp.addons = readXmlStringList(node, "", AddonElementName, nullptr);
else if (strcmp(node->Name(), TagsElementName) == 0)
node->Attribute(TagElementName); // FIXME: Write some warning
else if (strcmp(node->Name(), ToolsElementName) == 0)
node->Attribute(ToolElementName); // FIXME: Write some warning
else if (strcmp(node->Name(), CheckHeadersElementName) == 0)
else if (strcmp(node->Name(), CppcheckXml::AddonsElementName) == 0)
temp.addons = readXmlStringList(node, "", CppcheckXml::AddonElementName, nullptr);
else if (strcmp(node->Name(), CppcheckXml::TagsElementName) == 0)
node->Attribute(CppcheckXml::TagElementName); // FIXME: Write some warning
else if (strcmp(node->Name(), CppcheckXml::ToolsElementName) == 0)
node->Attribute(CppcheckXml::ToolElementName); // FIXME: Write some warning
else if (strcmp(node->Name(), CppcheckXml::CheckHeadersElementName) == 0)
temp.checkHeaders = (strcmp(node->GetText(), "true") == 0);
else if (strcmp(node->Name(), CheckUnusedTemplatesElementName) == 0)
else if (strcmp(node->Name(), CppcheckXml::CheckUnusedTemplatesElementName) == 0)
temp.checkUnusedTemplates = (strcmp(node->GetText(), "true") == 0);
else if (strcmp(node->Name(), MaxCtuDepthElementName) == 0)
else if (strcmp(node->Name(), CppcheckXml::MaxCtuDepthElementName) == 0)
temp.maxCtuDepth = std::atoi(node->GetText());
else if (strcmp(node->Name(), CppcheckXml::CheckUnknownFunctionReturn) == 0)
; // TODO
else if (strcmp(node->Name(), Settings::SafeChecks::XmlRootName) == 0) {
for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
if (strcmp(child->Name(), Settings::SafeChecks::XmlClasses) == 0)

View File

@ -110,6 +110,51 @@ private:
std::string mPath;
};
namespace CppcheckXml {
constexpr char ProjectElementName[] = "project";
constexpr char ProjectVersionAttrib[] = "version";
constexpr char ProjectFileVersion[] = "1";
constexpr char BuildDirElementName[] = "builddir";
constexpr char ImportProjectElementName[] = "importproject";
constexpr char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
constexpr char IncludeDirElementName[] = "includedir";
constexpr char DirElementName[] = "dir";
constexpr char DirNameAttrib[] = "name";
constexpr char DefinesElementName[] = "defines";
constexpr char DefineName[] = "define";
constexpr char DefineNameAttrib[] = "name";
constexpr char UndefinesElementName[] = "undefines";
constexpr char UndefineName[] = "undefine";
constexpr char PathsElementName[] = "paths";
constexpr char PathName[] = "dir";
constexpr char PathNameAttrib[] = "name";
constexpr char RootPathName[] = "root";
constexpr char RootPathNameAttrib[] = "name";
constexpr char IgnoreElementName[] = "ignore";
constexpr char IgnorePathName[] = "path";
constexpr char IgnorePathNameAttrib[] = "name";
constexpr char ExcludeElementName[] = "exclude";
constexpr char ExcludePathName[] = "path";
constexpr char ExcludePathNameAttrib[] = "name";
constexpr char LibrariesElementName[] = "libraries";
constexpr char LibraryElementName[] = "library";
constexpr char PlatformElementName[] = "platform";
constexpr char SuppressionsElementName[] = "suppressions";
constexpr char SuppressionElementName[] = "suppression";
constexpr char AddonElementName[] = "addon";
constexpr char AddonsElementName[] = "addons";
constexpr char ToolElementName[] = "tool";
constexpr char ToolsElementName[] = "tools";
constexpr char TagsElementName[] = "tags";
constexpr char TagElementName[] = "tag";
constexpr char CheckHeadersElementName[] = "check-headers";
constexpr char CheckUnusedTemplatesElementName[] = "check-unused-templates";
constexpr char MaxCtuDepthElementName[] = "max-ctu-depth";
constexpr char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
constexpr char Name[] = "name";
}
/// @}
//---------------------------------------------------------------------------
#endif // importprojectH