PchManager: Fix generated file handling in PchCreator

Task-number: QTCREATORBUG-21843
Change-Id: I0517b87725117b7db7db14d32b737a0a6f2b3c35
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-01-22 14:38:39 +01:00
parent 693c896e5a
commit df8653dda9
5 changed files with 34 additions and 2 deletions

View File

@@ -148,7 +148,7 @@ const ProjectPartPch &PchCreator::projectPartPch()
void PchCreator::setUnsavedFiles(const V2::FileContainers &fileContainers)
{
m_unsavedFiles = fileContainers;
m_clangTool.addUnsavedFiles(fileContainers);
}
void PchCreator::setIsUsed(bool isUsed)
@@ -163,6 +163,7 @@ bool PchCreator::isUsed() const
void PchCreator::clear()
{
m_clangTool = ClangTool{};
m_projectPartPch = {};
}

View File

@@ -89,12 +89,16 @@ public:
static std::unique_ptr<QFile> generateFileWithContent(const Utils::SmallString &filePath,
const Utils::SmallString &content);
const ClangTool &clangTool() const
{
return m_clangTool;
}
private:
mutable std::mt19937_64 randomNumberGenator{std::random_device{}()};
ClangTool m_clangTool;
ProjectPartPch m_projectPartPch;
FilePathCaching m_filePathCache;
V2::FileContainers m_unsavedFiles;
Environment &m_environment;
PchManagerClientInterface &m_pchManagerClient;
bool m_isUsed = false;

View File

@@ -149,4 +149,10 @@ clang::tooling::ClangTool ClangTool::createOutputTool() const
return tool;
}
bool ClangTool::isClean() const
{
return m_sourceFilePaths.empty() && m_fileContents.empty()
&& m_compilationDatabase.getAllFiles().empty() && m_unsavedFileContents.empty();
}
} // namespace ClangBackEnd

View File

@@ -93,6 +93,10 @@ public:
clang::tooling::ClangTool createTool() const;
clang::tooling::ClangTool createOutputTool() const;
bool isClean() const;
private:
RefactoringCompilationDatabase m_compilationDatabase;
std::vector<FileContent> m_fileContents;

View File

@@ -227,6 +227,15 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchCleared)
ASSERT_THAT(creator.projectPartPch(), ClangBackEnd::ProjectPartPch{});
}
TEST_F(PchCreatorVerySlowTest, ClangToolCleared)
{
creator.generatePch(std::move(pchTask1));
creator.clear();
ASSERT_TRUE(creator.clangTool().isClean());
}
TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask)
{
PchTask faultyPchTask{"faultyProjectPart",
@@ -245,4 +254,12 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask
Field(&ProjectPartPch::lastModified, Eq(-1))));
}
TEST_F(PchCreatorVerySlowTest, GeneratedFile)
{
creator.clear();
creator.setUnsavedFiles({generatedFile});
ASSERT_FALSE(creator.clangTool().isClean());
}
}