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