qmakenodes.h 11.8 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
12 13 14
** 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.
15
**
16 17 18 19 20 21 22
** 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.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

hjk's avatar
hjk committed
26
#pragma once
con's avatar
con committed
27

28
#include "qmakeprojectmanager_global.h"
29
#include "qmakeparsernodes.h"
30
#include "proparser/prowriter.h"
31
#include "proparser/profileevaluator.h"
32

33
#include <coreplugin/idocument.h>
con's avatar
con committed
34
#include <projectexplorer/projectnodes.h>
35
#include <cpptools/generatedcodemodelsupport.h>
con's avatar
con committed
36

37 38 39 40
#include <QHash>
#include <QStringList>
#include <QMap>
#include <QFutureWatcher>
con's avatar
con committed
41

42 43
namespace Utils { class FileName; }

hjk's avatar
hjk committed
44
namespace QtSupport { class ProFileReader; }
con's avatar
con committed
45

hjk's avatar
hjk committed
46
namespace ProjectExplorer { class RunConfiguration; }
con's avatar
con committed
47

48
namespace QmakeProjectManager {
49
class QmakeBuildConfiguration;
50 51
class QmakeProFileNode;
class QmakeProject;
con's avatar
con committed
52

Daniel Teske's avatar
Daniel Teske committed
53
namespace Internal {
54
class QmakePriFileNodeDocument;
Daniel Teske's avatar
Daniel Teske committed
55
struct InternalNode;
56

57 58 59
class EvalInput;
class EvalResult;
class PriFileEvalResult;
Daniel Teske's avatar
Daniel Teske committed
60
}
61

62 63
struct InstallsList;

64
// Implements ProjectNode for qmake .pri files
65
class QMAKEPROJECTMANAGER_EXPORT QmakePriFileNode : public ProjectExplorer::ProjectNode
66
{
con's avatar
con committed
67
public:
68
    QmakePriFileNode(QmakeProject *project, QmakeProFileNode *qmakeProFileNode, const Utils::FileName &filePath);
69
    ~QmakePriFileNode() override;
con's avatar
con committed
70

71
    void update(const Internal::PriFileEvalResult &result);
dt's avatar
dt committed
72

73 74
    // ProjectNode interface
    QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const override;
con's avatar
con committed
75

76
    bool showInSimpleTree() const override { return false; }
con's avatar
con committed
77

78
    bool canAddSubProject(const QString &proFilePath) const override;
79

80 81
    bool addSubProjects(const QStringList &proFilePaths) override;
    bool removeSubProjects(const QStringList &proFilePaths) override;
con's avatar
con committed
82

83 84
    bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
    bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) override;
85 86 87 88
    bool deleteFiles(const QStringList &filePaths) override;
    bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
    bool renameFile(const QString &filePath, const QString &newFilePath) override;
    AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
con's avatar
con committed
89

90 91 92
    bool setProVariable(const QString &var, const QStringList &values,
                        const QString &scope = QString(),
                        int flags = QmakeProjectManager::Internal::ProWriter::ReplaceValues);
93

94
    bool folderChanged(const QString &changedFolder, const QSet<Utils::FileName> &newFiles);
95

96 97
    bool deploysFolder(const QString &folder) const override;
    QList<ProjectExplorer::RunConfiguration *> runConfigurations() const override;
dt's avatar
dt committed
98

99 100
    QmakeProFileNode *proFileNode() const;
    QList<QmakePriFileNode*> subProjectNodesExact() const;
101 102 103 104

