2017-01-30 11:24:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
#include <builddependenciesprovider.h>
|
|
|
|
|
#include <builddependenciesstorage.h>
|
|
|
|
|
#include <builddependencycollector.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <clangpathwatcher.h>
|
|
|
|
|
#include <connectionserver.h>
|
|
|
|
|
#include <environment.h>
|
2019-02-22 11:37:30 +01:00
|
|
|
#include <executeinloop.h>
|
2019-03-13 15:09:30 +01:00
|
|
|
#include <filepathcaching.h>
|
2018-09-11 14:02:59 +02:00
|
|
|
#include <generatedfiles.h>
|
2018-12-17 12:06:57 +01:00
|
|
|
#include <modifiedtimechecker.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <pchcreator.h>
|
|
|
|
|
#include <pchmanagerclientproxy.h>
|
2019-03-13 15:09:30 +01:00
|
|
|
#include <pchmanagerserver.h>
|
2018-12-17 12:06:57 +01:00
|
|
|
#include <pchtaskgenerator.h>
|
|
|
|
|
#include <pchtaskqueue.h>
|
|
|
|
|
#include <pchtasksmerger.h>
|
2018-09-11 17:02:45 +02:00
|
|
|
#include <precompiledheaderstorage.h>
|
|
|
|
|
#include <processormanager.h>
|
2018-09-27 17:52:44 +02:00
|
|
|
#include <progresscounter.h>
|
2019-03-04 14:42:16 +01:00
|
|
|
#include <projectpartsmanager.h>
|
2019-03-13 15:09:30 +01:00
|
|
|
#include <projectpartsstorage.h>
|
2017-09-21 11:43:59 +02:00
|
|
|
#include <refactoringdatabaseinitializer.h>
|
|
|
|
|
#include <sqlitedatabase.h>
|
2018-09-11 17:02:45 +02:00
|
|
|
#include <taskscheduler.h>
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
|
#include <QCoreApplication>
|
2018-12-17 12:06:57 +01:00
|
|
|
#include <QDateTime>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
|
#include <QLoggingCategory>
|
2017-01-31 14:21:05 +01:00
|
|
|
#include <QProcess>
|
2017-01-30 11:24:46 +01:00
|
|
|
#include <QTemporaryDir>
|
2017-01-31 11:14:54 +01:00
|
|
|
#include <QTimer>
|
2018-03-28 17:55:14 +02:00
|
|
|
#include <chrono>
|
2019-01-30 09:07:45 +01:00
|
|
|
#include <iostream>
|
2017-01-31 14:21:05 +01:00
|
|
|
#include <thread>
|
|
|
|
|
|
2018-03-28 17:55:14 +02:00
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
using ClangBackEnd::ClangPathWatcher;
|
|
|
|
|
using ClangBackEnd::ConnectionServer;
|
2019-03-13 15:09:30 +01:00
|
|
|
using ClangBackEnd::FilePathCache;
|
|
|
|
|
using ClangBackEnd::FilePathView;
|
2018-09-11 14:02:59 +02:00
|
|
|
using ClangBackEnd::GeneratedFiles;
|
2017-01-30 11:24:46 +01:00
|
|
|
using ClangBackEnd::PchCreator;
|
|
|
|
|
using ClangBackEnd::PchManagerClientProxy;
|
|
|
|
|
using ClangBackEnd::PchManagerServer;
|
2018-09-11 17:02:45 +02:00
|
|
|
using ClangBackEnd::PrecompiledHeaderStorage;
|
2019-03-04 14:42:16 +01:00
|
|
|
using ClangBackEnd::ProjectPartsManager;
|
2019-03-13 15:09:30 +01:00
|
|
|
using ClangBackEnd::ProjectPartsStorage;
|
2018-12-17 12:06:57 +01:00
|
|
|
using ClangBackEnd::TimeStamp;
|
2017-01-30 11:24:46 +01:00
|
|
|
|
2018-09-11 14:02:59 +02:00
|
|
|
class PchManagerApplication final : public QCoreApplication
|
2018-03-29 18:38:43 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using QCoreApplication::QCoreApplication;
|
|
|
|
|
|
|
|
|
|
bool notify(QObject *object, QEvent *event) override
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return QCoreApplication::notify(object, event);
|
|
|
|
|
} catch (Sqlite::Exception &exception) {
|
|
|
|
|
exception.printWarning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-11 14:02:59 +02:00
|
|
|
class ApplicationEnvironment final : public ClangBackEnd::Environment
|
2017-01-30 11:24:46 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2018-04-05 10:58:33 +02:00
|
|
|
ApplicationEnvironment(const QString &pchsPath)
|
|
|
|
|
: m_pchBuildDirectoryPath(pchsPath)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
QString pchBuildDirectory() const override
|
|
|
|
|
{
|
2018-04-05 10:58:33 +02:00
|
|
|
return m_pchBuildDirectoryPath;
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-16 12:50:59 +01:00
|
|
|
uint hardwareConcurrency() const override
|
2017-01-31 14:21:05 +01:00
|
|
|
{
|
|
|
|
|
return std::thread::hardware_concurrency();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
private:
|
2018-04-05 10:58:33 +02:00
|
|
|
QString m_pchBuildDirectoryPath;
|
2017-01-30 11:24:46 +01:00
|
|
|
};
|
|
|
|
|
|
2017-11-27 16:42:59 +01:00
|
|
|
QStringList processArguments(QCoreApplication &application)
|
2017-01-30 11:24:46 +01:00
|
|
|
{
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
parser.setApplicationDescription(QStringLiteral("Qt Creator Clang PchManager Backend"));
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection"));
|
2017-11-27 16:42:59 +01:00
|
|
|
parser.addPositionalArgument(QStringLiteral("databasepath"), QStringLiteral("Database path"));
|
2018-04-05 10:58:33 +02:00
|
|
|
parser.addPositionalArgument(QStringLiteral("pchspath"), QStringLiteral("PCHs path"));
|
2017-01-30 11:24:46 +01:00
|
|
|
|
|
|
|
|
parser.process(application);
|
|
|
|
|
|
|
|
|
|
if (parser.positionalArguments().isEmpty())
|
|
|
|
|
parser.showHelp(1);
|
|
|
|
|
|
2017-11-27 16:42:59 +01:00
|
|
|
return parser.positionalArguments();
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 17:02:45 +02:00
|
|
|
class PchCreatorManager final : public ClangBackEnd::ProcessorManager<ClangBackEnd::PchCreator>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using Processor = ClangBackEnd::PchCreator;
|
|
|
|
|
PchCreatorManager(const ClangBackEnd::GeneratedFiles &generatedFiles,
|
|
|
|
|
ClangBackEnd::Environment &environment,
|
|
|
|
|
Sqlite::Database &database,
|
2019-01-28 14:00:30 +01:00
|
|
|
PchManagerServer &pchManagerServer,
|
2019-02-25 19:07:19 +01:00
|
|
|
ClangBackEnd::ClangPathWatcherInterface &pathWatcher,
|
|
|
|
|
ClangBackEnd::BuildDependenciesStorageInterface &buildDependenciesStorage)
|
|
|
|
|
: ProcessorManager(generatedFiles)
|
|
|
|
|
, m_environment(environment)
|
|
|
|
|
, m_database(database)
|
|
|
|
|
, m_pchManagerServer(pchManagerServer)
|
|
|
|
|
, m_pathWatcher(pathWatcher)
|
|
|
|
|
, m_buildDependenciesStorage(buildDependenciesStorage)
|
2018-09-11 17:02:45 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::unique_ptr<ClangBackEnd::PchCreator> createProcessor() const override
|
|
|
|
|
{
|
|
|
|
|
return std::make_unique<PchCreator>(m_environment,
|
|
|
|
|
m_database,
|
2019-01-28 14:00:30 +01:00
|
|
|
*m_pchManagerServer.client(),
|
2019-02-25 19:07:19 +01:00
|
|
|
m_pathWatcher,
|
|
|
|
|
m_buildDependenciesStorage);
|
2018-09-11 17:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ClangBackEnd::Environment &m_environment;
|
|
|
|
|
Sqlite::Database &m_database;
|
|
|
|
|
ClangBackEnd::PchManagerServer &m_pchManagerServer;
|
2019-01-28 14:00:30 +01:00
|
|
|
ClangBackEnd::ClangPathWatcherInterface &m_pathWatcher;
|
2019-02-25 19:07:19 +01:00
|
|
|
ClangBackEnd::BuildDependenciesStorageInterface &m_buildDependenciesStorage;
|
2018-09-11 17:02:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Data // because we have a cycle dependency
|
|
|
|
|
{
|
2018-12-17 12:06:57 +01:00
|
|
|
using TaskScheduler = ClangBackEnd::TaskScheduler<PchCreatorManager, ClangBackEnd::PchTaskQueue::Task>;
|
2018-09-11 17:02:45 +02:00
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
Data(const QString &databasePath, const QString &pchsPath)
|
|
|
|
|
: database{Utils::PathString{databasePath}, 100000ms}
|
|
|
|
|
, environment{pchsPath}
|
2018-09-11 17:02:45 +02:00
|
|
|
{}
|
|
|
|
|
Sqlite::Database database;
|
|
|
|
|
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
|
|
|
|
|
ClangBackEnd::FilePathCaching filePathCache{database};
|
|
|
|
|
ClangPathWatcher<QFileSystemWatcher, QTimer> includeWatcher{filePathCache};
|
|
|
|
|
ApplicationEnvironment environment;
|
2019-03-13 15:09:30 +01:00
|
|
|
ProjectPartsStorage<> projectPartsStorage{database};
|
2019-03-19 17:00:03 +01:00
|
|
|
PrecompiledHeaderStorage<> preCompiledHeaderStorage{database};
|
|
|
|
|
ProjectPartsManager projectParts{projectPartsStorage, preCompiledHeaderStorage};
|
2018-09-11 17:02:45 +02:00
|
|
|
GeneratedFiles generatedFiles;
|
2019-01-28 14:00:30 +01:00
|
|
|
PchCreatorManager pchCreatorManager{generatedFiles,
|
|
|
|
|
environment,
|
|
|
|
|
database,
|
|
|
|
|
clangPchManagerServer,
|
2019-02-25 19:07:19 +01:00
|
|
|
includeWatcher,
|
|
|
|
|
buildDependencyStorage};
|
2019-02-19 20:46:08 +01:00
|
|
|
ClangBackEnd::ProgressCounter pchCreationProgressCounter{[&](int progress, int total) {
|
|
|
|
|
executeInLoop([&] {
|
|
|
|
|
clangPchManagerServer.setPchCreationProgress(progress, total);
|
|
|
|
|
});
|
|
|
|
|
}};
|
|
|
|
|
ClangBackEnd::ProgressCounter dependencyCreationProgressCounter{[&](int progress, int total) {
|
|
|
|
|
executeInLoop([&] {
|
|
|
|
|
clangPchManagerServer.setDependencyCreationProgress(progress, total);
|
|
|
|
|
});
|
2019-02-11 18:11:04 +01:00
|
|
|
}};
|
2018-12-17 12:06:57 +01:00
|
|
|
ClangBackEnd::PchTaskQueue pchTaskQueue{systemTaskScheduler,
|
|
|
|
|
projectTaskScheduler,
|
2019-02-19 20:46:08 +01:00
|
|
|
pchCreationProgressCounter,
|
2018-12-17 12:06:57 +01:00
|
|
|
preCompiledHeaderStorage,
|
|
|
|
|
database};
|
|
|
|
|
ClangBackEnd::PchTasksMerger pchTaskMerger{pchTaskQueue};
|
|
|
|
|
ClangBackEnd::BuildDependenciesStorage<> buildDependencyStorage{database};
|
2019-02-06 17:18:15 +01:00
|
|
|
ClangBackEnd::BuildDependencyCollector buildDependencyCollector{filePathCache,
|
|
|
|
|
generatedFiles,
|
|
|
|
|
environment};
|
2018-12-17 12:06:57 +01:00
|
|
|
std::function<TimeStamp(FilePathView filePath)> getModifiedTime{
|
|
|
|
|
[&](ClangBackEnd::FilePathView path) -> TimeStamp {
|
|
|
|
|
return QFileInfo(QString(path)).lastModified().toSecsSinceEpoch();
|
|
|
|
|
}};
|
2019-03-21 17:55:24 +01:00
|
|
|
ClangBackEnd::ModifiedTimeChecker<ClangBackEnd::SourceEntries> modifiedTimeChecker{getModifiedTime,
|
|
|
|
|
filePathCache};
|
2018-12-17 12:06:57 +01:00
|
|
|
ClangBackEnd::BuildDependenciesProvider buildDependencyProvider{buildDependencyStorage,
|
|
|
|
|
modifiedTimeChecker,
|
|
|
|
|
buildDependencyCollector,
|
|
|
|
|
database};
|
2019-02-13 13:36:27 +01:00
|
|
|
ClangBackEnd::PchTaskGenerator pchTaskGenerator{buildDependencyProvider,
|
|
|
|
|
pchTaskMerger,
|
2019-02-19 20:46:08 +01:00
|
|
|
dependencyCreationProgressCounter};
|
2019-02-13 13:36:27 +01:00
|
|
|
PchManagerServer clangPchManagerServer{includeWatcher,
|
|
|
|
|
pchTaskGenerator,
|
|
|
|
|
projectParts,
|
|
|
|
|
generatedFiles};
|
2019-01-24 15:01:30 +01:00
|
|
|
TaskScheduler systemTaskScheduler{pchCreatorManager,
|
|
|
|
|
pchTaskQueue,
|
2019-02-19 20:46:08 +01:00
|
|
|
pchCreationProgressCounter,
|
2019-01-24 15:01:30 +01:00
|
|
|
std::thread::hardware_concurrency(),
|
|
|
|
|
ClangBackEnd::CallDoInMainThreadAfterFinished::No};
|
|
|
|
|
TaskScheduler projectTaskScheduler{pchCreatorManager,
|
|
|
|
|
pchTaskQueue,
|
2019-02-19 20:46:08 +01:00
|
|
|
pchCreationProgressCounter,
|
2019-01-24 15:01:30 +01:00
|
|
|
std::thread::hardware_concurrency(),
|
|
|
|
|
ClangBackEnd::CallDoInMainThreadAfterFinished::Yes};
|
2018-09-11 17:02:45 +02:00
|
|
|
};
|
|
|
|
|
|
2019-01-30 09:07:45 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
std::wcout << msg.toStdWString() << std::endl;
|
|
|
|
|
if (type == QtFatalMsg)
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-01-30 11:24:46 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2019-01-30 09:07:45 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
qInstallMessageHandler(messageOutput);
|
|
|
|
|
#endif
|
2018-03-28 13:18:39 +02:00
|
|
|
try {
|
|
|
|
|
QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
|
|
|
|
|
QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org"));
|
|
|
|
|
QCoreApplication::setApplicationName(QStringLiteral("ClangPchManagerBackend"));
|
|
|
|
|
QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0"));
|
|
|
|
|
|
2018-03-29 18:38:43 +02:00
|
|
|
PchManagerApplication application(argc, argv);
|
2018-03-28 13:18:39 +02:00
|
|
|
|
|
|
|
|
const QStringList arguments = processArguments(application);
|
|
|
|
|
const QString connectionName = arguments[0];
|
|
|
|
|
const QString databasePath = arguments[1];
|
2018-04-05 10:58:33 +02:00
|
|
|
const QString pchsPath = arguments[2];
|
2018-03-28 13:18:39 +02:00
|
|
|
|
2018-09-11 17:02:45 +02:00
|
|
|
Data data{databasePath, pchsPath};
|
|
|
|
|
|
|
|
|
|
data.includeWatcher.setNotifier(&data.clangPchManagerServer);
|
2018-03-28 13:18:39 +02:00
|
|
|
|
|
|
|
|
ConnectionServer<PchManagerServer, PchManagerClientProxy> connectionServer;
|
2018-09-11 17:02:45 +02:00
|
|
|
connectionServer.setServer(&data.clangPchManagerServer);
|
2018-03-28 13:18:39 +02:00
|
|
|
connectionServer.start(connectionName);
|
|
|
|
|
|
|
|
|
|
return application.exec();
|
|
|
|
|
} catch (const Sqlite::Exception &exception) {
|
|
|
|
|
exception.printWarning();
|
|
|
|
|
}
|
2017-01-30 11:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|