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