From 29492ecf2494d875e3e2fa4951326aed275a3033 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Fri, 15 Feb 2019 16:15:01 +0100 Subject: [PATCH] ClangPchManager: Do not build pch and index inactive project parts Some project parts should not be built as well as some files can be inactive inside project part. We should not try to build pch-s or index them. Change-Id: I8e62365b817a424ae38a0df94b6703820a4cde9d Reviewed-by: Marco Bubke --- .../clangpchmanager/projectupdater.cpp | 13 +++++++++-- tests/unit/unittest/projectupdater-test.cpp | 23 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp index 28127fc39d1..4e5cf950178 100644 --- a/src/plugins/clangpchmanager/projectupdater.cpp +++ b/src/plugins/clangpchmanager/projectupdater.cpp @@ -143,8 +143,10 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart( HeaderAndSources headerAndSources; headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2); - for (const CppTools::ProjectFile &projectFile : projectPart->files) - addToHeaderAndSources(headerAndSources, projectFile); + for (const CppTools::ProjectFile &projectFile : projectPart->files) { + if (projectFile.active) + addToHeaderAndSources(headerAndSources, projectFile); + } std::sort(headerAndSources.sources.begin(), headerAndSources.sources.end()); std::sort(headerAndSources.headers.begin(), headerAndSources.headers.end()); @@ -297,6 +299,13 @@ ClangBackEnd::ProjectPartContainers ProjectUpdater::toProjectPartContainers( std::vector projectPartContainers; projectPartContainers.reserve(projectParts.size()); + projectParts.erase(std::remove_if(projectParts.begin(), + projectParts.end(), + [](const CppTools::ProjectPart *projectPart) { + return !projectPart->selectedForBuilding; + }), + projectParts.end()); + std::transform(projectParts.begin(), projectParts.end(), std::back_inserter(projectPartContainers), diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 293a4ef15ef..0ae47387d61 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -86,6 +86,7 @@ protected: projectPart.files.push_back(header2ProjectFile); projectPart.files.push_back(source1ProjectFile); projectPart.files.push_back(source2ProjectFile); + projectPart.files.push_back(nonActiveProjectFile); projectPart.displayName = "projectb"; projectPart.projectMacros = {{"FOO", "2"}, {"BAR", "1"}}; projectPartId = projectPart.id(); @@ -94,15 +95,19 @@ protected: projectPart2.files.push_back(header1ProjectFile); projectPart2.files.push_back(source2ProjectFile); projectPart2.files.push_back(source1ProjectFile); + projectPart2.files.push_back(nonActiveProjectFile); projectPart2.displayName = "projectaa"; projectPart2.projectMacros = {{"BAR", "1"}, {"FOO", "2"}}; projectPartId2 = projectPart2.id(); + nonBuildingProjectPart.files.push_back(cannotBuildSourceProjectFile); + nonBuildingProjectPart.displayName = "nonbuilding"; + nonBuildingProjectPart.selectedForBuilding = false; - Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::toolChainArguments( - &projectPart)}; - Utils::SmallStringVector arguments2{ClangPchManager::ProjectUpdater::toolChainArguments( - &projectPart2)}; + Utils::SmallStringVector arguments{ + ClangPchManager::ProjectUpdater::toolChainArguments(&projectPart)}; + Utils::SmallStringVector arguments2{ + ClangPchManager::ProjectUpdater::toolChainArguments(&projectPart2)}; expectedContainer = {projectPartId.clone(), arguments.clone(), @@ -143,9 +148,14 @@ protected: CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource}; - CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), CppTools::ProjectFile::CXXSource}; + CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), + CppTools::ProjectFile::CXXSource}; + CppTools::ProjectFile cannotBuildSourceProjectFile{QString("/cannot/build"), + CppTools::ProjectFile::CXXSource}; + CppTools::ProjectFile nonActiveProjectFile{QString("/foo"), CppTools::ProjectFile::CXXSource, false}; CppTools::ProjectPart projectPart; CppTools::ProjectPart projectPart2; + CppTools::ProjectPart nonBuildingProjectPart; ProjectPartContainer expectedContainer; ProjectPartContainer expectedContainer2; FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}}; @@ -240,7 +250,8 @@ TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer) TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLikeProjectParts) { - auto containers = updater.toProjectPartContainers({&projectPart, &projectPart}); + auto containers = updater.toProjectPartContainers( + {&projectPart, &projectPart, &nonBuildingProjectPart}); ASSERT_THAT(containers, SizeIs(2)); }