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_PRODUCTBUILDDATA_H
40 #define QBS_PRODUCTBUILDDATA_H
41 
42 #include "artifact.h"
43 #include "nodeset.h"
44 #include "rescuableartifactdata.h"
45 #include <language/filetags.h>
46 #include <language/forward_decls.h>
47 #include <tools/persistence.h>
48 
49 #include <QtCore/qlist.h>
50 
51 #include <mutex>
52 
53 namespace qbs {
54 namespace Internal {
55 
56 class Logger;
57 
58 using ArtifactSetByFileTag = QHash<FileTag, ArtifactSet>;
59 
60 class QBS_AUTOTEST_EXPORT ProductBuildData
61 {
62 public:
63     ~ProductBuildData();
64 
65     const TypeFilter<Artifact> rootArtifacts() const;
allNodes()66     const NodeSet &allNodes() const { return m_nodes; }
rootNodes()67     const NodeSet &rootNodes() const { return m_roots; }
68 
addNode(BuildGraphNode * node)69     void addNode(BuildGraphNode *node) { m_nodes.insert(node); }
addRootNode(BuildGraphNode * node)70     void addRootNode(BuildGraphNode *node) { m_roots.insert(node); }
removeFromRootNodes(BuildGraphNode * node)71     void removeFromRootNodes(BuildGraphNode *node) { m_roots.remove(node); }
72     void addArtifact(Artifact *artifact);
73     void addArtifactToSet(Artifact *artifact);
74     void removeArtifact(Artifact *artifact);
75     void removeArtifactFromSetByFileTag(Artifact *artifact, const FileTag &fileTag);
76     void addFileTagToArtifact(Artifact *artifact, const FileTag &tag);
77 
78     ArtifactSetByFileTag artifactsByFileTag() const;
79 
rescuableArtifactData()80     AllRescuableArtifactData rescuableArtifactData() const { return m_rescuableArtifactData; }
81     void setRescuableArtifactData(const AllRescuableArtifactData &rad);
82     RescuableArtifactData removeFromRescuableArtifactData(const QString &filePath);
83     void addRescuableArtifactData(const QString &filePath, const RescuableArtifactData &rad);
84 
buildPriority()85     unsigned int buildPriority() const { return m_buildPriority; }
setBuildPriority(unsigned int prio)86     void setBuildPriority(unsigned int prio) { m_buildPriority = prio; }
87 
88     bool checkAndSetJsArtifactsMapUpToDateFlag();
89 
completeSerializationOp(PersistentPool & pool)90     template<PersistentPool::OpType opType> void completeSerializationOp(PersistentPool &pool)
91     {
92         pool.serializationOp<opType>(m_nodes, m_roots, m_rescuableArtifactData,
93                                      m_artifactsByFileTag);
94     }
95 
96 private:
97     void removeArtifactFromSet(Artifact *artifact);
98 
99     NodeSet m_nodes;
100     NodeSet m_roots;
101 
102     // After change tracking, this is the relevant data of artifacts that were in the build data
103     // of the restored product, and will potentially be re-created by our rules.
104     // If and when that happens, the relevant data will be copied over to the newly created
105     // artifact.
106     AllRescuableArtifactData m_rescuableArtifactData;
107 
108     // Do not store, initialized in executor. Higher prioritized artifacts are built first.
109     unsigned int m_buildPriority = 0;
110 
111     ArtifactSetByFileTag m_artifactsByFileTag;
112     mutable std::mutex m_artifactsMapMutex;
113 
114     bool m_jsArtifactsMapUpToDate = true;
115 };
116 
117 } // namespace Internal
118 } // namespace qbs
119 
120 #endif // QBS_PRODUCTBUILDDATA_H
121