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)); }