2 # This file is used to define each component of the build database
4 # Copyright (c) 2007 - 2014, 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
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.
17 import Common
.LongFilePathOs
as os
, string
, copy
, pdb
, copy
20 from InfClassObject
import *
21 from DecClassObject
import *
22 from DscClassObject
import *
24 from BuildToolError
import *
25 from Misc
import sdict
26 import Database
as Database
31 # This Class is used for PcdObject
33 # @param object: Inherited from object class
34 # @param Name: Input value for Name of Pcd, default is None
35 # @param Guid: Input value for Guid of Pcd, default is None
36 # @param Type: Input value for Type of Pcd, default is None
37 # @param DatumType: Input value for DatumType of Pcd, default is None
38 # @param Value: Input value for Value of Pcd, default is None
39 # @param Token: Input value for Token of Pcd, default is None
40 # @param MaxDatumSize: Input value for MaxDatumSize of Pcd, default is None
41 # @param SkuInfoList: Input value for SkuInfoList of Pcd, default is {}
42 # @param IsOverrided: Input value for IsOverrided of Pcd, default is False
44 # @var TokenCName: To store value for TokenCName
45 # @var TokenSpaceGuidCName: To store value for TokenSpaceGuidCName
46 # @var Type: To store value for Type
47 # @var DatumType: To store value for DatumType
48 # @var TokenValue: To store value for TokenValue
49 # @var MaxDatumSize: To store value for MaxDatumSize
50 # @var SkuInfoList: To store value for SkuInfoList
51 # @var IsOverrided: To store value for IsOverrided
52 # @var Phase: To store value for Phase, default is "DXE"
54 class PcdClassObject(object):
55 def __init__(self
, Name
= None, Guid
= None, Type
= None, DatumType
= None, Value
= None, Token
= None, MaxDatumSize
= None, SkuInfoList
= {}, IsOverrided
= False):
56 self
.TokenCName
= Name
57 self
.TokenSpaceGuidCName
= Guid
59 self
.DatumType
= DatumType
60 self
.DefaultValue
= Value
61 self
.TokenValue
= Token
62 self
.MaxDatumSize
= MaxDatumSize
63 self
.SkuInfoList
= SkuInfoList
64 self
.IsOverrided
= IsOverrided
67 ## Convert the class to a string
69 # Convert each member of the class to string
70 # Organize to a signle line format string
72 # @retval Rtn Formatted String
75 Rtn
= '\tTokenCName=' + str(self
.TokenCName
) + ', ' + \
76 'TokenSpaceGuidCName=' + str(self
.TokenSpaceGuidCName
) + ', ' + \
77 'Type=' + str(self
.Type
) + ', ' + \
78 'DatumType=' + str(self
.DatumType
) + ', ' + \
79 'DefaultValue=' + str(self
.DefaultValue
) + ', ' + \
80 'TokenValue=' + str(self
.TokenValue
) + ', ' + \
81 'MaxDatumSize=' + str(self
.MaxDatumSize
) + ', '
82 for Item
in self
.SkuInfoList
.values():
83 Rtn
= Rtn
+ 'SkuId=' + Item
.SkuId
+ ', ' + 'SkuIdName=' + Item
.SkuIdName
84 Rtn
= Rtn
+ str(self
.IsOverrided
)
88 ## Override __eq__ function
90 # Check whether pcds are the same
92 # @retval False The two pcds are different
93 # @retval True The two pcds are the same
95 def __eq__(self
, Other
):
96 return Other
is not None and self
.TokenCName
== Other
.TokenCName
and self
.TokenSpaceGuidCName
== Other
.TokenSpaceGuidCName
98 ## Override __hash__ function
100 # Use (TokenCName, TokenSpaceGuidCName) as key in hash table
102 # @retval truple() Key for hash table
105 return hash((self
.TokenCName
, self
.TokenSpaceGuidCName
))
107 ## LibraryClassObject
109 # This Class defines LibraryClassObject used in BuildDatabase
111 # @param object: Inherited from object class
112 # @param Name: Input value for LibraryClassName, default is None
113 # @param SupModList: Input value for SupModList, default is []
114 # @param Type: Input value for Type, default is None
116 # @var LibraryClass: To store value for LibraryClass
117 # @var SupModList: To store value for SupModList
118 # @var Type: To store value for Type
120 class LibraryClassObject(object):
121 def __init__(self
, Name
= None, SupModList
= [], Type
= None):
122 self
.LibraryClass
= Name
123 self
.SupModList
= SupModList
125 self
.SupModList
= CleanString(Type
).split(DataType
.TAB_SPACE_SPLIT
)
127 ## ModuleBuildClassObject
129 # This Class defines ModuleBuildClass
131 # @param object: Inherited from object class
133 # @var DescFilePath: To store value for DescFilePath
134 # @var BaseName: To store value for BaseName
135 # @var ModuleType: To store value for ModuleType
136 # @var Guid: To store value for Guid
137 # @var Version: To store value for Version
138 # @var PcdIsDriver: To store value for PcdIsDriver
139 # @var BinaryModule: To store value for BinaryModule
140 # @var CustomMakefile: To store value for CustomMakefile
141 # @var Specification: To store value for Specification
142 # @var Shadow To store value for Shadow
143 # @var LibraryClass: To store value for LibraryClass, it is a list structure as
144 # [ LibraryClassObject, ...]
145 # @var ModuleEntryPointList: To store value for ModuleEntryPointList
146 # @var ModuleUnloadImageList: To store value for ModuleUnloadImageList
147 # @var ConstructorList: To store value for ConstructorList
148 # @var DestructorList: To store value for DestructorList
149 # @var Binaries: To store value for Binaries, it is a list structure as
150 # [ ModuleBinaryClassObject, ...]
151 # @var Sources: To store value for Sources, it is a list structure as
152 # [ ModuleSourceFilesClassObject, ... ]
153 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
154 # { [LibraryClassName, ModuleType] : LibraryClassInfFile }
155 # @var Protocols: To store value for Protocols, it is a list structure as
156 # [ ProtocolName, ... ]
157 # @var Ppis: To store value for Ppis, it is a list structure as
159 # @var Guids: To store value for Guids, it is a list structure as
161 # @var Includes: To store value for Includes, it is a list structure as
162 # [ IncludePath, ... ]
163 # @var Packages: To store value for Packages, it is a list structure as
164 # [ DecFileName, ... ]
165 # @var Pcds: To store value for Pcds, it is a set structure as
166 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
167 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
168 # { [BuildOptionKey] : BuildOptionValue}
169 # @var Depex: To store value for Depex
171 class ModuleBuildClassObject(object):
173 self
.AutoGenVersion
= 0
174 self
.DescFilePath
= ''
179 self
.PcdIsDriver
= ''
180 self
.BinaryModule
= ''
182 self
.CustomMakefile
= {}
183 self
.Specification
= {}
184 self
.LibraryClass
= []
185 self
.ModuleEntryPointList
= []
186 self
.ModuleUnloadImageList
= []
187 self
.ConstructorList
= []
188 self
.DestructorList
= []
192 self
.LibraryClasses
= sdict()
200 self
.BuildOptions
= {}
203 ## Convert the class to a string
205 # Convert member DescFilePath of the class to a string
207 # @retval string Formatted String
210 return self
.DescFilePath
212 ## Override __eq__ function
214 # Check whether ModuleBuildClassObjects are the same
216 # @retval False The two ModuleBuildClassObjects are different
217 # @retval True The two ModuleBuildClassObjects are the same
219 def __eq__(self
, Other
):
220 return self
.DescFilePath
== str(Other
)
222 ## Override __hash__ function
224 # Use DescFilePath as key in hash table
226 # @retval string Key for hash table
229 return hash(self
.DescFilePath
)
231 ## PackageBuildClassObject
233 # This Class defines PackageBuildClass
235 # @param object: Inherited from object class
237 # @var DescFilePath: To store value for DescFilePath
238 # @var PackageName: To store value for PackageName
239 # @var Guid: To store value for Guid
240 # @var Version: To store value for Version
241 # @var Protocols: To store value for Protocols, it is a set structure as
242 # { [ProtocolName] : Protocol Guid, ... }
243 # @var Ppis: To store value for Ppis, it is a set structure as
244 # { [PpiName] : Ppi Guid, ... }
245 # @var Guids: To store value for Guids, it is a set structure as
246 # { [GuidName] : Guid, ... }
247 # @var Includes: To store value for Includes, it is a list structure as
248 # [ IncludePath, ... ]
249 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
250 # { [LibraryClassName] : LibraryClassInfFile }
251 # @var Pcds: To store value for Pcds, it is a set structure as
252 # { [(PcdCName, PcdGuidCName)] : PcdClassObject}
254 class PackageBuildClassObject(object):
256 self
.DescFilePath
= ''
257 self
.PackageName
= ''
265 self
.LibraryClasses
= {}
268 ## Convert the class to a string
270 # Convert member DescFilePath of the class to a string
272 # @retval string Formatted String
275 return self
.DescFilePath
277 ## Override __eq__ function
279 # Check whether PackageBuildClassObjects are the same
281 # @retval False The two PackageBuildClassObjects are different
282 # @retval True The two PackageBuildClassObjects are the same
284 def __eq__(self
, Other
):
285 return self
.DescFilePath
== str(Other
)
287 ## Override __hash__ function
289 # Use DescFilePath as key in hash table
291 # @retval string Key for hash table
294 return hash(self
.DescFilePath
)
296 ## PlatformBuildClassObject
298 # This Class defines PlatformBuildClass
300 # @param object: Inherited from object class
302 # @var DescFilePath: To store value for DescFilePath
303 # @var PlatformName: To store value for PlatformName
304 # @var Guid: To store value for Guid
305 # @var Version: To store value for Version
306 # @var DscSpecification: To store value for DscSpecification
307 # @var OutputDirectory: To store value for OutputDirectory
308 # @var FlashDefinition: To store value for FlashDefinition
309 # @var BuildNumber: To store value for BuildNumber
310 # @var MakefileName: To store value for MakefileName
311 # @var SkuIds: To store value for SkuIds, it is a set structure as
312 # { 'SkuName' : SkuId, '!include' : includefilename, ...}
313 # @var Modules: To store value for Modules, it is a list structure as
314 # [ InfFileName, ... ]
315 # @var Libraries: To store value for Libraries, it is a list structure as
316 # [ InfFileName, ... ]
317 # @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
318 # { (LibraryClassName, ModuleType) : LibraryClassInfFile }
319 # @var Pcds: To store value for Pcds, it is a set structure as
320 # { [(PcdCName, PcdGuidCName)] : PcdClassObject }
321 # @var BuildOptions: To store value for BuildOptions, it is a set structure as
322 # { [BuildOptionKey] : BuildOptionValue }
324 class PlatformBuildClassObject(object):
326 self
.DescFilePath
= ''
327 self
.PlatformName
= ''
330 self
.DscSpecification
= ''
331 self
.OutputDirectory
= ''
332 self
.FlashDefinition
= ''
333 self
.BuildNumber
= ''
334 self
.MakefileName
= ''
338 self
.LibraryInstances
= []
339 self
.LibraryClasses
= {}
342 self
.BuildOptions
= {}
344 ## Convert the class to a string
346 # Convert member DescFilePath of the class to a string
348 # @retval string Formatted String
351 return self
.DescFilePath
353 ## Override __eq__ function
355 # Check whether PlatformBuildClassObjects are the same
357 # @retval False The two PlatformBuildClassObjects are different
358 # @retval True The two PlatformBuildClassObjects are the same
360 def __eq__(self
, other
):
361 return self
.DescFilePath
== str(other
)
363 ## Override __hash__ function
365 # Use DescFilePath as key in hash table
367 # @retval string Key for hash table
370 return hash(self
.DescFilePath
)
374 # This Class defines Module/Platform/Package databases for build system
376 # @param object: Inherited from object class
377 # @param Arch: Build arch
378 # @param Platform: Build Platform
379 # @param Package: Build Package
380 # @param Module: Build Module
382 # @var Arch: To store value for Build Arch
383 # @var PlatformDatabase: To store value for PlatformDatabase, it is a set structure as
384 # { [DscFileName] : PlatformBuildClassObject, ...}
385 # @var PackageDatabase: To store value for PackageDatabase, it is a set structure as
386 # { [DecFileName] : PacakgeBuildClassObject, ...}
387 # @var ModuleDatabase: To store value for ModuleDatabase, it is a list structure as
388 # { [InfFileName] : ModuleBuildClassObject, ...}
390 class ItemBuild(object):
391 def __init__(self
, Arch
, Platform
= None, Package
= None, Module
= None):
393 self
.PlatformDatabase
= {}
394 self
.PackageDatabase
= {}
395 self
.ModuleDatabase
= {}
399 # This class is used to parse active platform to init all inf/dec/dsc files
400 # Generate module/package/platform databases for build
402 # @param object: Inherited from object class
403 # @param ActivePlatform: Input value for current active platform
404 # @param WorkspaceDir: Input value for current WorkspaceDir
406 # @var WorkspaceDir: To store value for WorkspaceDir
407 # @var SupArchList: To store value for SupArchList, selection scope is in below list
408 # EBC | IA32 | X64 | IPF | ARM | PPC | AARCH64
409 # @var BuildTarget: To store value for WorkspaceDir, selection scope is in below list
411 # @var SkuId: To store value for SkuId
412 # @var Fdf: To store value for Fdf
413 # @var FdTargetList: To store value for FdTargetList
414 # @var FvTargetList: To store value for FvTargetList
415 # @var TargetTxt: To store value for TargetTxt, it is a set structure as
416 # TargetTxtClassObject
417 # @var ToolDef: To store value for ToolDef, it is a set structure as
419 # @var InfDatabase: To store value for InfDatabase, it is a set structure as
420 # { [InfFileName] : InfClassObject}
421 # @var DecDatabase: To store value for DecDatabase, it is a set structure as
422 # { [DecFileName] : DecClassObject}
423 # @var DscDatabase: To store value for DscDatabase, it is a set structure as
424 # { [DscFileName] : DscClassObject}
425 # @var Build: To store value for DscDatabase, it is a set structure as
427 # @var DscFileName: To store value for Active Platform
428 # @var UnFoundPcdInDsc: To store values for the pcds defined in INF/DEC but not found in DSC, it is a set structure as
429 # { (PcdGuid, PcdCName, Arch) : DecFileName }
431 class WorkspaceBuild(object):
432 def __init__(self
, ActivePlatform
, WorkspaceDir
):
433 self
.WorkspaceDir
= NormPath(WorkspaceDir
)
434 self
.SupArchList
= []
435 self
.BuildTarget
= []
438 self
.FdTargetList
= []
439 self
.FvTargetList
= []
440 self
.TargetTxt
= None
443 self
.InfDatabase
= {}
444 self
.DecDatabase
= {}
445 self
.DscDatabase
= {}
447 self
.UnFoundPcdInDsc
= {}
450 # Init build for all arches
453 for Arch
in DataType
.ARCH_LIST
:
454 self
.Build
[Arch
] = ItemBuild(Arch
)
457 # Init build database
459 self
.Db
= Database
.Database(DATABASE_PATH
)
460 self
.Db
.InitDatabase()
463 # Get active platform
465 self
.DscFileName
= NormPath(ActivePlatform
)
466 File
= self
.WorkspaceFile(self
.DscFileName
)
467 if os
.path
.exists(File
) and os
.path
.isfile(File
):
468 self
.DscDatabase
[self
.DscFileName
] = Dsc(File
, False, True, self
.WorkspaceDir
, self
.Db
)
470 EdkLogger
.error("AutoGen", FILE_NOT_FOUND
, ExtraData
= File
)
473 # Parse platform to get module
475 for DscFile
in self
.DscDatabase
.keys():
476 Platform
= self
.DscDatabase
[DscFile
].Platform
479 # Get global information
482 for Arch
in DataType
.ARCH_LIST
:
483 for Item
in Platform
.Header
[Arch
].SupArchList
:
485 self
.SupArchList
= list(Tmp
)
487 for Arch
in DataType
.ARCH_LIST
:
488 for Item
in Platform
.Header
[Arch
].BuildTargets
:
490 self
.BuildTarget
= list(Tmp
)
491 for Arch
in self
.SupArchList
:
492 self
.SkuId
= Platform
.Header
[Arch
].SkuIdName
493 self
.Fdf
= Platform
.FlashDefinitionFile
.FilePath
498 for Item
in Platform
.LibraryClasses
.LibraryList
:
499 for Arch
in Item
.SupArchList
:
500 self
.AddToInfDatabase(Item
.FilePath
)
502 for Item
in Platform
.Libraries
.LibraryList
:
503 for Arch
in Item
.SupArchList
:
504 self
.AddToInfDatabase(Item
.FilePath
)
506 for Item
in Platform
.Modules
.ModuleList
:
507 for Arch
in Item
.SupArchList
:
511 Module
= Item
.FilePath
512 self
.AddToInfDatabase(Module
)
514 # Add library used in modules
516 for Lib
in Item
.LibraryClasses
.LibraryList
:
517 self
.AddToInfDatabase(Lib
.FilePath
)
518 self
.UpdateLibraryClassOfModule(Module
, Lib
.Name
, Arch
, Lib
.FilePath
)
521 # Parse module to get package
523 for InfFile
in self
.InfDatabase
.keys():
524 Module
= self
.InfDatabase
[InfFile
].Module
528 for Item
in Module
.PackageDependencies
:
529 for Arch
in Item
.SupArchList
:
530 self
.AddToDecDatabase(Item
.FilePath
)
533 ## Generate PlatformDatabase
535 # Go through each arch to get all items in DscDatabase to PlatformDatabase
537 def GenPlatformDatabase(self
, PcdsSet
={}):
538 for Dsc
in self
.DscDatabase
.keys():
539 Platform
= self
.DscDatabase
[Dsc
].Platform
540 for Arch
in self
.SupArchList
:
541 Pb
= PlatformBuildClassObject()
546 Pb
.DescFilePath
= Dsc
547 Pb
.PlatformName
= Platform
.Header
[Arch
].Name
548 if Pb
.PlatformName
== '':
549 EdkLogger
.error("AutoGen", PARSER_ERROR
, "The BaseName of platform %s is not defined for arch %s" % (Dsc
, Arch
))
550 Pb
.Guid
= Platform
.Header
[Arch
].Guid
551 Pb
.Version
= Platform
.Header
[Arch
].Version
552 Pb
.DscSpecification
= Platform
.Header
[Arch
].DscSpecification
553 Pb
.OutputDirectory
= Platform
.Header
[Arch
].OutputDirectory
554 Pb
.FlashDefinition
= Platform
.FlashDefinitionFile
.FilePath
555 Pb
.BuildNumber
= Platform
.Header
[Arch
].BuildNumber
560 for Key
in Platform
.SkuInfos
.SkuInfoList
.keys():
561 Pb
.SkuIds
[Key
] = Platform
.SkuInfos
.SkuInfoList
[Key
]
566 for Item
in Platform
.Modules
.ModuleList
:
567 if Arch
in Item
.SupArchList
:
568 Pb
.Modules
.append(Item
.FilePath
)
573 for Item
in Platform
.BuildOptions
.BuildOptionList
:
574 if Arch
in Item
.SupArchList
:
575 Pb
.BuildOptions
[(Item
.ToolChainFamily
, Item
.ToolChain
)] = Item
.Option
580 for Item
in Platform
.LibraryClasses
.LibraryList
:
581 SupModuleList
= self
.FindSupModuleListOfLibraryClass(Item
, Platform
.LibraryClasses
.LibraryList
, Arch
)
582 if Arch
in Item
.SupArchList
:
583 for ModuleType
in SupModuleList
:
584 Pb
.LibraryClasses
[(Item
.Name
, ModuleType
)] = Item
.FilePath
589 for Item
in Platform
.Libraries
.LibraryList
:
590 for ItemArch
in Item
.SupArchList
:
591 Library
= self
.InfDatabase
[Item
.FilePath
]
592 if ItemArch
not in Library
.Module
.Header
:
594 Pb
.Libraries
[Library
.Module
.Header
[ItemArch
].Name
] = Item
.FilePath
599 for Item
in Platform
.DynamicPcdBuildDefinitions
:
600 if Arch
in Item
.SupArchList
:
602 Guid
= Item
.TokenSpaceGuidCName
604 DatumType
= Item
.DatumType
605 Value
= Item
.DefaultValue
607 MaxDatumSize
= Item
.MaxDatumSize
608 SkuInfoList
= Item
.SkuInfoList
609 Pb
.Pcds
[(Name
, Guid
)] = PcdClassObject(Name
, Guid
, Type
, DatumType
, Value
, Token
, MaxDatumSize
, SkuInfoList
, False)
611 for (Name
, Guid
) in PcdsSet
:
612 Value
= PcdsSet
[Name
, Guid
]
613 for PcdType
in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
614 for Dec
in self
.Build
[Arch
].PackageDatabase
:
615 Pcds
= self
.Build
[Arch
].PackageDatabase
[Dec
].Pcds
616 if (Name
, Guid
, PcdType
) in Pcds
:
617 Pcd
= Pcds
[(Name
, Guid
, PcdType
)]
619 DatumType
= Pcd
.DatumType
620 Token
= Pcd
.TokenValue
621 MaxDatumSize
= Pcd
.MaxDatumSize
622 SkuInfoList
= Pcd
.SkuInfoList
623 Pb
.Pcds
[(Name
, Guid
)] = PcdClassObject(Name
, Guid
, Type
, DatumType
, Value
, Token
, MaxDatumSize
, SkuInfoList
, False)
628 # found in one package, find next PCD
631 EdkLogger
.error("AutoGen", PARSER_ERROR
, "PCD is not found in any package", ExtraData
="%s.%s" % (Guid
, Name
))
635 self
.Build
[Arch
].PlatformDatabase
[Dsc
] = Pb
638 ## Generate PackageDatabase
640 # Go through each arch to get all items in DecDatabase to PackageDatabase
642 def GenPackageDatabase(self
):
643 for Dec
in self
.DecDatabase
.keys():
644 Package
= self
.DecDatabase
[Dec
].Package
646 for Arch
in self
.SupArchList
:
647 Pb
= PackageBuildClassObject()
652 Pb
.DescFilePath
= Dec
653 Pb
.PackageName
= Package
.Header
[Arch
].Name
654 if Pb
.PackageName
== '':
655 EdkLogger
.error("AutoGen", PARSER_ERROR
, "The BaseName of package %s is not defined for arch %s" % (Dec
, Arch
))
657 Pb
.Guid
= Package
.Header
[Arch
].Guid
658 Pb
.Version
= Package
.Header
[Arch
].Version
663 for Item
in Package
.ProtocolDeclarations
:
664 if Arch
in Item
.SupArchList
:
665 Pb
.Protocols
[Item
.CName
] = Item
.Guid
670 for Item
in Package
.PpiDeclarations
:
671 if Arch
in Item
.SupArchList
:
672 Pb
.Ppis
[Item
.CName
] = Item
.Guid
677 for Item
in Package
.GuidDeclarations
:
678 if Arch
in Item
.SupArchList
:
679 Pb
.Guids
[Item
.CName
] = Item
.Guid
684 for Item
in Package
.Includes
:
685 if Arch
in Item
.SupArchList
:
686 Pb
.Includes
.append(Item
.FilePath
)
691 for Item
in Package
.LibraryClassDeclarations
:
692 if Arch
in Item
.SupArchList
:
693 Pb
.LibraryClasses
[Item
.LibraryClass
] = Item
.RecommendedInstance
698 for Item
in Package
.PcdDeclarations
:
699 if Arch
in Item
.SupArchList
:
701 Guid
= Item
.TokenSpaceGuidCName
703 DatumType
= Item
.DatumType
704 Value
= Item
.DefaultValue
706 MaxDatumSize
= Item
.MaxDatumSize
707 SkuInfoList
= Item
.SkuInfoList
708 Pb
.Pcds
[(Name
, Guid
, Type
)] = PcdClassObject(Name
, Guid
, Type
, DatumType
, Value
, Token
, MaxDatumSize
, SkuInfoList
, False)
713 self
.Build
[Arch
].PackageDatabase
[Dec
] = Pb
716 ## Generate ModuleDatabase
718 # Go through each arch to get all items in InfDatabase to ModuleDatabase
720 def GenModuleDatabase(self
, InfList
= []):
721 for Inf
in self
.InfDatabase
.keys():
722 Module
= self
.InfDatabase
[Inf
].Module
724 for Arch
in self
.SupArchList
:
725 if not self
.IsModuleDefinedInPlatform(Inf
, Arch
, InfList
) or Arch
not in Module
.Header
:
728 ModuleHeader
= Module
.Header
[Arch
]
729 Pb
= ModuleBuildClassObject()
734 Pb
.DescFilePath
= Inf
735 Pb
.BaseName
= ModuleHeader
.Name
736 if Pb
.BaseName
== '':
737 EdkLogger
.error("AutoGen", PARSER_ERROR
, "The BaseName of module %s is not defined for arch %s" % (Inf
, Arch
))
738 Pb
.Guid
= ModuleHeader
.Guid
739 Pb
.Version
= ModuleHeader
.Version
740 Pb
.ModuleType
= ModuleHeader
.ModuleType
741 Pb
.PcdIsDriver
= ModuleHeader
.PcdIsDriver
742 Pb
.BinaryModule
= ModuleHeader
.BinaryModule
743 Pb
.CustomMakefile
= ModuleHeader
.CustomMakefile
744 Pb
.Shadow
= ModuleHeader
.Shadow
749 Pb
.Specification
= ModuleHeader
.Specification
750 Pb
.Specification
[TAB_INF_DEFINES_EDK_RELEASE_VERSION
] = ModuleHeader
.EdkReleaseVersion
751 Pb
.Specification
[TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION
] = ModuleHeader
.UefiSpecificationVersion
752 Pb
.Specification
[TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
] = ModuleHeader
.UefiSpecificationVersion
753 Pb
.AutoGenVersion
= int(ModuleHeader
.InfVersion
, 0)
756 # LibraryClass of Defines
758 for Item
in ModuleHeader
.LibraryClass
:
759 Pb
.LibraryClass
.append(LibraryClassObject(Item
.LibraryClass
, Item
.SupModuleList
, None))
762 # Module image and library of Defines
764 for Item
in Module
.ExternImages
:
765 if Item
.ModuleEntryPoint
!= '' and Item
.ModuleEntryPoint
not in Pb
.ModuleEntryPointList
:
766 Pb
.ModuleEntryPointList
.append(Item
.ModuleEntryPoint
)
767 if Item
.ModuleUnloadImage
!= '' and Item
.ModuleUnloadImage
not in Pb
.ModuleUnloadImageList
:
768 Pb
.ModuleUnloadImageList
.append(Item
.ModuleUnloadImage
)
769 for Item
in Module
.ExternLibraries
:
770 if Item
.Constructor
!= '' and Item
.Constructor
not in Pb
.ConstructorList
:
771 Pb
.ConstructorList
.append(Item
.Constructor
)
772 if Item
.Destructor
!= '' and Item
.Destructor
not in Pb
.DestructorList
:
773 Pb
.DestructorList
.append(Item
.Destructor
)
778 for Item
in Module
.Binaries
:
779 if Arch
in Item
.SupArchList
:
780 FileName
= Item
.BinaryFile
781 FileType
= Item
.FileType
783 FeatureFlag
= Item
.FeatureFlag
784 Pb
.Binaries
.append(ModuleBinaryFileClass(FileName
, FileType
, Target
, FeatureFlag
, Arch
.split()))
789 for Item
in Module
.Sources
:
790 if Arch
in Item
.SupArchList
:
791 SourceFile
= Item
.SourceFile
792 TagName
= Item
.TagName
793 ToolCode
= Item
.ToolCode
794 ToolChainFamily
= Item
.ToolChainFamily
795 FeatureFlag
= Item
.FeatureFlag
796 Pb
.Sources
.append(ModuleSourceFileClass(SourceFile
, TagName
, ToolCode
, ToolChainFamily
, FeatureFlag
))
801 for Item
in Module
.Protocols
:
802 if Arch
in Item
.SupArchList
:
803 Pb
.Protocols
.append(Item
.CName
)
808 for Item
in Module
.Ppis
:
809 if Arch
in Item
.SupArchList
:
810 Pb
.Ppis
.append(Item
.CName
)
815 for Item
in Module
.Guids
:
816 if Arch
in Item
.SupArchList
:
817 Pb
.Ppis
.append(Item
.CName
)
822 for Item
in Module
.Includes
:
823 if Arch
in Item
.SupArchList
:
824 Pb
.Includes
.append(Item
.FilePath
)
829 for Item
in Module
.PackageDependencies
:
830 if Arch
in Item
.SupArchList
:
831 Pb
.Packages
.append(Item
.FilePath
)
836 for Item
in Module
.BuildOptions
:
837 if Arch
in Item
.SupArchList
:
838 if (Item
.ToolChainFamily
, Item
.ToolChain
) not in Pb
.BuildOptions
:
839 Pb
.BuildOptions
[(Item
.ToolChainFamily
, Item
.ToolChain
)] = Item
.Option
841 OptionString
= Pb
.BuildOptions
[(Item
.ToolChainFamily
, Item
.ToolChain
)]
842 Pb
.BuildOptions
[(Item
.ToolChainFamily
, Item
.ToolChain
)] = OptionString
+ " " + Item
.Option
843 self
.FindBuildOptions(Arch
, Inf
, Pb
.BuildOptions
)
848 for Item
in Module
.Depex
:
849 if Arch
in Item
.SupArchList
:
850 Pb
.Depex
= Pb
.Depex
+ Item
.Depex
+ ' '
851 Pb
.Depex
= Pb
.Depex
.strip()
856 for Item
in Module
.LibraryClasses
:
857 if Arch
in Item
.SupArchList
:
858 Lib
= Item
.LibraryClass
859 RecommendedInstance
= Item
.RecommendedInstance
860 if Pb
.LibraryClass
!= []:
864 for Libs
in Pb
.LibraryClass
:
865 for Type
in Libs
.SupModList
:
866 Instance
= self
.FindLibraryClassInstanceOfLibrary(Lib
, Arch
, Type
)
868 Instance
= RecommendedInstance
869 Pb
.LibraryClasses
[(Lib
, Type
)] = Instance
874 Instance
= self
.FindLibraryClassInstanceOfModule(Lib
, Arch
, Pb
.ModuleType
, Inf
)
876 Instance
= RecommendedInstance
877 Pb
.LibraryClasses
[(Lib
, Pb
.ModuleType
)] = Instance
882 for Item
in Module
.Libraries
:
883 if Arch
in Item
.SupArchList
:
884 Pb
.Libraries
.append(Item
.Library
)
889 for Item
in Module
.PcdCodes
:
890 if Arch
in Item
.SupArchList
:
892 Guid
= Item
.TokenSpaceGuidCName
894 Pb
.Pcds
[(Name
, Guid
)] = self
.FindPcd(Arch
, Inf
, Name
, Guid
, Type
)
899 self
.Build
[Arch
].ModuleDatabase
[Inf
] = Pb
902 ## Update Libraries Of Platform Database
904 # @param InfList: A list for all inf files
906 def UpdateLibrariesOfPlatform(self
, InfList
= []):
907 for Arch
in self
.SupArchList
:
908 PlatformDatabase
= self
.Build
[Arch
].PlatformDatabase
909 for Dsc
in PlatformDatabase
:
910 Platform
= PlatformDatabase
[Dsc
]
911 for Inf
in Platform
.Modules
:
912 if not self
.IsModuleDefinedInPlatform(Inf
, Arch
, InfList
):
914 Module
= self
.Build
[Arch
].ModuleDatabase
[Inf
]
915 if Module
.LibraryClass
is None or Module
.LibraryClass
== []:
916 self
.UpdateLibrariesOfModule(Platform
, Module
, Arch
)
917 for Key
in Module
.LibraryClasses
:
918 Lib
= Module
.LibraryClasses
[Key
]
919 if Lib
not in Platform
.LibraryInstances
:
920 Platform
.LibraryInstances
.append(Lib
)
923 ## Update Libraries Of Module Database
925 # @param Module: The module need to be updated libraries
926 # @param Arch: The supportted arch of the module
928 def UpdateLibrariesOfModule(self
, Platform
, Module
, Arch
):
929 ModuleDatabase
= self
.Build
[Arch
].ModuleDatabase
930 ModuleType
= Module
.ModuleType
933 if Module
.AutoGenVersion
< 0x00010005:
934 EdkLogger
.verbose("")
935 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), Arch
))
936 LibraryConsumerList
= [Module
]
938 # "CompilerStub" is a must for Edk modules
939 Module
.Libraries
.append("CompilerStub")
940 while len(LibraryConsumerList
) > 0:
941 M
= LibraryConsumerList
.pop()
942 for LibraryName
in M
.Libraries
:
943 if LibraryName
not in Platform
.Libraries
:
944 EdkLogger
.warn("AutoGen", "Library [%s] is not found" % LibraryName
,
945 ExtraData
="\t%s [%s]" % (str(Module
), Arch
))
948 LibraryFile
= Platform
.Libraries
[LibraryName
]
949 if (LibraryName
, ModuleType
) not in Module
.LibraryClasses
:
950 Module
.LibraryClasses
[LibraryName
, ModuleType
] = LibraryFile
951 LibraryConsumerList
.append(ModuleDatabase
[LibraryFile
])
952 EdkLogger
.verbose("\t" + LibraryName
+ " : " + LibraryFile
)
956 LibraryConsumerList
= [Module
]
958 ConsumedByList
= sdict()
959 LibraryInstance
= sdict()
961 EdkLogger
.verbose("")
962 EdkLogger
.verbose("Library instances of module [%s] [%s]:" % (str(Module
), Arch
))
963 while len(LibraryConsumerList
) > 0:
964 M
= LibraryConsumerList
.pop()
965 for Key
, LibraryPath
in M
.LibraryClasses
.iteritems():
966 # The "Key" is in format of (library_class_name, supported_module_type)
967 if ModuleType
!= "USER_DEFINED" and ModuleType
not in Key
:
968 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "%s for module type %s is not supported (%s)" % (Key
+ (LibraryPath
,)))
971 LibraryClassName
= Key
[0]
972 if LibraryClassName
not in LibraryInstance
or LibraryInstance
[LibraryClassName
] is None:
973 if LibraryPath
is None or LibraryPath
== "":
974 LibraryInstance
[LibraryClassName
] = None
976 LibraryModule
= ModuleDatabase
[LibraryPath
]
977 LibraryInstance
[LibraryClassName
] = LibraryModule
978 LibraryConsumerList
.append(LibraryModule
)
979 EdkLogger
.verbose("\t" + LibraryClassName
+ " : " + str(LibraryModule
))
980 elif LibraryPath
is None or LibraryPath
== "":
983 LibraryModule
= LibraryInstance
[LibraryClassName
]
985 if LibraryModule
.ConstructorList
!= [] and LibraryModule
not in Constructor
:
986 Constructor
.append(LibraryModule
)
988 if LibraryModule
not in ConsumedByList
:
989 ConsumedByList
[LibraryModule
] = []
991 if M
in ConsumedByList
[LibraryModule
]:
993 ConsumedByList
[LibraryModule
].append(M
)
995 # Initialize the sorted output list to the empty set
997 SortedLibraryList
= []
999 # Q <- Set of all nodes with no incoming edges
1001 LibraryList
= [] #LibraryInstance.values()
1003 for LibraryClassName
in LibraryInstance
:
1004 M
= LibraryInstance
[LibraryClassName
]
1006 EdkLogger
.error("AutoGen", AUTOGEN_ERROR
,
1007 "Library instance for library class [%s] is not found" % LibraryClassName
,
1008 ExtraData
="\t%s [%s]" % (str(Module
), Arch
))
1009 LibraryList
.append(M
)
1011 # check if there're duplicate library classes
1013 for Lc
in M
.LibraryClass
:
1014 if Lc
.SupModList
is not None and ModuleType
not in Lc
.SupModList
:
1015 EdkLogger
.error("AutoGen", AUTOGEN_ERROR
,
1016 "Module type [%s] is not supported by library instance [%s]" % (ModuleType
, str(M
)),
1017 ExtraData
="\t%s" % str(Module
))
1019 if Lc
.LibraryClass
in LibraryInstance
and str(M
) != str(LibraryInstance
[Lc
.LibraryClass
]):
1020 EdkLogger
.error("AutoGen", AUTOGEN_ERROR
,
1021 "More than one library instance found for library class [%s] in module [%s]" % (Lc
.LibraryClass
, Module
),
1022 ExtraData
="\t%s\n\t%s" % (LibraryInstance
[Lc
.LibraryClass
], str(M
))
1024 if ConsumedByList
[M
] == []:
1027 # while Q is not empty do
1031 # remove node from Q
1037 SortedLibraryList
.append(Node
)
1039 # for each node Item with an edge e from Node to Item do
1041 for Item
in LibraryList
:
1042 if Node
not in ConsumedByList
[Item
]:
1045 # remove edge e from the graph
1047 ConsumedByList
[Item
].remove(Node
)
1049 # If Item has no other incoming edges then
1051 if ConsumedByList
[Item
] == []:
1053 # insert Item into Q
1058 while Q
== [] and EdgeRemoved
:
1061 # for each node Item with a Constructor
1063 for Item
in LibraryList
:
1064 if Item
in Constructor
:
1066 # for each Node without a constructor with an edge e from Item to Node
1068 for Node
in ConsumedByList
[Item
]:
1069 if Node
not in Constructor
:
1071 # remove edge e from the graph
1073 ConsumedByList
[Item
].remove(Node
)
1075 if ConsumedByList
[Item
] == []:
1077 # insert Item into Q
1085 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
1087 for Item
in LibraryList
:
1088 if ConsumedByList
[Item
] != [] and Item
in Constructor
and len(Constructor
) > 1:
1089 ErrorMessage
= 'Library [%s] with constructors has a cycle' % str(Item
)
1090 EdkLogger
.error("AutoGen", AUTOGEN_ERROR
, ErrorMessage
,
1091 "\tconsumed by " + "\n\tconsumed by ".join([str(L
) for L
in ConsumedByList
[Item
]]))
1092 if Item
not in SortedLibraryList
:
1093 SortedLibraryList
.append(Item
)
1096 # Build the list of constructor and destructir names
1097 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
1099 SortedLibraryList
.reverse()
1100 Module
.LibraryClasses
= sdict()
1101 for L
in SortedLibraryList
:
1102 for Lc
in L
.LibraryClass
:
1103 Module
.LibraryClasses
[Lc
.LibraryClass
, ModuleType
] = str(L
)
1105 # Merge PCDs from library instance
1108 if Key
not in Module
.Pcds
:
1109 LibPcd
= L
.Pcds
[Key
]
1110 Module
.Pcds
[Key
] = self
.FindPcd(Arch
, str(Module
), LibPcd
.TokenCName
, LibPcd
.TokenSpaceGuidCName
, LibPcd
.Type
)
1112 # Merge GUIDs from library instance
1114 for CName
in L
.Guids
:
1115 if CName
not in Module
.Guids
:
1116 Module
.Guids
.append(CName
)
1118 # Merge Protocols from library instance
1120 for CName
in L
.Protocols
:
1121 if CName
not in Module
.Protocols
:
1122 Module
.Protocols
.append(CName
)
1124 # Merge Ppis from library instance
1126 for CName
in L
.Ppis
:
1127 if CName
not in Module
.Ppis
:
1128 Module
.Ppis
.append(CName
)
1132 # Generate build database for all arches
1134 # @param PcdsSet: Pcd list for override from Fdf parse result
1135 # @param InfList: Inf list for override from Fdf parse result
1137 def GenBuildDatabase(self
, PcdsSet
= {}, InfList
= []):
1139 # Add additional inf file defined in Fdf file
1141 for InfFile
in InfList
:
1142 self
.AddToInfDatabase(NormPath(InfFile
))
1145 # Generate PlatformDatabase, PackageDatabase and ModuleDatabase
1147 self
.GenPackageDatabase()
1148 self
.GenPlatformDatabase(PcdsSet
)
1149 self
.GenModuleDatabase(InfList
)
1154 # Update Libraries Of Platform
1156 self
.UpdateLibrariesOfPlatform(InfList
)
1159 # Output used Pcds not found in DSC file
1161 self
.ShowUnFoundPcds()
1163 ## ShowUnFoundPcds()
1165 # If there is any pcd used but not defined in DSC
1166 # Print warning message on screen and output a list of pcds
1168 def ShowUnFoundPcds(self
):
1169 if self
.UnFoundPcdInDsc
!= {}:
1170 WrnMessage
= '**** WARNING ****\n'
1171 WrnMessage
+= 'The following Pcds were not defined in the DSC file: %s\n' % self
.DscFileName
1172 WrnMessage
+= 'The default values were obtained from the DEC file that declares the PCD and the PCD default value\n'
1173 for (Guid
, Name
, Type
, Arch
) in self
.UnFoundPcdInDsc
:
1174 Dec
= self
.UnFoundPcdInDsc
[(Guid
, Name
, Type
, Arch
)]
1175 Pcds
= self
.Build
[Arch
].PackageDatabase
[Dec
].Pcds
1176 if (Name
, Guid
, Type
) in Pcds
:
1177 Pcd
= Pcds
[(Name
, Guid
, Type
)]
1178 PcdItemTypeUsed
= Pcd
.Type
1179 DefaultValue
= Pcd
.DefaultValue
1180 WrnMessage
+= '%s.%s: Defined in file %s, PcdItemType is Pcds%s, DefaultValue is %s\n' % (Guid
, Name
, Dec
, PcdItemTypeUsed
, DefaultValue
)
1181 EdkLogger
.verbose(WrnMessage
)
1183 ## Create a full path with workspace dir
1185 # Convert Filename with workspace dir to create a full path
1187 # @param Filename: The filename need to be added workspace dir
1189 # @retval string Full path
1191 def WorkspaceFile(self
, Filename
):
1192 return WorkspaceFile(self
.WorkspaceDir
, Filename
)
1194 ## Update LibraryClass of Module
1196 # If a module of a platform has its own override libraryclass but the libraryclass not defined in the module
1197 # Add this libraryclass to the module
1199 # @param InfFileName: InfFileName specificed in platform
1200 # @param LibraryClass: LibraryClass specificed in platform
1201 # @param Arch: Supportted Arch
1202 # @param InstanceFilePath: InstanceFilePath specificed in platform
1204 def UpdateLibraryClassOfModule(self
, InfFileName
, LibraryClass
, Arch
, InstanceFilePath
):
1206 # Update the library instance itself to add this libraryclass name
1208 LibraryModule
= self
.InfDatabase
[InstanceFilePath
].Module
1209 LibList
= LibraryModule
.Header
[Arch
].LibraryClass
1213 # Find this LibraryClass
1215 if Lib
.LibraryClass
== LibraryClass
:
1219 NewLib
= LibraryClassClass()
1220 NewLib
.LibraryClass
= LibraryClass
1221 NewLib
.SupModuleList
= DataType
.SUP_MODULE_LIST
# LibraryModule.Header[Arch].ModuleType.split()
1222 LibraryModule
.Header
[Arch
].LibraryClass
.append(NewLib
)
1225 # Add it to LibraryClasses Section for the module which is using the library
1227 Module
= self
.InfDatabase
[InfFileName
].Module
1228 LibList
= Module
.LibraryClasses
1232 # Find this LibraryClass
1234 if Lib
.LibraryClass
== LibraryClass
:
1235 if Arch
in Lib
.SupArchList
:
1238 Lib
.SupArchList
.append(Arch
)
1241 Lib
= LibraryClassClass()
1242 Lib
.LibraryClass
= LibraryClass
1243 Lib
.SupArchList
= [Arch
]
1244 Module
.LibraryClasses
.append(Lib
)
1246 ## Add Inf file to InfDatabase
1248 # Create a Inf instance for input inf file and add it to InfDatabase
1250 # @param InfFileName: The InfFileName need to be added to database
1252 def AddToInfDatabase(self
, InfFileName
):
1253 File
= self
.WorkspaceFile(InfFileName
)
1254 if os
.path
.exists(File
) and os
.path
.isfile(File
):
1255 if InfFileName
not in self
.InfDatabase
:
1256 self
.InfDatabase
[InfFileName
] = Inf(File
, False, True, self
.WorkspaceDir
, self
.Db
, self
.SupArchList
)
1258 EdkLogger
.error("AutoGen", FILE_NOT_FOUND
, ExtraData
=File
)
1260 ## Add Dec file to DecDatabase
1262 # Create a Dec instance for input dec file and add it to DecDatabase
1264 # @param DecFileName: The DecFileName need to be added to database
1266 def AddToDecDatabase(self
, DecFileName
):
1267 File
= self
.WorkspaceFile(DecFileName
)
1268 if os
.path
.exists(File
) and os
.path
.isfile(File
):
1269 if DecFileName
not in self
.DecDatabase
:
1270 self
.DecDatabase
[DecFileName
] = Dec(File
, False, True, self
.WorkspaceDir
, self
.Db
, self
.SupArchList
)
1272 EdkLogger
.error("AutoGen", FILE_NOT_FOUND
, ExtraData
=File
)
1274 ## Search LibraryClass Instance for Module
1276 # Search PlatformBuildDatabase to find LibraryClass Instance for Module
1277 # Return the instance if found
1279 # @param Lib: Input value for Library Class Name
1280 # @param Arch: Supportted Arch
1281 # @param ModuleType: Supportted ModuleType
1282 # @param ModuleName: Input value for Module Name
1284 # @retval string Found LibraryClass Instance file path
1286 def FindLibraryClassInstanceOfModule(self
, Lib
, Arch
, ModuleType
, ModuleName
):
1288 # First find if exist in <LibraryClass> of <Components> from dsc file
1290 for Dsc
in self
.DscDatabase
.keys():
1291 Platform
= self
.DscDatabase
[Dsc
].Platform
1292 for Module
in Platform
.Modules
.ModuleList
:
1293 if Arch
in Module
.SupArchList
:
1294 if Module
.FilePath
== ModuleName
:
1295 for LibraryClass
in Module
.LibraryClasses
.LibraryList
:
1296 if LibraryClass
.Name
== Lib
:
1297 return LibraryClass
.FilePath
1299 #Second find if exist in <LibraryClass> of <LibraryClasses> from dsc file
1301 return self
.FindLibraryClassInstanceOfLibrary(Lib
, Arch
, ModuleType
)
1303 ## Search LibraryClass Instance for Library
1305 # Search PlatformBuildDatabase to find LibraryClass Instance for Library
1306 # Return the instance if found
1308 # @param Lib: Input value for Library Class Name
1309 # @param Arch: Supportted Arch
1310 # @param Type: Supportted Library Usage Type
1312 # @retval string Found LibraryClass Instance file path
1313 # @retval None Not Found
1315 def FindLibraryClassInstanceOfLibrary(self
, Lib
, Arch
, Type
):
1316 for Dsc
in self
.DscDatabase
.keys():
1317 Platform
= self
.DscDatabase
[Dsc
].Platform
1318 if (Lib
, Type
) in self
.Build
[Arch
].PlatformDatabase
[Dsc
].LibraryClasses
:
1319 return self
.Build
[Arch
].PlatformDatabase
[Dsc
].LibraryClasses
[(Lib
, Type
)]
1320 elif (Lib
, '') in self
.Build
[Arch
].PlatformDatabase
[Dsc
].LibraryClasses
:
1321 return self
.Build
[Arch
].PlatformDatabase
[Dsc
].LibraryClasses
[(Lib
, '')]
1324 ## Find BuildOptions
1326 # Search DscDatabase to find component definition of ModuleName
1327 # Override BuildOption if it is defined in component
1329 # @param Arch: Supportted Arch
1330 # @param ModuleName: The module which has buildoption definition in component of platform
1331 # @param BuildOptions: The set of all buildopitons
1333 def FindBuildOptions(self
, Arch
, ModuleName
, BuildOptions
):
1334 for Dsc
in self
.DscDatabase
.keys():
1336 # First find if exist in <BuildOptions> of <Components> from dsc file
1337 # if find, use that override the one defined in inf file
1339 Platform
= self
.DscDatabase
[Dsc
].Platform
1340 for Module
in Platform
.Modules
.ModuleList
:
1341 if Arch
in Module
.SupArchList
:
1342 if Module
.FilePath
== ModuleName
:
1343 for BuildOption
in Module
.ModuleSaBuildOption
.BuildOptionList
:
1345 # Add to BuildOptions
1347 BuildOptions
[(BuildOption
.ToolChainFamily
, BuildOption
.ToolChain
)] = BuildOption
.Option
1351 # Search platform database, package database, module database and PcdsSet from Fdf
1354 # @param Arch: Supportted Arch
1355 # @param ModuleName: The module which has pcd definition in component of platform
1356 # @param Name: Name of Pcd
1357 # @param Guid: Guid of Pcd
1358 # @param Type: Type of Pcd
1360 # @retval PcdClassObject An instance for PcdClassObject with all members filled
1362 def FindPcd(self
, Arch
, ModuleName
, Name
, Guid
, Type
):
1370 IsFoundInDsc
= False
1371 IsFoundInDec
= False
1375 # Second get information from platform database
1378 for Dsc
in self
.Build
[Arch
].PlatformDatabase
.keys():
1379 Pcds
= self
.Build
[Arch
].PlatformDatabase
[Dsc
].Pcds
1380 if (Name
, Guid
) in Pcds
:
1382 Pcd
= Pcds
[(Name
, Guid
)]
1383 if Pcd
.Type
!= '' and Pcd
.Type
is not None:
1385 if NewType
in DataType
.PCD_DYNAMIC_TYPE_LIST
:
1386 NewType
= DataType
.TAB_PCDS_DYNAMIC
1387 elif NewType
in DataType
.PCD_DYNAMIC_EX_TYPE_LIST
:
1388 NewType
= DataType
.TAB_PCDS_DYNAMIC_EX
1392 if Type
!= '' and Type
!= NewType
:
1393 ErrorMsg
= "PCD %s.%s is declared as [%s] in module\n\t%s\n\n"\
1394 " But it's used as [%s] in platform\n\t%s"\
1395 % (Guid
, Name
, Type
, ModuleName
, NewType
, OwnerPlatform
)
1396 EdkLogger
.error("AutoGen", PARSER_ERROR
, ErrorMsg
)
1399 if Pcd
.DatumType
!= '' and Pcd
.DatumType
is not None:
1400 DatumType
= Pcd
.DatumType
1401 if Pcd
.TokenValue
!= '' and Pcd
.TokenValue
is not None:
1402 Token
= Pcd
.TokenValue
1403 if Pcd
.DefaultValue
!= '' and Pcd
.DefaultValue
is not None:
1404 Value
= Pcd
.DefaultValue
1405 if Pcd
.MaxDatumSize
!= '' and Pcd
.MaxDatumSize
is not None:
1406 MaxDatumSize
= Pcd
.MaxDatumSize
1407 SkuInfoList
= Pcd
.SkuInfoList
1414 # Third get information from <Pcd> of <Compontents> from module database
1416 for Dsc
in self
.DscDatabase
.keys():
1417 for Module
in self
.DscDatabase
[Dsc
].Platform
.Modules
.ModuleList
:
1418 if Arch
in Module
.SupArchList
:
1419 if Module
.FilePath
== ModuleName
:
1420 for Pcd
in Module
.PcdBuildDefinitions
:
1421 if (Name
, Guid
) == (Pcd
.CName
, Pcd
.TokenSpaceGuidCName
):
1422 if Pcd
.DefaultValue
!= '':
1423 Value
= Pcd
.DefaultValue
1424 if Pcd
.MaxDatumSize
!= '':
1425 MaxDatumSize
= Pcd
.MaxDatumSize
1432 # First get information from package database
1437 PcdTypeList
= [Type
]
1439 PcdTypeList
= ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]
1441 for Dec
in self
.Build
[Arch
].PackageDatabase
.keys():
1442 Pcds
= self
.Build
[Arch
].PackageDatabase
[Dec
].Pcds
1443 for PcdType
in PcdTypeList
:
1444 if (Name
, Guid
, PcdType
) in Pcds
:
1445 Pcd
= Pcds
[(Name
, Guid
, PcdType
)]
1449 FoundInDecFile
= Dec
1455 for Dec
in self
.Build
[Arch
].PackageDatabase
.keys():
1456 Pcds
= self
.Build
[Arch
].PackageDatabase
[Dec
].Pcds
1457 if (Name
, Guid
, NewType
) in Pcds
:
1458 Pcd
= Pcds
[(Name
, Guid
, NewType
)]
1461 FoundInDecFile
= Dec
1464 if not IsFoundInDec
:
1465 ErrorMsg
= "Pcd '%s.%s [%s]' defined in module '%s' is not found in any package for Arch '%s'" % (Guid
, Name
, NewType
, ModuleName
, Arch
)
1466 EdkLogger
.error("AutoGen", PARSER_ERROR
, ErrorMsg
)
1469 # Not found in any platform and fdf
1471 if not IsFoundInDsc
:
1472 Value
= Pcd
.DefaultValue
1473 if NewType
.startswith("Dynamic") and SkuInfoList
== {}:
1474 SkuIds
= self
.Build
[Arch
].PlatformDatabase
.values()[0].SkuIds
1475 SkuInfoList
['DEFAULT'] = SkuInfoClass(SkuIdName
='DEFAULT', SkuId
=SkuIds
['DEFAULT'], DefaultValue
=Value
)
1476 self
.UnFoundPcdInDsc
[(Guid
, Name
, NewType
, Arch
)] = FoundInDecFile
1477 #elif Type != '' and NewType.startswith("Dynamic"):
1478 # NewType = Pcd.Type
1479 DatumType
= Pcd
.DatumType
1480 if Token
in [None, '']:
1481 Token
= Pcd
.TokenValue
1482 if DatumType
== "VOID*" and MaxDatumSize
in ['', None]:
1483 EdkLogger
.verbose("No MaxDatumSize specified for PCD %s.%s in module [%s]" % (Guid
, Name
, ModuleName
))
1485 MaxDatumSize
= str(len(Value
) * 2)
1486 elif Value
[0] == '{':
1487 MaxDatumSize
= str(len(Value
.split(',')))
1489 MaxDatumSize
= str(len(Value
))
1491 return PcdClassObject(Name
, Guid
, NewType
, DatumType
, Value
, Token
, MaxDatumSize
, SkuInfoList
, IsOverrided
)
1493 ## Find Supportted Module List Of LibraryClass
1495 # Search in InfDatabase, find the supmodulelist of the libraryclass
1497 # @param LibraryClass: LibraryClass name for search
1498 # @param OverridedLibraryClassList: A list of all LibraryClass
1499 # @param Arch: Supportted Arch
1501 # @retval list SupModuleList
1503 def FindSupModuleListOfLibraryClass(self
, LibraryClass
, OverridedLibraryClassList
, Arch
):
1504 Name
= LibraryClass
.Name
1505 FilePath
= LibraryClass
.FilePath
1506 SupModuleList
= copy
.copy(LibraryClass
.SupModuleList
)
1509 # If the SupModuleList means all, remove overrided module types of platform
1511 if SupModuleList
== DataType
.SUP_MODULE_LIST
:
1512 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "\tLibraryClass %s supports all module types" % Name
)
1513 for Item
in OverridedLibraryClassList
:
1515 # Find a library class (Item) with the same name
1517 if Item
.Name
== Name
:
1519 # Do nothing if it is itself
1521 if Item
.SupModuleList
== DataType
.SUP_MODULE_LIST
:
1524 # If not itself, check arch first
1526 if Arch
in LibraryClass
.SupArchList
:
1528 # If arch is supportted, remove all related module type
1530 if Arch
in Item
.SupArchList
:
1531 for ModuleType
in Item
.SupModuleList
:
1532 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "\tLibraryClass %s has specific defined module types" % Name
)
1533 if ModuleType
in SupModuleList
:
1534 SupModuleList
.remove(ModuleType
)
1536 return SupModuleList
1538 ## Find Module inf Platform
1540 # Check if the module is defined in <Compentent> of <Platform>
1542 # @param Inf: Inf file (Module) need to be searched
1543 # @param Arch: Supportted Arch
1544 # @param InfList: A list for all Inf file
1546 # @retval True Mudule Found
1547 # @retval Flase Module Not Found
1549 def IsModuleDefinedInPlatform(self
, Inf
, Arch
, InfList
):
1550 for Dsc
in self
.DscDatabase
.values():
1551 for LibraryClass
in Dsc
.Platform
.LibraryClasses
.LibraryList
:
1552 if Inf
== LibraryClass
.FilePath
and Arch
in LibraryClass
.SupArchList
:
1554 for Module
in Dsc
.Platform
.Modules
.ModuleList
:
1555 if Inf
== Module
.FilePath
and Arch
in Module
.SupArchList
:
1557 for Item
in Module
.LibraryClasses
.LibraryList
:
1558 if Inf
== Item
.FilePath
:
1560 for Library
in Dsc
.Platform
.Libraries
.LibraryList
:
1561 if Inf
== Library
.FilePath
and Arch
in Library
.SupArchList
:
1566 ## Show all content of the workspacebuild
1568 # Print each item of the workspacebuild with (Key = Value) pair
1570 def ShowWorkspaceBuild(self
):
1571 print self
.DscDatabase
1572 print self
.InfDatabase
1573 print self
.DecDatabase
1574 print 'SupArchList', self
.SupArchList
1575 print 'BuildTarget', self
.BuildTarget
1576 print 'SkuId', self
.SkuId
1578 for Arch
in self
.SupArchList
:
1581 for Platform
in self
.Build
[Arch
].PlatformDatabase
.keys():
1582 P
= self
.Build
[Arch
].PlatformDatabase
[Platform
]
1583 print 'DescFilePath = ', P
.DescFilePath
1584 print 'PlatformName = ', P
.PlatformName
1585 print 'Guid = ', P
.Guid
1586 print 'Version = ', P
.Version
1587 print 'OutputDirectory = ', P
.OutputDirectory
1588 print 'FlashDefinition = ', P
.FlashDefinition
1589 print 'SkuIds = ', P
.SkuIds
1590 print 'Modules = ', P
.Modules
1591 print 'LibraryClasses = ', P
.LibraryClasses
1592 print 'Pcds = ', P
.Pcds
1593 for item
in P
.Pcds
.keys():
1595 print 'BuildOptions = ', P
.BuildOptions
1600 for Package
in self
.Build
[Arch
].PackageDatabase
.keys():
1601 P
= self
.Build
[Arch
].PackageDatabase
[Package
]
1602 print 'DescFilePath = ', P
.DescFilePath
1603 print 'PackageName = ', P
.PackageName
1604 print 'Guid = ', P
.Guid
1605 print 'Version = ', P
.Version
1606 print 'Protocols = ', P
.Protocols
1607 print 'Ppis = ', P
.Ppis
1608 print 'Guids = ', P
.Guids
1609 print 'Includes = ', P
.Includes
1610 print 'LibraryClasses = ', P
.LibraryClasses
1611 print 'Pcds = ', P
.Pcds
1612 for item
in P
.Pcds
.keys():
1618 for Module
in self
.Build
[Arch
].ModuleDatabase
.keys():
1619 P
= self
.Build
[Arch
].ModuleDatabase
[Module
]
1620 print 'DescFilePath = ', P
.DescFilePath
1621 print 'BaseName = ', P
.BaseName
1622 print 'ModuleType = ', P
.ModuleType
1623 print 'Guid = ', P
.Guid
1624 print 'Version = ', P
.Version
1625 print 'CustomMakefile = ', P
.CustomMakefile
1626 print 'Specification = ', P
.Specification
1627 print 'Shadow = ', P
.Shadow
1628 print 'PcdIsDriver = ', P
.PcdIsDriver
1629 for Lib
in P
.LibraryClass
:
1630 print 'LibraryClassDefinition = ', Lib
.LibraryClass
, 'SupModList = ', Lib
.SupModList
1631 print 'ModuleEntryPointList = ', P
.ModuleEntryPointList
1632 print 'ModuleUnloadImageList = ', P
.ModuleUnloadImageList
1633 print 'ConstructorList = ', P
.ConstructorList
1634 print 'DestructorList = ', P
.DestructorList
1637 for item
in P
.Binaries
:
1638 print item
.BinaryFile
, item
.FeatureFlag
, item
.SupArchList
1640 for item
in P
.Sources
:
1641 print item
.SourceFile
1642 print 'LibraryClasses = ', P
.LibraryClasses
1643 print 'Protocols = ', P
.Protocols
1644 print 'Ppis = ', P
.Ppis
1645 print 'Guids = ', P
.Guids
1646 print 'Includes = ', P
.Includes
1647 print 'Packages = ', P
.Packages
1648 print 'Pcds = ', P
.Pcds
1649 for item
in P
.Pcds
.keys():
1651 print 'BuildOptions = ', P
.BuildOptions
1652 print 'Depex = ', P
.Depex
1658 # This acts like the main() function for the script, unless it is 'import'ed into another
1661 if __name__
== '__main__':
1662 print 'Start!', time
.strftime('%H:%M:%S', time
.localtime())
1663 EdkLogger
.Initialize()
1664 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
1666 W
= os
.getenv('WORKSPACE')
1667 Ewb
= WorkspaceBuild('Nt32Pkg/Nt32Pkg.dsc', W
)
1668 Ewb
.GenBuildDatabase({('PcdDevicePathSupportDevicePathFromText', 'gEfiMdeModulePkgTokenSpaceGuid') : 'KKKKKKKKKKKKKKKKKKKKK'}, ['Test.Inf'])
1669 print 'Done!', time
.strftime('%H:%M:%S', time
.localtime())
1670 Ewb
.ShowWorkspaceBuild()