2009-06-22 10:57:17 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2018-03-31 20:59:09 +02:00
|
|
|
* Copyright (C) 2007-2018 Cppcheck team.
|
2009-06-22 10:57:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-22 10:57:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QXmlStreamReader>
|
2010-07-07 23:59:02 +02:00
|
|
|
#include <QXmlStreamWriter>
|
2009-06-22 10:57:17 +02:00
|
|
|
#include <QFile>
|
2011-02-28 16:18:14 +01:00
|
|
|
#include <QDir>
|
2009-06-22 10:57:17 +02:00
|
|
|
#include "projectfile.h"
|
2017-09-22 15:41:27 +02:00
|
|
|
#include "common.h"
|
2009-06-22 10:57:17 +02:00
|
|
|
|
|
|
|
static const char ProjectElementName[] = "project";
|
2010-07-07 23:59:02 +02:00
|
|
|
static const char ProjectVersionAttrib[] = "version";
|
|
|
|
static const char ProjectFileVersion[] = "1";
|
2016-11-19 20:38:50 +01:00
|
|
|
static const char BuildDirElementName[] = "builddir";
|
2016-08-18 21:58:50 +02:00
|
|
|
static const char ImportProjectElementName[] = "importproject";
|
2017-08-10 00:18:04 +02:00
|
|
|
static const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
|
2013-02-10 07:43:09 +01:00
|
|
|
static const char IncludeDirElementName[] = "includedir";
|
2009-07-04 00:38:47 +02:00
|
|
|
static const char DirElementName[] = "dir";
|
|
|
|
static const char DirNameAttrib[] = "name";
|
2010-05-20 07:22:19 +02:00
|
|
|
static const char DefinesElementName[] = "defines";
|
|
|
|
static const char DefineName[] = "define";
|
|
|
|
static const char DefineNameAttrib[] = "name";
|
2010-08-14 17:42:37 +02:00
|
|
|
static const char PathsElementName[] = "paths";
|
|
|
|
static const char PathName[] = "dir";
|
|
|
|
static const char PathNameAttrib[] = "name";
|
2010-08-20 22:58:00 +02:00
|
|
|
static const char RootPathName[] = "root";
|
|
|
|
static const char RootPathNameAttrib[] = "name";
|
2011-02-27 23:13:28 +01:00
|
|
|
static const char IgnoreElementName[] = "ignore";
|
2011-02-27 17:32:53 +01:00
|
|
|
static const char IgnorePathName[] = "path";
|
|
|
|
static const char IgnorePathNameAttrib[] = "name";
|
2011-08-23 18:54:53 +02:00
|
|
|
static const char ExcludeElementName[] = "exclude";
|
|
|
|
static const char ExcludePathName[] = "path";
|
|
|
|
static const char ExcludePathNameAttrib[] = "name";
|
2013-12-29 18:06:31 +01:00
|
|
|
static const char LibrariesElementName[] = "libraries";
|
|
|
|
static const char LibraryElementName[] = "library";
|
2018-03-13 13:07:10 +01:00
|
|
|
static const char PlatformElementName[] = "platform";
|
2013-12-30 22:32:50 +01:00
|
|
|
static const char SuppressionsElementName[] = "suppressions";
|
|
|
|
static const char SuppressionElementName[] = "suppression";
|
2017-08-03 12:30:28 +02:00
|
|
|
static const char AddonElementName[] = "addon";
|
|
|
|
static const char AddonsElementName[] = "addons";
|
2017-09-22 15:41:27 +02:00
|
|
|
static const char ToolElementName[] = "tool";
|
|
|
|
static const char ToolsElementName[] = "tools";
|
2017-08-18 17:25:08 +02:00
|
|
|
static const char TagsElementName[] = "tags";
|
|
|
|
static const char TagElementName[] = "tag";
|
2009-06-22 10:57:17 +02:00
|
|
|
|
|
|
|
ProjectFile::ProjectFile(QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent),
|
|
|
|
mFilename(filename)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
2017-07-31 12:02:51 +02:00
|
|
|
read();
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
void ProjectFile::clear()
|
|
|
|
{
|
|
|
|
mRootPath.clear();
|
|
|
|
mBuildDir.clear();
|
|
|
|
mImportProject.clear();
|
|
|
|
mAnalyzeAllVsConfigs = true;
|
|
|
|
mIncludeDirs.clear();
|
|
|
|
mDefines.clear();
|
|
|
|
mPaths.clear();
|
|
|
|
mExcludedPaths.clear();
|
|
|
|
mLibraries.clear();
|
2018-03-13 13:07:10 +01:00
|
|
|
mPlatform.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
mSuppressions.clear();
|
|
|
|
mAddons.clear();
|
2017-09-22 15:41:27 +02:00
|
|
|
mClangAnalyzer = mClangTidy = false;
|
2017-08-10 00:18:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
bool ProjectFile::read(const QString &filename)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!filename.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
mFilename = filename;
|
|
|
|
|
|
|
|
QFile file(mFilename);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
2009-06-22 10:57:17 +02:00
|
|
|
return false;
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
|
|
|
|
2009-06-22 10:57:17 +02:00
|
|
|
QXmlStreamReader xmlReader(&file);
|
|
|
|
bool insideProject = false;
|
2010-07-08 18:49:04 +02:00
|
|
|
bool projectTagFound = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
while (!xmlReader.atEnd()) {
|
|
|
|
switch (xmlReader.readNext()) {
|
2009-06-22 10:57:17 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-10-13 20:53:06 +02:00
|
|
|
if (xmlReader.name() == ProjectElementName) {
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = true;
|
2010-07-08 18:49:04 +02:00
|
|
|
projectTagFound = true;
|
|
|
|
}
|
2010-08-20 22:58:00 +02:00
|
|
|
// Read root path from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == RootPathName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readRootPath(xmlReader);
|
2010-08-20 22:58:00 +02:00
|
|
|
|
2016-11-19 20:38:50 +01:00
|
|
|
// Read root path from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == BuildDirElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readBuildDir(xmlReader);
|
2016-11-19 20:38:50 +01:00
|
|
|
|
2010-08-14 17:42:37 +02:00
|
|
|
// Find paths to check from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == PathsElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readCheckPaths(xmlReader);
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2016-08-18 21:58:50 +02:00
|
|
|
if (insideProject && xmlReader.name() == ImportProjectElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readImportProject(xmlReader);
|
2016-08-18 21:58:50 +02:00
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
if (insideProject && xmlReader.name() == AnalyzeAllVsConfigsElementName)
|
|
|
|
readAnalyzeAllVsConfigs(xmlReader);
|
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find include directory from inside project element
|
2013-02-10 07:43:09 +01:00
|
|
|
if (insideProject && xmlReader.name() == IncludeDirElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readIncludeDirs(xmlReader);
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find preprocessor define from inside project element
|
2010-05-20 07:22:19 +02:00
|
|
|
if (insideProject && xmlReader.name() == DefinesElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readDefines(xmlReader);
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
// Find exclude list from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == ExcludeElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readExcludes(xmlReader);
|
2011-08-23 18:54:53 +02:00
|
|
|
|
2011-02-27 17:32:53 +01:00
|
|
|
// Find ignore list from inside project element
|
2011-08-23 18:54:53 +02:00
|
|
|
// These are read for compatibility
|
2011-02-27 17:32:53 +01:00
|
|
|
if (insideProject && xmlReader.name() == IgnoreElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readExcludes(xmlReader);
|
2011-02-27 17:32:53 +01:00
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find libraries list from inside project element
|
2013-12-29 18:06:31 +01:00
|
|
|
if (insideProject && xmlReader.name() == LibrariesElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readStringList(mLibraries, xmlReader,LibraryElementName);
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
if (insideProject && xmlReader.name() == PlatformElementName)
|
|
|
|
readPlatform(xmlReader);
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find suppressions list from inside project element
|
|
|
|
if (insideProject && xmlReader.name() == SuppressionsElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readStringList(mSuppressions, xmlReader,SuppressionElementName);
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
// Addons
|
|
|
|
if (insideProject && xmlReader.name() == AddonsElementName)
|
|
|
|
readStringList(mAddons, xmlReader, AddonElementName);
|
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
// Tools
|
|
|
|
if (insideProject && xmlReader.name() == ToolsElementName) {
|
|
|
|
QStringList tools;
|
|
|
|
readStringList(tools, xmlReader, ToolElementName);
|
|
|
|
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
|
|
|
|
mClangTidy = tools.contains(CLANG_TIDY);
|
|
|
|
}
|
|
|
|
|
2017-08-18 17:25:08 +02:00
|
|
|
if (insideProject && xmlReader.name() == TagsElementName)
|
|
|
|
readStringList(mTags, xmlReader, TagElementName);
|
|
|
|
|
2009-06-22 10:57:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2010-04-02 07:30:58 +02:00
|
|
|
if (xmlReader.name() == ProjectElementName)
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = false;
|
|
|
|
break;
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2009-06-23 08:15:00 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2017-07-28 05:08:59 +02:00
|
|
|
return projectTagFound;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readRootPath(QXmlStreamReader &reader)
|
2010-08-20 22:58:00 +02:00
|
|
|
{
|
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), RootPathNameAttrib).toString();
|
2010-08-20 22:58:00 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mRootPath = name;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readBuildDir(QXmlStreamReader &reader)
|
2016-11-19 20:38:50 +01:00
|
|
|
{
|
|
|
|
mBuildDir.clear();
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mBuildDir = reader.text().toString();
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readImportProject(QXmlStreamReader &reader)
|
2016-08-18 21:58:50 +02:00
|
|
|
{
|
|
|
|
mImportProject.clear();
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mImportProject = reader.text().toString();
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
void ProjectFile::readAnalyzeAllVsConfigs(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mAnalyzeAllVsConfigs = (reader.text().toString() == "true");
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readIncludeDirs(QXmlStreamReader &reader)
|
2009-07-04 00:38:47 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2009-07-04 00:38:47 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == DirElementName) {
|
2009-07-04 00:38:47 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), DirNameAttrib).toString();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!name.isEmpty())
|
2009-07-04 00:38:47 +02:00
|
|
|
mIncludeDirs << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-02-10 07:43:09 +01:00
|
|
|
if (reader.name().toString() == IncludeDirElementName)
|
2009-07-04 00:38:47 +02:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2009-07-04 00:38:47 +02:00
|
|
|
}
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readDefines(QXmlStreamReader &reader)
|
2010-05-20 07:22:19 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-05-20 07:22:19 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read define-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == DefineName) {
|
2010-05-20 07:22:19 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), DefineNameAttrib).toString();
|
2010-05-20 07:22:19 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mDefines << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == DefinesElementName)
|
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-05-20 07:22:19 +02:00
|
|
|
}
|
2010-07-07 23:59:02 +02:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readCheckPaths(QXmlStreamReader &reader)
|
2010-08-14 17:42:37 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-08-14 17:42:37 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == PathName) {
|
2010-08-14 17:42:37 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), PathNameAttrib).toString();
|
2010-08-14 17:42:37 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mPaths << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == PathsElementName)
|
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-08-14 17:42:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readExcludes(QXmlStreamReader &reader)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2011-02-27 17:32:53 +01:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-08-23 18:54:53 +02:00
|
|
|
// Read exclude-elements
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name().toString() == ExcludePathName) {
|
2011-08-23 18:54:53 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), ExcludePathNameAttrib).toString();
|
2011-08-23 18:54:53 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mExcludedPaths << name;
|
|
|
|
}
|
|
|
|
// Read ignore-elements - deprecated but support reading them
|
2011-10-13 20:53:06 +02:00
|
|
|
else if (reader.name().toString() == IgnorePathName) {
|
2011-02-27 17:32:53 +01:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2017-08-03 12:39:31 +02:00
|
|
|
QString name = attribs.value(QString(), IgnorePathNameAttrib).toString();
|
2011-02-27 17:32:53 +01:00
|
|
|
if (!name.isEmpty())
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths << name;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == IgnoreElementName)
|
|
|
|
allRead = true;
|
2011-08-23 18:54:53 +02:00
|
|
|
if (reader.name().toString() == ExcludeElementName)
|
|
|
|
allRead = true;
|
2011-02-27 17:32:53 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
void ProjectFile::readPlatform(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mPlatform = reader.text().toString();
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[])
|
2013-12-29 18:06:31 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() == elementname) {
|
2013-12-29 18:06:31 +01:00
|
|
|
type = reader.readNext();
|
|
|
|
if (type == QXmlStreamReader::Characters) {
|
2013-12-30 22:32:50 +01:00
|
|
|
QString text = reader.text().toString();
|
|
|
|
stringlist << text;
|
2013-12-29 18:06:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() != elementname)
|
2013-12-29 18:06:31 +01:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2013-12-29 18:06:31 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!allRead);
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setIncludes(const QStringList &includes)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mIncludeDirs = includes;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setDefines(const QStringList &defines)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mDefines = defines;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setCheckPaths(const QStringList &paths)
|
2010-08-14 17:42:37 +02:00
|
|
|
{
|
|
|
|
mPaths = paths;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setExcludedPaths(const QStringList &paths)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths = paths;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setLibraries(const QStringList &libraries)
|
2013-12-29 18:06:31 +01:00
|
|
|
{
|
|
|
|
mLibraries = libraries;
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
void ProjectFile::setPlatform(const QString &platform)
|
|
|
|
{
|
|
|
|
mPlatform = platform;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setSuppressions(const QStringList &suppressions)
|
2013-12-30 22:32:50 +01:00
|
|
|
{
|
|
|
|
mSuppressions = suppressions;
|
|
|
|
}
|
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
void ProjectFile::setAddons(const QStringList &addons)
|
|
|
|
{
|
|
|
|
mAddons = addons;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
bool ProjectFile::write(const QString &filename)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
2010-07-08 15:16:25 +02:00
|
|
|
if (!filename.isEmpty())
|
|
|
|
mFilename = filename;
|
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
QFile file(mFilename);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QXmlStreamWriter xmlWriter(&file);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.writeStartDocument("1.0");
|
|
|
|
xmlWriter.writeStartElement(ProjectElementName);
|
|
|
|
xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mRootPath.isEmpty()) {
|
2010-08-20 22:58:00 +02:00
|
|
|
xmlWriter.writeStartElement(RootPathName);
|
|
|
|
xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2016-11-19 20:38:50 +01:00
|
|
|
if (!mBuildDir.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement(BuildDirElementName);
|
|
|
|
xmlWriter.writeCharacters(mBuildDir);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
if (!mPlatform.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement(PlatformElementName);
|
|
|
|
xmlWriter.writeCharacters(mPlatform);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2016-08-18 21:58:50 +02:00
|
|
|
if (!mImportProject.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement(ImportProjectElementName);
|
|
|
|
xmlWriter.writeCharacters(mImportProject);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
xmlWriter.writeStartElement(AnalyzeAllVsConfigsElementName);
|
|
|
|
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mIncludeDirs.isEmpty()) {
|
2013-02-10 07:43:09 +01:00
|
|
|
xmlWriter.writeStartElement(IncludeDirElementName);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (QString incdir, mIncludeDirs) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DirElementName);
|
|
|
|
xmlWriter.writeAttribute(DirNameAttrib, incdir);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mDefines.isEmpty()) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DefinesElementName);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (QString define, mDefines) {
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeStartElement(DefineName);
|
|
|
|
xmlWriter.writeAttribute(DefineNameAttrib, define);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2010-08-14 17:42:37 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mPaths.isEmpty()) {
|
2010-08-14 17:42:37 +02:00
|
|
|
xmlWriter.writeStartElement(PathsElementName);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (QString path, mPaths) {
|
2010-08-14 17:42:37 +02:00
|
|
|
xmlWriter.writeStartElement(PathName);
|
|
|
|
xmlWriter.writeAttribute(PathNameAttrib, path);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mExcludedPaths.isEmpty()) {
|
2011-08-23 18:54:53 +02:00
|
|
|
xmlWriter.writeStartElement(ExcludeElementName);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (QString path, mExcludedPaths) {
|
2011-08-23 18:54:53 +02:00
|
|
|
xmlWriter.writeStartElement(ExcludePathName);
|
|
|
|
xmlWriter.writeAttribute(ExcludePathNameAttrib, path);
|
2011-02-28 15:08:14 +01:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
writeStringList(xmlWriter,
|
2013-12-30 22:32:50 +01:00
|
|
|
mLibraries,
|
|
|
|
LibrariesElementName,
|
|
|
|
LibraryElementName);
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
writeStringList(xmlWriter,
|
2013-12-30 22:32:50 +01:00
|
|
|
mSuppressions,
|
|
|
|
SuppressionsElementName,
|
|
|
|
SuppressionElementName);
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
writeStringList(xmlWriter,
|
|
|
|
mAddons,
|
|
|
|
AddonsElementName,
|
|
|
|
AddonElementName);
|
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
QStringList tools;
|
|
|
|
if (mClangAnalyzer)
|
|
|
|
tools << CLANG_ANALYZER;
|
|
|
|
if (mClangTidy)
|
|
|
|
tools << CLANG_TIDY;
|
|
|
|
writeStringList(xmlWriter,
|
|
|
|
tools,
|
|
|
|
ToolsElementName,
|
|
|
|
ToolElementName);
|
|
|
|
|
2017-08-18 17:25:08 +02:00
|
|
|
writeStringList(xmlWriter, mTags, TagsElementName, TagElementName);
|
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeEndDocument();
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::writeStringList(QXmlStreamWriter &xmlWriter, const QStringList &stringlist, const char startelementname[], const char stringelementname[])
|
2013-12-30 22:32:50 +01:00
|
|
|
{
|
|
|
|
if (stringlist.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
xmlWriter.writeStartElement(startelementname);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (QString str, stringlist) {
|
2013-12-30 22:32:50 +01:00
|
|
|
xmlWriter.writeStartElement(stringelementname);
|
|
|
|
xmlWriter.writeCharacters(str);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2016-10-02 18:03:21 +02:00
|
|
|
|
|
|
|
QStringList ProjectFile::fromNativeSeparators(const QStringList &paths)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
|
|
|
foreach (const QString &path, paths)
|
|
|
|
ret << QDir::fromNativeSeparators(path);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-09-22 15:41:27 +02:00
|
|
|
|
2017-09-22 18:57:53 +02:00
|
|
|
QStringList ProjectFile::getAddonsAndTools() const
|
|
|
|
{
|
|
|
|
QStringList ret(mAddons);
|
|
|
|
if (mClangAnalyzer)
|
|
|
|
ret << CLANG_ANALYZER;
|
|
|
|
if (mClangTidy)
|
|
|
|
ret << CLANG_TIDY;
|
|
|
|
return ret;
|
|
|
|
}
|