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