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