da265b68f1af510e844dc3d804e53e1c3ff2c446
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / BuildClassObject.py
1 ## @file
2 # This file is used to define each component of the build database
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 import Common.LongFilePathOs as os
15
16 from Common.Misc import sdict
17 from Common.Misc import RealPath2
18 from Common.BuildToolError import *
19 import collections
20
21 ## PcdClassObject
22 #
23 # This Class is used for PcdObject
24 #
25 # @param object: Inherited from object class
26 # @param Name: Input value for Name of Pcd, default is None
27 # @param Guid: Input value for Guid of Pcd, default is None
28 # @param Type: Input value for Type of Pcd, default is None
29 # @param DatumType: Input value for DatumType of Pcd, default is None
30 # @param Value: Input value for Value of Pcd, default is None
31 # @param Token: Input value for Token of Pcd, default is None
32 # @param MaxDatumSize: Input value for MaxDatumSize of Pcd, default is None
33 # @param SkuInfoList: Input value for SkuInfoList of Pcd, default is {}
34 # @param IsOverrided: Input value for IsOverrided of Pcd, default is False
35 # @param GuidValue: Input value for TokenSpaceGuidValue of Pcd, default is None
36 #
37 # @var TokenCName: To store value for TokenCName
38 # @var TokenSpaceGuidCName: To store value for TokenSpaceGuidCName
39 # @var Type: To store value for Type
40 # @var DatumType: To store value for DatumType
41 # @var TokenValue: To store value for TokenValue
42 # @var MaxDatumSize: To store value for MaxDatumSize
43 # @var SkuInfoList: To store value for SkuInfoList
44 # @var IsOverrided: To store value for IsOverrided
45 # @var Phase: To store value for Phase, default is "DXE"
46 #
47 class PcdClassObject(object):
48 def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None, SkuInfoList = {}, IsOverrided = False, GuidValue = None, validateranges = [], validlists = [], expressions = [], IsDsc = False):
49 self.TokenCName = Name
50 self.TokenSpaceGuidCName = Guid
51 self.TokenSpaceGuidValue = GuidValue
52 self.Type = Type
53 self.DatumType = DatumType
54 self.DefaultValue = Value
55 self.TokenValue = Token
56 self.MaxDatumSize = MaxDatumSize
57 self.SkuInfoList = SkuInfoList
58 self.Phase = "DXE"
59 self.Pending = False
60 self.IsOverrided = IsOverrided
61 self.IsFromBinaryInf = False
62 self.IsFromDsc = False
63 self.validateranges = validateranges
64 self.validlists = validlists
65 self.expressions = expressions
66 self.DscDefaultValue = None
67 if IsDsc:
68 self.DscDefaultValue = Value
69
70 ## Convert the class to a string
71 #
72 # Convert each member of the class to string
73 # Organize to a signle line format string
74 #
75 # @retval Rtn Formatted String
76 #
77 def __str__(self):
78 Rtn = '\tTokenCName=' + str(self.TokenCName) + ', ' + \
79 'TokenSpaceGuidCName=' + str(self.TokenSpaceGuidCName) + ', ' + \
80 'Type=' + str(self.Type) + ', ' + \
81 'DatumType=' + str(self.DatumType) + ', ' + \
82 'DefaultValue=' + str(self.DefaultValue) + ', ' + \
83 'TokenValue=' + str(self.TokenValue) + ', ' + \
84 'MaxDatumSize=' + str(self.MaxDatumSize) + ', '
85 for Item in self.SkuInfoList.values():
86 Rtn = Rtn + 'SkuId=' + Item.SkuId + ', ' + 'SkuIdName=' + Item.SkuIdName
87 Rtn = Rtn + ', IsOverrided=' + str(self.IsOverrided)
88
89 return Rtn
90
91 ## Override __eq__ function
92 #
93 # Check whether pcds are the same
94 #
95 # @retval False The two pcds are different
96 # @retval True The two pcds are the same
97 #
98 def __eq__(self, Other):
99 return Other and self.TokenCName == Other.TokenCName and self.TokenSpaceGuidCName == Other.TokenSpaceGuidCName
100
101 ## Override __hash__ function
102 #
103 # Use (TokenCName, TokenSpaceGuidCName) as key in hash table
104 #
105 # @retval truple() Key for hash table
106 #
107 def __hash__(self):
108 return hash((self.TokenCName, self.TokenSpaceGuidCName))
109
110 class StructurePcd(PcdClassObject):
111 def __init__(self, StructuredPcdIncludeFile="", Packages=None, Name=None, Guid=None, Type=None, DatumType=None, Value=None, Token=None, MaxDatumSize=None, SkuInfoList={}, IsOverrided=False, GuidValue=None, validateranges=[], validlists=[], expressions=[]):
112 super(StructurePcd, self).__init__(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, IsOverrided, GuidValue, validateranges, validlists, expressions)
113 self.StructuredPcdIncludeFile = StructuredPcdIncludeFile
114 self.PackageDecs = Packages
115 self.DefaultStoreName = ['STANDARD']
116 self.DefaultValues = collections.OrderedDict({})
117 self.PcdMode = None
118 self.SkuOverrideValues = collections.OrderedDict({})
119 self.FlexibleFieldName = None
120
121 def __repr__(self):
122 return self.TypeName
123
124 def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
125 self.DefaultValues[FieldName] = [Value.strip(), FileName, LineNo]
126 return self.DefaultValues[FieldName]
127
128 def AddOverrideValue (self, FieldName, Value, SkuName, FileName="", LineNo=0):
129 if SkuName not in self.SkuOverrideValues:
130 self.SkuOverrideValues[SkuName] = collections.OrderedDict({})
131 self.SkuOverrideValues[SkuName][FieldName] = [Value.strip(), FileName, LineNo]
132 return self.SkuOverrideValues[SkuName][FieldName]
133
134 def SetPcdMode (self, PcdMode):
135 self.PcdMode = PcdMode
136
137 def SetFlexibleFieldName (self, FlexibleFieldName):
138 self.FlexibleFieldName = FlexibleFieldName
139
140 def copy(self, PcdObject):
141 self.TokenCName = PcdObject.TokenCName if PcdObject.TokenCName else self.TokenCName
142 self.TokenSpaceGuidCName = PcdObject.TokenSpaceGuidCName if PcdObject.TokenSpaceGuidCName else PcdObject.TokenSpaceGuidCName
143 self.TokenSpaceGuidValue = PcdObject.TokenSpaceGuidValue if PcdObject.TokenSpaceGuidValue else self.TokenSpaceGuidValue
144 self.Type = PcdObject.Type if PcdObject.Type else self.Type
145 self.DatumType = PcdObject.DatumType if PcdObject.DatumType else self.DatumType
146 self.DefaultValue = PcdObject.DefaultValue if PcdObject.DefaultValue else self.DefaultValue
147 self.TokenValue = PcdObject.TokenValue if PcdObject.TokenValue else self.TokenValue
148 self.MaxDatumSize = PcdObject.MaxDatumSize if PcdObject.MaxDatumSize else self.MaxDatumSize
149 self.SkuInfoList = PcdObject.SkuInfoList if PcdObject.SkuInfoList else self.SkuInfoList
150 self.Phase = PcdObject.Phase if PcdObject.Phase else self.Phase
151 self.Pending = PcdObject.Pending if PcdObject.Pending else self.Pending
152 self.IsOverrided = PcdObject.IsOverrided if PcdObject.IsOverrided else self.IsOverrided
153 self.IsFromBinaryInf = PcdObject.IsFromBinaryInf if PcdObject.IsFromBinaryInf else self.IsFromBinaryInf
154 self.IsFromDsc = PcdObject.IsFromDsc if PcdObject.IsFromDsc else self.IsFromDsc
155 self.validateranges = PcdObject.validateranges if PcdObject.validateranges else self.validateranges
156 self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists
157 self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions
158 if type(PcdObject) is StructurePcd:
159 self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile
160 self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
161 self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
162 self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
163 self.DefaultFromDSC=None
164 self.OverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
165 self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
166
167 ## LibraryClassObject
168 #
169 # This Class defines LibraryClassObject used in BuildDatabase
170 #
171 # @param object: Inherited from object class
172 # @param Name: Input value for LibraryClassName, default is None
173 # @param SupModList: Input value for SupModList, default is []
174 # @param Type: Input value for Type, default is None
175 #
176 # @var LibraryClass: To store value for LibraryClass
177 # @var SupModList: To store value for SupModList
178 # @var Type: To store value for Type
179 #
180 class LibraryClassObject(object):
181 def __init__(self, Name = None, SupModList = [], Type = None):
182 self.LibraryClass = Name
183 self.SupModList = SupModList
184 if Type != None:
185 self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)
186
187 ## ModuleBuildClassObject
188 #
189 # This Class defines ModuleBuildClass
190 #
191 # @param object: Inherited from object class
192 #
193 # @var MetaFile: To store value for module meta file path
194 # @var BaseName: To store value for BaseName
195 # @var ModuleType: To store value for ModuleType
196 # @var Guid: To store value for Guid
197 # @var Version: To store value for Version
198 # @var PcdIsDriver: To store value for PcdIsDriver
199 # @var BinaryModule: To store value for BinaryModule
200 # @var CustomMakefile: To store value for CustomMakefile
201 # @var Specification: To store value for Specification
202 # @var Shadow To store value for Shadow
203 # @var LibraryClass: To store value for LibraryClass, it is a list structure as
204 # [ LibraryClassObject, ...]
205 # @var ModuleEntryPointList: To store value for ModuleEntryPointList
206 # @var ModuleUnloadImageList: To store value for ModuleUnloadImageList
207 # @var ConstructorList: To store value for ConstructorList
208 # @var DestructorList: To store value for DestructorList
209 # @var Binaries: To store value for Binaries, it is a list structure as
210 # [ ModuleBinaryClassObject, ...]
211 # @var Sources: To store value for Sources, it is a list structure as
212 # [ ModuleSourceFilesClassObject, ... ]
213 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
214 # { [LibraryClassName, ModuleType] : LibraryClassInfFile }
215 # @var Protocols: To store value for Protocols, it is a list structure as
216 # [ ProtocolName, ... ]
217 # @var Ppis: To store value for Ppis, it is a list structure as
218 # [ PpiName, ... ]
219 # @var Guids: To store value for Guids, it is a list structure as
220 # [ GuidName, ... ]
221 # @var Includes: To store value for Includes, it is a list structure as
222 # [ IncludePath, ... ]
223 # @var Packages: To store value for Packages, it is a list structure as
224 # [ DecFileName, ... ]
225 # @var Pcds: To store value for Pcds, it is a set structure as
226 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
227 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
228 # { [BuildOptionKey] : BuildOptionValue}
229 # @var Depex: To store value for Depex
230 #
231 class ModuleBuildClassObject(object):
232 def __init__(self):
233 self.AutoGenVersion = 0
234 self.MetaFile = ''
235 self.BaseName = ''
236 self.ModuleType = ''
237 self.Guid = ''
238 self.Version = ''
239 self.PcdIsDriver = ''
240 self.BinaryModule = ''
241 self.Shadow = ''
242 self.SourceOverridePath = ''
243 self.CustomMakefile = {}
244 self.Specification = {}
245 self.LibraryClass = []
246 self.ModuleEntryPointList = []
247 self.ModuleUnloadImageList = []
248 self.ConstructorList = []
249 self.DestructorList = []
250
251 self.Binaries = []
252 self.Sources = []
253 self.LibraryClasses = sdict()
254 self.Libraries = []
255 self.Protocols = []
256 self.Ppis = []
257 self.Guids = []
258 self.Includes = []
259 self.Packages = []
260 self.Pcds = {}
261 self.BuildOptions = {}
262 self.Depex = {}
263
264 ## Convert the class to a string
265 #
266 # Convert member MetaFile of the class to a string
267 #
268 # @retval string Formatted String
269 #
270 def __str__(self):
271 return str(self.MetaFile)
272
273 ## Override __eq__ function
274 #
275 # Check whether ModuleBuildClassObjects are the same
276 #
277 # @retval False The two ModuleBuildClassObjects are different
278 # @retval True The two ModuleBuildClassObjects are the same
279 #
280 def __eq__(self, Other):
281 return self.MetaFile == Other
282
283 ## Override __hash__ function
284 #
285 # Use MetaFile as key in hash table
286 #
287 # @retval string Key for hash table
288 #
289 def __hash__(self):
290 return hash(self.MetaFile)
291
292 ## PackageBuildClassObject
293 #
294 # This Class defines PackageBuildClass
295 #
296 # @param object: Inherited from object class
297 #
298 # @var MetaFile: To store value for package meta file path
299 # @var PackageName: To store value for PackageName
300 # @var Guid: To store value for Guid
301 # @var Version: To store value for Version
302 # @var Protocols: To store value for Protocols, it is a set structure as
303 # { [ProtocolName] : Protocol Guid, ... }
304 # @var Ppis: To store value for Ppis, it is a set structure as
305 # { [PpiName] : Ppi Guid, ... }
306 # @var Guids: To store value for Guids, it is a set structure as
307 # { [GuidName] : Guid, ... }
308 # @var Includes: To store value for Includes, it is a list structure as
309 # [ IncludePath, ... ]
310 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
311 # { [LibraryClassName] : LibraryClassInfFile }
312 # @var Pcds: To store value for Pcds, it is a set structure as
313 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
314 #
315 class PackageBuildClassObject(object):
316 def __init__(self):
317 self.MetaFile = ''
318 self.PackageName = ''
319 self.Guid = ''
320 self.Version = ''
321
322 self.Protocols = {}
323 self.Ppis = {}
324 self.Guids = {}
325 self.Includes = []
326 self.LibraryClasses = {}
327 self.Pcds = {}
328
329 ## Convert the class to a string
330 #
331 # Convert member MetaFile of the class to a string
332 #
333 # @retval string Formatted String
334 #
335 def __str__(self):
336 return str(self.MetaFile)
337
338 ## Override __eq__ function
339 #
340 # Check whether PackageBuildClassObjects are the same
341 #
342 # @retval False The two PackageBuildClassObjects are different
343 # @retval True The two PackageBuildClassObjects are the same
344 #
345 def __eq__(self, Other):
346 return self.MetaFile == Other
347
348 ## Override __hash__ function
349 #
350 # Use MetaFile as key in hash table
351 #
352 # @retval string Key for hash table
353 #
354 def __hash__(self):
355 return hash(self.MetaFile)
356
357 ## PlatformBuildClassObject
358 #
359 # This Class defines PlatformBuildClass
360 #
361 # @param object: Inherited from object class
362 #
363 # @var MetaFile: To store value for platform meta-file path
364 # @var PlatformName: To store value for PlatformName
365 # @var Guid: To store value for Guid
366 # @var Version: To store value for Version
367 # @var DscSpecification: To store value for DscSpecification
368 # @var OutputDirectory: To store value for OutputDirectory
369 # @var FlashDefinition: To store value for FlashDefinition
370 # @var BuildNumber: To store value for BuildNumber
371 # @var MakefileName: To store value for MakefileName
372 # @var SkuIds: To store value for SkuIds, it is a set structure as
373 # { 'SkuName' : SkuId, '!include' : includefilename, ...}
374 # @var Modules: To store value for Modules, it is a list structure as
375 # [ InfFileName, ... ]
376 # @var Libraries: To store value for Libraries, it is a list structure as
377 # [ InfFileName, ... ]
378 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
379 # { (LibraryClassName, ModuleType) : LibraryClassInfFile }
380 # @var Pcds: To store value for Pcds, it is a set structure as
381 # { [(PcdCName, PcdGuidCName)] : PcdClassObject }
382 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
383 # { [BuildOptionKey] : BuildOptionValue }
384 #
385 class PlatformBuildClassObject(object):
386 def __init__(self):
387 self.MetaFile = ''
388 self.PlatformName = ''
389 self.Guid = ''
390 self.Version = ''
391 self.DscSpecification = ''
392 self.OutputDirectory = ''
393 self.FlashDefinition = ''
394 self.BuildNumber = ''
395 self.MakefileName = ''
396
397 self.SkuIds = {}
398 self.Modules = []
399 self.LibraryInstances = []
400 self.LibraryClasses = {}
401 self.Libraries = {}
402 self.Pcds = {}
403 self.BuildOptions = {}
404
405 ## Convert the class to a string
406 #
407 # Convert member MetaFile of the class to a string
408 #
409 # @retval string Formatted String
410 #
411 def __str__(self):
412 return str(self.MetaFile)
413
414 ## Override __eq__ function
415 #
416 # Check whether PlatformBuildClassObjects are the same
417 #
418 # @retval False The two PlatformBuildClassObjects are different
419 # @retval True The two PlatformBuildClassObjects are the same
420 #
421 def __eq__(self, Other):
422 return self.MetaFile == Other
423
424 ## Override __hash__ function
425 #
426 # Use MetaFile as key in hash table
427 #
428 # @retval string Key for hash table
429 #
430 def __hash__(self):
431 return hash(self.MetaFile)
432