c188b47534f889f75bf8fa34b6cbb99bcc377efc
[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 - 2018, 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 collections import OrderedDict
17 from Common.Misc import RealPath2
18 from Common.BuildToolError import *
19 from Common.DataType import *
20 import collections
21
22 ## PcdClassObject
23 #
24 # This Class is used for PcdObject
25 #
26 # @param object: Inherited from object class
27 # @param Name: Input value for Name of Pcd, default is None
28 # @param Guid: Input value for Guid of Pcd, default is None
29 # @param Type: Input value for Type of Pcd, default is None
30 # @param DatumType: Input value for DatumType of Pcd, default is None
31 # @param Value: Input value for Value of Pcd, default is None
32 # @param Token: Input value for Token of Pcd, default is None
33 # @param MaxDatumSize: Input value for MaxDatumSize of Pcd, default is None
34 # @param SkuInfoList: Input value for SkuInfoList of Pcd, default is {}
35 # @param IsOverrided: Input value for IsOverrided of Pcd, default is False
36 # @param GuidValue: Input value for TokenSpaceGuidValue of Pcd, default is None
37 #
38 # @var TokenCName: To store value for TokenCName
39 # @var TokenSpaceGuidCName: To store value for TokenSpaceGuidCName
40 # @var Type: To store value for Type
41 # @var DatumType: To store value for DatumType
42 # @var TokenValue: To store value for TokenValue
43 # @var MaxDatumSize: To store value for MaxDatumSize
44 # @var SkuInfoList: To store value for SkuInfoList
45 # @var IsOverrided: To store value for IsOverrided
46 # @var Phase: To store value for Phase, default is "DXE"
47 #
48 class PcdClassObject(object):
49 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):
50 self.TokenCName = Name
51 self.TokenSpaceGuidCName = Guid
52 self.TokenSpaceGuidValue = GuidValue
53 self.Type = Type
54 self.DatumType = DatumType
55 self.DefaultValue = Value
56 self.TokenValue = Token
57 self.MaxDatumSize = MaxDatumSize
58 self.MaxSizeUserSet = None
59 self.SkuInfoList = SkuInfoList
60 self.Phase = "DXE"
61 self.Pending = False
62 self.IsOverrided = IsOverrided
63 self.IsFromBinaryInf = False
64 self.IsFromDsc = False
65 self.validateranges = validateranges
66 self.validlists = validlists
67 self.expressions = expressions
68 self.DscDefaultValue = None
69 self.DscRawValue = None
70 if IsDsc:
71 self.DscDefaultValue = Value
72 self.PcdValueFromComm = ""
73 self.DefinitionPosition = ("", "")
74
75 ## Get the maximum number of bytes
76 def GetPcdMaxSize(self):
77 if self.DatumType in TAB_PCD_NUMERIC_TYPES:
78 return MAX_SIZE_TYPE[self.DatumType]
79
80 MaxSize = int(self.MaxDatumSize, 10) if self.MaxDatumSize else 0
81 if self.PcdValueFromComm:
82 if self.PcdValueFromComm.startswith("{") and self.PcdValueFromComm.endswith("}"):
83 return max([len(self.PcdValueFromComm.split(",")), MaxSize])
84 elif self.PcdValueFromComm.startswith("\"") or self.PcdValueFromComm.startswith("\'"):
85 return max([len(self.PcdValueFromComm)-2+1, MaxSize])
86 elif self.PcdValueFromComm.startswith("L\""):
87 return max([2*(len(self.PcdValueFromComm)-3+1), MaxSize])
88 else:
89 return max([len(self.PcdValueFromComm), MaxSize])
90 return MaxSize
91
92 ## Get the number of bytes
93 def GetPcdSize(self):
94 if self.DatumType in TAB_PCD_NUMERIC_TYPES:
95 return MAX_SIZE_TYPE[self.DatumType]
96 if not self.DefaultValue:
97 return 1
98 elif self.DefaultValue[0] == 'L':
99 return (len(self.DefaultValue) - 2) * 2
100 elif self.DefaultValue[0] == '{':
101 return len(self.DefaultValue.split(','))
102 else:
103 return len(self.DefaultValue) - 1
104
105
106 ## Convert the class to a string
107 #
108 # Convert each member of the class to string
109 # Organize to a signle line format string
110 #
111 # @retval Rtn Formatted String
112 #
113 def __str__(self):
114 Rtn = '\tTokenCName=' + str(self.TokenCName) + ', ' + \
115 'TokenSpaceGuidCName=' + str(self.TokenSpaceGuidCName) + ', ' + \
116 'Type=' + str(self.Type) + ', ' + \
117 'DatumType=' + str(self.DatumType) + ', ' + \
118 'DefaultValue=' + str(self.DefaultValue) + ', ' + \
119 'TokenValue=' + str(self.TokenValue) + ', ' + \
120 'MaxDatumSize=' + str(self.MaxDatumSize) + ', '
121 for Item in self.SkuInfoList.values():
122 Rtn = Rtn + 'SkuId=' + Item.SkuId + ', ' + 'SkuIdName=' + Item.SkuIdName
123 Rtn = Rtn + ', IsOverrided=' + str(self.IsOverrided)
124
125 return Rtn
126
127 ## Override __eq__ function
128 #
129 # Check whether pcds are the same
130 #
131 # @retval False The two pcds are different
132 # @retval True The two pcds are the same
133 #
134 def __eq__(self, Other):
135 return Other and self.TokenCName == Other.TokenCName and self.TokenSpaceGuidCName == Other.TokenSpaceGuidCName
136
137 ## Override __hash__ function
138 #
139 # Use (TokenCName, TokenSpaceGuidCName) as key in hash table
140 #
141 # @retval truple() Key for hash table
142 #
143 def __hash__(self):
144 return hash((self.TokenCName, self.TokenSpaceGuidCName))
145
146 class StructurePcd(PcdClassObject):
147 def __init__(self, StructuredPcdIncludeFile=None, Packages=None, Name=None, Guid=None, Type=None, DatumType=None, Value=None, Token=None, MaxDatumSize=None, SkuInfoList=None, IsOverrided=False, GuidValue=None, validateranges=None, validlists=None, expressions=None,default_store = TAB_DEFAULT_STORES_DEFAULT):
148 if SkuInfoList is None:
149 SkuInfoList = {}
150 if validateranges is None:
151 validateranges = []
152 if validlists is None:
153 validlists = []
154 if expressions is None:
155 expressions = []
156 if Packages is None:
157 Packages = []
158 super(StructurePcd, self).__init__(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, IsOverrided, GuidValue, validateranges, validlists, expressions)
159 self.StructuredPcdIncludeFile = [] if StructuredPcdIncludeFile is None else StructuredPcdIncludeFile
160 self.PackageDecs = Packages
161 self.DefaultStoreName = [default_store]
162 self.DefaultValues = collections.OrderedDict()
163 self.PcdMode = None
164 self.SkuOverrideValues = collections.OrderedDict()
165 self.FlexibleFieldName = None
166 self.StructName = None
167 self.PcdDefineLineNo = 0
168 self.PkgPath = ""
169 self.DefaultValueFromDec = ""
170 self.ValueChain = set()
171 self.PcdFieldValueFromComm = collections.OrderedDict()
172 def __repr__(self):
173 return self.TypeName
174
175 def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
176 if FieldName in self.DefaultValues:
177 del self.DefaultValues[FieldName]
178 self.DefaultValues[FieldName] = [Value.strip(), FileName, LineNo]
179 return self.DefaultValues[FieldName]
180
181 def SetDecDefaultValue(self, DefaultValue):
182 self.DefaultValueFromDec = DefaultValue
183 def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0):
184 if SkuName not in self.SkuOverrideValues:
185 self.SkuOverrideValues[SkuName] = collections.OrderedDict()
186 if DefaultStoreName not in self.SkuOverrideValues[SkuName]:
187 self.SkuOverrideValues[SkuName][DefaultStoreName] = collections.OrderedDict()
188 if FieldName in self.SkuOverrideValues[SkuName][DefaultStoreName]:
189 del self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName]
190 self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName] = [Value.strip(), FileName, LineNo]
191 return self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName]
192
193 def SetPcdMode (self, PcdMode):
194 self.PcdMode = PcdMode
195
196 def SetFlexibleFieldName (self, FlexibleFieldName):
197 self.FlexibleFieldName = FlexibleFieldName
198
199 def copy(self, PcdObject):
200 self.TokenCName = PcdObject.TokenCName if PcdObject.TokenCName else self.TokenCName
201 self.TokenSpaceGuidCName = PcdObject.TokenSpaceGuidCName if PcdObject.TokenSpaceGuidCName else PcdObject.TokenSpaceGuidCName
202 self.TokenSpaceGuidValue = PcdObject.TokenSpaceGuidValue if PcdObject.TokenSpaceGuidValue else self.TokenSpaceGuidValue
203 self.Type = PcdObject.Type if PcdObject.Type else self.Type
204 self.DatumType = PcdObject.DatumType if PcdObject.DatumType else self.DatumType
205 self.DefaultValue = PcdObject.DefaultValue if PcdObject.DefaultValue else self.DefaultValue
206 self.TokenValue = PcdObject.TokenValue if PcdObject.TokenValue else self.TokenValue
207 self.MaxDatumSize = PcdObject.MaxDatumSize if PcdObject.MaxDatumSize else self.MaxDatumSize
208 self.SkuInfoList = PcdObject.SkuInfoList if PcdObject.SkuInfoList else self.SkuInfoList
209 self.Phase = PcdObject.Phase if PcdObject.Phase else self.Phase
210 self.Pending = PcdObject.Pending if PcdObject.Pending else self.Pending
211 self.IsOverrided = PcdObject.IsOverrided if PcdObject.IsOverrided else self.IsOverrided
212 self.IsFromBinaryInf = PcdObject.IsFromBinaryInf if PcdObject.IsFromBinaryInf else self.IsFromBinaryInf
213 self.IsFromDsc = PcdObject.IsFromDsc if PcdObject.IsFromDsc else self.IsFromDsc
214 self.validateranges = PcdObject.validateranges if PcdObject.validateranges else self.validateranges
215 self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists
216 self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions
217 self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue
218 self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm
219 self.DefinitionPosition = PcdObject.DefinitionPosition if PcdObject.DefinitionPosition else self.DefinitionPosition
220 if isinstance(PcdObject, StructurePcd):
221 self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile
222 self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
223 self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
224 self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
225 self.DefaultFromDSC=None
226 self.DefaultValueFromDec = PcdObject.DefaultValueFromDec if PcdObject.DefaultValueFromDec else self.DefaultValueFromDec
227 self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
228 self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
229 self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
230 self.PcdDefineLineNo = PcdObject.PcdDefineLineNo if PcdObject.PcdDefineLineNo else self.PcdDefineLineNo
231 self.PkgPath = PcdObject.PkgPath if PcdObject.PkgPath else self.PkgPath
232 self.ValueChain = PcdObject.ValueChain if PcdObject.ValueChain else self.ValueChain
233 self.PcdFieldValueFromComm = PcdObject.PcdFieldValueFromComm if PcdObject.PcdFieldValueFromComm else self.PcdFieldValueFromComm
234
235 ## LibraryClassObject
236 #
237 # This Class defines LibraryClassObject used in BuildDatabase
238 #
239 # @param object: Inherited from object class
240 # @param Name: Input value for LibraryClassName, default is None
241 # @param SupModList: Input value for SupModList, default is []
242 # @param Type: Input value for Type, default is None
243 #
244 # @var LibraryClass: To store value for LibraryClass
245 # @var SupModList: To store value for SupModList
246 # @var Type: To store value for Type
247 #
248 class LibraryClassObject(object):
249 def __init__(self, Name = None, SupModList = [], Type = None):
250 self.LibraryClass = Name
251 self.SupModList = SupModList
252 if Type is not None:
253 self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)
254
255 ## ModuleBuildClassObject
256 #
257 # This Class defines ModuleBuildClass
258 #
259 # @param object: Inherited from object class
260 #
261 # @var MetaFile: To store value for module meta file path
262 # @var BaseName: To store value for BaseName
263 # @var ModuleType: To store value for ModuleType
264 # @var Guid: To store value for Guid
265 # @var Version: To store value for Version
266 # @var PcdIsDriver: To store value for PcdIsDriver
267 # @var BinaryModule: To store value for BinaryModule
268 # @var CustomMakefile: To store value for CustomMakefile
269 # @var Specification: To store value for Specification
270 # @var Shadow To store value for Shadow
271 # @var LibraryClass: To store value for LibraryClass, it is a list structure as
272 # [ LibraryClassObject, ...]
273 # @var ModuleEntryPointList: To store value for ModuleEntryPointList
274 # @var ModuleUnloadImageList: To store value for ModuleUnloadImageList
275 # @var ConstructorList: To store value for ConstructorList
276 # @var DestructorList: To store value for DestructorList
277 # @var Binaries: To store value for Binaries, it is a list structure as
278 # [ ModuleBinaryClassObject, ...]
279 # @var Sources: To store value for Sources, it is a list structure as
280 # [ ModuleSourceFilesClassObject, ... ]
281 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
282 # { [LibraryClassName, ModuleType] : LibraryClassInfFile }
283 # @var Protocols: To store value for Protocols, it is a list structure as
284 # [ ProtocolName, ... ]
285 # @var Ppis: To store value for Ppis, it is a list structure as
286 # [ PpiName, ... ]
287 # @var Guids: To store value for Guids, it is a list structure as
288 # [ GuidName, ... ]
289 # @var Includes: To store value for Includes, it is a list structure as
290 # [ IncludePath, ... ]
291 # @var Packages: To store value for Packages, it is a list structure as
292 # [ DecFileName, ... ]
293 # @var Pcds: To store value for Pcds, it is a set structure as
294 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
295 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
296 # { [BuildOptionKey] : BuildOptionValue}
297 # @var Depex: To store value for Depex
298 #
299 class ModuleBuildClassObject(object):
300 def __init__(self):
301 self.AutoGenVersion = 0
302 self.MetaFile = ''
303 self.BaseName = ''
304 self.ModuleType = ''
305 self.Guid = ''
306 self.Version = ''
307 self.PcdIsDriver = ''
308 self.BinaryModule = ''
309 self.Shadow = ''
310 self.SourceOverridePath = ''
311 self.CustomMakefile = {}
312 self.Specification = {}
313 self.LibraryClass = []
314 self.ModuleEntryPointList = []
315 self.ModuleUnloadImageList = []
316 self.ConstructorList = []
317 self.DestructorList = []
318
319 self.Binaries = []
320 self.Sources = []
321 self.LibraryClasses = OrderedDict()
322 self.Libraries = []
323 self.Protocols = []
324 self.Ppis = []
325 self.Guids = []
326 self.Includes = []
327 self.Packages = []
328 self.Pcds = {}
329 self.BuildOptions = {}
330 self.Depex = {}
331
332 ## Convert the class to a string
333 #
334 # Convert member MetaFile of the class to a string
335 #
336 # @retval string Formatted String
337 #
338 def __str__(self):
339 return str(self.MetaFile)
340
341 ## Override __eq__ function
342 #
343 # Check whether ModuleBuildClassObjects are the same
344 #
345 # @retval False The two ModuleBuildClassObjects are different
346 # @retval True The two ModuleBuildClassObjects are the same
347 #
348 def __eq__(self, Other):
349 return self.MetaFile == Other
350
351 ## Override __hash__ function
352 #
353 # Use MetaFile as key in hash table
354 #
355 # @retval string Key for hash table
356 #
357 def __hash__(self):
358 return hash(self.MetaFile)
359
360 ## PackageBuildClassObject
361 #
362 # This Class defines PackageBuildClass
363 #
364 # @param object: Inherited from object class
365 #
366 # @var MetaFile: To store value for package meta file path
367 # @var PackageName: To store value for PackageName
368 # @var Guid: To store value for Guid
369 # @var Version: To store value for Version
370 # @var Protocols: To store value for Protocols, it is a set structure as
371 # { [ProtocolName] : Protocol Guid, ... }
372 # @var Ppis: To store value for Ppis, it is a set structure as
373 # { [PpiName] : Ppi Guid, ... }
374 # @var Guids: To store value for Guids, it is a set structure as
375 # { [GuidName] : Guid, ... }
376 # @var Includes: To store value for Includes, it is a list structure as
377 # [ IncludePath, ... ]
378 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
379 # { [LibraryClassName] : LibraryClassInfFile }
380 # @var Pcds: To store value for Pcds, it is a set structure as
381 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
382 #
383 class PackageBuildClassObject(object):
384 def __init__(self):
385 self.MetaFile = ''
386 self.PackageName = ''
387 self.Guid = ''
388 self.Version = ''
389
390 self.Protocols = {}
391 self.Ppis = {}
392 self.Guids = {}
393 self.Includes = []
394 self.LibraryClasses = {}
395 self.Pcds = {}
396
397 ## Convert the class to a string
398 #
399 # Convert member MetaFile of the class to a string
400 #
401 # @retval string Formatted String
402 #
403 def __str__(self):
404 return str(self.MetaFile)
405
406 ## Override __eq__ function
407 #
408 # Check whether PackageBuildClassObjects are the same
409 #
410 # @retval False The two PackageBuildClassObjects are different
411 # @retval True The two PackageBuildClassObjects are the same
412 #
413 def __eq__(self, Other):
414 return self.MetaFile == Other
415
416 ## Override __hash__ function
417 #
418 # Use MetaFile as key in hash table
419 #
420 # @retval string Key for hash table
421 #
422 def __hash__(self):
423 return hash(self.MetaFile)
424
425 ## PlatformBuildClassObject
426 #
427 # This Class defines PlatformBuildClass
428 #
429 # @param object: Inherited from object class
430 #
431 # @var MetaFile: To store value for platform meta-file path
432 # @var PlatformName: To store value for PlatformName
433 # @var Guid: To store value for Guid
434 # @var Version: To store value for Version
435 # @var DscSpecification: To store value for DscSpecification
436 # @var OutputDirectory: To store value for OutputDirectory
437 # @var FlashDefinition: To store value for FlashDefinition
438 # @var BuildNumber: To store value for BuildNumber
439 # @var MakefileName: To store value for MakefileName
440 # @var SkuIds: To store value for SkuIds, it is a set structure as
441 # { 'SkuName' : SkuId, '!include' : includefilename, ...}
442 # @var Modules: To store value for Modules, it is a list structure as
443 # [ InfFileName, ... ]
444 # @var Libraries: To store value for Libraries, it is a list structure as
445 # [ InfFileName, ... ]
446 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
447 # { (LibraryClassName, ModuleType) : LibraryClassInfFile }
448 # @var Pcds: To store value for Pcds, it is a set structure as
449 # { [(PcdCName, PcdGuidCName)] : PcdClassObject }
450 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
451 # { [BuildOptionKey] : BuildOptionValue }
452 #
453 class PlatformBuildClassObject(object):
454 def __init__(self):
455 self.MetaFile = ''
456 self.PlatformName = ''
457 self.Guid = ''
458 self.Version = ''
459 self.DscSpecification = ''
460 self.OutputDirectory = ''
461 self.FlashDefinition = ''
462 self.BuildNumber = ''
463 self.MakefileName = ''
464
465 self.SkuIds = {}
466 self.Modules = []
467 self.LibraryInstances = []
468 self.LibraryClasses = {}
469 self.Libraries = {}
470 self.Pcds = {}
471 self.BuildOptions = {}
472
473 ## Convert the class to a string
474 #
475 # Convert member MetaFile of the class to a string
476 #
477 # @retval string Formatted String
478 #
479 def __str__(self):
480 return str(self.MetaFile)
481
482 ## Override __eq__ function
483 #
484 # Check whether PlatformBuildClassObjects are the same
485 #
486 # @retval False The two PlatformBuildClassObjects are different
487 # @retval True The two PlatformBuildClassObjects are the same
488 #
489 def __eq__(self, Other):
490 return self.MetaFile == Other
491
492 ## Override __hash__ function
493 #
494 # Use MetaFile as key in hash table
495 #
496 # @retval string Key for hash table
497 #
498 def __hash__(self):
499 return hash(self.MetaFile)