Clang: Use the whole path in the IncludeCollector

Change-Id: I406f0050b0c244b6c0d1352b5889d4e65a43fa33
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-02-02 11:46:19 +01:00
parent bdfb466cd2
commit 5c7f49f278
3 changed files with 37 additions and 26 deletions

View File

@@ -60,7 +60,7 @@ public:
bool /*isAngled*/, bool /*isAngled*/,
clang::CharSourceRange /*fileNameRange*/, clang::CharSourceRange /*fileNameRange*/,
const clang::FileEntry *file, const clang::FileEntry *file,
llvm::StringRef /*searchPath*/, llvm::StringRef searchPath,
llvm::StringRef /*relativePath*/, llvm::StringRef /*relativePath*/,
const clang::Module * /*imported*/) override const clang::Module * /*imported*/) override
{ {
@@ -73,7 +73,10 @@ public:
auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID); auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID);
if (notAlreadyIncluded.first) { if (notAlreadyIncluded.first) {
m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, fileUID); m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, fileUID);
uint includeId = m_filePathCache.stringId({fileName.data(), fileName.size()}); Utils::PathString filePath = fromNativePath({{searchPath.data(), searchPath.size()},
"/",
{fileName.data(), fileName.size()}});
uint includeId = m_filePathCache.stringId(filePath);
m_includeIds.emplace_back(includeId); m_includeIds.emplace_back(includeId);
} }
} }
@@ -105,6 +108,14 @@ public:
} }
Utils::PathString fromNativePath(Utils::PathString &&filePath)
{
#ifdef _WIN32
filePath.replace('\\', '/');
#endif
return std::move(filePath);
}
private: private:
clang::HeaderSearch &m_headerSearch; clang::HeaderSearch &m_headerSearch;
std::vector<uint> &m_includeIds; std::vector<uint> &m_includeIds;

View File

@@ -52,15 +52,15 @@ TEST_F(IncludeCollector, IncludesExternalHeader)
collector.collectIncludes(); collector.collectIncludes();
ASSERT_THAT(collector.takeIncludeIds(), ASSERT_THAT(collector.takeIncludeIds(),
AllOf(Contains(id("includecollector_external1.h")), AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")),
Contains(id("../data/includecollector_external2.h")))); Contains(id(TESTDATA_DIR "/../data/includecollector_external2.h"))));
} }
TEST_F(IncludeCollector, DoesNotIncludesInternalHeader) TEST_F(IncludeCollector, DoesNotIncludesInternalHeader)
{ {
collector.collectIncludes(); collector.collectIncludes();
ASSERT_THAT(collector.takeIncludeIds(), Not(Contains(id("includecollector_header1.h")))); ASSERT_THAT(collector.takeIncludeIds(), Not(Contains(id(TESTDATA_DIR "/includecollector_header1.h"))));
} }
TEST_F(IncludeCollector, NoDuplicate) TEST_F(IncludeCollector, NoDuplicate)
@@ -68,8 +68,8 @@ TEST_F(IncludeCollector, NoDuplicate)
collector.collectIncludes(); collector.collectIncludes();
ASSERT_THAT(collector.takeIncludeIds(), ASSERT_THAT(collector.takeIncludeIds(),
UnorderedElementsAre(id("includecollector_external1.h"), UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"),
id("../data/includecollector_external2.h"))); id(TESTDATA_DIR "/../data/includecollector_external2.h")));
} }
TEST_F(IncludeCollector, IncludesAreSorted) TEST_F(IncludeCollector, IncludesAreSorted)
@@ -77,8 +77,8 @@ TEST_F(IncludeCollector, IncludesAreSorted)
collector.collectIncludes(); collector.collectIncludes();
ASSERT_THAT(collector.takeIncludeIds(), ASSERT_THAT(collector.takeIncludeIds(),
ElementsAre(id("includecollector_external1.h"), ElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"),
id("../data/includecollector_external2.h"))); id(TESTDATA_DIR "/../data/includecollector_external2.h")));
} }
void IncludeCollector::SetUp() void IncludeCollector::SetUp()

View File

