clangpchmanagerbackendmain.cpp 4.2 KB
Newer Older
Marco Bubke's avatar
Marco Bubke committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/****************************************************************************
**
** 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 <clangpathwatcher.h>
#include <connectionserver.h>
#include <environment.h>
#include <pchcreator.h>
Marco Bubke's avatar
Marco Bubke committed
30
#include <pchgenerator.h>
Marco Bubke's avatar
Marco Bubke committed
31 32 33 34 35 36 37 38 39
#include <pchmanagerserver.h>
#include <pchmanagerclientproxy.h>
#include <projectparts.h>
#include <stringcache.h>

#include <QCommandLineParser>
#include <QCoreApplication>
#include <QFileSystemWatcher>
#include <QLoggingCategory>
Marco Bubke's avatar
Marco Bubke committed
40
#include <QProcess>
Marco Bubke's avatar
Marco Bubke committed
41
#include <QTemporaryDir>
42
#include <QTimer>
Marco Bubke's avatar
Marco Bubke committed
43

Marco Bubke's avatar
Marco Bubke committed
44 45
#include <thread>

Marco Bubke's avatar
Marco Bubke committed
46 47 48
using ClangBackEnd::ClangPathWatcher;
using ClangBackEnd::ConnectionServer;
using ClangBackEnd::PchCreator;
Marco Bubke's avatar
Marco Bubke committed
49
using ClangBackEnd::PchGenerator;
Marco Bubke's avatar
Marco Bubke committed
50 51 52
using ClangBackEnd::PchManagerClientProxy;
using ClangBackEnd::PchManagerServer;
using ClangBackEnd::ProjectParts;
Marco Bubke's avatar
Marco Bubke committed
53
using ClangBackEnd::FilePathCache;
Marco Bubke's avatar
Marco Bubke committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67

class ApplicationEnvironment : public ClangBackEnd::Environment
{
public:
    QString pchBuildDirectory() const override
    {
        return temporaryDirectory.path();
    }

    QString clangCompilerPath() const override
    {
        return QString(CLANG_COMPILER_PATH);
    }

68
    uint hardwareConcurrency() const override
Marco Bubke's avatar
Marco Bubke committed
69 70 71 72
    {
        return std::thread::hardware_concurrency();
    }

Marco Bubke's avatar
Marco Bubke committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
private:
    QTemporaryDir temporaryDirectory;
};

QString processArguments(QCoreApplication &application)
{
    QCommandLineParser parser;
    parser.setApplicationDescription(QStringLiteral("Qt Creator Clang PchManager Backend"));
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection"));

    parser.process(application);

    if (parser.positionalArguments().isEmpty())
        parser.showHelp(1);

    return parser.positionalArguments().first();
}

int main(int argc, char *argv[])
{
    //QLoggingCategory::setFilterRules(QStringLiteral("*.debug=false"));

    QCoreApplication::setOrganizationName(QStringLiteral("QtProject"));
    QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org"));
    QCoreApplication::setApplicationName(QStringLiteral("ClangPchManagerBackend"));
    QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0"));

    QCoreApplication application(argc, argv);

    const QString connection =  processArguments(application);

Marco Bubke's avatar
Marco Bubke committed
106
    FilePathCache<> filePathCache;
107
    ClangPathWatcher<QFileSystemWatcher, QTimer> includeWatcher(filePathCache);
Marco Bubke's avatar
Marco Bubke committed
108
    ApplicationEnvironment environment;
Marco Bubke's avatar
Marco Bubke committed
109
    PchGenerator<QProcess> pchGenerator(environment);
Marco Bubke's avatar
Marco Bubke committed
110
    PchCreator pchCreator(environment, filePathCache);
Marco Bubke's avatar
Marco Bubke committed
111
    pchCreator.setGenerator(&pchGenerator);
Marco Bubke's avatar
Marco Bubke committed
112
    ProjectParts projectParts;
113 114 115 116 117
    PchManagerServer clangPchManagerServer(filePathCache,
                                           includeWatcher,
                                           pchCreator,
                                           projectParts);
    includeWatcher.setNotifier(&clangPchManagerServer);
Marco Bubke's avatar
Marco Bubke committed
118 119
    pchGenerator.setNotifier(&clangPchManagerServer);

Marco Bubke's avatar
Marco Bubke committed
120 121 122 123 124 125 126 127
    ConnectionServer<PchManagerServer, PchManagerClientProxy> connectionServer(connection);
    connectionServer.start();
    connectionServer.setServer(&clangPchManagerServer);

    return application.exec();
}