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