pchcreator.h 5.57 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.
**
****************************************************************************/

#pragma once

#include "pchcreatorinterface.h"

Marco Bubke's avatar
Marco Bubke committed
30
#include "pchgeneratorinterface.h"
Marco Bubke's avatar
Marco Bubke committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include "stringcache.h"
#include "idpaths.h"

#include <projectpartpch.h>
#include <projectpartcontainerv2.h>

#include <vector>

QT_FORWARD_DECLARE_CLASS(QFile)
QT_FORWARD_DECLARE_CLASS(QCryptographicHash)
QT_FORWARD_DECLARE_CLASS(QProcess)

namespace ClangBackEnd {

class Environment;

class PchCreator final : public PchCreatorInterface
{
public:
    PchCreator(Environment &environment,
Marco Bubke's avatar
Marco Bubke committed
51
               FilePathCache<> &filePathCache);
Marco Bubke's avatar
Marco Bubke committed
52 53
    PchCreator(V2::ProjectPartContainers &&projectsParts,
               Environment &environment,
Marco Bubke's avatar
Marco Bubke committed
54
               FilePathCache<> &filePathCache,
Marco Bubke's avatar
Marco Bubke committed
55 56
               PchGeneratorInterface *pchGenerator,
               V2::FileContainers &&generatedFiles);
Marco Bubke's avatar
Marco Bubke committed
57 58

    void generatePchs(V2::ProjectPartContainers &&projectsParts) override;
Marco Bubke's avatar
Marco Bubke committed
59
    void setGeneratedFiles(V2::FileContainers &&generatedFiles) override;
Marco Bubke's avatar
Marco Bubke committed
60 61
    std::vector<IdPaths> takeProjectsIncludes() override;

Marco Bubke's avatar
Marco Bubke committed
62 63
    void setGenerator(PchGeneratorInterface *pchGenerator);

Marco Bubke's avatar
Marco Bubke committed
64
unittest_public:
Marco Bubke's avatar
Marco Bubke committed
65 66 67
    Utils::PathStringVector generateGlobalHeaderPaths() const;
    Utils::PathStringVector generateGlobalSourcePaths() const;
    Utils::PathStringVector generateGlobalHeaderAndSourcePaths() const;
Marco Bubke's avatar
Marco Bubke committed
68 69 70 71 72
    Utils::SmallStringVector generateGlobalArguments() const;
    Utils::SmallStringVector generateGlobalCommandLine() const;
    Utils::SmallStringVector generateGlobalPchCompilerArguments() const;
    Utils::SmallStringVector generateGlobalClangCompilerArguments() const;

Marco Bubke's avatar
Marco Bubke committed
73
    std::vector<FilePathIndex> generateGlobalPchIncludeIds() const;
Marco Bubke's avatar
Marco Bubke committed
74

Marco Bubke's avatar
Marco Bubke committed
75
    Utils::SmallString generatePchIncludeFileContent(const std::vector<FilePathIndex> &includeIds) const;
Marco Bubke's avatar
Marco Bubke committed
76 77
    Utils::SmallString generateGlobalPchHeaderFileContent() const;
    std::unique_ptr<QFile> generateGlobalPchHeaderFile();
Marco Bubke's avatar
Marco Bubke committed
78 79
    void generatePch(Utils::SmallStringVector &&commandLineArguments,
                     ProjectPartPch &&projectPartPch);
Marco Bubke's avatar
Marco Bubke committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93
    void generateGlobalPch();

    Utils::SmallString globalPchContent() const;

    static QStringList convertToQStringList(const Utils::SmallStringVector &convertToQStringList);

    Utils::SmallString generateGlobalPchFilePathWithoutExtension() const;
    Utils::SmallString generateGlobalPchHeaderFilePath() const;
    Utils::SmallString generateGlobalPchFilePath() const;

    Utils::SmallStringVector generateProjectPartCommandLine(
            const V2::ProjectPartContainer &projectPart) const;
    Utils::SmallString generateProjectPartPchFilePathWithoutExtension(
            const V2::ProjectPartContainer &projectPart) const;
Marco Bubke's avatar
Marco Bubke committed
94 95
    Utils::PathStringVector generateProjectPartHeaders(
            const V2::ProjectPartContainer &projectPart) const;
96 97
    static Utils::SmallString generateProjectPartHeaderAndSourcesContent(
            const V2::ProjectPartContainer &projectPart);
Marco Bubke's avatar
Marco Bubke committed
98
    static Utils::PathStringVector generateProjectPartHeaderAndSourcePaths(
Marco Bubke's avatar
Marco Bubke committed
99
            const V2::ProjectPartContainer &projectPart);
Marco Bubke's avatar
Marco Bubke committed
100
    std::vector<FilePathIndex> generateProjectPartPchIncludes(
Marco Bubke's avatar
Marco Bubke committed
101 102 103 104 105
            const V2::ProjectPartContainer &projectPart) const;
    Utils::SmallString generateProjectPathPchHeaderFilePath(
            const V2::ProjectPartContainer &projectPart) const;
    Utils::SmallString  generateProjectPartPchFilePath(
           const V2::ProjectPartContainer &projectPart) const;
106 107
    Utils::SmallString  generateProjectPartSourceFilePath(
           const V2::ProjectPartContainer &projectPart) const;
Marco Bubke's avatar
Marco Bubke committed
108 109 110 111
    Utils::SmallStringVector generateProjectPartPchCompilerArguments(
            const V2::ProjectPartContainer &projectPart) const;
    Utils::SmallStringVector generateProjectPartClangCompilerArguments(
             const V2::ProjectPartContainer &projectPart) const;
Marco Bubke's avatar
Marco Bubke committed
112
    IdPaths generateProjectPartPch(
Marco Bubke's avatar
Marco Bubke committed
113
            const V2::ProjectPartContainer &projectPart);
114
    static std::unique_ptr<QFile> generateFileWithContent(
Marco Bubke's avatar
Marco Bubke committed
115 116 117 118 119 120 121 122 123 124 125
            const Utils::SmallString &filePath,
            const Utils::SmallString &content);

    void generatePchs();

private:
    static QByteArray projectPartHash(const V2::ProjectPartContainer &projectPart);
    QByteArray globalProjectHash() const;

private:
    V2::ProjectPartContainers m_projectParts;
Marco Bubke's avatar
Marco Bubke committed
126
    V2::FileContainers m_generatedFiles;
Marco Bubke's avatar
Marco Bubke committed
127 128 129
    std::vector<ProjectPartPch> m_projectPartPchs;
    std::vector<IdPaths> m_projectsIncludeIds;
    Environment &m_environment;
Marco Bubke's avatar
Marco Bubke committed
130
    FilePathCache<> &m_filePathCache;
Marco Bubke's avatar
Marco Bubke committed
131
    PchGeneratorInterface *m_pchGenerator = nullptr;
Marco Bubke's avatar
Marco Bubke committed
132 133 134
};

} // namespace ClangBackEnd