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