forked from qt-creator/qt-creator
Clang: Add ClangPchManager
Compiling every header file again and again is quite time comsuming. There are technics to improve this like preambles(a kind of automated precompiled header) but they don't share their data between translation units. This approach provides an automatically generated precompiled header for every project and subproject to improve the loading time. Change-Id: I34f5bd4db21951175920e2a9bbf6b97b1d705969 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
21
src/plugins/clangpchmanager/ClangPchManager.json.in
Normal file
21
src/plugins/clangpchmanager/ClangPchManager.json.in
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
\"Name\" : \"ClangPchManager\",
|
||||
\"Version\" : \"$$QTCREATOR_VERSION\",
|
||||
\"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\",
|
||||
\"Experimental\" : true,
|
||||
\"HiddenByDefault\": true,
|
||||
\"Vendor\" : \"The Qt Company Ltd\",
|
||||
\"Copyright\" : \"(C) 2016 The Qt Company Ltd\",
|
||||
\"License\" : [ \"Commercial Usage\",
|
||||
\"\",
|
||||
\"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\",
|
||||
\"\",
|
||||
\"GNU General Public License Usage\",
|
||||
\"\",
|
||||
\"Alternatively, this plugin 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 plugin. 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.\"
|
||||
],
|
||||
\"Category\" : \"C++\",
|
||||
\"Description\" : \"Clang precompiled header plugin.\",
|
||||
\"Url\" : \"http://www.qt.io\",
|
||||
$$dependencyList
|
||||
}
|
||||
22
src/plugins/clangpchmanager/clangpchmanager-source.pri
Normal file
22
src/plugins/clangpchmanager/clangpchmanager-source.pri
Normal file
@@ -0,0 +1,22 @@
|
||||
shared|dll {
|
||||
DEFINES += CLANGPCHMANAGER_LIB
|
||||
} else {
|
||||
DEFINES += CLANGPCHMANAGER_STATIC_LIB
|
||||
}
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/pchmanagerclient.h \
|
||||
$$PWD/pchmanagernotifierinterface.h \
|
||||
$$PWD/pchmanagerconnectionclient.h \
|
||||
$$PWD/clangpchmanager_global.h \
|
||||
$$PWD/projectupdater.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/pchmanagerclient.cpp \
|
||||
$$PWD/pchmanagernotifierinterface.cpp \
|
||||
$$PWD/pchmanagerconnectionclient.cpp \
|
||||
$$PWD/projectupdater.cpp
|
||||
|
||||
13
src/plugins/clangpchmanager/clangpchmanager.pro
Normal file
13
src/plugins/clangpchmanager/clangpchmanager.pro
Normal file
@@ -0,0 +1,13 @@
|
||||
include(../../qtcreatorplugin.pri)
|
||||
include(clangpchmanager-source.pri)
|
||||
include(../../shared/clang/clang_installation.pri)
|
||||
|
||||
DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\"
|
||||
DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\""
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/clangpchmanagerplugin.h \
|
||||
qtcreatorprojectupdater.h
|
||||
SOURCES += \
|
||||
$$PWD/clangpchmanagerplugin.cpp \
|
||||
qtcreatorprojectupdater.cpp
|
||||
@@ -0,0 +1,8 @@
|
||||
QTC_PLUGIN_NAME = ClangPchManager
|
||||
QTC_LIB_DEPENDS += \
|
||||
utils \
|
||||
clangbackendipc
|
||||
QTC_PLUGIN_DEPENDS += \
|
||||
coreplugin \
|
||||
cpptools
|
||||
|
||||
42
src/plugins/clangpchmanager/clangpchmanager_global.h
Normal file
42
src/plugins/clangpchmanager/clangpchmanager_global.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <qglobal.h>
|
||||
|
||||
#if defined(CLANGPCHMANAGER_LIB)
|
||||
# define CLANGPCHMANAGER_EXPORT Q_DECL_EXPORT
|
||||
#elif defined(CLANGPCHMANAGER_STATIC_LIB) // Abuse single files for manual tests
|
||||
# define CLANGPCHMANAGER_EXPORT
|
||||
#else
|
||||
# define CLANGPCHMANAGER_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef UNIT_TESTS
|
||||
#define unittest_public public
|
||||
#else
|
||||
#define unittest_public private
|
||||
#endif
|
||||
100
src/plugins/clangpchmanager/clangpchmanagerplugin.cpp
Normal file
100
src/plugins/clangpchmanager/clangpchmanagerplugin.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "clangpchmanagerplugin.h"
|
||||
|
||||
#include "pchmanagerconnectionclient.h"
|
||||
#include "pchmanagerclient.h"
|
||||
#include "qtcreatorprojectupdater.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
namespace {
|
||||
|
||||
QString backendProcessPath()
|
||||
{
|
||||
return Core::ICore::libexecPath()
|
||||
+ QStringLiteral("/clangpchmanagerbackend")
|
||||
+ QStringLiteral(QTC_HOST_EXE_SUFFIX);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
class ClangPchManagerPluginData
|
||||
{
|
||||
public:
|
||||
PchManagerClient pchManagerClient;
|
||||
PchManagerConnectionClient connectionClient{&pchManagerClient};
|
||||
QtCreatorProjectUpdater projectUpdate{connectionClient.serverProxy(), pchManagerClient};
|
||||
};
|
||||
|
||||
std::unique_ptr<ClangPchManagerPluginData> ClangPchManagerPlugin::d;
|
||||
|
||||
ClangPchManagerPlugin::ClangPchManagerPlugin() = default;
|
||||
ClangPchManagerPlugin::~ClangPchManagerPlugin() = default;
|
||||
|
||||
bool ClangPchManagerPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/)
|
||||
{
|
||||
d.reset(new ClangPchManagerPluginData);
|
||||
|
||||
startBackend();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClangPchManagerPlugin::extensionsInitialized()
|
||||
{
|
||||
}
|
||||
|
||||
ExtensionSystem::IPlugin::ShutdownFlag ClangPchManagerPlugin::aboutToShutdown()
|
||||
{
|
||||
d->connectionClient.finishProcess();
|
||||
|
||||
d.reset();
|
||||
|
||||
return SynchronousShutdown;
|
||||
}
|
||||
|
||||
void ClangPchManagerPlugin::startBackend()
|
||||
{
|
||||
d->pchManagerClient.setConnectionClient(&d->connectionClient);
|
||||
|
||||
d->connectionClient.setProcessPath(backendProcessPath());
|
||||
|
||||
d->connectionClient.startProcessAndConnectToServerAsynchronously();
|
||||
}
|
||||
|
||||
|
||||
PchManagerClient &ClangPchManagerPlugin::pchManagerClient()
|
||||
{
|
||||
return d->pchManagerClient;
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
59
src/plugins/clangpchmanager/clangpchmanagerplugin.h
Normal file
59
src/plugins/clangpchmanager/clangpchmanagerplugin.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <extensionsystem/iplugin.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
class ClangPchManagerPluginData;
|
||||
class PchManagerClient;
|
||||
|
||||
class ClangPchManagerPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangPchManager.json")
|
||||
|
||||
public:
|
||||
ClangPchManagerPlugin();
|
||||
~ClangPchManagerPlugin();
|
||||
|
||||
bool initialize(const QStringList &arguments, QString *errorMessage);
|
||||
void extensionsInitialized();
|
||||
ShutdownFlag aboutToShutdown();
|
||||
|
||||
static PchManagerClient &pchManagerClient();
|
||||
|
||||
private:
|
||||
void startBackend();
|
||||
|
||||
private:
|
||||
static std::unique_ptr<ClangPchManagerPluginData> d;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
87
src/plugins/clangpchmanager/pchmanagerclient.cpp
Normal file
87
src/plugins/clangpchmanager/pchmanagerclient.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "pchmanagerclient.h"
|
||||
|
||||
#include <precompiledheadersupdatedmessage.h>
|
||||
#include <pchmanagerconnectionclient.h>
|
||||
|
||||
#include <pchmanagernotifierinterface.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
void PchManagerClient::alive()
|
||||
{
|
||||
if (m_connectionClient)
|
||||
m_connectionClient->resetProcessAliveTimer();
|
||||
}
|
||||
|
||||
void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message)
|
||||
{
|
||||
for (const ClangBackEnd::ProjectPartPch &projectPartPch : message.projectPartPchs())
|
||||
precompiledHeaderUpdated(projectPartPch.id(), projectPartPch.path());
|
||||
}
|
||||
|
||||
void PchManagerClient::precompiledHeaderRemoved(const QString &projectPartId)
|
||||
{
|
||||
for (auto notifier : m_notifiers)
|
||||
notifier->precompiledHeaderRemoved(projectPartId);
|
||||
}
|
||||
|
||||
void PchManagerClient::setConnectionClient(PchManagerConnectionClient *connectionClient)
|
||||
{
|
||||
m_connectionClient = connectionClient;
|
||||
}
|
||||
|
||||
void PchManagerClient::attach(PchManagerNotifierInterface *notifier)
|
||||
{
|
||||
m_notifiers.push_back(notifier);
|
||||
}
|
||||
|
||||
void PchManagerClient::detach(PchManagerNotifierInterface *notifierToBeDeleted)
|
||||
{
|
||||
auto newEnd = std::partition(m_notifiers.begin(),
|
||||
m_notifiers.end(),
|
||||
[&] (PchManagerNotifierInterface *notifier) {
|
||||
return notifier != notifierToBeDeleted;
|
||||
});
|
||||
|
||||
m_notifiers.erase(newEnd, m_notifiers.end());
|
||||
}
|
||||
|
||||
const std::vector<PchManagerNotifierInterface *> &PchManagerClient::notifiers() const
|
||||
{
|
||||
return m_notifiers;
|
||||
}
|
||||
|
||||
void PchManagerClient::precompiledHeaderUpdated(const QString &projectPartId, const QString &pchFilePath)
|
||||
{
|
||||
for (auto notifier : m_notifiers)
|
||||
notifier->precompiledHeaderUpdated(projectPartId, pchFilePath);
|
||||
}
|
||||
|
||||
} // namespace ClangPchManager
|
||||
60
src/plugins/clangpchmanager/pchmanagerclient.h
Normal file
60
src/plugins/clangpchmanager/pchmanagerclient.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <pchmanagerclientinterface.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ClangPchManager {
|
||||
class PchManagerConnectionClient;
|
||||
|
||||
class PchManagerNotifierInterface;
|
||||
|
||||
class PchManagerClient final : public ClangBackEnd::PchManagerClientInterface
|
||||
{
|
||||
friend class PchManagerNotifierInterface;
|
||||
public:
|
||||
void alive() override;
|
||||
void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override;
|
||||
|
||||
void precompiledHeaderRemoved(const QString &projectPartId);
|
||||
|
||||
void setConnectionClient(PchManagerConnectionClient *connectionClient);
|
||||
|
||||
unitttest_public:
|
||||
const std::vector<PchManagerNotifierInterface*> ¬ifiers() const;
|
||||
void precompiledHeaderUpdated(const QString &projectPartId, const QString &pchFilePath);
|
||||
|
||||
void attach(PchManagerNotifierInterface *notifier);
|
||||
void detach(PchManagerNotifierInterface *notifier);
|
||||
|
||||
private:
|
||||
std::vector<PchManagerNotifierInterface*> m_notifiers;
|
||||
PchManagerConnectionClient *m_connectionClient=nullptr;
|
||||
};
|
||||
|
||||
} // namespace ClangPchManager
|
||||
75
src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp
Normal file
75
src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "pchmanagerconnectionclient.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
namespace {
|
||||
|
||||
QString currentProcessId()
|
||||
{
|
||||
return QString::number(QCoreApplication::applicationPid());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ClangPchManager::PchManagerConnectionClient::PchManagerConnectionClient(
|
||||
ClangBackEnd::PchManagerClientInterface *client)
|
||||
: serverProxy_(client, ioDevice())
|
||||
{
|
||||
stdErrPrefixer().setPrefix("PchManagerConnectionClient.stderr: ");
|
||||
stdOutPrefixer().setPrefix("PchManagerConnectionClient.stdout: ");
|
||||
}
|
||||
|
||||
ClangBackEnd::PchManagerServerProxy &ClangPchManager::PchManagerConnectionClient::serverProxy()
|
||||
{
|
||||
return serverProxy_;
|
||||
}
|
||||
|
||||
void ClangPchManager::PchManagerConnectionClient::sendEndCommand()
|
||||
{
|
||||
serverProxy_.end();
|
||||
}
|
||||
|
||||
void PchManagerConnectionClient::resetCounter()
|
||||
{
|
||||
serverProxy_.resetCounter();
|
||||
}
|
||||
|
||||
QString ClangPchManager::PchManagerConnectionClient::connectionName() const
|
||||
{
|
||||
return temporaryDirectory().path() + QStringLiteral("/ClangPchManagerBackEnd-") + currentProcessId();
|
||||
}
|
||||
|
||||
QString PchManagerConnectionClient::outputName() const
|
||||
{
|
||||
return QStringLiteral("PchManagerConnectionClient");
|
||||
}
|
||||
|
||||
} // namespace ClangPchManager
|
||||
50
src/plugins/clangpchmanager/pchmanagerconnectionclient.h
Normal file
50
src/plugins/clangpchmanager/pchmanagerconnectionclient.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <connectionclient.h>
|
||||
#include <pchmanagerserverproxy.h>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
class PchManagerConnectionClient : public ClangBackEnd::ConnectionClient
|
||||
{
|
||||
public:
|
||||
PchManagerConnectionClient(ClangBackEnd::PchManagerClientInterface *client);
|
||||
|
||||
ClangBackEnd::PchManagerServerProxy &serverProxy();
|
||||
|
||||
protected:
|
||||
void sendEndCommand() override;
|
||||
void resetCounter() override;
|
||||
QString connectionName() const override;
|
||||
QString outputName() const override;
|
||||
|
||||
private:
|
||||
ClangBackEnd::PchManagerServerProxy serverProxy_;
|
||||
};
|
||||
|
||||
} // namespace ClangPchManager
|
||||
43
src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp
Normal file
43
src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "pchmanagernotifierinterface.h"
|
||||
|
||||
#include <pchmanagerclient.h>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
PchManagerNotifierInterface::PchManagerNotifierInterface(PchManagerClient &pchManagerClient)
|
||||
: m_pchManagerClient(pchManagerClient)
|
||||
{
|
||||
m_pchManagerClient.attach(this);
|
||||
}
|
||||
|
||||
PchManagerNotifierInterface::~PchManagerNotifierInterface()
|
||||
{
|
||||
m_pchManagerClient.detach(this);
|
||||
}
|
||||
|
||||
} // namespace ClangPchManager
|
||||
49
src/plugins/clangpchmanager/pchmanagernotifierinterface.h
Normal file
49
src/plugins/clangpchmanager/pchmanagernotifierinterface.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <QtGlobal>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QString)
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
class PchManagerClient;
|
||||
|
||||
class PchManagerNotifierInterface
|
||||
{
|
||||
public:
|
||||
PchManagerNotifierInterface(PchManagerClient &pchManagerClient);
|
||||
|
||||
virtual ~PchManagerNotifierInterface();
|
||||
virtual void precompiledHeaderUpdated(const QString &projectPartId,
|
||||
const QString &pchFilePath) = 0;
|
||||
virtual void precompiledHeaderRemoved(const QString &projectPartId) = 0;
|
||||
|
||||
PchManagerClient &m_pchManagerClient;
|
||||
};
|
||||
|
||||
} // namespace ClangPchManager
|
||||
126
src/plugins/clangpchmanager/projectupdater.cpp
Normal file
126
src/plugins/clangpchmanager/projectupdater.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "projectupdater.h"
|
||||
|
||||
#include "pchmanagerclient.h"
|
||||
|
||||
#include <pchmanagerserverinterface.h>
|
||||
#include <removepchprojectpartsmessage.h>
|
||||
#include <updatepchprojectpartsmessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
ProjectUpdater::ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
|
||||
PchManagerClient &client)
|
||||
: m_server(server),
|
||||
m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
void ProjectUpdater::updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts)
|
||||
{
|
||||
ClangBackEnd::UpdatePchProjectPartsMessage message{toProjectPartContainers(projectParts)};
|
||||
|
||||
m_server.updatePchProjectParts(std::move(message));
|
||||
}
|
||||
|
||||
void ProjectUpdater::removeProjectParts(const QStringList &projectPartIds)
|
||||
{
|
||||
ClangBackEnd::RemovePchProjectPartsMessage message{Utils::SmallStringVector(projectPartIds)};
|
||||
|
||||
m_server.removePchProjectParts(std::move(message));
|
||||
|
||||
for (const QString &projectPartiId : projectPartIds)
|
||||
m_client.precompiledHeaderRemoved(projectPartiId);
|
||||
}
|
||||
|
||||
namespace {
|
||||
class HeaderAndSources
|
||||
{
|
||||
public:
|
||||
void reserve(std::size_t size)
|
||||
{
|
||||
headers.reserve(size);
|
||||
sources.reserve(size);
|
||||
}
|
||||
|
||||
Utils::SmallStringVector headers;
|
||||
Utils::SmallStringVector sources;
|
||||
};
|
||||
|
||||
HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
HeaderAndSources headerAndSources;
|
||||
headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2);
|
||||
|
||||
for (const CppTools::ProjectFile &projectFile : projectPart->files) {
|
||||
if (projectFile.isSource())
|
||||
headerAndSources.sources.push_back(projectFile.path);
|
||||
else if (projectFile.isHeader())
|
||||
headerAndSources.headers.push_back(projectFile.path);
|
||||
}
|
||||
|
||||
return headerAndSources;
|
||||
}
|
||||
}
|
||||
|
||||
ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
QStringList arguments = ClangCompilerOptionsBuilder::build(
|
||||
projectPart,
|
||||
CppTools::ProjectFile::CXXHeader,
|
||||
ClangCompilerOptionsBuilder::PchUsage::None,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR);
|
||||
|
||||
HeaderAndSources headerAndSources = headerAndSourcesFromProjectPart(projectPart);
|
||||
|
||||
return ClangBackEnd::V2::ProjectPartContainer(projectPart->displayName,
|
||||
Utils::SmallStringVector(arguments),
|
||||
std::move(headerAndSources.headers),
|
||||
std::move(headerAndSources.sources));
|
||||
}
|
||||
|
||||
std::vector<ClangBackEnd::V2::ProjectPartContainer> ProjectUpdater::toProjectPartContainers(
|
||||
std::vector<CppTools::ProjectPart *> projectParts)
|
||||
{
|
||||
std::vector<ClangBackEnd::V2::ProjectPartContainer> projectPartContainers;
|
||||
projectPartContainers.reserve(projectParts.size());
|
||||
|
||||
std::transform(projectParts.begin(),
|
||||
projectParts.end(),
|
||||
std::back_inserter(projectPartContainers),
|
||||
ProjectUpdater::toProjectPartContainer);
|
||||
|
||||
return projectPartContainers;
|
||||
}
|
||||
|
||||
} // namespace ClangPchManager
|
||||
70
src/plugins/clangpchmanager/projectupdater.h
Normal file
70
src/plugins/clangpchmanager/projectupdater.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 <clangpchmanager_global.h>
|
||||
|
||||
namespace CppTools {
|
||||
class ProjectPart;
|
||||
}
|
||||
|
||||
namespace ClangBackEnd {
|
||||
class PchManagerServerInterface;
|
||||
|
||||
namespace V2 {
|
||||
class ProjectPartContainer;
|
||||
}
|
||||
}
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QStringList)
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
class PchManagerClient;
|
||||
|
||||
class ProjectUpdater
|
||||
{
|
||||
public:
|
||||
ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
|
||||
PchManagerClient &client);
|
||||
|
||||
void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts);
|
||||
void removeProjectParts(const QStringList &projectPartIds);
|
||||
|
||||
unittest_public:
|
||||
static ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer(
|
||||
CppTools::ProjectPart *projectPart);
|
||||
static std::vector<ClangBackEnd::V2::ProjectPartContainer> toProjectPartContainers(
|
||||
std::vector<CppTools::ProjectPart *> projectParts);
|
||||
|
||||
private:
|
||||
ClangBackEnd::PchManagerServerInterface &m_server;
|
||||
PchManagerClient &m_client;
|
||||
};
|
||||
|
||||
} // namespace ClangPchManager
|
||||
84
src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp
Normal file
84
src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "qtcreatorprojectupdater.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
static CppTools::CppModelManager *cppModelManager()
|
||||
{
|
||||
return CppTools::CppModelManager::instance();
|
||||
}
|
||||
|
||||
QtCreatorProjectUpdater::QtCreatorProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
|
||||
PchManagerClient &client)
|
||||
: ProjectUpdater(server, client)
|
||||
{
|
||||
connectToCppModelManager();
|
||||
}
|
||||
|
||||
void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *project)
|
||||
{
|
||||
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
|
||||
|
||||
const QVector<CppTools::ProjectPart::Ptr> projectPartSharedPointers = projectInfo.projectParts();
|
||||
|
||||
std::vector<CppTools::ProjectPart*> projectParts;
|
||||
projectParts.reserve(std::size_t(projectPartSharedPointers.size()));
|
||||
|
||||
auto convertToRawPointer = [] (const CppTools::ProjectPart::Ptr &sharedPointer) {
|
||||
return sharedPointer.data();
|
||||
};
|
||||
|
||||
std::transform(projectPartSharedPointers.begin(),
|
||||
projectPartSharedPointers.end(),
|
||||
std::back_inserter(projectParts),
|
||||
convertToRawPointer);
|
||||
|
||||
updateProjectParts(projectParts);
|
||||
}
|
||||
|
||||
void QtCreatorProjectUpdater::projectPartsRemoved(const QStringList &projectPartIds)
|
||||
{
|
||||
removeProjectParts(projectPartIds);
|
||||
}
|
||||
|
||||
void QtCreatorProjectUpdater::connectToCppModelManager()
|
||||
{
|
||||
connect(cppModelManager(),
|
||||
&CppTools::CppModelManager::projectPartsUpdated,
|
||||
this,
|
||||
&QtCreatorProjectUpdater::projectPartsUpdated);
|
||||
connect(cppModelManager(),
|
||||
&CppTools::CppModelManager::projectPartsRemoved,
|
||||
this,
|
||||
&QtCreatorProjectUpdater::projectPartsRemoved);
|
||||
}
|
||||
|
||||
} // namespace ClangPchManager
|
||||
51
src/plugins/clangpchmanager/qtcreatorprojectupdater.h
Normal file
51
src/plugins/clangpchmanager/qtcreatorprojectupdater.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "projectupdater.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
}
|
||||
|
||||
namespace ClangPchManager {
|
||||
|
||||
class QtCreatorProjectUpdater : public QObject, public ProjectUpdater
|
||||
{
|
||||
public:
|
||||
QtCreatorProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
|
||||
PchManagerClient &client);
|
||||
|
||||
void projectPartsUpdated(ProjectExplorer::Project *project);
|
||||
void projectPartsRemoved(const QStringList &projectPartIds);
|
||||
|
||||
private:
|
||||
void connectToCppModelManager();
|
||||
};
|
||||
|
||||
} // namespace ClangPchManager
|
||||
Reference in New Issue
Block a user