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
@@ -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)
{