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