BaseTools: Fixed the issue of Multiple Skus are always disables
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / BuildClassObject.py
1 ## @file
2 # This file is used to define each component of the build database
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 import Common.LongFilePathOs as os
15
16 from Common.Misc import sdict
17 from Common.Misc import RealPath2
18 from Common.BuildToolError import *
19 from Common.DataType import *
20 import collections
21
22 ## PcdClassObject
23 #
24 # This Class is used for PcdObject
25 #
26 # @param object: Inherited from object class
27 # @param Name: Input value for Name of Pcd, default is None
28 # @param Guid: Input value for Guid of Pcd, default is None
29 # @param Type: Input value for Type of Pcd, default is None
30 # @param DatumType: Input value for DatumType of Pcd, default is None
31 # @param Value: Input value for Value of Pcd, default is None
32 # @param Token: Input value for Token of Pcd, default is None
33 # @param MaxDatumSize: Input value for MaxDatumSize of Pcd, default is None
34 # @param SkuInfoList: Input value for SkuInfoList of Pcd, default is {}
35 # @param IsOverrided: Input value for IsOverrided of Pcd, default is False
36 # @param GuidValue: Input value for TokenSpaceGuidValue of Pcd, default is None
37 #
38 # @var TokenCName: To store value for TokenCName
39 # @var TokenSpaceGuidCName: To store value for TokenSpaceGuidCName
40 # @var Type: To store value for Type
41 # @var DatumType: To store value for DatumType
42 # @var TokenValue: To store value for TokenValue
43 # @var MaxDatumSize: To store value for MaxDatumSize
44 # @var SkuInfoList: To store value for SkuInfoList
45 # @var IsOverrided: To store value for IsOverrided
46 # @var Phase: To store value for Phase, default is "DXE"
47 #
48 class PcdClassObject(object):
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):
50 self.TokenCName = Name
51 self.TokenSpaceGuidCName = Guid
52 self.TokenSpaceGuidValue = GuidValue
53 self.Type = Type
54 self.DatumType = DatumType
55 self.DefaultValue = Value
56 self.TokenValue = Token
57 self.MaxDatumSize = MaxDatumSize
58 self.SkuInfoList = SkuInfoList
59 self.Phase = "DXE"
60 self.Pending = False
61 self.IsOverrided = IsOverrided
62 self.IsFromBinaryInf = False
63 self.IsFromDsc = False
64 self.validateranges = validateranges
65 self.validlists = validlists
66 self.expressions = expressions
67 self.DscDefaultValue = None
68 if IsDsc:
69 self.DscDefaultValue = Value
70
71 ## Convert the class to a string
72 #
73 # Convert each member of the class to string
74 # Organize to a signle line format string
75 #
76 # @retval Rtn Formatted String
77 #
78 def __str__(self):
79 Rtn = '\tTokenCName=' + str(self.TokenCName) + ', ' + \
80 'TokenSpaceGuidCName=' + str(self.TokenSpaceGuidCName) + ', ' + \
81 'Type=' + str(self.Type) + ', ' + \
82 'DatumType=' + str(self.DatumType) + ', ' + \
83 'DefaultValue=' + str(self.DefaultValue) + ', ' + \
84 'TokenValue=' + str(self.TokenValue) + ', ' + \
85 'MaxDatumSize=' + str(self.MaxDatumSize) + ', '
86 for Item in self.SkuInfoList.values():
87 Rtn = Rtn + 'SkuId=' + Item.SkuId + ', ' + 'SkuIdName=' + Item.SkuIdName
88 Rtn = Rtn + ', IsOverrided=' + str(self.IsOverrided)
89
90 return Rtn
91
92 ## Override __eq__ function
93 #
94 # Check whether pcds are the same
95 #
96 # @retval False The two pcds are different
97 # @retval True The two pcds are the same
98 #
99 def __eq__(self, Other):
100 return Other and self.TokenCName == Other.TokenCName and self.TokenSpaceGuidCName == Other.TokenSpaceGuidCName
101
102 ## Override __hash__ function
103 #
104 # Use (TokenCName, TokenSpaceGuidCName) as key in hash table
105 #
106 # @retval truple() Key for hash table
107 #
108 def __hash__(self):
109 return hash((self.TokenCName, self.TokenSpaceGuidCName))
110
111 class StructurePcd(PcdClassObject):
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):
113 super(StructurePcd, self).__init__(Name, Guid, Type, DatumType, Value, Token, MaxDatumSize, SkuInfoList, IsOverrided, GuidValue, validateranges, validlists, expressions)
114 self.StructuredPcdIncludeFile = StructuredPcdIncludeFile
115 self.PackageDecs = Packages
116 self.DefaultStoreName = [default_store]
117 self.DefaultValues = collections.OrderedDict({})
118 self.PcdMode = None
119 self.SkuOverrideValues = collections.OrderedDict({})
120 self.FlexibleFieldName = None
121 self.StructName = None
122 def __repr__(self):
123 return self.TypeName
124
125 def AddDefaultValue (self, FieldName, Value, FileName="", LineNo=0):
126 if FieldName in self.DefaultValues:
127 del self.DefaultValues[FieldName]
128 self.DefaultValues[FieldName] = [Value.strip(), FileName, LineNo]
129 return self.DefaultValues[FieldName]
130
131 def AddOverrideValue (self, FieldName, Value, SkuName, DefaultStoreName, FileName="", LineNo=0):
132 if SkuName not in self.SkuOverrideValues:
133 self.SkuOverrideValues[SkuName] = collections.OrderedDict({})
134 if DefaultStoreName not in self.SkuOverrideValues[SkuName]:
135 self.SkuOverrideValues[SkuName][DefaultStoreName] = collections.OrderedDict({})
136 if FieldName in self.SkuOverrideValues[SkuName][DefaultStoreName]:
137 del self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName]
138 self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName] = [Value.strip(), FileName, LineNo]
139 return self.SkuOverrideValues[SkuName][DefaultStoreName][FieldName]
140
141 def SetPcdMode (self, PcdMode):
142 self.PcdMode = PcdMode
143
144 def SetFlexibleFieldName (self, FlexibleFieldName):
145 self.FlexibleFieldName = FlexibleFieldName
146
147 def copy(self, PcdObject):
148 self.TokenCName = PcdObject.TokenCName if PcdObject.TokenCName else self.TokenCName
149 self.TokenSpaceGuidCName = PcdObject.TokenSpaceGuidCName if PcdObject.TokenSpaceGuidCName else PcdObject.TokenSpaceGuidCName
150 self.TokenSpaceGuidValue = PcdObject.TokenSpaceGuidValue if PcdObject.TokenSpaceGuidValue else self.TokenSpaceGuidValue
151 self.Type = PcdObject.Type if PcdObject.Type else self.Type
152 self.DatumType = PcdObject.DatumType if PcdObject.DatumType else self.DatumType
153 self.DefaultValue = PcdObject.DefaultValue if PcdObject.DefaultValue else self.DefaultValue
154 self.TokenValue = PcdObject.TokenValue if PcdObject.TokenValue else self.TokenValue
155 self.MaxDatumSize = PcdObject.MaxDatumSize if PcdObject.MaxDatumSize else self.MaxDatumSize
156 self.SkuInfoList = PcdObject.SkuInfoList if PcdObject.SkuInfoList else self.SkuInfoList
157 self.Phase = PcdObject.Phase if PcdObject.Phase else self.Phase
158 self.Pending = PcdObject.Pending if PcdObject.Pending else self.Pending
159 self.IsOverrided = PcdObject.IsOverrided if PcdObject.IsOverrided else self.IsOverrided
160 self.IsFromBinaryInf = PcdObject.IsFromBinaryInf if PcdObject.IsFromBinaryInf else self.IsFromBinaryInf
161 self.IsFromDsc = PcdObject.IsFromDsc if PcdObject.IsFromDsc else self.IsFromDsc
162 self.validateranges = PcdObject.validateranges if PcdObject.validateranges else self.validateranges
163 self.validlists = PcdObject.validlists if PcdObject.validlists else self.validlists
164 self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions
165 if type(PcdObject) is StructurePcd:
166 self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile
167 self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs
168 self.DefaultValues = PcdObject.DefaultValues if PcdObject.DefaultValues else self.DefaultValues
169 self.PcdMode = PcdObject.PcdMode if PcdObject.PcdMode else self.PcdMode
170 self.DefaultFromDSC=None
171 self.SkuOverrideValues = PcdObject.SkuOverrideValues if PcdObject.SkuOverrideValues else self.SkuOverrideValues
172 self.FlexibleFieldName = PcdObject.FlexibleFieldName if PcdObject.FlexibleFieldName else self.FlexibleFieldName
173 self.StructName = PcdObject.DatumType if PcdObject.DatumType else self.StructName
174
175 ## LibraryClassObject
176 #
177 # This Class defines LibraryClassObject used in BuildDatabase
178 #
179 # @param object: Inherited from object class
180 # @param Name: Input value for LibraryClassName, default is None
181 # @param SupModList: Input value for SupModList, default is []
182 # @param Type: Input value for Type, default is None
183 #
184 # @var LibraryClass: To store value for LibraryClass
185 # @var SupModList: To store value for SupModList
186 # @var Type: To store value for Type
187 #
188 class LibraryClassObject(object):
189 def __init__(self, Name = None, SupModList = [], Type = None):
190 self.LibraryClass = Name
191 self.SupModList = SupModList
192 if Type != None:
193 self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)
194
195 ## ModuleBuildClassObject
196 #
197 # This Class defines ModuleBuildClass
198 #
199 # @param object: Inherited from object class
200 #
201 # @var MetaFile: To store value for module meta file path
202 # @var BaseName: To store value for BaseName
203 # @var ModuleType: To store value for ModuleType
204 # @var Guid: To store value for Guid
205 # @var Version: To store value for Version
206 # @var PcdIsDriver: To store value for PcdIsDriver
207 # @var BinaryModule: To store value for BinaryModule
208 # @var CustomMakefile: To store value for CustomMakefile
209 # @var Specification: To store value for Specification
210 # @var Shadow To store value for Shadow
211 # @var LibraryClass: To store value for LibraryClass, it is a list structure as
212 # [ LibraryClassObject, ...]
213 # @var ModuleEntryPointList: To store value for ModuleEntryPointList
214 # @var ModuleUnloadImageList: To store value for ModuleUnloadImageList
215 # @var ConstructorList: To store value for ConstructorList
216 # @var DestructorList: To store value for DestructorList
217 # @var Binaries: To store value for Binaries, it is a list structure as
218 # [ ModuleBinaryClassObject, ...]
219 # @var Sources: To store value for Sources, it is a list structure as
220 # [ ModuleSourceFilesClassObject, ... ]
221 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
222 # { [LibraryClassName, ModuleType] : LibraryClassInfFile }
223 # @var Protocols: To store value for Protocols, it is a list structure as
224 # [ ProtocolName, ... ]
225 # @var Ppis: To store value for Ppis, it is a list structure as
226 # [ PpiName, ... ]
227 # @var Guids: To store value for Guids, it is a list structure as
228 # [ GuidName, ... ]
229 # @var Includes: To store value for Includes, it is a list structure as
230 # [ IncludePath, ... ]
231 # @var Packages: To store value for Packages, it is a list structure as
232 # [ DecFileName, ... ]
233 # @var Pcds: To store value for Pcds, it is a set structure as
234 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
235 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
236 # { [BuildOptionKey] : BuildOptionValue}
237 # @var Depex: To store value for Depex
238 #
239 class ModuleBuildClassObject(object):
240 def __init__(self):
241 self.AutoGenVersion = 0
242 self.MetaFile = ''
243 self.BaseName = ''
244 self.ModuleType = ''
245 self.Guid = ''
246 self.Version = ''
247 self.PcdIsDriver = ''
248 self.BinaryModule = ''
249 self.Shadow = ''
250 self.SourceOverridePath = ''
251 self.CustomMakefile = {}
252 self.Specification = {}
253 self.LibraryClass = []
254 self.ModuleEntryPointList = []
255 self.ModuleUnloadImageList = []
256 self.ConstructorList = []
257 self.DestructorList = []
258
259 self.Binaries = []
260 self.Sources = []
261 self.LibraryClasses = sdict()
262 self.Libraries = []
263 self.Protocols = []
264 self.Ppis = []
265 self.Guids = []
266 self.Includes = []
267 self.Packages = []
268 self.Pcds = {}
269 self.BuildOptions = {}
270 self.Depex = {}
271
272 ## Convert the class to a string
273 #
274 # Convert member MetaFile of the class to a string
275 #
276 # @retval string Formatted String
277 #
278 def __str__(self):
279 return str(self.MetaFile)
280
281 ## Override __eq__ function
282 #
283 # Check whether ModuleBuildClassObjects are the same
284 #
285 # @retval False The two ModuleBuildClassObjects are different
286 # @retval True The two ModuleBuildClassObjects are the same
287 #
288 def __eq__(self, Other):
289 return self.MetaFile == Other
290
291 ## Override __hash__ function
292 #
293 # Use MetaFile as key in hash table
294 #
295 # @retval string Key for hash table
296 #
297 def __hash__(self):
298 return hash(self.MetaFile)
299
300 ## PackageBuildClassObject
301 #
302 # This Class defines PackageBuildClass
303 #
304 # @param object: Inherited from object class
305 #
306 # @var MetaFile: To store value for package meta file path
307 # @var PackageName: To store value for PackageName
308 # @var Guid: To store value for Guid
309 # @var Version: To store value for Version
310 # @var Protocols: To store value for Protocols, it is a set structure as
311 # { [ProtocolName] : Protocol Guid, ... }
312 # @var Ppis: To store value for Ppis, it is a set structure as
313 # { [PpiName] : Ppi Guid, ... }
314 # @var Guids: To store value for Guids, it is a set structure as
315 # { [GuidName] : Guid, ... }
316 # @var Includes: To store value for Includes, it is a list structure as
317 # [ IncludePath, ... ]
318 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
319 # { [LibraryClassName] : LibraryClassInfFile }
320 # @var Pcds: To store value for Pcds, it is a set structure as
321 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
322 #
323 class PackageBuildClassObject(object):
324 def __init__(self):
325 self.MetaFile = ''
326 self.PackageName = ''
327 self.Guid = ''
328 self.Version = ''
329
330 self.Protocols = {}
331 self.Ppis = {}
332 self.Guids = {}
333 self.Includes = []
334 self.LibraryClasses = {}
335 self.Pcds = {}
336
337 ## Convert the class to a string
338 #
339 # Convert member MetaFile of the class to a string
340 #
341 # @retval string Formatted String
342 #
343 def __str__(self):
344 return str(self.MetaFile)
345
346 ## Override __eq__ function
347 #
348 # Check whether PackageBuildClassObjects are the same
349 #
350 # @retval False The two PackageBuildClassObjects are different
351 # @retval True The two PackageBuildClassObjects are the same
352 #
353 def __eq__(self, Other):
354 return self.MetaFile == Other
355
356 ## Override __hash__ function
357 #
358 # Use MetaFile as key in hash table
359 #
360 # @retval string Key for hash table
361 #
362 def __hash__(self):
363 return hash(self.MetaFile)
364
365 ## PlatformBuildClassObject
366 #
367 # This Class defines PlatformBuildClass
368 #
369 # @param object: Inherited from object class
370 #
371 # @var MetaFile: To store value for platform meta-file path
372 # @var PlatformName: To store value for PlatformName
373 # @var Guid: To store value for Guid
374 # @var Version: To store value for Version
375 # @var DscSpecification: To store value for DscSpecification
376 # @var OutputDirectory: To store value for OutputDirectory
377 # @var FlashDefinition: To store value for FlashDefinition
378 # @var BuildNumber: To store value for BuildNumber
379 # @var MakefileName: To store value for MakefileName
380 # @var SkuIds: To store value for SkuIds, it is a set structure as
381 # { 'SkuName' : SkuId, '!include' : includefilename, ...}
382 # @var Modules: To store value for Modules, it is a list structure as
383 # [ InfFileName, ... ]
384 # @var Libraries: To store value for Libraries, it is a list structure as
385 # [ InfFileName, ... ]
386 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
387 # { (LibraryClassName, ModuleType) : LibraryClassInfFile }
388 # @var Pcds: To store value for Pcds, it is a set structure as
389 # { [(PcdCName, PcdGuidCName)] : PcdClassObject }
390 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
391 # { [BuildOptionKey] : BuildOptionValue }
392 #
393 class PlatformBuildClassObject(object):
394 def __init__(self):
395 self.MetaFile = ''
396 self.PlatformName = ''
397 self.Guid = ''
398 self.Version = ''
399 self.DscSpecification = ''
400 self.OutputDirectory = ''
401 self.FlashDefinition = ''
402 self.BuildNumber = ''
403 self.MakefileName = ''
404
405 self.SkuIds = {}
406 self.Modules = []
407 self.LibraryInstances = []
408 self.LibraryClasses = {}
409 self.Libraries = {}
410 self.Pcds = {}
411 self.BuildOptions = {}
412
413 ## Convert the class to a string
414 #
415 # Convert member MetaFile of the class to a string
416 #
417 # @retval string Formatted String
418 #
419 def __str__(self):
420 return str(self.MetaFile)
421
422 ## Override __eq__ function
423 #
424 # Check whether PlatformBuildClassObjects are the same
425 #
426 # @retval False The two PlatformBuildClassObjects are different
427 # @retval True The two PlatformBuildClassObjects are the same
428 #
429 def __eq__(self, Other):
430 return self.MetaFile == Other
431
432 ## Override __hash__ function
433 #
434 # Use MetaFile as key in hash table
435 #
436 # @retval string Key for hash table
437 #
438 def __hash__(self):
439 return hash(self.MetaFile)
440