logic: indexer command refactoring

* moved SystemHeaderSearchPaths and FramewordSeearchPaths of indexer cxx indexer commands to CompilerFlags section
* added SourceGroupTestSuite to test indexer command generation of all source groups
* removed "compile_commands.json" from gitignore, because a resource file for the tests has this name
This commit is contained in:
mlangkabel
2018-09-18 17:09:28 +02:00
parent 07454f2045
commit 9dc2bcc2f9
577 changed files with 11357 additions and 9443 deletions
@@ -20,8 +20,6 @@ void SharedIndexerCommand::fromLocal(IndexerCommand* indexerCommand)
setIncludeFilters(cmd->getIncludeFilters());
setWorkingDirectory(cmd->getWorkingDirectory());
setCompilerFlags(cmd->getCompilerFlags());
setSystemHeaderSearchPaths(cmd->getSystemHeaderSearchPaths());
setFrameworkSearchhPaths(cmd->getFrameworkSearchPaths());
}
else if (dynamic_cast<IndexerCommandJava*>(indexerCommand) != nullptr)
{
@@ -50,8 +48,6 @@ std::shared_ptr<IndexerCommand> SharedIndexerCommand::fromShared(const SharedInd
indexerCommand.getExcludeFilters(),
indexerCommand.getIncludeFilters(),
indexerCommand.getWorkingDirectory(),
indexerCommand.getSystemHeaderSearchPaths(),
indexerCommand.getFrameworkSearchhPaths(),
indexerCommand.getCompilerFlags()
);
return command;
@@ -83,8 +79,6 @@ SharedIndexerCommand::SharedIndexerCommand(SharedMemory::Allocator* allocator)
, m_workingDirectory("", allocator)
, m_languageStandard("", allocator)
, m_compilerFlags(allocator)
, m_systemHeaderSearchPaths(allocator)
, m_frameworkSearchPaths(allocator)
, m_classPaths(allocator)
{
}
@@ -221,58 +215,6 @@ void SharedIndexerCommand::setCompilerFlags(const std::vector<std::wstring>& com
}
}
std::vector<FilePath> SharedIndexerCommand::getSystemHeaderSearchPaths() const
{
std::vector<FilePath> result;
result.reserve(m_systemHeaderSearchPaths.size());
for (unsigned int i = 0; i < m_systemHeaderSearchPaths.size(); i++)
{
result.push_back(FilePath(utility::decodeFromUtf8(m_systemHeaderSearchPaths[i].c_str())));
}
return result;
}
void SharedIndexerCommand::setSystemHeaderSearchPaths(const std::vector<FilePath>& filePaths)
{
m_systemHeaderSearchPaths.clear();
m_systemHeaderSearchPaths.reserve(filePaths.size());
for (const FilePath& filePath : filePaths)
{
SharedMemory::String path(m_systemHeaderSearchPaths.get_allocator());
path = utility::encodeToUtf8(filePath.wstr()).c_str();
m_systemHeaderSearchPaths.push_back(path);
}
}
std::vector<FilePath> SharedIndexerCommand::getFrameworkSearchhPaths() const
{
std::vector<FilePath> result;
result.reserve(m_frameworkSearchPaths.size());
for (unsigned int i = 0; i < m_frameworkSearchPaths.size(); i++)
{
result.push_back(FilePath(utility::decodeFromUtf8(m_frameworkSearchPaths[i].c_str())));
}
return result;
}
void SharedIndexerCommand::setFrameworkSearchhPaths(const std::vector<FilePath>& searchPaths)
{
m_frameworkSearchPaths.clear();
m_frameworkSearchPaths.reserve(searchPaths.size());
for (const FilePath& searchPath : searchPaths)
{
SharedMemory::String path(m_frameworkSearchPaths.get_allocator());
path = utility::encodeToUtf8(searchPath.wstr()).c_str();
m_frameworkSearchPaths.push_back(path);
}
}
std::vector<FilePath> SharedIndexerCommand::getClassPaths() const
{
std::vector<FilePath> result;
@@ -39,12 +39,6 @@ public:
std::vector<std::wstring> getCompilerFlags() const;
void setCompilerFlags(const std::vector<std::wstring>& compilerFlags);
std::vector<FilePath> getSystemHeaderSearchPaths() const;
void setSystemHeaderSearchPaths(const std::vector<FilePath>& filePaths);
std::vector<FilePath> getFrameworkSearchhPaths() const;
void setFrameworkSearchhPaths(const std::vector<FilePath>& searchPaths);
std::vector<FilePath> getClassPaths() const;
void setClassPaths(const std::vector<FilePath>& classPaths);
@@ -71,8 +65,6 @@ private:
SharedMemory::String m_workingDirectory;
SharedMemory::String m_languageStandard;
SharedMemory::Vector<SharedMemory::String> m_compilerFlags;
SharedMemory::Vector<SharedMemory::String> m_systemHeaderSearchPaths;
SharedMemory::Vector<SharedMemory::String> m_frameworkSearchPaths;
// java
SharedMemory::Vector<SharedMemory::String> m_classPaths;
@@ -200,15 +200,17 @@ namespace Sonargraph
LOG_ERROR(L"Source group doesn't specify any indexed header paths");
}
const std::vector<FilePath> systemHeaderSearchPaths = (appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>());
const std::vector<FilePath> frameworkSearchPaths = (appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>());
std::vector<std::wstring> compilerFlags;
compilerFlags.emplace_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>()));
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
if (std::shared_ptr<XsdRootPathWithFiles> rootPathWithFiles = std::dynamic_pointer_cast<XsdRootPathWithFiles>(rootPath))
{
utility::append(indexerCommands, getIndexerCommandsForRootPath(
rootPathWithFiles, indexedHeaderPaths, languageStandard, systemHeaderSearchPaths, frameworkSearchPaths
rootPathWithFiles, indexedHeaderPaths, compilerFlags
));
}
}
@@ -216,7 +218,7 @@ namespace Sonargraph
for (std::shared_ptr<XsdRootPathWithFiles> rootPath : m_rootPathWithFiles)
{
utility::append(indexerCommands, getIndexerCommandsForRootPath(
rootPath, indexedHeaderPaths, languageStandard, systemHeaderSearchPaths, frameworkSearchPaths
rootPath, indexedHeaderPaths, compilerFlags
));
}
@@ -294,9 +296,7 @@ namespace Sonargraph
std::vector<std::shared_ptr<IndexerCommand>> XsdCmakeJsonModule::getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath>& indexedHeaderPaths,
const std::wstring& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const
const std::vector<std::wstring>& compilerFlags) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
if (rootPath)
@@ -319,11 +319,11 @@ namespace Sonargraph
{
if (systemExtension->hasCompilerOptionsForId(id))
{
return systemExtension->getCompilerOptionsForId(id);
return utility::concat(systemExtension->getCompilerOptionsForId(id), compilerFlags);
}
}
}
return std::vector<std::wstring>();
return compilerFlags;
});
for (const XsdRootPathWithFiles::SourceFile& sourceFile : getIncludedSourceFilesForRootPath(
@@ -337,14 +337,9 @@ namespace Sonargraph
excludeFilters,
includeFilters,
softwareSystem->getBaseDirectory(),
systemHeaderSearchPaths,
frameworkSearchPaths,
utility::concat(
compilerOptionCache.getValue(sourceFile.compilerOptionSetId),
{
L"-std=" + languageStandard,
sourceFilePath.wstr()
}
sourceFilePath.wstr()
)
));
}
@@ -34,9 +34,7 @@ namespace Sonargraph
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath>& indexedHeaderPaths,
const std::wstring& languageStandard,
const std::vector<FilePath>& systemHeaderSearchPaths,
const std::vector<FilePath>& frameworkSearchPaths) const;
const std::vector<std::wstring>& compilerFlags) const;
std::vector<std::shared_ptr<XsdRootPathWithFiles>> m_rootPathWithFiles;
};
@@ -150,8 +150,6 @@ namespace Sonargraph
return std::vector<std::shared_ptr<IndexerCommand>>();
}
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
std::set<FilePath> indexedHeaderPaths;
std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic();
@@ -167,13 +165,10 @@ namespace Sonargraph
LOG_ERROR(L"Source group doesn't specify any indexed header paths");
}
const std::vector<FilePath> systemHeaderSearchPaths = (appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>());
const std::vector<FilePath> frameworkSearchPaths = (appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>());
const std::set<FilePathFilter> excludeFilters = utility::toSet(getDerivedExcludeFilters());
const std::set<FilePathFilter> includeFilters = utility::toSet(getDerivedIncludeFilters());
std::vector<std::wstring> processedOptions;
std::vector<std::wstring> compilerFlags;
{
const std::vector<std::wstring> optionPrefixes = getIncludeOptionPrefixes();
const FilePath baseIncludeDir = m_basePathForIncludes.isAbsolute() ? m_basePathForIncludes : softwareSystem->getBaseDirectory().getConcatenated(m_basePathForIncludes);
@@ -187,16 +182,16 @@ namespace Sonargraph
{
isIncludeOption = true;
processedOptions.push_back(L"-isystem");
compilerFlags.push_back(L"-isystem");
FilePath headerSearchPath(utility::trim(compilerOption.substr(optionPrefix.size())));
if (headerSearchPath.isAbsolute())
{
processedOptions.push_back(headerSearchPath.wstr());
compilerFlags.push_back(headerSearchPath.wstr());
}
else
{
processedOptions.push_back(baseIncludeDir.getConcatenated(headerSearchPath).wstr());
compilerFlags.push_back(baseIncludeDir.getConcatenated(headerSearchPath).wstr());
}
break;
}
@@ -204,13 +199,16 @@ namespace Sonargraph
if (!isIncludeOption)
{
processedOptions.push_back(compilerOption);
compilerFlags.push_back(compilerOption);
}
}
}
processedOptions.push_back(L"-std=" + languageStandard);
compilerFlags.emplace_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>()));
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (const FilePath& sourceFilePath : getAllSourceFilePathsCanonical())
{
indexerCommands.push_back(std::make_shared<IndexerCommandCxx>(
@@ -219,9 +217,7 @@ namespace Sonargraph
excludeFilters,
includeFilters,
softwareSystem->getBaseDirectory(),
systemHeaderSearchPaths,
frameworkSearchPaths,
utility::concat(processedOptions, { sourceFilePath.wstr() })
utility::concat(compilerFlags, sourceFilePath.wstr())
));
}
+23
View File
@@ -37,6 +37,12 @@ namespace utility
template<typename T>
std::set<T> concat(const std::set<T>& a, const std::set<T>& b);
template<typename T>
std::vector<T> concat(const std::vector<T>& a, const T& b);
template<typename T>
std::set<T> concat(const std::set<T>& a, const T& b);
template<typename T>
void append(std::vector<T>& a, const std::vector<T>& b);
@@ -162,6 +168,7 @@ template<typename T>
std::vector<T> utility::concat(const std::vector<T>& a, const std::vector<T>& b)
{
std::vector<T> r;
r.reserve(a.size() + b.size());
append(r, a);
append(r, b);
return r;
@@ -176,6 +183,22 @@ std::set<T> utility::concat(const std::set<T>& a, const std::set<T>& b)
return r;
}
template<typename T>
std::vector<T> utility::concat(const std::vector<T>& a, const T& b)
{
std::vector<T> r = a;
r.emplace_back(b);
return r;
}
template<typename T>
std::set<T> utility::concat(const std::set<T>& a, const T& b)
{
std::set<T> r = a;
r.emplace(b);
return r;
}
template<typename T>
void utility::append(std::vector<T>& a, const std::vector<T>& b)
{