1# Copyright (c) 2020 The Linux Foundation
2#
3# SPDX-License-Identifier: Apache-2.0
4
5from enum import Enum
6
7class Codemodel:
8
9    def __init__(self):
10        super(Codemodel, self).__init__()
11
12        self.paths_source = ""
13        self.paths_build = ""
14        self.configurations = []
15
16    def __repr__(self):
17        return f"Codemodel: source {self.paths_source}, build {self.paths_build}"
18
19# A member of the codemodel configurations array
20class Config:
21
22    def __init__(self):
23        super(Config, self).__init__()
24
25        self.name = ""
26        self.directories = []
27        self.projects = []
28        self.configTargets = []
29
30    def __repr__(self):
31        if self.name == "":
32            return f"Config: [no name]"
33        else:
34            return f"Config: {self.name}"
35
36# A member of the configuration.directories array
37class ConfigDir:
38
39    def __init__(self):
40        super(ConfigDir, self).__init__()
41
42        self.source = ""
43        self.build = ""
44        self.parentIndex = -1
45        self.childIndexes = []
46        self.projectIndex = -1
47        self.targetIndexes = []
48        self.minimumCMakeVersion = ""
49        self.hasInstallRule = False
50
51        # actual items, calculated from indices after loading
52        self.parent = None
53        self.children = []
54        self.project = None
55        self.targets = []
56
57    def __repr__(self):
58        return f"ConfigDir: source {self.source}, build {self.build}"
59
60# A member of the configuration.projects array
61class ConfigProject:
62
63    def __init__(self):
64        super(ConfigProject, self).__init__()
65
66        self.name = ""
67        self.parentIndex = -1
68        self.childIndexes = []
69        self.directoryIndexes = []
70        self.targetIndexes = []
71
72        # actual items, calculated from indices after loading
73        self.parent = None
74        self.children = []
75        self.directories = []
76        self.targets = []
77
78    def __repr__(self):
79        return f"ConfigProject: {self.name}"
80
81# A member of the configuration.configTargets array
82class ConfigTarget:
83
84    def __init__(self):
85        super(ConfigTarget, self).__init__()
86
87        self.name = ""
88        self.id = ""
89        self.directoryIndex = -1
90        self.projectIndex = -1
91        self.jsonFile = ""
92
93        # actual target data, loaded from self.jsonFile
94        self.target = None
95
96        # actual items, calculated from indices after loading
97        self.directory = None
98        self.project = None
99
100    def __repr__(self):
101        return f"ConfigTarget: {self.name}"
102
103# The available values for Target.type
104class TargetType(Enum):
105    UNKNOWN = 0
106    EXECUTABLE = 1
107    STATIC_LIBRARY = 2
108    SHARED_LIBRARY = 3
109    MODULE_LIBRARY = 4
110    OBJECT_LIBRARY = 5
111    UTILITY = 6
112
113# A member of the target.install_destinations array
114class TargetInstallDestination:
115
116    def __init__(self):
117        super(TargetInstallDestination, self).__init__()
118
119        self.path = ""
120        self.backtrace = -1
121
122    def __repr__(self):
123        return f"TargetInstallDestination: {self.path}"
124
125# A member of the target.link_commandFragments and
126# archive_commandFragments array
127class TargetCommandFragment:
128
129    def __init__(self):
130        super(TargetCommandFragment, self).__init__()
131
132        self.fragment = ""
133        self.role = ""
134
135    def __repr__(self):
136        return f"TargetCommandFragment: {self.fragment}"
137
138# A member of the target.dependencies array
139class TargetDependency:
140
141    def __init__(self):
142        super(TargetDependency, self).__init__()
143
144        self.id = ""
145        self.backtrace = -1
146
147    def __repr__(self):
148        return f"TargetDependency: {self.id}"
149
150# A member of the target.sources array
151class TargetSource:
152
153    def __init__(self):
154        super(TargetSource, self).__init__()
155
156        self.path = ""
157        self.compileGroupIndex = -1
158        self.sourceGroupIndex = -1
159        self.isGenerated = False
160        self.backtrace = -1
161
162        # actual items, calculated from indices after loading
163        self.compileGroup = None
164        self.sourceGroup = None
165
166    def __repr__(self):
167        return f"TargetSource: {self.path}"
168
169# A member of the target.sourceGroups array
170class TargetSourceGroup:
171
172    def __init__(self):
173        super(TargetSourceGroup, self).__init__()
174
175        self.name = ""
176        self.sourceIndexes = []
177
178        # actual items, calculated from indices after loading
179        self.sources = []
180
181    def __repr__(self):
182        return f"TargetSourceGroup: {self.name}"
183
184# A member of the target.compileGroups.includes array
185class TargetCompileGroupInclude:
186
187    def __init__(self):
188        super(TargetCompileGroupInclude, self).__init__()
189
190        self.path = ""
191        self.isSystem = False
192        self.backtrace = -1
193
194    def __repr__(self):
195        return f"TargetCompileGroupInclude: {self.path}"
196
197# A member of the target.compileGroups.precompileHeaders array
198class TargetCompileGroupPrecompileHeader:
199
200    def __init__(self):
201        super(TargetCompileGroupPrecompileHeader, self).__init__()
202
203        self.header = ""
204        self.backtrace = -1
205
206    def __repr__(self):
207        return f"TargetCompileGroupPrecompileHeader: {self.header}"
208
209# A member of the target.compileGroups.defines array
210class TargetCompileGroupDefine:
211
212    def __init__(self):
213        super(TargetCompileGroupDefine, self).__init__()
214
215        self.define = ""
216        self.backtrace = -1
217
218    def __repr__(self):
219        return f"TargetCompileGroupDefine: {self.define}"
220
221# A member of the target.compileGroups array
222class TargetCompileGroup:
223
224    def __init__(self):
225        super(TargetCompileGroup, self).__init__()
226
227        self.sourceIndexes = []
228        self.language = ""
229        self.compileCommandFragments = []
230        self.includes = []
231        self.precompileHeaders = []
232        self.defines = []
233        self.sysroot = ""
234
235        # actual items, calculated from indices after loading
236        self.sources = []
237
238    def __repr__(self):
239        return f"TargetCompileGroup: {self.sources}"
240
241# A member of the target.backtraceGraph_nodes array
242class TargetBacktraceGraphNode:
243
244    def __init__(self):
245        super(TargetBacktraceGraphNode, self).__init__()
246
247        self.file = -1
248        self.line = -1
249        self.command = -1
250        self.parent = -1
251
252    def __repr__(self):
253        return f"TargetBacktraceGraphNode: {self.command}"
254
255# Actual data in config.target.target, loaded from
256# config.target.jsonFile
257class Target:
258
259    def __init__(self):
260        super(Target, self).__init__()
261
262        self.name = ""
263        self.id = ""
264        self.type = TargetType.UNKNOWN
265        self.backtrace = -1
266        self.folder = ""
267        self.paths_source = ""
268        self.paths_build = ""
269        self.nameOnDisk = ""
270        self.artifacts = []
271        self.isGeneratorProvided = False
272
273        # only if install rule is present
274        self.install_prefix = ""
275        self.install_destinations = []
276
277        # only for executables and shared library targets that link into
278        # a runtime binary
279        self.link_language = ""
280        self.link_commandFragments = []
281        self.link_lto = False
282        self.link_sysroot = ""
283
284        # only for static library targets
285        self.archive_commandFragments = []
286        self.archive_lto = False
287
288        # only if the target depends on other targets
289        self.dependencies = []
290
291        # corresponds to target's source files
292        self.sources = []
293
294        # only if sources are grouped together by source_group() or by default
295        self.sourceGroups = []
296
297        # only if target has sources that compile
298        self.compileGroups = []
299
300        # graph of backtraces referenced from elsewhere
301        self.backtraceGraph_nodes = []
302        self.backtraceGraph_commands = []
303        self.backtraceGraph_files = []
304
305    def __repr__(self):
306        return f"Target: {self.name}"
307