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