@@ -132,16 +132,16 @@ TEST_F(PchCreatorVerySlowTest, CreateGlobalPchIncludes)
auto includeIds = creator.generateGlobalPchIncludeIds(); auto includeIds = creator.generateGlobalPchIncludeIds();
ASSERT_THAT(includeIds, ASSERT_THAT(includeIds,
UnorderedElementsAre(id("includecollector_external3.h"), UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external3.h"),
id("includecollector_external1.h"), id(TESTDATA_DIR "/includecollector_external1.h"),
id("includecollector_external2.h"))); id(TESTDATA_DIR "/includecollector_external2.h")));
} }
TEST_F(PchCreatorVerySlowTest, CreateGlobalPchFileContent) TEST_F(PchCreatorVerySlowTest, CreateGlobalPchFileContent)
{ {
auto content = creator.generateGlobalPchHeaderFileContent(); auto content = creator.generateGlobalPchHeaderFileContent();
ASSERT_THAT(content, "#include <includecollector_external3.h>\n#include <includecollector_external1.h>\n#include <includecollector_external2.h>\n"); ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_external3.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n");
} }
TEST_F(PchCreatorVerySlowTest, CreateGlobalPchHeaderFile) TEST_F(PchCreatorVerySlowTest, CreateGlobalPchHeaderFile)
@@ -151,7 +151,7 @@ TEST_F(PchCreatorVerySlowTest, CreateGlobalPchHeaderFile)
auto content = file->readAll(); auto content = file->readAll();
ASSERT_THAT(content, "#include <includecollector_external3.h>\n#include <includecollector_external1.h>\n#include <includecollector_external2.h>\n"); ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_external3.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n");
} }
TEST_F(PchCreator, ConvertToQStringList) TEST_F(PchCreator, ConvertToQStringList)
@@ -203,9 +203,9 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes)
{ {
auto includeIds = creator.generateProjectPartPchIncludes(projectPart1); auto includeIds = creator.generateProjectPartPchIncludes(projectPart1);
ASSERT_THAT(includeIds, UnorderedElementsAre(id("includecollector_external1.h"), ASSERT_THAT(includeIds, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"),
id("includecollector_external2.h"), id(TESTDATA_DIR "/includecollector_external2.h"),
id("includecollector_header2.h"))); id(TESTDATA_DIR "/includecollector_header2.h")));
} }
TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent) TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
@@ -214,7 +214,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent)
auto content = creator.generatePchIncludeFileContent(includes); auto content = creator.generatePchIncludeFileContent(includes);
ASSERT_THAT(content, "#include <includecollector_header2.h>\n#include <includecollector_external1.h>\n#include <includecollector_external2.h>\n"); ASSERT_THAT(content, "#include <" TESTDATA_DIR "/includecollector_header2.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n");
} }
TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile) TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
@@ -227,7 +227,7 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile)
auto fileContent = file->readAll(); auto fileContent = file->readAll();
ASSERT_THAT(fileContent, "#include <includecollector_header2.h>\n#include <includecollector_external1.h>\n#include <includecollector_external2.h>\n"); ASSERT_THAT(fileContent, "#include <" TESTDATA_DIR "/includecollector_header2.h>\n#include <" TESTDATA_DIR "/includecollector_external1.h>\n#include <" TESTDATA_DIR "/includecollector_external2.h>\n");
} }
TEST_F(PchCreator, CreateProjectPartPchCompilerArguments) TEST_F(PchCreator, CreateProjectPartPchCompilerArguments)
@@ -303,14 +303,14 @@ TEST_F(PchCreatorVerySlowTest, IdPathsForCreatePchsForProjectParts)
ASSERT_THAT(creator.takeProjectsIncludes(), ASSERT_THAT(creator.takeProjectsIncludes(),
ElementsAre(AllOf(Field(&IdPaths::id, "project1"), ElementsAre(AllOf(Field(&IdPaths::id, "project1"),
Field(&IdPaths::paths, UnorderedElementsAre(id("includecollector_header2.h"), Field(&IdPaths::paths, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_header2.h"),
id("includecollector_external1.h"), id(TESTDATA_DIR "/includecollector_external1.h"),
id("includecollector_external2.h")))), id(TESTDATA_DIR "/includecollector_external2.h")))),
AllOf(Field(&IdPaths::id, "project2"), AllOf(Field(&IdPaths::id, "project2"),
Field(&IdPaths::paths, UnorderedElementsAre(id("includecollector_external1.h"), Field(&IdPaths::paths, UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h"),
id("includecollector_external3.h"), id(TESTDATA_DIR "/includecollector_external3.h"),
id("includecollector_header1.h"), id(TESTDATA_DIR "/includecollector_header1.h"),
id("../data/includecollector_external2.h")))))); id(TESTDATA_DIR "/../data/includecollector_external2.h"))))));
} }
uint PchCreator::id(const Utils::SmallString &path) uint PchCreator::id(const Utils::SmallString &path)