ClangPchManager: Don't generate a PCH header file any more

We used an extra process to generate the PCH but now we use clang tooling
so we can utilize the in memory file system.

Task-number: QTCREATORBUG-21933
Change-Id: I1c1d39248e9513c87269d854c35d38b373b0f515
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-02-04 18:14:44 +01:00
parent aaec90c6bc
commit 4da11c355f
4 changed files with 38 additions and 85 deletions

View File

@@ -82,15 +82,6 @@ bool PchCreator::generatePch()
return tool.run(action.get()) != 1;
}
FilePath PchCreator::generatePchHeaderFilePath() const
{
std::uniform_int_distribution<std::mt19937_64::result_type> distribution;
return FilePathView{Utils::PathString{Utils::SmallString(m_environment.pchBuildDirectory()),
"/",
std::to_string(distribution(randomNumberGenator)),
".h"}};
}
FilePath PchCreator::generatePchFilePath() const
{
@@ -121,15 +112,12 @@ void PchCreator::generatePch(PchTask &&pchTask)
{
long long lastModified = QDateTime::currentSecsSinceEpoch();
auto content = generatePchIncludeFileContent(pchTask.includes);
auto pchSourceFilePath = generatePchHeaderFilePath();
auto pchOutputPath = generatePchFilePath();
generateFileWithContent(pchSourceFilePath, content);
m_clangTool.addFile(
pchSourceFilePath.directory(),
pchSourceFilePath.name(),
"",
generateClangCompilerArguments(pchTask, pchSourceFilePath, pchOutputPath));
m_clangTool.addFile(m_environment.pchBuildDirectory().toStdString(),
"dummy.h",
Utils::SmallStringView(content),
generateClangCompilerArguments(pchTask, "dummy.h", pchOutputPath));
bool success = generatePch();
@@ -179,17 +167,4 @@ const FilePathCaching &PchCreator::filePathCache()
return m_filePathCache;
}
std::unique_ptr<QFile> PchCreator::generateFileWithContent(const Utils::SmallString &filePath,
const Utils::SmallString &content)
{
std::unique_ptr<QFile> precompiledIncludeFile(new QFile(QString(filePath)));
precompiledIncludeFile->open(QIODevice::WriteOnly);
precompiledIncludeFile->write(content.data(), qint64(content.size()));
precompiledIncludeFile->close();
return precompiledIncludeFile;
}
} // namespace ClangBackEnd

View File

@@ -83,13 +83,10 @@ public:
Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const;
bool generatePch();
FilePath generatePchHeaderFilePath() const;
FilePath generatePchFilePath() const;
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
FilePathView includePchHeaderPath,
FilePathView pchPath);
static std::unique_ptr<QFile> generateFileWithContent(const Utils::SmallString &filePath,
const Utils::SmallString &content);
const ClangTool &clangTool() const
{

View File

@@ -130,21 +130,6 @@ TEST_F(PchCreator, CreateProjectPartPchFileContent)
HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n")));
}
TEST_F(PchCreator, CreatePchIncludeFile)
{
auto content = creator.generatePchIncludeFileContent(pchTask1.includes);
auto pchIncludeFilePath = creator.generatePchHeaderFilePath();
auto file = creator.generateFileWithContent(pchIncludeFilePath, content);
file->open(QIODevice::ReadOnly);
auto fileContent = file->readAll();
ASSERT_THAT(fileContent.toStdString(),
AllOf(HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/project/header2.h\"\n"),
HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external1.h\"\n"),
HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n")));
}
TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
{
auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1),

View File

@@ -91,46 +91,42 @@ TEST_F(PchTaskGenerator, AddProjectParts)
mockPchTaskMerger,
mergeTasks(
ElementsAre(AllOf(
Field(
&PchTaskSet::system,
AllOf(
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(5)),
Field(&PchTask::allIncludes, IsEmpty()),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
Field(&PchTask::systemIncludeSearchPaths,
ElementsAre(
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
Field(&PchTask::projectIncludeSearchPaths,
ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))),
Field(&PchTaskSet::system,
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(5)),
Field(&PchTask::allIncludes, IsEmpty()),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
Field(&PchTask::systemIncludeSearchPaths,
ElementsAre(
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
Field(&PchTask::projectIncludeSearchPaths, IsEmpty()),
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))),
AllOf(Field(
&PchTaskSet::project,
AllOf(
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(3)),
Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
Field(&PchTask::systemIncludeSearchPaths,
ElementsAre(
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
Field(&PchTask::projectIncludeSearchPaths,
ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))),
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(3)),
Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
Field(&PchTask::systemIncludeSearchPaths,
ElementsAre(
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
Field(&PchTask::projectIncludeSearchPaths,
ElementsAre(
IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))),
ElementsAre(Eq("ToolChainArgument"))));
generator.addProjectParts({projectPart1}, {"ToolChainArgument"});