logic: source groups for project settings
* project can not have multiple source groups with different types * language of a project is now inferred from source groups * setting global NameHierarchy delimiter of first sourceGroup in project * added project settings migrations for source groups * Add Settings Migration classes (MoveKey, DeleteKey, Lambda) * Update sample projects with migrations * added method to config to retrieve sublevel key names * implemented recursive removing of keys in settings * moved project files out of top level * removed solution parsing code as it is not used anymore fortune cookie message = The secret of getting ahead is getting started.
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
#include "project/SourceGroupCxx.h"
|
||||
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
#include "clang/Tooling/CompilationDatabase.h"
|
||||
#include "clang/Tooling/JSONCompilationDatabase.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandCxxManual.h"
|
||||
#include "data/indexer/IndexerCxxCdb.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
SourceGroupCxx::SourceGroupCxx(std::shared_ptr<SourceGroupSettingsCxx> settings)
|
||||
: m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
SourceGroupCxx::~SourceGroupCxx()
|
||||
{
|
||||
}
|
||||
|
||||
SourceGroupType SourceGroupCxx::getType() const
|
||||
{
|
||||
return m_settings->getType();
|
||||
}
|
||||
|
||||
bool SourceGroupCxx::prepareRefresh()
|
||||
{
|
||||
FilePath cdbPath = m_settings->getAbsoluteCompilationDatabasePath();
|
||||
if (!cdbPath.empty() && !cdbPath.exists())
|
||||
{
|
||||
MessageStatus("Can't refresh project").dispatch();
|
||||
|
||||
if (Application::getInstance()->hasGUI())
|
||||
{
|
||||
std::vector<std::string> options;
|
||||
options.push_back("Ok");
|
||||
Application::getInstance()->handleDialog(
|
||||
"Can't refresh. The compilation database of the project does not exist anymore: " + cdbPath.str(),
|
||||
options
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SourceGroupCxx::fetchAllSourceFilePaths()
|
||||
{
|
||||
std::vector<FilePath> sourcePaths;
|
||||
|
||||
FilePath cdbPath = m_settings->getAbsoluteCompilationDatabasePath();
|
||||
if (cdbPath.exists())
|
||||
{
|
||||
sourcePaths = IndexerCxxCdb::getSourceFilesFromCDB(cdbPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
sourcePaths = m_settings->getAbsoluteSourcePaths();
|
||||
}
|
||||
|
||||
m_sourceFilePathsToIndex.clear();
|
||||
FileManager fileManager;
|
||||
fileManager.update(sourcePaths, m_settings->getAbsoluteExcludePaths(), m_settings->getSourceExtensions());
|
||||
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupCxx::getIndexerCommands(const bool fullRefresh)
|
||||
{
|
||||
std::shared_ptr<ApplicationSettings> appSettings = ApplicationSettings::getInstance();
|
||||
|
||||
std::vector<FilePath> systemHeaderSearchPaths;
|
||||
utility::append(systemHeaderSearchPaths, m_settings->getAbsoluteHeaderSearchPaths());
|
||||
utility::append(systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded());
|
||||
|
||||
// Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files.
|
||||
for (const FilePath& sourcePath: m_settings->getAbsoluteSourcePaths())
|
||||
{
|
||||
if (sourcePath.isDirectory())
|
||||
{
|
||||
systemHeaderSearchPaths.push_back(sourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all subdirectories of the header search paths
|
||||
if (m_settings->getUseSourcePathsForHeaderSearch())
|
||||
{
|
||||
std::vector<FilePath> headerSearchSubPaths;
|
||||
for (const FilePath& sourcePath : m_settings->getAbsoluteSourcePaths())
|
||||
{
|
||||
utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(sourcePath));
|
||||
}
|
||||
|
||||
utility::append(systemHeaderSearchPaths, utility::unique(headerSearchSubPaths));
|
||||
}
|
||||
|
||||
std::vector<FilePath> frameworkSearchPaths;
|
||||
utility::append(frameworkSearchPaths, m_settings->getAbsoluteFrameworkSearchPaths());
|
||||
utility::append(frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded());
|
||||
|
||||
const std::vector<std::string> compilerFlags = m_settings->getCompilerFlags();
|
||||
|
||||
std::set<FilePath> indexedPaths;
|
||||
for (FilePath p: m_settings->getAbsoluteSourcePaths())
|
||||
{
|
||||
if (p.exists())
|
||||
{
|
||||
indexedPaths.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
std::set<FilePath> excludedPaths;
|
||||
for (FilePath p: m_settings->getAbsoluteExcludePaths())
|
||||
{
|
||||
if (p.exists())
|
||||
{
|
||||
excludedPaths.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
|
||||
|
||||
const std::set<FilePath>& sourceFilePathsToIndex = (fullRefresh ? getAllSourceFilePaths() : getSourceFilePathsToIndex());
|
||||
|
||||
FilePath cdbPath = m_settings->getAbsoluteCompilationDatabasePath();
|
||||
if (cdbPath.exists())
|
||||
{
|
||||
std::string error;
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = std::shared_ptr<clang::tooling::JSONCompilationDatabase>
|
||||
(clang::tooling::JSONCompilationDatabase::loadFromFile(cdbPath.str(), error));
|
||||
for (clang::tooling::CompileCommand command: cdb->getAllCompileCommands())
|
||||
{
|
||||
if (sourceFilePathsToIndex.find(FilePath(command.Filename)) != sourceFilePathsToIndex.end())
|
||||
{
|
||||
std::vector<std::string> currentCompilerFlags = compilerFlags;
|
||||
currentCompilerFlags.insert(currentCompilerFlags.end(), command.CommandLine.begin(), command.CommandLine.end());
|
||||
|
||||
indexerCommands.push_back(std::make_shared<IndexerCommandCxxCdb>(
|
||||
FilePath(command.Filename),
|
||||
indexedPaths,
|
||||
excludedPaths,
|
||||
FilePath(command.Directory),
|
||||
currentCompilerFlags,
|
||||
systemHeaderSearchPaths,
|
||||
frameworkSearchPaths
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const FilePath& sourcePath: sourceFilePathsToIndex)
|
||||
{
|
||||
indexerCommands.push_back(std::make_shared<IndexerCommandCxxManual>(
|
||||
sourcePath,
|
||||
indexedPaths,
|
||||
excludedPaths,
|
||||
m_settings->getStandard(),
|
||||
systemHeaderSearchPaths,
|
||||
frameworkSearchPaths,
|
||||
compilerFlags
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return indexerCommands;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef SOURCE_GROUP_CXX_H
|
||||
#define SOURCE_GROUP_CXX_H
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include "project/SourceGroup.h"
|
||||
#include "settings/SourceGroupSettingsCxx.h"
|
||||
#include "utility/file/FileManager.h"
|
||||
|
||||
class SourceGroupCxx: public SourceGroup
|
||||
{
|
||||
public:
|
||||
SourceGroupCxx(std::shared_ptr<SourceGroupSettingsCxx> settings);
|
||||
virtual ~SourceGroupCxx();
|
||||
|
||||
virtual SourceGroupType getType() const;
|
||||
|
||||
virtual bool prepareRefresh();
|
||||
|
||||
virtual void fetchAllSourceFilePaths();
|
||||
|
||||
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const bool fullRefresh);
|
||||
|
||||
private:
|
||||
std::shared_ptr<SourceGroupSettingsCxx> m_settings;
|
||||
};
|
||||
|
||||
#endif // SOURCE_GROUP_CXX_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "project/SourceGroupFactoryModuleC.h"
|
||||
|
||||
#include "project/SourceGroupCxx.h"
|
||||
#include "settings/SourceGroupSettingsCxx.h"
|
||||
|
||||
SourceGroupFactoryModuleC::~SourceGroupFactoryModuleC()
|
||||
{
|
||||
}
|
||||
|
||||
bool SourceGroupFactoryModuleC::supports(SourceGroupType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SOURCE_GROUP_C_EMPTY:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleC::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings)
|
||||
{
|
||||
std::shared_ptr<SourceGroup> sourceGroup;
|
||||
if (std::shared_ptr<SourceGroupSettingsCxx> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxx>(settings))
|
||||
{
|
||||
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupCxx(cxxSettings));
|
||||
}
|
||||
return sourceGroup;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SOURCE_GROUP_FACTORY_MODULE_C_H
|
||||
#define SOURCE_GROUP_FACTORY_MODULE_C_H
|
||||
|
||||
#include "project/SourceGroupFactoryModule.h"
|
||||
|
||||
class SourceGroupFactoryModuleC: public SourceGroupFactoryModule
|
||||
{
|
||||
public:
|
||||
virtual ~SourceGroupFactoryModuleC();
|
||||
virtual bool supports(SourceGroupType type) const;
|
||||
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
|
||||
};
|
||||
|
||||
#endif // SOURCE_GROUP_FACTORY_MODULE_C_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "project/SourceGroupFactoryModuleCpp.h"
|
||||
|
||||
#include "project/SourceGroupCxx.h"
|
||||
#include "settings/SourceGroupSettingsCxx.h"
|
||||
|
||||
SourceGroupFactoryModuleCpp::~SourceGroupFactoryModuleCpp()
|
||||
{
|
||||
}
|
||||
|
||||
bool SourceGroupFactoryModuleCpp::supports(SourceGroupType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SOURCE_GROUP_CPP_EMPTY:
|
||||
case SOURCE_GROUP_CXX_CDB:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleCpp::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings)
|
||||
{
|
||||
std::shared_ptr<SourceGroup> sourceGroup;
|
||||
if (std::shared_ptr<SourceGroupSettingsCxx> cxxSettings = std::dynamic_pointer_cast<SourceGroupSettingsCxx>(settings))
|
||||
{
|
||||
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupCxx(cxxSettings));
|
||||
}
|
||||
return sourceGroup;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef SOURCE_GROUP_FACTORY_MODULE_CPP_H
|
||||
#define SOURCE_GROUP_FACTORY_MODULE_CPP_H
|
||||
|
||||
#include "project/SourceGroupFactoryModule.h"
|
||||
|
||||
class SourceGroupFactoryModuleCpp: public SourceGroupFactoryModule
|
||||
{
|
||||
public:
|
||||
virtual ~SourceGroupFactoryModuleCpp();
|
||||
virtual bool supports(SourceGroupType type) const;
|
||||
virtual std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings);
|
||||
};
|
||||
|
||||
#endif // SOURCE_GROUP_FACTORY_MODULE_CPP_H
|
||||
Reference in New Issue
Block a user