    // Set by parent
    bool includedInExactParse() const;

105
    static QSet<Utils::FileName> recursiveEnumerate(const QString &folder);
106

con's avatar
con committed
107
protected:
108
    void setIncludedInExactParse(bool b);
109
    static QStringList varNames(ProjectExplorer::FileType type, QtSupport::ProFileReader *readerExact);
110 111
    static QStringList varNamesForRemoving();
    static QString varNameForAdding(const QString &mimeType);
112 113
    static QSet<Utils::FileName> filterFilesProVariables(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
    static QSet<Utils::FileName> filterFilesRecursiveEnumerata(ProjectExplorer::FileType fileType, const QSet<Utils::FileName> &files);
con's avatar
con committed
114 115 116 117 118 119

    enum ChangeType {
        AddToProFile,
        RemoveFromProFile
    };

120 121 122 123 124
    enum class Change { Save, TestOnly };
    bool renameFile(const QString &oldName,
                    const QString &newName,
                    const QString &mimeType,
                    Change mode = Change::Save);
125
    void changeFiles(const QString &mimeType,
con's avatar
con committed
126 127
                     const QStringList &filePaths,
                     QStringList *notChanged,
128 129
                     ChangeType change,
                     Change mode = Change::Save);
130

131
private:
132 133
    void scheduleUpdate();

134
    bool prepareForChange();
135 136
    static bool ensureWriteableProFile(const QString &file);
    static QPair<ProFile *, QStringList> readProFile(const QString &file);
137
    static QPair<ProFile *, QStringList> readProFileFromContents(const QString &contents);
138
    void save(const QStringList &lines);
139
    bool priFileWritable(const QString &absoluteFilePath);
140
    bool saveModifiedEditors();
141
    QStringList formResources(const QString &formFile) const;
142 143
    static QStringList baseVPaths(QtSupport::ProFileReader *reader, const QString &projectDir, const QString &buildDir);
    static QStringList fullVPaths(const QStringList &baseVPaths, QtSupport::ProFileReader *reader, const QString &qmakeVariable, const QString &projectDir);
144 145 146 147
    static void extractSources(
            QHash<const ProFile *, Internal::PriFileEvalResult *> proToResult,
            Internal::PriFileEvalResult *fallback,
            QVector<ProFileEvaluator::SourceFile> sourceFiles, ProjectExplorer::FileType type);
148 149 150 151 152
    static void extractInstalls(
            QHash<const ProFile *, Internal::PriFileEvalResult *> proToResult,
            Internal::PriFileEvalResult *fallback,
            const InstallsList &installList);
    static void processValues(Internal::PriFileEvalResult &result);
153
    void watchFolders(const QSet<QString> &folders);
con's avatar
con committed
154

155 156
    QmakeProject *m_project;
    QmakeProFileNode *m_qmakeProFileNode;
157
    Utils::FileName m_projectFilePath;
con's avatar
con committed
158
    QString m_projectDir;
159

160
    Internal::QmakePriFileNodeDocument *m_qmakePriFile;
dt's avatar
dt committed
161

162
    // Memory is cheap...
163 164
    QMap<ProjectExplorer::FileType, QSet<Utils::FileName> > m_files;
    QSet<Utils::FileName> m_recursiveEnumerateFiles;
165
    QSet<QString> m_watchedFolders;
166
    bool m_includedInExactParse = true;
167

168
    // managed by QmakeProFileNode
169
    friend class QmakeProjectManager::QmakeProFileNode;
170
    friend class Internal::QmakePriFileNodeDocument; // for scheduling updates on modified
171
    // internal temporary subtree representation
Daniel Teske's avatar
Daniel Teske committed
172
    friend struct Internal::InternalNode;
con's avatar
con committed
173 174
};

175
class QMAKEPROJECTMANAGER_EXPORT TargetInformation
dt's avatar
dt committed
176
{
177
public:
178
    bool valid = false;
dt's avatar
dt committed
179
    QString target;
180
    QString destDir;
181
    QString buildDir;
182
    QString buildTarget;
dt's avatar
dt committed
183 184
    bool operator==(const TargetInformation &other) const
    {
185
        return target == other.target
186
                && valid == other.valid
187 188 189
                && destDir == other.destDir
                && buildDir == other.buildDir
                && buildTarget == other.buildTarget;
dt's avatar
dt committed
190 191 192 193 194 195
    }
    bool operator!=(const TargetInformation &other) const
    {
        return !(*this == other);
    }

196
    TargetInformation() = default;
dt's avatar
dt committed
197

198
    TargetInformation(const TargetInformation &other) = default;
dt's avatar
dt committed
199 200
};

201
struct QMAKEPROJECTMANAGER_EXPORT InstallsItem {
202
    InstallsItem() = default;
203 204
    InstallsItem(QString p, QVector<ProFileEvaluator::SourceFile> f, bool a)
        : path(p), files(f), active(a) {}
205
    QString path;
206
    QVector<ProFileEvaluator::SourceFile> files;
207
    bool active = false;
208 209
};

210
struct QMAKEPROJECTMANAGER_EXPORT InstallsList {
211 212
    void clear() { targetPath.clear(); items.clear(); }
    QString targetPath;
213
    QVector<InstallsItem> items;
214 215
};

216
// Implements ProjectNode for qmake .pro files
217
class QMAKEPROJECTMANAGER_EXPORT QmakeProFileNode : public QmakePriFileNode
218
{
con's avatar
con committed
219
public:
220
    QmakeProFileNode(QmakeProject *project, const Utils::FileName &filePath);
221
    ~QmakeProFileNode() override;
con's avatar
con committed
222

223
    bool isParent(QmakeProFileNode *node);
dt's avatar
dt committed
224

225
    bool showInSimpleTree() const override;
con's avatar
con committed
226

227
    AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
228

229
    QmakeProjectManager::ProjectType projectType() const;
con's avatar
con committed
230

231 232
    QStringList variableValue(const Variable var) const;
    QString singleVariableValue(const Variable var) const;
con's avatar
con committed
233

234 235 236 237
    bool isSubProjectDeployable(const QString &filePath) const {
        return !m_subProjectsNotToDeploy.contains(filePath);
    }

238
    QString sourceDir() const;
239
    QString buildDir(QmakeBuildConfiguration *bc = nullptr) const;
240

241 242 243
    QStringList generatedFiles(const QString &buildDirectory,
                               const ProjectExplorer::FileNode *sourceFile) const;
    QList<ProjectExplorer::ExtraCompiler *> extraCompilers() const;
244

245
    QmakeProFileNode *findProFileFor(const Utils::FileName &string) const;
246
    TargetInformation targetInformation() const;
247

248 249
    InstallsList installsList() const;

250
    QString makefile() const;
251 252
    QString objectExtension() const;
    QString objectsDirectory() const;
253
    QByteArray cxxDefines() const;
254

255
    void scheduleUpdate(QmakeProFile::AsyncUpdateDelay delay);
dt's avatar
dt committed
256

257
    bool validParse() const;
258
    bool parseInProgress() const;
259

260
    bool showInSimpleTree(ProjectType projectType) const;
Orgad Shaneh's avatar
Orgad Shaneh committed
261
    bool isDebugAndRelease() const;
262
    bool isQtcRunnable() const;
dt's avatar
dt committed
263

Daniel Teske's avatar
Daniel Teske committed
264
    void setParseInProgressRecursive(bool b);
265

dt's avatar
dt committed
266 267
    void asyncUpdate();

268
private:
hjk's avatar
hjk committed
269 270 271
    void setParseInProgress(bool b);
    void setValidParseRecursive(bool b);

dt's avatar
dt committed
272
    void applyAsyncEvaluate();
con's avatar
con committed
273

dt's avatar
dt committed
274
    void setupReader();
275 276 277
    Internal::EvalInput evalInput() const;

    static Internal::EvalResult *evaluate(const Internal::EvalInput &input);
278
    void applyEvaluate(Internal::EvalResult *parseResult);
dt's avatar
dt committed
279

280
    void asyncEvaluate(QFutureInterface<Internal::EvalResult *> &fi, Internal::EvalInput input);
281
    void cleanupProFileReaders();
dt's avatar
dt committed
282

283
    using VariablesHash = QHash<Variable, QStringList>;
284

285
    void updateGeneratedFiles(const QString &buildDir);
con's avatar
con committed
286

287 288
    static QString uiDirPath(QtSupport::ProFileReader *reader, const QString &buildDir);
    static QString mocDirPath(QtSupport::ProFileReader *reader, const QString &buildDir);
289 290
    static QString sysrootify(const QString &path, const QString &sysroot, const QString &baseDir, const QString &outputDir);
    static QStringList includePaths(QtSupport::ProFileReader *reader, const QString &sysroot, const QString &buildDir, const QString &projectDir);
291
    static QStringList libDirectories(QtSupport::ProFileReader *reader);
292
    static Utils::FileNameList subDirsPaths(QtSupport::ProFileReader *reader, const QString &projectDir, QStringList *subProjectsNotToDeploy, QStringList *errors);
293

294
    static TargetInformation targetInformation(QtSupport::ProFileReader *reader, QtSupport::ProFileReader *readerBuildPass, const QString &buildDir, const QString &projectFilePath);
295
    static InstallsList installsList(const QtSupport::ProFileReader *reader, const QString &projectFilePath, const QString &projectDir, const QString &buildDir);
con's avatar
con committed
296

297
    bool m_validParse = false;
298
    bool m_parseInProgress = false;
299

300
    ProjectType m_projectType = ProjectType::Invalid;
301
    VariablesHash m_varValues;
302
    QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers;
con's avatar
con committed
303

304
    TargetInformation m_qmakeTargetInformation;
305
    QStringList m_subProjectsNotToDeploy;
306
    InstallsList m_installsList;
dt's avatar
dt committed
307 308

    // Async stuff
309
    QFutureWatcher<Internal::EvalResult *> m_parseFutureWatcher;
310 311
    QtSupport::ProFileReader *m_readerExact = nullptr;
    QtSupport::ProFileReader *m_readerCumulative = nullptr;
con's avatar
con committed
312 313
};

314
} // namespace QmakeProjectManager