forked from qt-creator/qt-creator
Clang: Add top system includes to include collector
If we want to split the project part we have to filter out the top system includes. Task-number: QTCREATORBUG-21345 Change-Id: I258fa33ac39bd94b4699f4f39923d6ad274c1dc7 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -41,11 +41,13 @@ class CollectIncludesAction final : public clang::PreprocessOnlyAction
|
|||||||
public:
|
public:
|
||||||
CollectIncludesAction(FilePathIds &includeIds,
|
CollectIncludesAction(FilePathIds &includeIds,
|
||||||
FilePathIds &topIncludeIds,
|
FilePathIds &topIncludeIds,
|
||||||
|
FilePathIds &topsSystemIncludeIds,
|
||||||
const FilePathCachingInterface &filePathCache,
|
const FilePathCachingInterface &filePathCache,
|
||||||
std::vector<uint> &excludedIncludeUID,
|
std::vector<uint> &excludedIncludeUID,
|
||||||
std::vector<uint> &alreadyIncludedFileUIDs)
|
std::vector<uint> &alreadyIncludedFileUIDs)
|
||||||
: m_includeIds(includeIds),
|
: m_includeIds(includeIds),
|
||||||
m_topIncludeIds(topIncludeIds),
|
m_topIncludeIds(topIncludeIds),
|
||||||
|
m_topsSystemIncludeIds(topsSystemIncludeIds),
|
||||||
m_filePathCache(filePathCache),
|
m_filePathCache(filePathCache),
|
||||||
m_excludedIncludeUID(excludedIncludeUID),
|
m_excludedIncludeUID(excludedIncludeUID),
|
||||||
m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs)
|
m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs)
|
||||||
@@ -62,6 +64,7 @@ public:
|
|||||||
auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks(
|
auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks(
|
||||||
m_includeIds,
|
m_includeIds,
|
||||||
m_topIncludeIds,
|
m_topIncludeIds,
|
||||||
|
m_topsSystemIncludeIds,
|
||||||
m_filePathCache,
|
m_filePathCache,
|
||||||
m_excludedIncludeUID,
|
m_excludedIncludeUID,
|
||||||
m_alreadyIncludedFileUIDs,
|
m_alreadyIncludedFileUIDs,
|
||||||
@@ -83,6 +86,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
FilePathIds &m_includeIds;
|
FilePathIds &m_includeIds;
|
||||||
FilePathIds &m_topIncludeIds;
|
FilePathIds &m_topIncludeIds;
|
||||||
|
FilePathIds &m_topsSystemIncludeIds;
|
||||||
const FilePathCachingInterface &m_filePathCache;
|
const FilePathCachingInterface &m_filePathCache;
|
||||||
std::vector<uint> &m_excludedIncludeUID;
|
std::vector<uint> &m_excludedIncludeUID;
|
||||||
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
||||||
|
@@ -50,12 +50,14 @@ class CollectIncludesPreprocessorCallbacks final : public clang::PPCallbacks
|
|||||||
public:
|
public:
|
||||||
CollectIncludesPreprocessorCallbacks(FilePathIds &includeIds,
|
CollectIncludesPreprocessorCallbacks(FilePathIds &includeIds,
|
||||||
FilePathIds &topIncludeIds,
|
FilePathIds &topIncludeIds,
|
||||||
|
FilePathIds &topsSystemIncludeIds,
|
||||||
const FilePathCachingInterface &filePathCache,
|
const FilePathCachingInterface &filePathCache,
|
||||||
const std::vector<uint> &excludedIncludeUID,
|
const std::vector<uint> &excludedIncludeUID,
|
||||||
std::vector<uint> &alreadyIncludedFileUIDs,
|
std::vector<uint> &alreadyIncludedFileUIDs,
|
||||||
clang::SourceManager &sourceManager)
|
clang::SourceManager &sourceManager)
|
||||||
: m_includeIds(includeIds),
|
: m_includeIds(includeIds),
|
||||||
m_topIncludeIds(topIncludeIds),
|
m_topIncludeIds(topIncludeIds),
|
||||||
|
m_topsSystemIncludeIds(topsSystemIncludeIds),
|
||||||
m_filePathCache(filePathCache),
|
m_filePathCache(filePathCache),
|
||||||
m_excludedIncludeUID(excludedIncludeUID),
|
m_excludedIncludeUID(excludedIncludeUID),
|
||||||
m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs),
|
m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs),
|
||||||
@@ -70,11 +72,8 @@ public:
|
|||||||
const clang::FileEntry *file,
|
const clang::FileEntry *file,
|
||||||
llvm::StringRef /*searchPath*/,
|
llvm::StringRef /*searchPath*/,
|
||||||
llvm::StringRef /*relativePath*/,
|
llvm::StringRef /*relativePath*/,
|
||||||
const clang::Module * /*imported*/
|
const clang::Module * /*imported*/,
|
||||||
#if LLVM_VERSION_MAJOR >= 7
|
clang::SrcMgr::CharacteristicKind fileType) override
|
||||||
, clang::SrcMgr::CharacteristicKind /*fileType*/
|
|
||||||
#endif
|
|
||||||
) override
|
|
||||||
{
|
{
|
||||||
if (!m_skipInclude && file) {
|
if (!m_skipInclude && file) {
|
||||||
auto fileUID = file->getUID();
|
auto fileUID = file->getUID();
|
||||||
@@ -87,6 +86,8 @@ public:
|
|||||||
if (!filePath.empty()) {
|
if (!filePath.empty()) {
|
||||||
FilePathId includeId = m_filePathCache.filePathId(filePath);
|
FilePathId includeId = m_filePathCache.filePathId(filePath);
|
||||||
m_includeIds.emplace_back(includeId);
|
m_includeIds.emplace_back(includeId);
|
||||||
|
if (isSystem(fileType) && !isInSystemHeader(hashLocation))
|
||||||
|
m_topsSystemIncludeIds.emplace_back(includeId);
|
||||||
if (isInExcludedIncludeUID(sourceFileUID))
|
if (isInExcludedIncludeUID(sourceFileUID))
|
||||||
m_topIncludeIds.emplace_back(includeId);
|
m_topIncludeIds.emplace_back(includeId);
|
||||||
}
|
}
|
||||||
@@ -116,6 +117,16 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSystem(clang::SrcMgr::CharacteristicKind kind)
|
||||||
|
{
|
||||||
|
return kind != clang::SrcMgr::C_User && kind != clang::SrcMgr::C_User_ModuleMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInSystemHeader(clang::SourceLocation location)
|
||||||
|
{
|
||||||
|
return m_sourceManager.isInSystemHeader(location);
|
||||||
|
}
|
||||||
|
|
||||||
void ensureDirectory(const QString &directory, const QString &fileName)
|
void ensureDirectory(const QString &directory, const QString &fileName)
|
||||||
{
|
{
|
||||||
QStringList directoryEntries = fileName.split('/');
|
QStringList directoryEntries = fileName.split('/');
|
||||||
@@ -163,6 +174,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
FilePathIds &m_includeIds;
|
FilePathIds &m_includeIds;
|
||||||
FilePathIds &m_topIncludeIds;
|
FilePathIds &m_topIncludeIds;
|
||||||
|
FilePathIds &m_topsSystemIncludeIds;
|
||||||
const FilePathCachingInterface &m_filePathCache;
|
const FilePathCachingInterface &m_filePathCache;
|
||||||
const std::vector<uint> &m_excludedIncludeUID;
|
const std::vector<uint> &m_excludedIncludeUID;
|
||||||
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
||||||
|
@@ -39,10 +39,12 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac
|
|||||||
public:
|
public:
|
||||||
CollectIncludesToolAction(FilePathIds &includeIds,
|
CollectIncludesToolAction(FilePathIds &includeIds,
|
||||||
FilePathIds &topIncludeIds,
|
FilePathIds &topIncludeIds,
|
||||||
|
FilePathIds &topsSystemIncludeIds,
|
||||||
const FilePathCachingInterface &filePathCache,
|
const FilePathCachingInterface &filePathCache,
|
||||||
const Utils::PathStringVector &excludedIncludes)
|
const Utils::PathStringVector &excludedIncludes)
|
||||||
: m_includeIds(includeIds),
|
: m_includeIds(includeIds),
|
||||||
m_topIncludeIds(topIncludeIds),
|
m_topIncludeIds(topIncludeIds),
|
||||||
|
m_topsSystemIncludeIds(topsSystemIncludeIds),
|
||||||
m_filePathCache(filePathCache),
|
m_filePathCache(filePathCache),
|
||||||
m_excludedIncludes(excludedIncludes)
|
m_excludedIncludes(excludedIncludes)
|
||||||
{}
|
{}
|
||||||
@@ -66,6 +68,7 @@ public:
|
|||||||
{
|
{
|
||||||
return new CollectIncludesAction(m_includeIds,
|
return new CollectIncludesAction(m_includeIds,
|
||||||
m_topIncludeIds,
|
m_topIncludeIds,
|
||||||
|
m_topsSystemIncludeIds,
|
||||||
m_filePathCache,
|
m_filePathCache,
|
||||||
m_excludedIncludeUIDs,
|
m_excludedIncludeUIDs,
|
||||||
m_alreadyIncludedFileUIDs);
|
m_alreadyIncludedFileUIDs);
|
||||||
@@ -93,6 +96,7 @@ private:
|
|||||||
std::vector<uint> m_excludedIncludeUIDs;
|
std::vector<uint> m_excludedIncludeUIDs;
|
||||||
FilePathIds &m_includeIds;
|
FilePathIds &m_includeIds;
|
||||||
FilePathIds &m_topIncludeIds;
|
FilePathIds &m_topIncludeIds;
|
||||||
|
FilePathIds &m_topsSystemIncludeIds;
|
||||||
const FilePathCachingInterface &m_filePathCache;
|
const FilePathCachingInterface &m_filePathCache;
|
||||||
const Utils::PathStringVector &m_excludedIncludes;
|
const Utils::PathStringVector &m_excludedIncludes;
|
||||||
};
|
};
|
||||||
|
@@ -45,6 +45,7 @@ void IncludeCollector::collectIncludes()
|
|||||||
auto action = std::unique_ptr<CollectIncludesToolAction>(
|
auto action = std::unique_ptr<CollectIncludesToolAction>(
|
||||||
new CollectIncludesToolAction(m_includeIds,
|
new CollectIncludesToolAction(m_includeIds,
|
||||||
m_topIncludeIds,
|
m_topIncludeIds,
|
||||||
|
m_topsSystemIncludeIds,
|
||||||
m_filePathCache,
|
m_filePathCache,
|
||||||
m_excludedIncludes));
|
m_excludedIncludes));
|
||||||
|
|
||||||
@@ -84,6 +85,11 @@ FilePathIds IncludeCollector::takeTopIncludeIds()
|
|||||||
return std::move(m_topIncludeIds);
|
return std::move(m_topIncludeIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePathIds IncludeCollector::takeTopsSystemIncludeIds()
|
||||||
|
{
|
||||||
|
return std::move(m_topsSystemIncludeIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
@@ -42,11 +42,13 @@ public:
|
|||||||
|
|
||||||
FilePathIds takeIncludeIds();
|
FilePathIds takeIncludeIds();
|
||||||
FilePathIds takeTopIncludeIds();
|
FilePathIds takeTopIncludeIds();
|
||||||
|
FilePathIds takeTopsSystemIncludeIds();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::PathStringVector m_excludedIncludes;
|
Utils::PathStringVector m_excludedIncludes;
|
||||||
FilePathIds m_includeIds;
|
FilePathIds m_includeIds;
|
||||||
FilePathIds m_topIncludeIds;
|
FilePathIds m_topIncludeIds;
|
||||||
|
FilePathIds m_topsSystemIncludeIds;
|
||||||
Utils::SmallStringVector m_directories;
|
Utils::SmallStringVector m_directories;
|
||||||
const FilePathCachingInterface &m_filePathCache;
|
const FilePathCachingInterface &m_filePathCache;
|
||||||
};
|
};
|
||||||
|
@@ -236,7 +236,7 @@ Utils::PathStringVector PchCreator::generateProjectPartSourcePaths(
|
|||||||
return includeAndSources;
|
return includeAndSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<FilePathIds,FilePathIds> PchCreator::generateProjectPartPchIncludes(
|
PchCreatorIncludes PchCreator::generateProjectPartPchIncludes(
|
||||||
const V2::ProjectPartContainer &projectPart) const
|
const V2::ProjectPartContainer &projectPart) const
|
||||||
{
|
{
|
||||||
Utils::SmallString jointedFileContent = generateProjectPartSourcesContent(projectPart);
|
Utils::SmallString jointedFileContent = generateProjectPartSourcesContent(projectPart);
|
||||||
@@ -261,7 +261,7 @@ std::pair<FilePathIds,FilePathIds> PchCreator::generateProjectPartPchIncludes(
|
|||||||
|
|
||||||
jointFile->remove();
|
jointFile->remove();
|
||||||
|
|
||||||
return {collector.takeIncludeIds(), collector.takeTopIncludeIds()};
|
return {collector.takeIncludeIds(), collector.takeTopIncludeIds(), collector.takeTopsSystemIncludeIds()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString PchCreator::generateProjectPathPchHeaderFilePath(
|
Utils::SmallString PchCreator::generateProjectPathPchHeaderFilePath(
|
||||||
@@ -312,10 +312,8 @@ Utils::SmallStringVector PchCreator::generateProjectPartClangCompilerArguments(
|
|||||||
IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &projectPart)
|
IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &projectPart)
|
||||||
{
|
{
|
||||||
long long lastModified = QDateTime::currentSecsSinceEpoch();
|
long long lastModified = QDateTime::currentSecsSinceEpoch();
|
||||||
FilePathIds allExternalIncludes;
|
auto includes = generateProjectPartPchIncludes(projectPart);
|
||||||
FilePathIds topExternalIncludes;
|
auto content = generatePchIncludeFileContent(includes.topIncludeIds);
|
||||||
std::tie(allExternalIncludes, topExternalIncludes) = generateProjectPartPchIncludes(projectPart);
|
|
||||||
auto content = generatePchIncludeFileContent(topExternalIncludes);
|
|
||||||
auto pchIncludeFilePath = generateProjectPathPchHeaderFilePath(projectPart);
|
auto pchIncludeFilePath = generateProjectPathPchHeaderFilePath(projectPart);
|
||||||
auto pchFilePath = generateProjectPartPchFilePath(projectPart);
|
auto pchFilePath = generateProjectPartPchFilePath(projectPart);
|
||||||
generateFileWithContent(pchIncludeFilePath, content);
|
generateFileWithContent(pchIncludeFilePath, content);
|
||||||
@@ -329,7 +327,7 @@ IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &proje
|
|||||||
m_projectPartPch.lastModified = lastModified;
|
m_projectPartPch.lastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {projectPart.projectPartId.clone(), std::move(allExternalIncludes)};
|
return {projectPart.projectPartId.clone(), std::move(includes.includeIds)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void PchCreator::generatePch(const V2::ProjectPartContainer &projectPart)
|
void PchCreator::generatePch(const V2::ProjectPartContainer &projectPart)
|
||||||
|
@@ -46,6 +46,14 @@ class GeneratedFiles;
|
|||||||
class PchManagerClientInterface;
|
class PchManagerClientInterface;
|
||||||
class ClangPathWatcherInterface;
|
class ClangPathWatcherInterface;
|
||||||
|
|
||||||
|
class PchCreatorIncludes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FilePathIds includeIds;
|
||||||
|
FilePathIds topIncludeIds;
|
||||||
|
FilePathIds topSystemIncludeIds;
|
||||||
|
};
|
||||||
|
|
||||||
class PchCreator final : public PchCreatorInterface
|
class PchCreator final : public PchCreatorInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -87,7 +95,7 @@ public:
|
|||||||
const V2::ProjectPartContainer &projectPart) const;
|
const V2::ProjectPartContainer &projectPart) const;
|
||||||
Utils::PathStringVector generateProjectPartSourcePaths(
|
Utils::PathStringVector generateProjectPartSourcePaths(
|
||||||
const V2::ProjectPartContainer &projectPart) const;
|
const V2::ProjectPartContainer &projectPart) const;
|
||||||
std::pair<FilePathIds,FilePathIds> generateProjectPartPchIncludes(
|
PchCreatorIncludes generateProjectPartPchIncludes(
|
||||||
const V2::ProjectPartContainer &projectPart) const;
|
const V2::ProjectPartContainer &projectPart) const;
|
||||||
Utils::SmallString generateProjectPathPchHeaderFilePath(
|
Utils::SmallString generateProjectPathPchHeaderFilePath(
|
||||||
const V2::ProjectPartContainer &projectPart) const;
|
const V2::ProjectPartContainer &projectPart) const;
|
||||||
|
3
tests/unit/unittest/data/includecollector/external/external1.h
vendored
Normal file
3
tests/unit/unittest/data/includecollector/external/external1.h
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "indirect_external.h"
|
3
tests/unit/unittest/data/includecollector/external/indirect_external.h
vendored
Normal file
3
tests/unit/unittest/data/includecollector/external/indirect_external.h
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "indirect_external2.h"
|
@@ -0,0 +1 @@
|
|||||||
|
#include "faulty.h"
|
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "external3.h"
|
7
tests/unit/unittest/data/includecollector/project/if.cpp
Normal file
7
tests/unit/unittest/data/includecollector/project/if.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#if 0
|
||||||
|
#include "false.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
#include "true.h"
|
||||||
|
#endif
|
@@ -0,0 +1,4 @@
|
|||||||
|
#include "header1.h"
|
||||||
|
#include "header2.h"
|
||||||
|
#include "external1.h"
|
||||||
|
#include "../external/external2.h"
|
@@ -0,0 +1,5 @@
|
|||||||
|
#include "header1.h"
|
||||||
|
#include "header2.h"
|
||||||
|
#include "external1.h"
|
||||||
|
#include "../external/external2.h"
|
||||||
|
#include "generated_file.h"
|
@@ -0,0 +1,6 @@
|
|||||||
|
#include <header1.h>
|
||||||
|
#include <header2.h>
|
||||||
|
#include <external1.h>
|
||||||
|
#include <external2.h>
|
||||||
|
#include <system1.h>
|
||||||
|
|
@@ -3,4 +3,4 @@
|
|||||||
#include <missing_file2.moc>
|
#include <missing_file2.moc>
|
||||||
#include <foo2/missing_file2.moc>
|
#include <foo2/missing_file2.moc>
|
||||||
|
|
||||||
#include "includecollector_external1.h"
|
#include "external1.h"
|
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "indirect_system2.h"
|
@@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
|
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "indirect_system.h"
|
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
@@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "includecollector_indirect_external.h"
|
|
@@ -1 +0,0 @@
|
|||||||
#include "includecollector_faulty.h"
|
|
@@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "includecollector_external3.h"
|
|
@@ -1,7 +0,0 @@
|
|||||||
#if 0
|
|
||||||
#include "includecollector_false.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
#include "includecollector_true.h"
|
|
||||||
#endif
|
|
@@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "includecollector_indirect_external2.h"
|
|
@@ -1,4 +0,0 @@
|
|||||||
#include "includecollector_header1.h"
|
|
||||||
#include "includecollector_header2.h"
|
|
||||||
#include "includecollector_external1.h"
|
|
||||||
#include "../data/includecollector_external2.h"
|
|
@@ -1,5 +0,0 @@
|
|||||||
#include "includecollector_header1.h"
|
|
||||||
#include "includecollector_header2.h"
|
|
||||||
#include "includecollector_external1.h"
|
|
||||||
#include "../data/includecollector_external2.h"
|
|
||||||
#include "includecollector_generated_file.h"
|
|
@@ -1,4 +0,0 @@
|
|||||||
#include <includecollector_header1.h>
|
|
||||||
#include <includecollector_header2.h>
|
|
||||||
#include <includecollector_external1.h>
|
|
||||||
#include <includecollector_external2.h>
|
|
@@ -42,6 +42,7 @@
|
|||||||
#include <filepath.h>
|
#include <filepath.h>
|
||||||
#include <fulltokeninfo.h>
|
#include <fulltokeninfo.h>
|
||||||
#include <nativefilepath.h>
|
#include <nativefilepath.h>
|
||||||
|
#include <pchcreator.h>
|
||||||
#include <precompiledheadersupdatedmessage.h>
|
#include <precompiledheadersupdatedmessage.h>
|
||||||
#include <projectpartartefact.h>
|
#include <projectpartartefact.h>
|
||||||
#include <sourcedependency.h>
|
#include <sourcedependency.h>
|
||||||
@@ -1000,6 +1001,11 @@ std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task)
|
|||||||
return out << "(" << task.filePathId << ", " << task.projectPartId << ")";
|
return out << "(" << task.filePathId << ", " << task.projectPartId << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes)
|
||||||
|
{
|
||||||
|
return out << "(" << includes.includeIds << ", " << includes.topIncludeIds << ", " << includes.topSystemIncludeIds << ")";
|
||||||
|
}
|
||||||
|
|
||||||
void PrintTo(const FilePath &filePath, ::std::ostream *os)
|
void PrintTo(const FilePath &filePath, ::std::ostream *os)
|
||||||
{
|
{
|
||||||
*os << filePath;
|
*os << filePath;
|
||||||
|
@@ -169,6 +169,7 @@ class RemoveGeneratedFilesMessage;
|
|||||||
class SuspendResumeJobsEntry;
|
class SuspendResumeJobsEntry;
|
||||||
class ReferencesResult;
|
class ReferencesResult;
|
||||||
class SymbolIndexerTask;
|
class SymbolIndexerTask;
|
||||||
|
class PchCreatorIncludes;
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
|
std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry);
|
||||||
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
|
std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths);
|
||||||
@@ -248,6 +249,7 @@ std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &m
|
|||||||
std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry);
|
std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry);
|
||||||
std::ostream &operator<<(std::ostream &os, const ReferencesResult &value);
|
std::ostream &operator<<(std::ostream &os, const ReferencesResult &value);
|
||||||
std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task);
|
std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes);
|
||||||
|
|
||||||
void PrintTo(const FilePath &filePath, ::std::ostream *os);
|
void PrintTo(const FilePath &filePath, ::std::ostream *os);
|
||||||
void PrintTo(const FilePathView &filePathView, ::std::ostream *os);
|
void PrintTo(const FilePathView &filePathView, ::std::ostream *os);
|
||||||
|
@@ -74,27 +74,27 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
|
||||||
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
||||||
FilePath main1Path = TESTDATA_DIR "/includecollector_main3.cpp";
|
FilePath main1Path = TESTDATA_DIR "/includecollector/project/main3.cpp";
|
||||||
FilePath main2Path = TESTDATA_DIR "/includecollector_main2.cpp";
|
FilePath main2Path = TESTDATA_DIR "/includecollector/project/main2.cpp";
|
||||||
FilePath header1Path = TESTDATA_DIR "/includecollector_header1.h";
|
FilePath header1Path = TESTDATA_DIR "/includecollector/project/header1.h";
|
||||||
FilePath header2Path = TESTDATA_DIR "/includecollector_header2.h";
|
FilePath header2Path = TESTDATA_DIR "/includecollector/project/header2.h";
|
||||||
Utils::SmallStringView generatedFileName = "includecollector_generated_file.h";
|
Utils::SmallStringView generatedFileName = "includecollector/project/generated_file.h";
|
||||||
FilePath generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h";
|
FilePath generatedFilePath = TESTDATA_DIR "/includecollector/project/generated_file.h";
|
||||||
TestEnvironment environment;
|
TestEnvironment environment;
|
||||||
FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}};
|
FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}};
|
||||||
NiceMock<MockPchManagerClient> mockPchManagerClient;
|
NiceMock<MockPchManagerClient> mockPchManagerClient;
|
||||||
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
|
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
|
||||||
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
|
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
|
||||||
ProjectPartContainer projectPart1{"project1",
|
ProjectPartContainer projectPart1{"project1",
|
||||||
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1"}},
|
||||||
{"/includes"},
|
{TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"},
|
||||||
{id(header1Path)},
|
{id(header1Path)},
|
||||||
{id(main1Path)}};
|
{id(main1Path)}};
|
||||||
ProjectPartContainer projectPart2{"project2",
|
ProjectPartContainer projectPart2{"project2",
|
||||||
{"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
{"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"},
|
||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1"}},
|
||||||
{"/includes"},
|
{TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"},
|
||||||
{id(header2Path)},
|
{id(header2Path)},
|
||||||
{id(main2Path)}};
|
{id(main2Path)}};
|
||||||
};
|
};
|
||||||
@@ -112,7 +112,7 @@ TEST_F(PchCreator, CreateProjectPartCommandLine)
|
|||||||
{
|
{
|
||||||
auto commandLine = creator.generateProjectPartCommandLine(projectPart1);
|
auto commandLine = creator.generateProjectPartCommandLine(projectPart1);
|
||||||
|
|
||||||
ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"));
|
ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreator, CreateProjectPartHeaders)
|
TEST_F(PchCreator, CreateProjectPartHeaders)
|
||||||
@@ -131,39 +131,41 @@ TEST_F(PchCreator, CreateProjectPartSources)
|
|||||||
|
|
||||||
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
|
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
|
||||||
{
|
{
|
||||||
using IncludePair = decltype(creator.generateProjectPartPchIncludes(projectPart1));
|
using ClangBackEnd::PchCreatorIncludes;
|
||||||
|
|
||||||
auto includeIds = creator.generateProjectPartPchIncludes(projectPart1);
|
auto includeIds = creator.generateProjectPartPchIncludes(projectPart1);
|
||||||
|
|
||||||
ASSERT_THAT(includeIds,
|
ASSERT_THAT(includeIds,
|
||||||
AllOf(
|
AllOf(
|
||||||
Field(&IncludePair::first,
|
Field(&PchCreatorIncludes::includeIds,
|
||||||
AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")),
|
AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
|
||||||
Contains(id(TESTDATA_DIR "/includecollector_external2.h")),
|
Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")),
|
||||||
Contains(id(TESTDATA_DIR "/includecollector_header2.h")))),
|
Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")),
|
||||||
Field(&IncludePair::second,
|
Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")))),
|
||||||
AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")),
|
Field(&PchCreatorIncludes::topSystemIncludeIds,
|
||||||
Contains(id(TESTDATA_DIR "/includecollector_external2.h"))))));
|
AllOf(Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")),
|
||||||
|
Not(Contains(id(TESTDATA_DIR "/includecollector/system/indirect_system.h"))))),
|
||||||
|
Field(&PchCreatorIncludes::topIncludeIds,
|
||||||
|
AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
|
||||||
|
Contains(id(TESTDATA_DIR "/includecollector/external/external2.h"))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
|
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
|
||||||
{
|
{
|
||||||
FilePathIds topExternalIncludes;
|
auto includes = creator.generateProjectPartPchIncludes(projectPart1);
|
||||||
std::tie(std::ignore, topExternalIncludes) = creator.generateProjectPartPchIncludes(projectPart1);
|
|
||||||
|
|
||||||
auto content = creator.generatePchIncludeFileContent(topExternalIncludes);
|
auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds);
|
||||||
|
|
||||||
ASSERT_THAT(std::string(content),
|
ASSERT_THAT(std::string(content),
|
||||||
AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_header2.h\"\n"),
|
AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"),
|
||||||
HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"),
|
HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"),
|
||||||
HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n")));
|
HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
|
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
|
||||||
{
|
{
|
||||||
FilePathIds topExternalIncludes;
|
auto includes = creator.generateProjectPartPchIncludes(projectPart1);
|
||||||
std::tie(std::ignore, topExternalIncludes) = creator.generateProjectPartPchIncludes(projectPart1);
|
auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds);
|
||||||
auto content = creator.generatePchIncludeFileContent(topExternalIncludes);
|
|
||||||
auto pchIncludeFilePath = creator.generateProjectPathPchHeaderFilePath(projectPart1);
|
auto pchIncludeFilePath = creator.generateProjectPathPchHeaderFilePath(projectPart1);
|
||||||
auto file = creator.generateFileWithContent(pchIncludeFilePath, content);
|
auto file = creator.generateFileWithContent(pchIncludeFilePath, content);
|
||||||
file->open(QIODevice::ReadOnly);
|
file->open(QIODevice::ReadOnly);
|
||||||
@@ -171,9 +173,9 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
|
|||||||
auto fileContent = file->readAll();
|
auto fileContent = file->readAll();
|
||||||
|
|
||||||
ASSERT_THAT(fileContent.toStdString(),
|
ASSERT_THAT(fileContent.toStdString(),
|
||||||
AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_header2.h\"\n"),
|
AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"),
|
||||||
HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"),
|
HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"),
|
||||||
HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n")));
|
HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreator, CreateProjectPartPchCompilerArguments)
|
TEST_F(PchCreator, CreateProjectPartPchCompilerArguments)
|
||||||
@@ -233,9 +235,9 @@ TEST_F(PchCreatorVerySlowTest, IdPathsForCreatePchsForProjectParts)
|
|||||||
|
|
||||||
ASSERT_THAT(creator.takeProjectIncludes(),
|
ASSERT_THAT(creator.takeProjectIncludes(),
|
||||||
AllOf(Field(&IdPaths::id, "project1"),
|
AllOf(Field(&IdPaths::id, "project1"),
|
||||||
Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/includecollector_header2.h")),
|
Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")),
|
||||||
Contains(id(TESTDATA_DIR "/includecollector_external1.h")),
|
Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")),
|
||||||
Contains(id(TESTDATA_DIR "/includecollector_external2.h"))))));
|
Contains(id(TESTDATA_DIR "/includecollector/external/external2.h"))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForProjectPart)
|
TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForProjectPart)
|
||||||
@@ -274,7 +276,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesNoPchForProjectPart
|
|||||||
{{"DEFINE", "1"}},
|
{{"DEFINE", "1"}},
|
||||||
{"/includes"},
|
{"/includes"},
|
||||||
{},
|
{},
|
||||||
{id(TESTDATA_DIR "/includecollector_faulty.cpp")}};
|
{id(TESTDATA_DIR "/includecollector/project/faulty.cpp")}};
|
||||||
|
|
||||||
creator.generatePch(faultyProjectPart);
|
creator.generatePch(faultyProjectPart);
|
||||||
|
|
||||||
@@ -288,14 +290,14 @@ TEST_F(PchCreator, CreateProjectPartSourcesContent)
|
|||||||
{
|
{
|
||||||
auto content = creator.generateProjectPartSourcesContent(projectPart1);
|
auto content = creator.generateProjectPartSourcesContent(projectPart1);
|
||||||
|
|
||||||
ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector_main3.cpp\"\n"));
|
ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PchCreator, Call)
|
TEST_F(PchCreator, Call)
|
||||||
{
|
{
|
||||||
auto content = creator.generateProjectPartSourcesContent(projectPart1);
|
auto content = creator.generateProjectPartSourcesContent(projectPart1);
|
||||||
|
|
||||||
ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector_main3.cpp\"\n"));
|
ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user