From f644ea0a0165e1d967b5d4654b48143b4534d2b1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 25 Oct 2018 11:08:39 +0200 Subject: ClangPchManager: Add BuildDependenciesProvider It is still unfinished but I want to add other changes first. Change-Id: Ife7ac56576f85d800633ea1e8f1c3f4f16486d5f Task-number: QTCREATORBUG-21377 Reviewed-by: Ivan Donchevskii --- .../source/builddependencies.h | 44 --------- .../source/builddependenciesgeneratorinterface.h | 43 +++++++++ .../source/builddependenciesprovider.cpp | 106 +++++++++++++++++++++ .../source/builddependenciesprovider.h | 61 ++++++++++++ .../source/builddependenciesproviderinterface.h | 4 +- .../source/builddependenciesstorageinterface.h | 55 +++++++++++ .../source/builddependency.h | 44 +++++++++ .../source/clangpchmanagerbackend-source.pri | 10 +- .../source/modifiedtimecheckerinterface.h | 46 +++++++++ src/tools/clangpchmanagerbackend/source/pchtask.h | 2 +- .../clangpchmanagerbackend/source/sourceentry.h | 80 ++++++++++++++++ 11 files changed, 446 insertions(+), 49 deletions(-) delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependencies.h create mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesgeneratorinterface.h create mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp create mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h create mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h create mode 100644 src/tools/clangpchmanagerbackend/source/builddependency.h create mode 100644 src/tools/clangpchmanagerbackend/source/modifiedtimecheckerinterface.h create mode 100644 src/tools/clangpchmanagerbackend/source/sourceentry.h (limited to 'src') diff --git a/src/tools/clangpchmanagerbackend/source/builddependencies.h b/src/tools/clangpchmanagerbackend/source/builddependencies.h deleted file mode 100644 index 9e0eb3f629..0000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependencies.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -#include - -namespace ClangBackEnd { - -class BuildDependency -{ -public: - FilePathIds includeIds; - FilePathIds topIncludeIds; - FilePathIds topsSystemIncludeIds; -}; - -using BuildDependencies = std::vector; - -} diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesgeneratorinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesgeneratorinterface.h new file mode 100644 index 0000000000..f3863d8027 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesgeneratorinterface.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "builddependency.h" + +#include "projectpartcontainerv2.h" + +namespace ClangBackEnd { + +class BuildDependenciesGeneratorInterface +{ +public: + virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) = 0; + +protected: + ~BuildDependenciesGeneratorInterface() = default; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp new file mode 100644 index 0000000000..5044f9e294 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "builddependenciesprovider.h" + +#include "builddependenciesstorageinterface.h" +#include "modifiedtimecheckerinterface.h" +#include "builddependenciesgeneratorinterface.h" + +#include + +namespace ClangBackEnd { + +template +OutputContainer setUnion(InputContainer1 &&input1, + InputContainer2 &&input2) +{ + OutputContainer results; + results.reserve(input1.size() + input2.size()); + + std::set_union(std::begin(input1), + std::end(input1), + std::begin(input2), + std::end(input2), + std::back_inserter(results)); + + return results; +} + +BuildDependency BuildDependenciesProvider::create(const V2::ProjectPartContainer &projectPart) const +{ + SourceEntries includes = createSourceEntriesFromStorage(projectPart.sourcePathIds); + + if (!m_modifiedTimeChecker.isUpToDate(includes)) + return m_buildDependenciesGenerator.create(projectPart); + + return createBuildDependencyFromStorage(std::move(includes)); + +} + +BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage(SourceEntries &&includes) const +{ + BuildDependency buildDependency; + + buildDependency.usedMacros = createUsedMacrosFromStorage(includes); + buildDependency.includes = std::move(includes); + + return buildDependency; +} + +UsedMacros BuildDependenciesProvider::createUsedMacrosFromStorage(const SourceEntries &includes) const +{ + UsedMacros usedMacros; + usedMacros.reserve(1024); + + for (const SourceEntry &entry : includes) { + UsedMacros macros = m_buildDependenciesStorage.fetchUsedMacros(entry.sourceId); + std::sort(macros.begin(), macros.end()); + usedMacros.insert(usedMacros.end(), + std::make_move_iterator(macros.begin()), + std::make_move_iterator(macros.end())); + } + + return usedMacros; +} + +SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( + const FilePathIds &sourcePathIds) const +{ + SourceEntries includes; + + for (FilePathId sourcePathId : sourcePathIds) { + SourceEntries entries = m_buildDependenciesStorage.fetchDependSources(sourcePathId); + SourceEntries mergedEntries = setUnion(includes, entries); + + includes = std::move(mergedEntries); + } + + return includes; +} + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h new file mode 100644 index 0000000000..c9aab60de4 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "builddependenciesproviderinterface.h" + +namespace ClangBackEnd { + +class BuildDependenciesStorageInterface; +class ModifiedTimeCheckerInterface; +class BuildDependenciesGeneratorInterface; + +class BuildDependenciesProvider : public BuildDependenciesProviderInterface +{ +public: + BuildDependenciesProvider(BuildDependenciesStorageInterface &buildDependenciesStorage, + ModifiedTimeCheckerInterface &modifiedTimeChecker, + BuildDependenciesGeneratorInterface &buildDependenciesGenerator) + : m_buildDependenciesStorage(buildDependenciesStorage), + m_modifiedTimeChecker(modifiedTimeChecker), + m_buildDependenciesGenerator(buildDependenciesGenerator) + { + } + + BuildDependency create(const V2::ProjectPartContainer &projectPart) const override; + +private: + BuildDependency createBuildDependencyFromStorage(SourceEntries &&includes) const; + UsedMacros createUsedMacrosFromStorage(const SourceEntries &includes) const; + SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds) const; + +private: + BuildDependenciesStorageInterface &m_buildDependenciesStorage; + ModifiedTimeCheckerInterface &m_modifiedTimeChecker; + BuildDependenciesGeneratorInterface &m_buildDependenciesGenerator; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h index b02831a7ba..f596b83da9 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h @@ -25,7 +25,7 @@ #pragma once -#include "builddependencies.h" +#include "builddependency.h" #include "projectpartcontainerv2.h" @@ -34,7 +34,7 @@ namespace ClangBackEnd { class BuildDependenciesProviderInterface { public: - virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) = 0; + virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) const = 0; protected: ~BuildDependenciesProviderInterface() = default; diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h new file mode 100644 index 0000000000..265065b0d0 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include + +namespace ClangBackEnd { + +class BuildDependenciesStorageInterface +{ +public: + BuildDependenciesStorageInterface() = default; + BuildDependenciesStorageInterface(const BuildDependenciesStorageInterface &) = delete; + BuildDependenciesStorageInterface &operator=(const BuildDependenciesStorageInterface &) = delete; + + virtual void updateSources(const SourceEntries &sourceIds) = 0; + virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0; + virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0; + virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0; + virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0; + virtual SourceEntries fetchDependSources(FilePathId sourceId) const = 0; + virtual UsedMacros fetchUsedMacros(FilePathId sourceId) const = 0; + +protected: + ~BuildDependenciesStorageInterface() = default; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependency.h b/src/tools/clangpchmanagerbackend/source/builddependency.h new file mode 100644 index 0000000000..8821b0162c --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependency.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "sourceentry.h" +#include "usedmacro.h" + +namespace ClangBackEnd { + +class BuildDependency +{ +public: + SourceEntries includes; + FilePathIds topIncludeIds; + FilePathIds topsSystemIncludeIds; + UsedMacros usedMacros; +}; + +using BuildDependencies = std::vector; + +} diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index ad17b98f18..4b5ac43a7e 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -4,7 +4,8 @@ SOURCES += \ $$PWD/pchmanagerserver.cpp \ $$PWD/projectparts.cpp \ $$PWD/projectpartqueue.cpp \ - $$PWD/pchtaskgenerator.cpp + $$PWD/pchtaskgenerator.cpp \ + $$PWD/builddependenciesprovider.cpp HEADERS += \ $$PWD/pchmanagerserver.h \ @@ -28,7 +29,12 @@ HEADERS += \ $$PWD/pchtaskgenerator.h \ $$PWD/pchtask.h \ $$PWD/builddependenciesproviderinterface.h \ - $$PWD/builddependencies.h + $$PWD/builddependenciesprovider.h \ + $$PWD/builddependenciesstorageinterface.h \ + $$PWD/builddependency.h \ + $$PWD/modifiedtimecheckerinterface.h \ + $$PWD/sourceentry.h \ + $$PWD/builddependenciesgeneratorinterface.h !isEmpty(LIBTOOLING_LIBS) { SOURCES += \ diff --git a/src/tools/clangpchmanagerbackend/source/modifiedtimecheckerinterface.h b/src/tools/clangpchmanagerbackend/source/modifiedtimecheckerinterface.h new file mode 100644 index 0000000000..c0cae1cf4b --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/modifiedtimecheckerinterface.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "sourceentry.h" + +namespace ClangBackEnd { + +class ModifiedTimeCheckerInterface +{ +public: + ModifiedTimeCheckerInterface() = default; + ModifiedTimeCheckerInterface(const ModifiedTimeCheckerInterface &) = delete; + ModifiedTimeCheckerInterface &operator=(const ModifiedTimeCheckerInterface &) = delete; + + virtual bool isUpToDate(const SourceEntries &sourceEntries) const = 0; + +protected: + ~ModifiedTimeCheckerInterface() = default; +}; + +} // namespace ClangBackEnd + diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h index 39c7bbf01a..48ae6864ea 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtask.h +++ b/src/tools/clangpchmanagerbackend/source/pchtask.h @@ -25,7 +25,7 @@ #pragma once -#include "builddependencies.h" +#include "builddependency.h" #include diff --git a/src/tools/clangpchmanagerbackend/source/sourceentry.h b/src/tools/clangpchmanagerbackend/source/sourceentry.h new file mode 100644 index 0000000000..2e0646b987 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/sourceentry.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include + +#include + +namespace ClangBackEnd { + +enum SourceType : unsigned char +{ + Any, + TopInclude, + TopSystemInclude +}; + +class TimeStamp +{ + using int64 = long long; +public: + TimeStamp(int64 value) + : value(value) + {} + + operator int64() const + { + return value; + } + + int64 value = -1; +}; + +class SourceEntry +{ +public: + friend + bool operator<(SourceEntry first, SourceEntry second) + { + return first.sourceId < second.sourceId; + } + + friend + bool operator==(SourceEntry first, SourceEntry second) + { + return first.sourceId == second.sourceId; + } + +public: + FilePathId sourceId; + SourceType sourceType = SourceType::Any; + TimeStamp lastModified; +}; + +using SourceEntries = std::vector; + +} -- cgit v1.2.1