diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 935e446f53c..777252dece5 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -82,15 +82,6 @@ bool PchCreator::generatePch() return tool.run(action.get()) != 1; } -FilePath PchCreator::generatePchHeaderFilePath() const -{ - std::uniform_int_distribution 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 PchCreator::generateFileWithContent(const Utils::SmallString &filePath, - const Utils::SmallString &content) -{ - std::unique_ptr precompiledIncludeFile(new QFile(QString(filePath))); - - precompiledIncludeFile->open(QIODevice::WriteOnly); - - precompiledIncludeFile->write(content.data(), qint64(content.size())); - precompiledIncludeFile->close(); - - return precompiledIncludeFile; -} - } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 0d55adbcdd4..1e36e18b6e1 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -83,13 +83,10 @@ public: Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const; bool generatePch(); - FilePath generatePchHeaderFilePath() const; FilePath generatePchFilePath() const; static std::vector generateClangCompilerArguments(const PchTask &pchTask, FilePathView includePchHeaderPath, FilePathView pchPath); - static std::unique_ptr generateFileWithContent(const Utils::SmallString &filePath, - const Utils::SmallString &content); const ClangTool &clangTool() const { diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 26ca9965c2f..a75ff4267ab 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -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), diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp index a3ebb3c17be..08a0079ad84 100644 --- a/tests/unit/unittest/pchtaskgenerator-test.cpp +++ b/tests/unit/unittest/pchtaskgenerator-test.cpp @@ -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"});