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 
40 #ifndef QBS_ARTIFACT_H
41 #define QBS_ARTIFACT_H
42 
43 #include "filedependency.h"
44 #include "buildgraphnode.h"
45 #include "forward_decls.h"
46 #include <language/filetags.h>
47 #include <tools/dynamictypecheck.h>
48 #include <tools/filetime.h>
49 #include <tools/set.h>
50 
51 #include <QtCore/qstring.h>
52 
53 #include <utility>
54 #include <vector>
55 
56 namespace qbs {
57 namespace Internal {
58 class Logger;
59 
60 class Artifact;
61 using ArtifactSet = Set<Artifact *>;
62 
63 /**
64  * The Artifact class
65  *
66  * Let artifact P be the parent of artifact C. Thus C is child of P.
67  * C produces P using the transformer P.transformer.
68  *
69  *
70  */
71 class QBS_AUTOTEST_EXPORT Artifact : public FileResourceBase, public BuildGraphNode
72 {
73 public:
74     Artifact();
75     ~Artifact() override;
76 
type()77     Type type() const override { return ArtifactNodeType; }
fileType()78     FileType fileType() const override { return FileTypeArtifact; }
79     void accept(BuildGraphVisitor *visitor) override;
80     QString toString() const override;
81 
82     void addFileTag(const FileTag &t);
83     void removeFileTag(const FileTag &t);
84     void setFileTags(const FileTags &newFileTags);
fileTags()85     const FileTags &fileTags() const { return m_fileTags; }
86 
87     RuleNode *producer() const;
88 
89     ArtifactSet childrenAddedByScanner;
90     Set<FileDependency *> fileDependencies;
91     TransformerPtr transformer;
92     PropertyMapPtr properties;
93     QString targetOfModule;
94 
95     // The tags set directly via an Artifact item or an outputArtifacts script,
96     // not the result of file taggers or fileTagsFilter groups, nor the ones inherited from
97     // the product.
98     FileTags pureFileTags;
99 
100     // The properties attached directly to an artifact in an Artifact item or outputArtifacts
101     // script.
102     std::vector<std::pair<QStringList, QVariant>> pureProperties;
103 
104     enum ArtifactType
105     {
106         Unknown = 1,
107         SourceFile = 2,
108         Generated = 4
109     };
110 
111     ArtifactType artifactType;
112     bool inputsScanned : 1;                 // Do not serialize. Will be refreshed for every build.
113     bool timestampRetrieved : 1;            // Do not serialize. Will be refreshed for every build.
114     bool alwaysUpdated : 1;
115     bool oldDataPossiblyPresent : 1;
116 
117     const TypeFilter<Artifact> parentArtifacts() const;
118     const TypeFilter<Artifact> childArtifacts() const;
119     void onChildDisconnected(BuildGraphNode *child) override;
120 
isTargetOfModule()121     bool isTargetOfModule() const { return !targetOfModule.isEmpty(); }
122 
123     void load(PersistentPool &pool) override;
124     void store(PersistentPool &pool) override;
125 
126 private:
127     FileTags m_fileTags;
128 };
129 
toString(Artifact * const & artifact)130 template<> inline QString Set<Artifact *>::toString(Artifact * const &artifact) const
131 {
132     return artifact ? artifact->filePath() : QStringLiteral("<null>");
133 }
uniqueAddress(const Artifact * a)134 template<> inline const void *uniqueAddress(const Artifact *a)
135 {
136     return static_cast<const BuildGraphNode *>(a);
137 }
138 
139 template<> inline bool hasDynamicType<Artifact>(const BuildGraphNode *n)
140 {
141     return n->type() == BuildGraphNode::ArtifactNodeType;
142 }
143 
144 // debugging helper
toString(Artifact::ArtifactType t)145 inline QString toString(Artifact::ArtifactType t)
146 {
147     switch (t) {
148     case Artifact::SourceFile:
149         return QStringLiteral("SourceFile");
150     case Artifact::Generated:
151         return QStringLiteral("Generated");
152     case Artifact::Unknown:
153     default:
154         return QStringLiteral("Unknown");
155     }
156 }
157 
158 // debugging helper
toString(BuildGraphNode::BuildState s)159 inline QString toString(BuildGraphNode::BuildState s)
160 {
161     switch (s) {
162     case BuildGraphNode::Untouched:
163         return QStringLiteral("Untouched");
164     case BuildGraphNode::Buildable:
165         return QStringLiteral("Buildable");
166     case BuildGraphNode::Building:
167         return QStringLiteral("Building");
168     case BuildGraphNode::Built:
169         return QStringLiteral("Built");
170     default:
171         return QStringLiteral("Unknown");
172     }
173 }
174 
175 } // namespace Internal
176 } // namespace qbs
177 
178 #endif // QBS_ARTIFACT_H
179