1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qbs.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 #ifndef QBS_PROJECT_H
40 #define QBS_PROJECT_H
41 
42 #include "rulecommand.h"
43 #include "transformerdata.h"
44 #include "../language/forward_decls.h"
45 #include "../tools/error.h"
46 #include "../tools/porting.h"
47 #include "../tools/qbs_export.h"
48 
49 #include <QtCore/qshareddata.h>
50 #include <QtCore/qhash.h>
51 #include <QtCore/qlist.h>
52 #include <QtCore/qstringlist.h>
53 #include <QtCore/qvariant.h>
54 
55 #include <set>
56 
57 QT_BEGIN_NAMESPACE
58 class QIODevice;
59 class QObject;
60 class QProcessEnvironment;
61 QT_END_NAMESPACE
62 
63 namespace qbs {
64 class BuildJob;
65 class BuildOptions;
66 class CleanJob;
67 class CleanOptions;
68 class GroupData;
69 class ILogSink;
70 class InstallJob;
71 class InstallOptions;
72 class ProductData;
73 class ProjectData;
74 class RunEnvironment;
75 class Settings;
76 class SetupProjectJob;
77 class SetupProjectParameters;
78 
79 namespace Internal {
80 class Logger;
81 class ProjectPrivate;
82 } // namespace Internal;
83 
84 class QBS_EXPORT Project
85 {
86     friend class SetupProjectJob;
87     friend QHashValueType qHash(const Project &p);
88 public:
89     SetupProjectJob *setupProject(const SetupProjectParameters &parameters,
90                                   ILogSink *logSink, QObject *jobOwner);
91 
92     Project();
93     Project(const Project &other);
94     Project &operator=(const Project &other);
95     ~Project();
96 
97     bool isValid() const;
98     QString profile() const;
99     ProjectData projectData() const;
100     RunEnvironment getRunEnvironment(const ProductData &product,
101             const InstallOptions &installOptions,
102             const QProcessEnvironment &environment,
103             const QStringList &setupRunEnvConfig, Settings *settings) const;
104 
105     enum ProductSelection { ProductSelectionDefaultOnly, ProductSelectionWithNonDefault };
106     BuildJob *buildAllProducts(const BuildOptions &options,
107                                ProductSelection productSelection = ProductSelectionDefaultOnly,
108                                QObject *jobOwner = nullptr) const;
109     BuildJob *buildSomeProducts(const QList<ProductData> &products, const BuildOptions &options,
110                                 QObject *jobOwner = nullptr) const;
111     BuildJob *buildOneProduct(const ProductData &product, const BuildOptions &options,
112                               QObject *jobOwner = nullptr) const;
113 
114     CleanJob *cleanAllProducts(const CleanOptions &options, QObject *jobOwner = nullptr) const;
115     CleanJob *cleanSomeProducts(const QList<ProductData> &products, const CleanOptions &options,
116                                 QObject *jobOwner = nullptr) const;
117     CleanJob *cleanOneProduct(const ProductData &product, const CleanOptions &options,
118                               QObject *jobOwner = nullptr) const;
119 
120     InstallJob *installAllProducts(const InstallOptions &options,
121                                    ProductSelection productSelection = ProductSelectionDefaultOnly,
122                                    QObject *jobOwner = nullptr) const;
123     InstallJob *installSomeProducts(const QList<ProductData> &products,
124                                     const InstallOptions &options,
125                                     QObject *jobOwner = nullptr) const;
126     InstallJob *installOneProduct(const ProductData &product, const InstallOptions &options,
127                                   QObject *jobOwner = nullptr) const;
128 
129     void updateTimestamps(const QList<ProductData> &products);
130 
131     bool operator==(const Project &other) const { return d.data() == other.d.data(); }
132 
133     QStringList generatedFiles(const ProductData &product, const QString &file,
134                                bool recursive, const QStringList &tags = QStringList()) const;
135 
136     QVariantMap projectConfiguration() const;
137 
138     std::set<QString> buildSystemFiles() const;
139 
140     RuleCommandList ruleCommands(const ProductData &product, const QString &inputFilePath,
141                                  const QString &outputFileTag, ErrorInfo *error = nullptr) const;
142     ProjectTransformerData transformerData(ErrorInfo *error = nullptr) const;
143 
144     ErrorInfo dumpNodesTree(QIODevice &outDevice, const QList<ProductData> &products);
145 
146 
147     class BuildGraphInfo
148     {
149     public:
150         QString bgFilePath;
151         QVariantMap overriddenProperties;
152         QVariantMap profileData;
153         QVariantMap requestedProperties;
154         ErrorInfo error;
155     };
156     static BuildGraphInfo getBuildGraphInfo(const QString &bgFilePath,
157                                             const QStringList &requestedProperties);
158 
159     // Use with loaded project. Does not set requestedProperties.
160     BuildGraphInfo getBuildGraphInfo() const;
161 
162 
163     ErrorInfo addGroup(const ProductData &product, const QString &groupName);
164     ErrorInfo addFiles(const ProductData &product, const GroupData &group,
165                        const QStringList &filePaths);
166     ErrorInfo removeFiles(const ProductData &product, const GroupData &group,
167                           const QStringList &filePaths);
168     ErrorInfo removeGroup(const ProductData &product, const GroupData &group);
169 
170 private:
171     Project(const Internal::TopLevelProjectPtr &internalProject, const Internal::Logger &logger);
172 
173     QExplicitlySharedDataPointer<Internal::ProjectPrivate> d;
174 };
175 
176 inline bool operator!=(const Project &p1, const Project &p2) { return !(p1 == p2); }
qHash(const Project & p)177 inline QHashValueType qHash(const Project &p) { return QT_PREPEND_NAMESPACE(qHash)(p.d.data()); }
178 
179 } // namespace qbs
180 
181 #endif // QBS_PROJECT_H
182