Improved handling of paths when importing cppcheck gui project

This commit is contained in:
Daniel Marjamäki 2019-04-11 21:02:49 +02:00
parent 7ede0feb2c
commit c9172b169a
1 changed files with 23 additions and 14 deletions

View File

@ -908,7 +908,14 @@ void ImportProject::importBcb6Prj(const std::string &projectFilename)
}
}
static std::list<std::string> readXmlStringList(const tinyxml2::XMLElement *node, const char name[], const char attribute[])
static std::string joinRelativePath(const std::string &path1, const std::string &path2)
{
if (!path1.empty() && !Path::isAbsolute(path2))
return path1 + path2;
return path2;
}
static std::list<std::string> readXmlStringList(const tinyxml2::XMLElement *node, const std::string &path, const char name[], const char attribute[])
{
std::list<std::string> ret;
for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
@ -916,7 +923,7 @@ static std::list<std::string> readXmlStringList(const tinyxml2::XMLElement *node
continue;
const char *attr = attribute ? child->Attribute(attribute) : child->GetText();
if (attr)
ret.push_back(attr);
ret.push_back(joinRelativePath(path, attr));
}
return ret;
}
@ -994,40 +1001,42 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
(void)ProjectFileVersion;
(void)ProjectVersionAttrib;
const std::string &path = mPath;
std::list<std::string> paths;
std::list<std::string> suppressions;
Settings temp;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(), RootPathName) == 0 && node->Attribute(RootPathNameAttrib))
temp.basePaths.push_back(node->Attribute(RootPathNameAttrib));
temp.basePaths.push_back(joinRelativePath(path, node->Attribute(RootPathNameAttrib)));
else if (strcmp(node->Name(), BuildDirElementName) == 0)
temp.buildDir = node->GetText() ? node->GetText() : "";
temp.buildDir = joinRelativePath(path, node->GetText() ? node->GetText() : "");
else if (strcmp(node->Name(), IncludeDirElementName) == 0)
temp.includePaths = readXmlStringList(node, DirElementName, DirNameAttrib);
temp.includePaths = readXmlStringList(node, path, DirElementName, DirNameAttrib);
else if (strcmp(node->Name(), DefinesElementName) == 0)
temp.userDefines = join(readXmlStringList(node, DefineName, DefineNameAttrib), ";");
temp.userDefines = join(readXmlStringList(node, "", DefineName, DefineNameAttrib), ";");
else if (strcmp(node->Name(), UndefinesElementName) == 0) {
for (const std::string &u : readXmlStringList(node, UndefineName, nullptr))
for (const std::string &u : readXmlStringList(node, "", UndefineName, nullptr))
temp.userUndefs.insert(u);
} else if (strcmp(node->Name(), ImportProjectElementName) == 0)
guiProject.projectFile = node->GetText() ? node->GetText() : "";
guiProject.projectFile = path + (node->GetText() ? node->GetText() : "");
else if (strcmp(node->Name(), PathsElementName) == 0)
paths = readXmlStringList(node, PathName, PathNameAttrib);
paths = readXmlStringList(node, path, PathName, PathNameAttrib);
else if (strcmp(node->Name(), ExcludeElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, ExcludePathName, ExcludePathNameAttrib);
guiProject.excludedPaths = readXmlStringList(node, "", ExcludePathName, ExcludePathNameAttrib);
else if (strcmp(node->Name(), IgnoreElementName) == 0)
guiProject.excludedPaths = readXmlStringList(node, IgnorePathName, IgnorePathNameAttrib);
guiProject.excludedPaths = readXmlStringList(node, "", IgnorePathName, IgnorePathNameAttrib);
else if (strcmp(node->Name(), LibrariesElementName) == 0)
guiProject.libraries = readXmlStringList(node, LibraryElementName, nullptr);
guiProject.libraries = readXmlStringList(node, "", LibraryElementName, nullptr);
else if (strcmp(node->Name(), SuppressionsElementName) == 0)
suppressions = readXmlStringList(node, SuppressionElementName, nullptr);
suppressions = readXmlStringList(node, "", SuppressionElementName, nullptr);
else if (strcmp(node->Name(), PlatformElementName) == 0)
guiProject.platform = node->GetText();
else if (strcmp(node->Name(), AnalyzeAllVsConfigsElementName) == 0)
; // FIXME: Write some warning
else if (strcmp(node->Name(), AddonsElementName) == 0)
temp.addons = readXmlStringList(node, AddonElementName, nullptr);
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)