logic: Added compilation database project setup
* Added CDB option to project type selection * show CDB source files in popup * define header paths separately * made generic content summary in wizzard and use it everywhere * fixed file paths not canonical in analysis * refactored wizzard content paths to use summary instead of subpaths * refactored files popup to simpler communication with content bug id = 35
This commit is contained in:
@@ -271,8 +271,6 @@ add_files(
|
||||
|
||||
utility/solution/ISolutionParser.cpp
|
||||
utility/solution/ISolutionParser.h
|
||||
utility/solution/SolutionParserCompilationDatabase.cpp
|
||||
utility/solution/SolutionParserCompilationDatabase.h
|
||||
utility/solution/SolutionParserVisualStudio.cpp
|
||||
utility/solution/SolutionParserVisualStudio.h
|
||||
|
||||
|
||||
+10
-2
@@ -168,12 +168,19 @@ void Project::updateFileManager()
|
||||
{
|
||||
std::shared_ptr<ProjectSettings> projSettings = ProjectSettings::getInstance();
|
||||
|
||||
std::vector<FilePath> sourcePaths(projSettings->getSourcePaths());
|
||||
std::vector<FilePath> sourcePaths = projSettings->getSourcePaths();
|
||||
std::vector<FilePath> headerPaths;
|
||||
|
||||
if (projSettings->getCompilationDatabasePath().exists())
|
||||
{
|
||||
headerPaths = sourcePaths;
|
||||
sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath());
|
||||
}
|
||||
|
||||
std::vector<std::string> sourceExtensions = projSettings->getSourceExtensions();
|
||||
std::vector<std::string> includeExtensions = projSettings->getHeaderExtensions();
|
||||
|
||||
m_fileManager.setPaths(sourcePaths, sourceExtensions, includeExtensions);
|
||||
m_fileManager.setPaths(sourcePaths, headerPaths, sourceExtensions, includeExtensions);
|
||||
}
|
||||
|
||||
Parser::Arguments Project::getParserArguments() const
|
||||
@@ -212,6 +219,7 @@ Parser::Arguments Project::getParserArguments() const
|
||||
|
||||
args.language = projSettings->getLanguage();
|
||||
args.languageStandard = projSettings->getStandard();
|
||||
args.compilationDatabasePath = projSettings->getCompilationDatabasePath();
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
bool logErrors;
|
||||
std::string language;
|
||||
std::string languageStandard;
|
||||
|
||||
FilePath compilationDatabasePath;
|
||||
};
|
||||
|
||||
Parser(ParserClient* client);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define TASK_PARSE_CXX_H
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
@@ -12,6 +12,14 @@ class ParserClient;
|
||||
class FileManager;
|
||||
class CxxParser;
|
||||
|
||||
namespace clang
|
||||
{
|
||||
namespace tooling
|
||||
{
|
||||
class JSONCompilationDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
class TaskParseCxx
|
||||
: public Task
|
||||
{
|
||||
@@ -23,6 +31,8 @@ public:
|
||||
const std::vector<FilePath>& files
|
||||
);
|
||||
|
||||
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
|
||||
|
||||
virtual void enter();
|
||||
virtual TaskState update();
|
||||
virtual void exit();
|
||||
@@ -36,9 +46,12 @@ private:
|
||||
const Parser::Arguments m_arguments;
|
||||
const std::vector<FilePath> m_files;
|
||||
|
||||
std::queue<FilePath> m_sourcePaths;
|
||||
std::deque<FilePath> m_sourcePaths;
|
||||
|
||||
TimePoint m_start;
|
||||
|
||||
bool m_isCDB;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_cdb;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_CXX_H
|
||||
|
||||
@@ -22,10 +22,12 @@ const std::vector<FilePath>& FileManager::getSourcePaths() const
|
||||
|
||||
void FileManager::setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> headerPaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
){
|
||||
m_sourcePaths = sourcePaths;
|
||||
m_headerPaths = headerPaths;
|
||||
m_sourceExtensions = sourceExtensions;
|
||||
m_includeExtensions = includeExtensions;
|
||||
}
|
||||
@@ -123,6 +125,7 @@ std::vector<FileInfo> FileManager::getFileInfosInProject() const
|
||||
std::vector<std::pair<std::vector<FilePath>, std::vector<std::string>>> pathsExtensionsPairs;
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_includeExtensions));
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_sourceExtensions));
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_headerPaths, m_includeExtensions));
|
||||
|
||||
for (size_t i = 0; i < pathsExtensionsPairs.size(); i++)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
|
||||
void setPaths(
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> headerPaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
);
|
||||
@@ -40,6 +41,8 @@ private:
|
||||
std::map<FilePath, FileInfo> m_files;
|
||||
|
||||
std::vector<FilePath> m_sourcePaths;
|
||||
std::vector<FilePath> m_headerPaths;
|
||||
|
||||
std::vector<std::string> m_sourceExtensions;
|
||||
std::vector<std::string> m_includeExtensions;
|
||||
|
||||
|
||||
@@ -138,7 +138,17 @@ size_t FileRegister::getFilesCount() const
|
||||
return m_sourceFilePaths.size() + m_includeFilePaths.size();
|
||||
}
|
||||
|
||||
size_t FileRegister::getSourceFilesCount() const
|
||||
{
|
||||
return m_sourceFilePaths.size();
|
||||
}
|
||||
|
||||
size_t FileRegister::getParsedFilesCount() const
|
||||
{
|
||||
return getFilesCount() - getUnparsedSourceFilePaths().size() - getUnparsedIncludeFilePaths().size();
|
||||
}
|
||||
|
||||
size_t FileRegister::getParsedSourceFilesCount() const
|
||||
{
|
||||
return getSourceFilesCount() - getUnparsedSourceFilePaths().size();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ public:
|
||||
void markParsingIncludeFilesParsed();
|
||||
|
||||
size_t getFilesCount() const;
|
||||
size_t getSourceFilesCount() const;
|
||||
size_t getParsedFilesCount() const;
|
||||
size_t getParsedSourceFilesCount() const;
|
||||
|
||||
private:
|
||||
enum ParseState
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
#include "utility/solution/SolutionParserCompilationDatabase.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "clang/Tooling/JSONCompilationDatabase.h"
|
||||
#include "settings/ProjectSettings.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
SolutionParserCompilationDatabase::SolutionParserCompilationDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
SolutionParserCompilationDatabase::~SolutionParserCompilationDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
std::string SolutionParserCompilationDatabase::getSolutionName()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> SolutionParserCompilationDatabase::getProjects()
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> SolutionParserCompilationDatabase::getProjectItems()
|
||||
{
|
||||
std::vector<std::string> files = getDatabase()->getAllFiles();
|
||||
|
||||
std::vector<std::string> extensions = ProjectSettings::getInstance()->getHeaderExtensions();
|
||||
std::vector<FileInfo> fileInfos = FileSystem::getFileInfosFromPaths(m_headerPaths, extensions);
|
||||
|
||||
for (const FileInfo& info : fileInfos)
|
||||
{
|
||||
files.push_back(info.path.str());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<std::string> SolutionParserCompilationDatabase::getIncludePaths()
|
||||
{
|
||||
return m_searchPaths;
|
||||
}
|
||||
|
||||
std::vector<std::string> SolutionParserCompilationDatabase::getFrameworkPaths()
|
||||
{
|
||||
return m_frameworkPaths;
|
||||
}
|
||||
|
||||
void SolutionParserCompilationDatabase::parseDatabase()
|
||||
{
|
||||
std::vector<clang::tooling::CompileCommand> commands = getDatabase()->getAllCompileCommands();
|
||||
|
||||
std::set<std::string> headerPaths;
|
||||
std::set<std::string> searchPaths;
|
||||
std::set<std::string> frameworkPaths;
|
||||
bool insertNext = false;
|
||||
bool insertFramework = false;
|
||||
for(clang::tooling::CompileCommand command : commands)
|
||||
{
|
||||
std::string dir = command.Directory;
|
||||
for(std::string argument : command.CommandLine)
|
||||
{
|
||||
if(insertNext)
|
||||
{
|
||||
searchPaths.insert(getIncludePath(argument, command.Directory));
|
||||
insertNext = false;
|
||||
}
|
||||
if(insertFramework)
|
||||
{
|
||||
frameworkPaths.insert(getIncludePath(argument,command.Directory));
|
||||
insertFramework = false;
|
||||
}
|
||||
if(argument.substr(0,2) == "-I")
|
||||
{
|
||||
std::string includePath = getIncludePath(argument.substr(2), command.Directory);
|
||||
headerPaths.insert(includePath);
|
||||
searchPaths.insert(includePath);
|
||||
}
|
||||
if(argument == "-isystem")
|
||||
{
|
||||
insertNext = true;
|
||||
}
|
||||
if (argument == "-iframework")
|
||||
{
|
||||
insertFramework = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(std::string p : headerPaths)
|
||||
{
|
||||
m_headerPaths.push_back(FilePath(p));
|
||||
}
|
||||
|
||||
for(std::string p : searchPaths)
|
||||
{
|
||||
m_searchPaths.push_back(p);
|
||||
}
|
||||
|
||||
for(std::string p : frameworkPaths)
|
||||
{
|
||||
m_frameworkPaths.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> SolutionParserCompilationDatabase::getProjectFiles()
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::string SolutionParserCompilationDatabase::getIncludePath(const std::string& path, const std::string& dir)
|
||||
{
|
||||
if (FilePath(path).isAbsolute())
|
||||
{
|
||||
return path;
|
||||
}
|
||||
return dir + "/" + path;
|
||||
}
|
||||
|
||||
clang::tooling::JSONCompilationDatabase* SolutionParserCompilationDatabase::getDatabase()
|
||||
{
|
||||
if(m_database == nullptr)
|
||||
{
|
||||
if(m_solutionPath.empty())
|
||||
{
|
||||
LOG_ERROR("No compilation database file");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string error;
|
||||
m_database = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
|
||||
( clang::tooling::JSONCompilationDatabase::loadFromFile(m_solutionPath + m_solutionName,error) );
|
||||
}
|
||||
if(m_database == nullptr)
|
||||
{
|
||||
LOG_ERROR("Could not load compilation database from file: " + m_solutionPath );
|
||||
}
|
||||
}
|
||||
return m_database.get();
|
||||
}
|
||||
*/
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
#ifndef COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H
|
||||
#define COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H
|
||||
|
||||
#include "utility/solution/ISolutionParser.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class FilePath;
|
||||
namespace clang
|
||||
{
|
||||
namespace tooling
|
||||
{
|
||||
class JSONCompilationDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
class SolutionParserCompilationDatabase : public ISolutionParser
|
||||
{
|
||||
public:
|
||||
SolutionParserCompilationDatabase();
|
||||
~SolutionParserCompilationDatabase();
|
||||
|
||||
virtual std::string getSolutionName();
|
||||
virtual std::vector<std::string> getProjects();
|
||||
virtual std::vector<std::string> getProjectFiles();
|
||||
virtual std::vector<std::string> getProjectItems();
|
||||
virtual std::vector<std::string> getIncludePaths();
|
||||
std::vector<std::string> getFrameworkPaths();
|
||||
|
||||
void parseDatabase();
|
||||
|
||||
private:
|
||||
clang::tooling::JSONCompilationDatabase* getDatabase();
|
||||
std::string getIncludePath(const std::string& argument, const std::string& dir);
|
||||
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> m_database;
|
||||
|
||||
std::vector<FilePath> m_headerPaths;
|
||||
std::vector<std::string> m_searchPaths;
|
||||
std::vector<std::string> m_frameworkPaths;
|
||||
};
|
||||
|
||||
|
||||
#endif //COATI_SOLUTIONPARSERCOMPILATIONDATABASE_H
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ namespace utility
|
||||
bool isPermutation(const std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
return (
|
||||
a.size() == b.size() &&
|
||||
a.size() == b.size() &&
|
||||
std::is_permutation(a.begin(), a.end(), b.begin())
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user