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