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