forked from qt-creator/qt-creator
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:
@@ -82,15 +82,6 @@ bool PchCreator::generatePch()
|
|||||||
return tool.run(action.get()) != 1;
|
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
|
FilePath PchCreator::generatePchFilePath() const
|
||||||
{
|
{
|
||||||
@@ -121,15 +112,12 @@ void PchCreator::generatePch(PchTask &&pchTask)
|
|||||||
{
|
{
|
||||||
long long lastModified = QDateTime::currentSecsSinceEpoch();
|
long long lastModified = QDateTime::currentSecsSinceEpoch();
|
||||||
auto content = generatePchIncludeFileContent(pchTask.includes);
|
auto content = generatePchIncludeFileContent(pchTask.includes);
|
||||||
auto pchSourceFilePath = generatePchHeaderFilePath();
|
|
||||||
auto pchOutputPath = generatePchFilePath();
|
auto pchOutputPath = generatePchFilePath();
|
||||||
generateFileWithContent(pchSourceFilePath, content);
|
|
||||||
|
|
||||||
m_clangTool.addFile(
|
m_clangTool.addFile(m_environment.pchBuildDirectory().toStdString(),
|
||||||
pchSourceFilePath.directory(),
|
"dummy.h",
|
||||||
pchSourceFilePath.name(),
|
Utils::SmallStringView(content),
|
||||||
"",
|
generateClangCompilerArguments(pchTask, "dummy.h", pchOutputPath));
|
||||||
generateClangCompilerArguments(pchTask, pchSourceFilePath, pchOutputPath));
|
|
||||||
|
|
||||||
bool success = generatePch();
|
bool success = generatePch();
|
||||||
|
|
||||||
@@ -179,17 +167,4 @@ const FilePathCaching &PchCreator::filePathCache()
|
|||||||
return m_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
|
} // namespace ClangBackEnd
|
||||||
|
@@ -83,13 +83,10 @@ public:
|
|||||||
Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const;
|
Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const;
|
||||||
bool generatePch();
|
bool generatePch();
|
||||||
|
|
||||||
FilePath generatePchHeaderFilePath() const;
|
|
||||||
FilePath generatePchFilePath() const;
|
FilePath generatePchFilePath() const;
|
||||||
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
|
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
|
||||||
FilePathView includePchHeaderPath,
|
FilePathView includePchHeaderPath,
|
||||||
FilePathView pchPath);
|
FilePathView pchPath);
|
||||||
static std::unique_ptr<QFile> generateFileWithContent(const Utils::SmallString &filePath,
|
|
||||||
const Utils::SmallString &content);
|
|
||||||
|
|
||||||
const ClangTool &clangTool() const
|
const ClangTool &clangTool() const
|
||||||
{
|
{
|
||||||
|
@@ -130,21 +130,6 @@ TEST_F(PchCreator, CreateProjectPartPchFileContent)
|
|||||||
HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n")));
|
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)
|
TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
|
||||||
{
|
{
|
||||||
auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1),
|
auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1),
|
||||||
|
@@ -91,46 +91,42 @@ TEST_F(PchTaskGenerator, AddProjectParts)
|
|||||||
mockPchTaskMerger,
|
mockPchTaskMerger,
|
||||||
mergeTasks(
|
mergeTasks(
|
||||||
ElementsAre(AllOf(
|
ElementsAre(AllOf(
|
||||||
Field(
|
Field(&PchTaskSet::system,
|
||||||
&PchTaskSet::system,
|
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
|
||||||
AllOf(
|
Field(&PchTask::includes, ElementsAre(5)),
|
||||||
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
|
Field(&PchTask::allIncludes, IsEmpty()),
|
||||||
Field(&PchTask::includes, ElementsAre(5)),
|
Field(&PchTask::compilerMacros,
|
||||||
Field(&PchTask::allIncludes, IsEmpty()),
|
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
|
||||||
Field(&PchTask::compilerMacros,
|
Field(&PchTask::systemIncludeSearchPaths,
|
||||||
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
|
ElementsAre(
|
||||||
Field(&PchTask::systemIncludeSearchPaths,
|
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
|
||||||
ElementsAre(
|
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
|
||||||
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
|
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
|
||||||
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
|
Field(&PchTask::projectIncludeSearchPaths, IsEmpty()),
|
||||||
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
|
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
|
||||||
Field(&PchTask::projectIncludeSearchPaths,
|
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
|
||||||
ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
|
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
|
||||||
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
|
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))),
|
||||||
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(
|
AllOf(Field(
|
||||||
&PchTaskSet::project,
|
&PchTaskSet::project,
|
||||||
AllOf(
|
AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
|
||||||
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
|
Field(&PchTask::includes, ElementsAre(3)),
|
||||||
Field(&PchTask::includes, ElementsAre(3)),
|
Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
|
||||||
Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
|
Field(&PchTask::compilerMacros,
|
||||||
Field(&PchTask::compilerMacros,
|
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
|
||||||
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
|
Field(&PchTask::systemIncludeSearchPaths,
|
||||||
Field(&PchTask::systemIncludeSearchPaths,
|
ElementsAre(
|
||||||
ElementsAre(
|
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
|
||||||
IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System},
|
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
|
||||||
IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn},
|
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
|
||||||
IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})),
|
Field(&PchTask::projectIncludeSearchPaths,
|
||||||
Field(&PchTask::projectIncludeSearchPaths,
|
ElementsAre(
|
||||||
ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
|
IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
|
||||||
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
|
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})),
|
||||||
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
|
Field(&PchTask::toolChainArguments, ElementsAre("--yi")),
|
||||||
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
|
Field(&PchTask::language, Eq(Utils::Language::Cxx)),
|
||||||
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
|
Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)),
|
||||||
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))),
|
Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))),
|
||||||
ElementsAre(Eq("ToolChainArgument"))));
|
ElementsAre(Eq("ToolChainArgument"))));
|
||||||
|
|
||||||
generator.addProjectParts({projectPart1}, {"ToolChainArgument"});
|
generator.addProjectParts({projectPart1}, {"ToolChainArgument"});
|
||||||
|
Reference in New Issue
Block a user