From cc87615fcdcd9bf555f00461911a3d0a6272b678 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 20 Jun 2019 18:34:02 +0200 Subject: Clang: Differentiate between user and non user includes for updating We don't want to recreate a PCH if the include or source is not contained by a PCH. Change-Id: If52fc1aed92054b4165cdc634656147fbe8baa47 Reviewed-by: Tim Jenssen --- src/libs/clangsupport/clangpathwatcher.h | 68 ++++++++-------------- src/libs/clangsupport/clangpathwatchernotifier.h | 7 +-- src/libs/clangsupport/clangsupport-lib.pri | 1 + src/libs/clangsupport/idpaths.h | 45 +++++++++++++- .../precompiledheadersupdatedmessage.h | 2 + 5 files changed, 72 insertions(+), 51 deletions(-) (limited to 'src/libs') diff --git a/src/libs/clangsupport/clangpathwatcher.h b/src/libs/clangsupport/clangpathwatcher.h index 1130b1ab29..5ce02458c4 100644 --- a/src/libs/clangsupport/clangpathwatcher.h +++ b/src/libs/clangsupport/clangpathwatcher.h @@ -1,4 +1,4 @@ -; /**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ @@ -57,7 +57,7 @@ void set_greedy_intersection_call( class WatcherEntry { public: - ProjectPartId id; + ProjectChunkId id; DirectoryPathId directoryPathId; FilePathId filePathId; long long lastModified = -1; @@ -140,25 +140,6 @@ public: m_notifier = notifier; } - static std::vector idsFromIdPaths(const std::vector &idPaths) - { - std::vector ids; - ids.reserve(idPaths.size()); - - auto extractId = [] (const IdPaths &idPath) { - return idPath.id; - }; - - std::transform(idPaths.begin(), - idPaths.end(), - std::back_inserter(ids), - extractId); - - std::sort(ids.begin(), ids.end()); - - return ids; - } - std::size_t sizeOfIdPaths(const std::vector &idPaths) { auto sumSize = [] (std::size_t size, const IdPaths &idPath) { @@ -168,19 +149,19 @@ public: return std::accumulate(idPaths.begin(), idPaths.end(), std::size_t(0), sumSize); } - std::pair convertIdPathsToWatcherEntriesAndIds( + std::pair convertIdPathsToWatcherEntriesAndIds( const std::vector &idPaths) { WatcherEntries entries; entries.reserve(sizeOfIdPaths(idPaths)); - ProjectPartIds ids; + ProjectChunkIds ids; ids.reserve(ids.size()); auto outputIterator = std::back_inserter(entries); for (const IdPaths &idPath : idPaths) { - ProjectPartId id = idPath.id; + ProjectChunkId id = idPath.id; ids.push_back(id); @@ -214,7 +195,7 @@ public: m_fileSystemWatcher.addPaths(convertWatcherEntriesToDirectoryPathList(filteredPaths)); } - void removeUnusedEntries(const WatcherEntries &entries, const ProjectPartIds &ids) + void removeUnusedEntries(const WatcherEntries &entries, const ProjectChunkIds &ids) { auto oldEntries = notAnymoreWatchedEntriesWithIds(entries, ids); @@ -294,7 +275,7 @@ public: } WatcherEntries notAnymoreWatchedEntriesWithIds(const WatcherEntries &newEntries, - const ProjectPartIds &ids) const + const ProjectChunkIds &ids) const { auto oldEntries = notAnymoreWatchedEntries(newEntries, std::less()); @@ -420,25 +401,22 @@ public: return filePathIds; } - ProjectPartIds idsForWatcherEntries(const WatcherEntries &foundEntries) + std::vector idPathsForWatcherEntries(WatcherEntries &&foundEntries) { - ProjectPartIds ids; - ids.reserve(foundEntries.size()); - - std::transform(foundEntries.begin(), - foundEntries.end(), - std::back_inserter(ids), - [&](WatcherEntry entry) { return entry.id; }); + std::sort(foundEntries.begin(), foundEntries.end(), [](WatcherEntry first, WatcherEntry second) { + return std::tie(first.id, first.filePathId) < std::tie(second.id, second.filePathId); + }); - return ids; - } + std::vector idPaths; + idPaths.reserve(foundEntries.size()); - ProjectPartIds uniqueIds(ProjectPartIds &&ids) - { - std::sort(ids.begin(), ids.end()); - ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); + for (WatcherEntry entry : foundEntries) { + if (idPaths.empty() || idPaths.back().id != entry.id) + idPaths.push_back({entry.id, {}}); + idPaths.back().filePathIds.push_back(entry.filePathId); + } - return std::move(ids); + return idPaths; } void addChangedPathForFilePath(DirectoryPathIds &&directoryPathIds) @@ -446,10 +424,12 @@ public: if (m_notifier) { WatcherEntries foundEntries = watchedEntriesForPaths(std::move(directoryPathIds)); - ProjectPartIds changedIds = idsForWatcherEntries(foundEntries); + FilePathIds watchedFilePathIds = watchedPaths(foundEntries); + + std::vector changedIdPaths = idPathsForWatcherEntries(std::move(foundEntries)); - m_notifier->pathsWithIdsChanged(uniqueIds(std::move(changedIds))); - m_notifier->pathsChanged(watchedPaths(foundEntries)); + m_notifier->pathsChanged(watchedFilePathIds); + m_notifier->pathsWithIdsChanged(changedIdPaths); } } diff --git a/src/libs/clangsupport/clangpathwatchernotifier.h b/src/libs/clangsupport/clangpathwatchernotifier.h index 393525dbf2..248925ffb9 100644 --- a/src/libs/clangsupport/clangpathwatchernotifier.h +++ b/src/libs/clangsupport/clangpathwatchernotifier.h @@ -26,9 +26,8 @@ #pragma once #include "clangsupport_global.h" - -#include -#include +#include "filepathid.h" +#include "idpaths.h" #include @@ -41,7 +40,7 @@ public: ClangPathWatcherNotifier(const ClangPathWatcherNotifier &) = delete; ClangPathWatcherNotifier &operator=(const ClangPathWatcherNotifier &) = delete; - virtual void pathsWithIdsChanged(const ProjectPartIds &ids) = 0; + virtual void pathsWithIdsChanged(const std::vector &idPaths) = 0; virtual void pathsChanged(const FilePathIds &filePathIds) = 0; protected: diff --git a/src/libs/clangsupport/clangsupport-lib.pri b/src/libs/clangsupport/clangsupport-lib.pri index dc66408e58..1705be3c26 100644 --- a/src/libs/clangsupport/clangsupport-lib.pri +++ b/src/libs/clangsupport/clangsupport-lib.pri @@ -120,6 +120,7 @@ HEADERS += \ $$PWD/projectpartid.h \ $$PWD/projectpartsstorage.h \ $$PWD/projectpartsstorageinterface.h \ + $$PWD/projectsourcechunk.h \ $$PWD/requestcompletionsmessage.h \ $$PWD/echomessage.h \ $$PWD/endmessage.h \ diff --git a/src/libs/clangsupport/idpaths.h b/src/libs/clangsupport/idpaths.h index d67a73e83e..d0945f7ff5 100644 --- a/src/libs/clangsupport/idpaths.h +++ b/src/libs/clangsupport/idpaths.h @@ -25,21 +25,60 @@ #pragma once -#include "projectpartid.h" #include "filepathid.h" +#include "projectpartid.h" +#include "sourceentry.h" namespace ClangBackEnd { -class IdPaths +class ProjectChunkId { public: ProjectPartId id; + SourceType sourceType; + + friend bool operator==(ProjectChunkId first, ProjectChunkId second) + { + return first.id == second.id && first.sourceType == second.sourceType; + } + + friend bool operator==(ProjectChunkId first, ProjectPartId second) + { + return first.id == second; + } + + friend bool operator==(ProjectPartId first, ProjectChunkId second) + { + return first == second.id; + } + + friend bool operator!=(ProjectChunkId first, ProjectChunkId second) + { + return !(first == second); + } + + friend bool operator<(ProjectChunkId first, ProjectChunkId second) + { + return std::tie(first.id, first.sourceType) < std::tie(second.id, second.sourceType); + } + + friend bool operator<(ProjectChunkId first, ProjectPartId second) { return first.id < second; } + + friend bool operator<(ProjectPartId first, ProjectChunkId second) { return first < second.id; } +}; + +class IdPaths +{ +public: + ProjectChunkId id; FilePathIds filePathIds; - friend bool operator==(const IdPaths &first, const IdPaths &second) + friend bool operator==(IdPaths first, IdPaths second) { return first.id == second.id && first.filePathIds == second.filePathIds; } }; +using ProjectChunkIds = std::vector; + } // namespace ClangBackEnd diff --git a/src/libs/clangsupport/precompiledheadersupdatedmessage.h b/src/libs/clangsupport/precompiledheadersupdatedmessage.h index 5bd24dcd49..9e3e3b981c 100644 --- a/src/libs/clangsupport/precompiledheadersupdatedmessage.h +++ b/src/libs/clangsupport/precompiledheadersupdatedmessage.h @@ -26,6 +26,7 @@ #pragma once #include "clangsupport_global.h" +#include "filepathid.h" #include "projectpartid.h" #include @@ -37,6 +38,7 @@ class PrecompiledHeadersUpdatedMessage public: PrecompiledHeadersUpdatedMessage() = default; PrecompiledHeadersUpdatedMessage(ProjectPartId projectPartId) + { projectPartIds.push_back(projectPartId); } -- cgit v1.2.3