diff --git a/src/libs/clangsupport/clangsupport.pro b/src/libs/clangsupport/clangsupport.pro index fa614e74ff6..0475a13103d 100644 --- a/src/libs/clangsupport/clangsupport.pro +++ b/src/libs/clangsupport/clangsupport.pro @@ -1,2 +1,5 @@ include(../../qtcreatorlibrary.pri) include(clangsupport-lib.pri) + +HEADERS += \ + commandlinebuilderinterface.h diff --git a/src/libs/clangsupport/commandlinebuilderinterface.h b/src/libs/clangsupport/commandlinebuilderinterface.h new file mode 100644 index 00000000000..9823581456c --- /dev/null +++ b/src/libs/clangsupport/commandlinebuilderinterface.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** 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 + +namespace ClangBackEnd { + +class CommandLineBuilderInterface +{ +public: + virtual Utils::PathStringVector create() = 0; + +protected: + ~CommandLineBuilderInterface() = default; +}; + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependencies.h b/src/tools/clangpchmanagerbackend/source/builddependencies.h new file mode 100644 index 00000000000..9e0eb3f6293 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependencies.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 + +#include + +namespace ClangBackEnd { + +class BuildDependency +{ +public: + FilePathIds includeIds; + FilePathIds topIncludeIds; + FilePathIds topsSystemIncludeIds; +}; + +using BuildDependencies = std::vector; + +} diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h new file mode 100644 index 00000000000..b02831a7bae --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.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 "builddependencies.h" + +#include "projectpartcontainerv2.h" + +namespace ClangBackEnd { + +class BuildDependenciesProviderInterface +{ +public: + virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) = 0; + +protected: + ~BuildDependenciesProviderInterface() = default; +}; + +} // namespace ClangBackEnd + diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index f0104c00eab..ad17b98f18e 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -3,7 +3,8 @@ INCLUDEPATH += $$PWD SOURCES += \ $$PWD/pchmanagerserver.cpp \ $$PWD/projectparts.cpp \ - $$PWD/projectpartqueue.cpp + $$PWD/projectpartqueue.cpp \ + $$PWD/pchtaskgenerator.cpp HEADERS += \ $$PWD/pchmanagerserver.h \ @@ -23,7 +24,11 @@ HEADERS += \ $$PWD/precompiledheaderstorage.h \ $$PWD/precompiledheaderstorageinterface.h \ $$PWD/usedmacroandsourcestorageinterface.h \ - $$PWD/usedmacroandsourcestorage.h + $$PWD/usedmacroandsourcestorage.h \ + $$PWD/pchtaskgenerator.h \ + $$PWD/pchtask.h \ + $$PWD/builddependenciesproviderinterface.h \ + $$PWD/builddependencies.h !isEmpty(LIBTOOLING_LIBS) { SOURCES += \ diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h new file mode 100644 index 00000000000..39c7bbf01a6 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/pchtask.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** 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 "builddependencies.h" + +#include + +namespace ClangBackEnd { + +class PchTask +{ +public: + PchTask(Utils::SmallStringVector &&ids, BuildDependency &&buildDependency) + : ids(std::move(ids)), + buildDependency(std::move(buildDependency)) + { + } + + Utils::SmallStringVector ids; + BuildDependency buildDependency; +}; + +using PchTasks = std::vector; +} diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp new file mode 100644 index 00000000000..a9be6f9c254 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** 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 "pchtaskgenerator.h" + +#include "builddependenciesproviderinterface.h" + +#include + +namespace ClangBackEnd { + +PchTasks PchTaskGenerator::create(V2::ProjectPartContainers &&projectParts) +{ + PchTasks tasks; + tasks.reserve(projectParts.size() * 2); + + for (auto &projectPart : projectParts) { + tasks.emplace_back(std::initializer_list{{projectPart.projectPartId}}, + m_buildDependenciesProvider.create(projectPart)); + } + + return tasks; +} + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h new file mode 100644 index 00000000000..c629d107609 --- /dev/null +++ b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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 "pchtask.h" + +#include + +namespace ClangBackEnd { + +class BuildDependenciesProviderInterface; + +class PchTaskGenerator +{ +public: + PchTaskGenerator(BuildDependenciesProviderInterface &buildDependenciesProvider) + : m_buildDependenciesProvider(buildDependenciesProvider) + {} + + PchTasks create(V2::ProjectPartContainers &&projectParts); + +private: + BuildDependenciesProviderInterface &m_buildDependenciesProvider; +}; + + +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/taskscheduler.h b/src/tools/clangpchmanagerbackend/source/taskscheduler.h index 35c3c519843..129cbbe9db1 100644 --- a/src/tools/clangpchmanagerbackend/source/taskscheduler.h +++ b/src/tools/clangpchmanagerbackend/source/taskscheduler.h @@ -63,11 +63,11 @@ public: using ProcessorInterface = typename ProcessorManager::Processor; using Future = std::future; - TaskScheduler(ProcessorManager &symbolsCollectorManager, + TaskScheduler(ProcessorManager &processorManager, QueueInterface &queue, uint hardwareConcurrency, std::launch launchPolicy = std::launch::async) - : m_processorManager(symbolsCollectorManager), + : m_processorManager(processorManager), m_queue(queue), m_hardwareConcurrency(hardwareConcurrency), m_launchPolicy(launchPolicy) diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 5d8507c8de9..89fbab64d90 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -32,6 +32,7 @@ #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -1005,6 +1007,18 @@ std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes) { return out << "(" << includes.includeIds << ", " << includes.topIncludeIds << ", " << includes.topSystemIncludeIds << ")"; } +std::ostream &operator<<(std::ostream &out, const PchTask &task) +{ + return out << "(" << task.ids << ", " << task.buildDependency << ")"; +} + +std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency) +{ + return out << "(" + << dependency.includeIds << ", " + << dependency.topsSystemIncludeIds << ", " + << dependency.topIncludeIds << ")"; +} void PrintTo(const FilePath &filePath, ::std::ostream *os) { diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index 4f3f6457b0c..ee968c1378d 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -170,6 +170,8 @@ class SuspendResumeJobsEntry; class ReferencesResult; class SymbolIndexerTask; class PchCreatorIncludes; +class PchTask; +class BuildDependency; std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); @@ -250,6 +252,8 @@ std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry); std::ostream &operator<<(std::ostream &os, const ReferencesResult &value); std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task); std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes); +std::ostream &operator<<(std::ostream &out, const PchTask &task); +std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency); void PrintTo(const FilePath &filePath, ::std::ostream *os); void PrintTo(const FilePathView &filePathView, ::std::ostream *os); diff --git a/tests/unit/unittest/mockbuilddependenciesprovider.h b/tests/unit/unittest/mockbuilddependenciesprovider.h new file mode 100644 index 00000000000..9bd8175a5f2 --- /dev/null +++ b/tests/unit/unittest/mockbuilddependenciesprovider.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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 "googletest.h" + +#include + +class MockBuildDependenciesProvider : public ClangBackEnd::BuildDependenciesProviderInterface +{ +public: + MOCK_METHOD1(create, + ClangBackEnd::BuildDependency (const ClangBackEnd::V2::ProjectPartContainer &projectPart)); +}; diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp new file mode 100644 index 00000000000..cfb34f4c5db --- /dev/null +++ b/tests/unit/unittest/pchtaskgenerator-test.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 "googletest.h" + +#include "mockbuilddependenciesprovider.h" + +#include + +namespace { + +using ClangBackEnd::BuildDependency; +using ClangBackEnd::BuildDependencies; +using ClangBackEnd::FilePathId; +using ClangBackEnd::PchTask; + +class PchTaskGenerator : public testing::Test +{ +protected: + NiceMock mockBuildDependenciesProvider; + ClangBackEnd::PchTaskGenerator generator{mockBuildDependenciesProvider}; + ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1", + {"--yi"}, + {{"YI","1"}}, + {"/yi"}, + {{1, 1}}, + {{1, 2}}}; + BuildDependency buildDependency{{{1, 1}}, {}, {}}; +}; + +TEST_F(PchTaskGenerator, Create) +{ + ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); + + auto tasks = generator.create({projectPart1}); + + ASSERT_THAT(tasks, + ElementsAre( + AllOf(Field(&PchTask::ids, ElementsAre("ProjectPart1")), + Field(&PchTask::buildDependency, + Field(&BuildDependency::includeIds, ElementsAre(FilePathId{1, 1})))))); +} + +} diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index f541665978c..e5d56d8b044 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -103,7 +103,8 @@ SOURCES += \ processormanager-test.cpp \ taskscheduler-test.cpp \ compileroptionsbuilder-test.cpp \ - usedmacroandsourcestorage-test.cpp + usedmacroandsourcestorage-test.cpp \ + pchtaskgenerator-test.cpp !isEmpty(LIBCLANG_LIBS) { SOURCES += \ @@ -247,7 +248,8 @@ HEADERS += \ mockprocessor.h \ mockprocessormanager.h \ mocktaskscheduler.h \ - mockusedmacroandsourcestorage.h + mockusedmacroandsourcestorage.h \ + mockbuilddependenciesprovider.h !isEmpty(LIBCLANG_LIBS) { HEADERS += \