1 ## @file InfPomAlignment.py
2 # This file contained the adapter for convert INF parser object to POM Object
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 from Logger
import StringTable
as ST
23 import Logger
.Log
as Logger
25 from Library
.String
import FORMAT_INVALID
26 from Library
.String
import PARSER_ERROR
27 from Library
.String
import NormPath
28 from Library
.String
import GetSplitValueList
29 from Library
.Misc
import ConvertVersionToDecimal
30 from Library
.Misc
import GetHelpStringByRemoveHashKey
31 from Library
.Misc
import ConvertArchList
32 from Library
.Parsing
import GetPkgInfoFromDec
33 from Library
import DataType
as DT
34 from Library
import GlobalData
36 from Object
.POM
import CommonObject
37 from Object
.POM
.ModuleObject
import ModuleObject
38 from Object
.POM
.ModuleObject
import ExternObject
39 from Object
.POM
.ModuleObject
import HobObject
40 from Object
.POM
.ModuleObject
import EventObject
41 from Object
.POM
.ModuleObject
import BootModeObject
42 from Object
.POM
.ModuleObject
import PackageDependencyObject
43 from Object
.POM
.ModuleObject
import SourceFileObject
44 from Object
.POM
.ModuleObject
import DepexObject
45 from Object
.POM
.ModuleObject
import AsBuildLibraryClassObject
46 from Object
.POM
.ModuleObject
import AsBuiltObject
47 from PomAdapter
.InfPomAlignmentMisc
import GenModuleHeaderUserExt
48 from PomAdapter
.InfPomAlignmentMisc
import GenBinaryData
49 from Parser
import InfParser
55 # Inherit from ModuleObject
57 class InfPomAlignment(ModuleObject
):
58 ## Construct of InfPomAlignment
59 # Skip means that UPT don't care the syntax of INF, this may be the not
60 # distributed INF files during creation or the INF files checked for
61 # dependency rule during remove.
63 def __init__(self
, FileName
, WorkSpace
=None, PackagePath
='', Skip
=False):
64 ModuleObject
.__init
__(self
)
67 self
.FileName
= FileName
68 self
.WorkSpace
= WorkSpace
70 self
.LibModuleTypeList
= []
73 self
.WorkspaceDir
= " "
74 self
.CustomMakefile
= []
76 self
.SetPackagePath(PackagePath
)
78 # Call GenInfPomObjects function to fill POM object.
81 OrigConfig
= Logger
.SUPRESS_ERROR
82 Logger
.SUPRESS_ERROR
= True
83 self
._GenInfPomObjects
(Skip
)
84 Logger
.SUPRESS_ERROR
= OrigConfig
86 self
._GenInfPomObjects
(Skip
)
89 # Generate all POM objects, the original input comes
90 # from INF parser's output
92 def _GenInfPomObjects(self
, Skip
):
94 # Call INF Parser to get information from INF file
96 self
.Parser
= InfParser
.InfParser(self
.FileName
, self
.WorkSpace
)
97 self
.FullPath
= self
.Parser
.FullPath
99 self
._GenModuleHeader
()
101 # Call GenBinaries after Module Header for Binary INF consideration.
104 self
._GenBuildOptions
()
105 self
._GenLibraryClasses
()
106 self
._GenPackages
(Skip
)
109 self
._GenUserExtensions
()
110 self
._GenGuidProtocolPpis
(DT
.TAB_GUIDS
)
111 self
._GenGuidProtocolPpis
(DT
.TAB_PROTOCOLS
)
112 self
._GenGuidProtocolPpis
(DT
.TAB_PPIS
)
114 self
._GenMiscFiles
(self
.FullPath
, Skip
)
116 ## Convert [Defines] section content to InfDefObject
118 # Convert [Defines] section content to InfDefObject
120 # @param Defines The content under [Defines] section
121 # @param ModuleHeader An object of ModuleHeaderClass
122 # @param Arch The supported ARCH
124 def _GenModuleHeader(self
):
125 Logger
.Debug(2, "Generate ModuleHeader ...")
127 # Get all defines information form InfParser Object
129 RecordSet
= self
.Parser
.InfDefSection
.Defines
131 # Should only have one ArchString Item.
133 ArchString
= RecordSet
.keys()[0]
134 ArchList
= GetSplitValueList(ArchString
, ' ')
135 ArchList
= ConvertArchList(ArchList
)
136 HasCalledFlag
= False
139 # Get data from Sdict()
141 ValueList
= RecordSet
[ArchString
]
142 self
.SetFileName(self
.FileName
)
143 self
.SetFullPath(self
.FullPath
)
145 # The INF's filename (without the directory path or the extension)
146 # must be used for the value of the
147 # ModuleSurfaceArea.Header.Name element
149 self
.SetName(os
.path
.splitext(os
.path
.basename(self
.FileName
))[0])
151 self
.WorkspaceDir
= " "
153 # CombinePath and ModulePath
155 PathCount
= self
.FullPath
.upper().find(self
.WorkSpace
.upper()) + len(self
.WorkSpace
) + 1
156 CombinePath
= self
.FullPath
[PathCount
:]
157 self
.SetCombinePath(CombinePath
)
159 ModulePath
= os
.path
.split(CombinePath
)[0]
160 ModuleRelativePath
= ModulePath
161 if self
.GetPackagePath() != '':
162 ModuleRelativePath
= ModulePath
[ModulePath
.find(self
.GetPackagePath()) + len(self
.GetPackagePath()) + 1:]
163 self
.SetModulePath(ModuleRelativePath
)
166 # For Define Seciton Items.
168 DefineObj
= ValueList
171 # Convert UEFI/PI version to decimal number
173 if DefineObj
.GetUefiSpecificationVersion() != None:
174 __UefiVersion
= DefineObj
.GetUefiSpecificationVersion().GetValue()
175 __UefiVersion
= ConvertVersionToDecimal(__UefiVersion
)
176 self
.SetUefiSpecificationVersion(str(__UefiVersion
))
177 if DefineObj
.GetPiSpecificationVersion() != None:
178 __PiVersion
= DefineObj
.GetPiSpecificationVersion().GetValue()
179 __PiVersion
= ConvertVersionToDecimal(__PiVersion
)
181 self
.SetPiSpecificationVersion(str(__PiVersion
))
183 SpecList
= DefineObj
.GetSpecification()
185 for SpecItem
in SpecList
:
186 NewSpecList
.append((SpecItem
[0], ConvertVersionToDecimal(SpecItem
[1])))
187 self
.SetSpecList(NewSpecList
)
190 # must exist items in INF define section
191 # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING
193 if DefineObj
.GetModuleType() == None:
194 Logger
.Error("InfParser", FORMAT_INVALID
,
195 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("MODULE_TYPE"), File
=self
.FullPath
)
197 self
.SetModuleType(DefineObj
.GetModuleType().GetValue())
198 ModuleType
= DefineObj
.GetModuleType().GetValue()
201 # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only
202 # libraries are permitted to a have a MODULE_TYPE of "BASE".
204 if len(DefineObj
.LibraryClass
) == 0 and ModuleType
== 'BASE':
205 Logger
.Error("InfParser",
207 ST
.ERR_INF_PARSER_MODULETYPE_INVALID
,
209 Line
=DefineObj
.ModuleType
.CurrentLine
.LineNo
,
210 ExtraData
=DefineObj
.ModuleType
.CurrentLine
.LineString
)
211 self
.LibModuleTypeList
.append(ModuleType
)
212 if DefineObj
.GetBaseName() == None:
213 Logger
.Error("InfParser", FORMAT_INVALID
,
214 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("BASE_NAME"), File
=self
.FullPath
)
216 self
.SetBaseName(DefineObj
.GetBaseName().GetValue())
217 if DefineObj
.GetInfVersion() == None:
218 Logger
.Error("InfParser", FORMAT_INVALID
,
219 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("INF_VERSION"), File
=self
.FullPath
)
221 self
.SetVersion(DefineObj
.GetInfVersion().GetValue())
222 if DefineObj
.GetFileGuid() == None:
223 Logger
.Error("InfParser", FORMAT_INVALID
,
224 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("FILE_GUID"), File
=self
.FullPath
)
226 self
.SetGuid(DefineObj
.GetFileGuid().GetValue())
227 if DefineObj
.GetVersionString() == None:
229 # VERSION_STRING is missing from the [Defines] section, tools must assume that the module's version is 0.
236 if DefineObj
.GetVersionString().GetValue() != "":
240 VersionString
= DefineObj
.GetVersionString().GetValue()
241 if len(VersionString
) > 0:
242 VersionString
= ConvertVersionToDecimal(VersionString
)
243 self
.SetVersion(VersionString
)
248 Logger
.Error("Parser", PARSER_ERROR
, ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
, ExtraData
=self
.FullPath
,
249 RaiseError
=Logger
.IS_RAISE_ERROR
)
252 # if there is Shadow, Should judge the MODULE_TYPE in
253 # SEC, PEI_CORE and PEIM
255 if DefineObj
.GetShadow():
256 ModuleTypeValue
= DefineObj
.GetModuleType().GetValue()
257 if not (ModuleTypeValue
== 'SEC' or ModuleTypeValue
== 'PEI_CORE' or ModuleTypeValue
== 'PEIM'):
258 Logger
.Error("InfParser", FORMAT_INVALID
, ST
.ERR_INF_PARSER_DEFINE_SHADOW_INVALID
, File
=self
.FullPath
)
260 if DefineObj
.GetPcdIsDriver() != None:
261 self
.SetPcdIsDriver(DefineObj
.GetPcdIsDriver().GetValue())
266 self
._GenModuleHeaderLibClass
(DefineObj
, ArchList
)
271 self
.CustomMakefile
= DefineObj
.GetCustomMakefile()
273 # Externs in Defines section
274 # Only one define section, so just call once.
276 if not HasCalledFlag
:
277 self
._GenModuleHeaderExterns
(DefineObj
)
281 # each module has only one module header
283 self
.SetSupArchList(ArchList
)
285 # Get Hob/BootMode/EventList information
287 self
._GenSpecialComments
()
289 # put all define statement into user-extension sections
291 DefinesDictNew
= GenModuleHeaderUserExt(DefineObj
, ArchString
)
294 UserExtension
= CommonObject
.UserExtensionObject()
295 UserExtension
.SetDefinesDict(DefinesDictNew
)
296 UserExtension
.SetIdentifier('DefineModifiers')
297 UserExtension
.SetUserID('EDK2')
298 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
301 # Get all meta-file header information
302 # the record is list of items formated:
303 # [LineValue, Arch, StartLine, ID, Third]
306 InfHeaderObj
= self
.Parser
.InfHeader
308 # Put header information into POM object
310 self
.SetAbstract(InfHeaderObj
.GetAbstract())
311 self
.SetDescription(InfHeaderObj
.GetDescription())
312 self
.SetCopyright(InfHeaderObj
.GetCopyright())
313 self
.SetLicense(InfHeaderObj
.GetLicense())
315 ## GenModuleHeaderLibClass
318 def _GenModuleHeaderLibClass(self
, DefineObj
, ArchList
):
319 LibraryList
= DefineObj
.GetLibraryClass()
320 for LibraryItem
in LibraryList
:
321 Lib
= CommonObject
.LibraryClassObject()
322 Lib
.SetLibraryClass(LibraryItem
.GetLibraryName())
323 Lib
.SetUsage(DT
.USAGE_ITEM_PRODUCES
)
324 SupModuleList
= LibraryItem
.GetTypes()
325 self
.LibModuleTypeList
+= SupModuleList
326 Lib
.SetSupModuleList(SupModuleList
)
327 Lib
.SetSupArchList(ArchList
)
328 self
.SetLibraryClassList(self
.GetLibraryClassList() + [Lib
])
329 self
.SetIsLibrary(True)
330 self
.SetIsLibraryModList(self
.GetIsLibraryModList() + SupModuleList
)
332 ## GenModuleHeaderExterns
335 def _GenModuleHeaderExterns(self
, DefineObj
):
336 EntryPointList
= DefineObj
.GetEntryPoint()
337 for EntryPoint
in EntryPointList
:
338 Image
= ExternObject()
339 Image
.SetEntryPoint(EntryPoint
.GetCName())
343 self
.SetExternList(self
.GetExternList() + [Image
])
347 UnloadImageList
= DefineObj
.GetUnloadImages()
348 for UnloadImage
in UnloadImageList
:
349 Image
= ExternObject()
353 Image
.SetUnloadImage(UnloadImage
.GetCName())
354 self
.SetExternList(self
.GetExternList() + [Image
])
358 ConstructorList
= DefineObj
.GetConstructor()
359 for ConstructorItem
in ConstructorList
:
360 Image
= ExternObject()
364 Image
.SetConstructor(ConstructorItem
.GetCName())
365 self
.SetExternList(self
.GetExternList() + [Image
])
369 DestructorList
= DefineObj
.GetDestructor()
370 for DestructorItem
in DestructorList
:
371 Image
= ExternObject()
375 Image
.SetDestructor(DestructorItem
.GetCName())
376 self
.SetExternList(self
.GetExternList() + [Image
])
378 ## GenModuleHeaderExterns
381 def _GenSpecialComments(self
):
382 SpecialCommentsList
= self
.Parser
.InfSpecialCommentSection
.GetSpecialComments()
383 for Key
in SpecialCommentsList
:
384 if Key
== DT
.TYPE_HOB_SECTION
:
386 for Item
in SpecialCommentsList
[Key
]:
388 Hob
.SetHobType(Item
.GetHobType())
389 Hob
.SetUsage(Item
.GetUsage())
390 Hob
.SetSupArchList(Item
.GetSupArchList())
391 if Item
.GetHelpString():
392 HelpTextObj
= CommonObject
.TextObject()
393 HelpTextObj
.SetString(Item
.GetHelpString())
394 Hob
.SetHelpTextList([HelpTextObj
])
396 self
.SetHobList(HobList
)
397 elif Key
== DT
.TYPE_EVENT_SECTION
:
399 for Item
in SpecialCommentsList
[Key
]:
400 Event
= EventObject()
401 Event
.SetEventType(Item
.GetEventType())
402 Event
.SetUsage(Item
.GetUsage())
403 if Item
.GetHelpString():
404 HelpTextObj
= CommonObject
.TextObject()
405 HelpTextObj
.SetString(Item
.GetHelpString())
406 Event
.SetHelpTextList([HelpTextObj
])
407 EventList
.append(Event
)
408 self
.SetEventList(EventList
)
409 elif Key
== DT
.TYPE_BOOTMODE_SECTION
:
411 for Item
in SpecialCommentsList
[Key
]:
412 BootMode
= BootModeObject()
413 BootMode
.SetSupportedBootModes(Item
.GetSupportedBootModes())
414 BootMode
.SetUsage(Item
.GetUsage())
415 if Item
.GetHelpString():
416 HelpTextObj
= CommonObject
.TextObject()
417 HelpTextObj
.SetString(Item
.GetHelpString())
418 BootMode
.SetHelpTextList([HelpTextObj
])
419 BootModeList
.append(BootMode
)
420 self
.SetBootModeList(BootModeList
)
424 # Gen BuildOptions of Inf
425 # [<Family>:]<ToolFlag>=Flag
428 def _GenBuildOptions(self
):
429 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BUILD_OPTIONS
)
431 # Get all BuildOptions
433 BuildOptionsList
= self
.Parser
.InfBuildOptionSection
.GetBuildOptions()
434 if not GlobalData
.gIS_BINARY_INF
:
437 for BuildOptionObj
in BuildOptionsList
:
438 ArchList
= BuildOptionObj
.GetSupArchList()
439 ArchList
= ConvertArchList(ArchList
)
440 BuildOptionsContent
= BuildOptionObj
.GetContent()
441 ArchString
= ' '.join(ArchList
)
443 if not BuildOptionsContent
:
446 BuildOptionDict
[ArchString
] = BuildOptionsContent
448 if not BuildOptionDict
:
450 UserExtension
= CommonObject
.UserExtensionObject()
451 UserExtension
.SetBuildOptionDict(BuildOptionDict
)
452 UserExtension
.SetIdentifier('BuildOptionModifiers')
453 UserExtension
.SetUserID('EDK2')
454 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
457 # Not process this information, will be processed in GenBinaries()
463 # Get LibraryClass of Inf
464 # <LibraryClassKeyWord>|<LibraryInstance>
466 # @param ContainerFile: The Inf file full path
468 def _GenLibraryClasses(self
):
469 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_LIBRARY_CLASSES
)
470 if not GlobalData
.gIS_BINARY_INF
:
472 # Get all LibraryClasses
474 LibClassObj
= self
.Parser
.InfLibraryClassSection
.LibraryClasses
475 Keys
= LibClassObj
.keys()
478 LibraryClassData
= LibClassObj
[Key
]
479 for Item
in LibraryClassData
:
480 LibraryClass
= CommonObject
.LibraryClassObject()
481 LibraryClass
.SetUsage(DT
.USAGE_ITEM_CONSUMES
)
482 LibraryClass
.SetLibraryClass(Item
.GetLibName())
483 LibraryClass
.SetRecommendedInstance(None)
484 LibraryClass
.SetFeatureFlag(Item
.GetFeatureFlagExp())
485 LibraryClass
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
486 LibraryClass
.SetSupModuleList(Item
.GetSupModuleList())
487 HelpStringObj
= Item
.GetHelpString()
489 if HelpStringObj
!= None:
490 CommentString
= GetHelpStringByRemoveHashKey(HelpStringObj
.HeaderComments
+
491 HelpStringObj
.TailComments
)
492 HelpTextHeaderObj
= CommonObject
.TextObject()
493 HelpTextHeaderObj
.SetString(CommentString
)
494 LibraryClass
.SetHelpTextList([HelpTextHeaderObj
])
496 self
.SetLibraryClassList(self
.GetLibraryClassList() + [LibraryClass
])
500 # Gen Packages of Inf
503 # @param ContainerFile: The Inf file full path
505 def _GenPackages(self
, Skip
):
506 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PACKAGES
)
510 PackageObj
= self
.Parser
.InfPackageSection
.Packages
513 # Go through each arch
515 for PackageItemObj
in PackageObj
:
517 # Need package information for dependency check usage
519 PackageDependency
= PackageDependencyObject()
520 PackageDependency
.SetPackageFilePath(NormPath(PackageItemObj
.GetPackageName()))
521 PackageDependency
.SetSupArchList(ConvertArchList(PackageItemObj
.GetSupArchList()))
522 PackageDependency
.SetFeatureFlag(PackageItemObj
.GetFeatureFlagExp())
524 PkgInfo
= GetPkgInfoFromDec(os
.path
.normpath(os
.path
.join(self
.WorkSpace
,
525 NormPath(PackageItemObj
.GetPackageName()))))
526 if PkgInfo
[1] and PkgInfo
[2]:
527 PackageDependency
.SetGuid(PkgInfo
[1])
528 PackageDependency
.SetVersion(PkgInfo
[2])
532 Logger
.Error("\nUPT", PARSER_ERROR
,
533 ST
.ERR_INF_GET_PKG_DEPENDENCY_FAIL
% PackageItemObj
.GetPackageName(), File
=self
.FullPath
)
535 PackageDependencyList
= self
.GetPackageDependencyList()
536 PackageDependencyList
.append(PackageDependency
)
537 self
.SetPackageDependencyList(PackageDependencyList
)
542 # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]]
544 # @param ContainerFile: The Inf file full path
547 if not GlobalData
.gIS_BINARY_INF
:
548 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PCDS
)
553 PcdObj
= self
.Parser
.InfPcdSection
.Pcds
554 KeysList
= PcdObj
.keys()
557 # Go through each arch
559 for (PcdType
, PcdKey
) in KeysList
:
560 PcdData
= PcdObj
[PcdType
, PcdKey
]
561 for PcdItemObj
in PcdData
:
562 CommentList
= PcdItemObj
.GetHelpStringList()
564 for CommentItem
in CommentList
:
565 Pcd
= CommonObject
.PcdObject()
566 Pcd
.SetCName(PcdItemObj
.GetCName())
567 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
568 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
569 Pcd
.SetItemType(PcdType
)
570 Pcd
.SetValidUsage(CommentItem
.GetUsageItem())
571 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
572 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
573 HelpTextObj
= CommonObject
.TextObject()
574 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
575 Pcd
.SetHelpTextList([HelpTextObj
])
576 PcdList
= self
.GetPcdList()
578 self
.SetPcdList(PcdList
)
583 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
585 # @param ContainerFile: The Inf file full path
587 def _GenSources(self
):
588 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_SOURCES
)
591 # Get all SourceFiles
593 SourceObj
= self
.Parser
.InfSourcesSection
.Sources
594 DataList
= SourceObj
.keys()
596 # Go through each arch
600 SourceData
= SourceObj
[Key
]
601 for Item
in SourceData
:
602 SourceFile
= Item
.GetSourceFileName()
603 Family
= Item
.GetFamily()
604 FeatureFlag
= Item
.GetFeatureFlagExp()
605 SupArchList
= ConvertArchList(Item
.GetSupArchList())
607 Source
= SourceFileObject()
608 Source
.SetSourceFile(SourceFile
)
609 Source
.SetFamily(Family
)
610 Source
.SetFeatureFlag(FeatureFlag
)
611 Source
.SetSupArchList(SupArchList
)
612 SourceList
.append(Source
)
614 self
.SetSourceFileList(self
.GetSourceFileList() + SourceList
)
619 # Gen UserExtensions of Inf
621 def _GenUserExtensions(self
):
625 UserExtensionObj
= self
.Parser
.InfUserExtensionSection
.UserExtension
626 Keys
= UserExtensionObj
.keys()
629 UserExtensionData
= UserExtensionObj
[Key
]
630 for UserExtensionDataObj
in UserExtensionData
:
631 UserExtension
= CommonObject
.UserExtensionObject()
632 UserId
= UserExtensionDataObj
.GetUserId()
633 if UserId
.startswith('"') and UserId
.endswith('"'):
634 UserId
= UserId
[1:-1]
635 UserExtension
.SetUserID(UserId
)
636 Identifier
= UserExtensionDataObj
.GetIdString()
637 if Identifier
.startswith('"') and Identifier
.endswith('"'):
638 Identifier
= Identifier
[1:-1]
639 UserExtension
.SetIdentifier(Identifier
)
640 UserExtension
.SetStatement(UserExtensionDataObj
.GetContent())
641 UserExtension
.SetSupArchList(ConvertArchList(UserExtensionDataObj
.GetSupArchList()))
642 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
644 def _GenDepexesList(self
, SmmDepexList
, DxeDepexList
, PeiDepexList
):
646 self
.SetSmmDepex(SmmDepexList
)
648 self
.SetDxeDepex(DxeDepexList
)
650 self
.SetPeiDepex(PeiDepexList
)
656 # @param ContainerFile: The Inf file full path
658 def _GenDepexes(self
):
659 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_DEPEX
)
661 PEI_LIST
= [DT
.SUP_MODULE_PEIM
]
662 SMM_LIST
= [DT
.SUP_MODULE_DXE_SMM_DRIVER
]
663 DXE_LIST
= [DT
.SUP_MODULE_DXE_DRIVER
, DT
.SUP_MODULE_DXE_SAL_DRIVER
,
664 DT
.SUP_MODULE_DXE_RUNTIME_DRIVER
]
666 IsLibraryClass
= self
.GetIsLibrary()
670 DepexData
= self
.Parser
.InfDepexSection
.GetDepex()
674 for Depex
in DepexData
:
675 ModuleType
= Depex
.GetModuleType()
678 if not self
.GetIsLibraryModList():
679 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS
,
680 self
.GetFullPath(), RaiseError
=True)
681 if ModuleType
and ModuleType
not in self
.GetIsLibraryModList():
682 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
683 self
.GetFullPath(), RaiseError
=True)
685 ModuleTypeList
= [ModuleType
]
687 for ModuleTypeInList
in self
.GetIsLibraryModList():
688 if ModuleTypeInList
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
689 ModuleTypeList
.append(ModuleTypeInList
)
690 if not ModuleTypeList
:
691 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
692 self
.GetFullPath(), RaiseError
=True)
695 ModuleType
= self
.ModuleType
696 if ModuleType
not in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
697 Logger
.Error("\nMkPkg", PARSER_ERROR
,
698 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
699 self
.GetFullPath(), RaiseError
=True)
700 if ModuleType
!= self
.ModuleType
:
701 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
702 self
.GetFullPath(), RaiseError
=True)
703 ModuleTypeList
= [ModuleType
]
704 for ModuleType
in ModuleTypeList
:
705 DepexIns
= DepexObject()
706 DepexIns
.SetDepex(Depex
.GetDepexContent())
708 DepexIns
.SetModuleType(ModuleType
)
710 if Depex
.GetModuleType():
711 DepexIns
.SetModuleType(Depex
.GetModuleType())
712 DepexIns
.SetSupArchList(ConvertArchList([Depex
.GetSupArch()]))
713 DepexIns
.SetFeatureFlag(Depex
.GetFeatureFlagExp())
715 HelpIns
= CommonObject
.TextObject()
716 HelpIns
.SetString(GetHelpStringByRemoveHashKey(Depex
.HelpString
))
717 DepexIns
.SetHelpText(HelpIns
)
719 if ModuleType
in SMM_LIST
:
720 SmmDepexList
.append(DepexIns
)
721 if ModuleType
in DXE_LIST
:
722 DxeDepexList
.append(DepexIns
)
723 if ModuleType
in PEI_LIST
:
724 PeiDepexList
.append(DepexIns
)
725 if ModuleType
== DT
.SUP_MODULE_UEFI_DRIVER
:
727 DxeDepexList
.append(DepexIns
)
729 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER
,
730 self
.GetFullPath(), RaiseError
=True)
732 #End of for ModuleType in ModuleTypeList
733 self
._GenDepexesList
(SmmDepexList
, DxeDepexList
, PeiDepexList
)
734 #End of for Depex in DepexData
738 # Gen Binary of Inf, must be called after Pcd/Library is generated
739 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
741 # @param ContainerFile: The Inf file full path
743 def _GenBinaries(self
):
744 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BINARIES
)
748 # Get all Binary data
750 BinaryObj
= self
.Parser
.InfBinariesSection
.GetBinary()
752 BinaryData
= BinaryObj
.keys()
756 # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section,
757 # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute
759 if BinaryObj
and not self
.Parser
.InfSourcesSection
.GetSources():
760 self
.BinaryModule
= True
762 self
.BinaryModule
= False
764 BinaryFileObjectList
= []
765 AsBuildLibraryClassList
= []
766 AsBuildBuildOptionList
= []
767 AsBuildIns
= AsBuiltObject()
769 # Library AsBuild Info
771 for LibItem
in self
.Parser
.InfLibraryClassSection
.GetLibraryClasses():
772 AsBuildLibIns
= AsBuildLibraryClassObject()
773 AsBuildLibIns
.SetLibGuid(LibItem
.GetFileGuid())
774 AsBuildLibIns
.SetLibVersion(LibItem
.GetVersion())
775 AsBuildLibraryClassList
.append(AsBuildLibIns
)
776 AsBuildIns
.SetLibraryInstancesList(AsBuildLibraryClassList
)
779 # BuildOption AsBuild Info
781 for BuildOptionItem
in self
.Parser
.InfBuildOptionSection
.GetBuildOptions():
782 AsBuildBuildOptionList
+= BuildOptionItem
.GetAsBuildList()
783 AsBuildIns
.SetBuildFlagsList(AsBuildBuildOptionList
)
788 AsBuildIns
= self
._GenAsBuiltPcds
(self
.Parser
.InfPcdSection
.GetPcds(), AsBuildIns
)
790 BinariesDict
, AsBuildIns
, BinaryFileObjectList
= GenBinaryData(BinaryData
, BinaryObj
,
793 BinaryFileObjectList
,
794 self
.GetSupArchList(),
798 for Key
in BinariesDict
:
799 ValueList
= BinariesDict
[Key
]
800 if len(ValueList
) > 1:
801 BinariesDict2
[Key
] = ValueList
804 # if there is no TagName, ToolCode, HelpStr,
805 # then do not need to put them into userextension
807 (Target
, Family
, TagName
, HelpStr
) = ValueList
[0]
808 if not (Target
or Family
or TagName
or HelpStr
):
811 BinariesDict2
[Key
] = ValueList
813 self
.SetBinaryFileList(self
.GetBinaryFileList() + BinaryFileObjectList
)
816 UserExtension
= CommonObject
.UserExtensionObject()
817 UserExtension
.SetBinariesDict(BinariesDict2
)
818 UserExtension
.SetIdentifier('BinaryFileModifiers')
819 UserExtension
.SetUserID('EDK2')
820 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
825 def _GenAsBuiltPcds(self
, PcdList
, AsBuildIns
):
826 AsBuildPatchPcdList
= []
827 AsBuildPcdExList
= []
831 for PcdItem
in PcdList
:
832 if PcdItem
[0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
833 PcdItemObj
= PcdItem
[1]
834 Pcd
= CommonObject
.PcdObject()
835 Pcd
.SetCName(PcdItemObj
.GetCName())
836 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
837 if PcdItemObj
.GetTokenSpaceGuidValue() == '' and self
.BinaryModule
:
838 Logger
.Error("\nMkPkg",
840 ST
.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS
% \
841 (PcdItemObj
.GetTokenSpaceGuidCName()),
842 self
.GetFullPath(), RaiseError
=True)
844 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
845 if (PcdItemObj
.GetToken() == '' or PcdItemObj
.GetDatumType() == '') and self
.BinaryModule
:
846 Logger
.Error("\nMkPkg",
848 ST
.ERR_ASBUILD_PCD_DECLARITION_MISS
% \
849 (PcdItemObj
.GetTokenSpaceGuidCName() + '.' + PcdItemObj
.GetCName()),
850 self
.GetFullPath(), RaiseError
=True)
851 Pcd
.SetToken(PcdItemObj
.GetToken())
852 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
853 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
854 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
855 Pcd
.SetOffset(PcdItemObj
.GetOffset())
856 Pcd
.SetItemType(PcdItem
[0])
857 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
858 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
859 HelpTextObj
= CommonObject
.TextObject()
860 HelpTextObj
.SetString(PcdItemObj
.GetHelpStringList())
861 Pcd
.SetHelpTextList([HelpTextObj
])
862 AsBuildPatchPcdList
.append(Pcd
)
864 PcdItemObj
= PcdItem
[1]
865 Pcd
= CommonObject
.PcdObject()
866 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
867 Pcd
.SetToken(PcdItemObj
.GetToken())
868 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
869 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
870 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
871 Pcd
.SetItemType(PcdItem
[0])
872 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
873 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
874 HelpTextObj
= CommonObject
.TextObject()
875 HelpTextObj
.SetString(PcdItemObj
.GetHelpStringList())
876 Pcd
.SetHelpTextList([HelpTextObj
])
877 AsBuildPcdExList
.append(Pcd
)
878 AsBuildIns
.SetPatchPcdList(AsBuildPatchPcdList
)
879 AsBuildIns
.SetPcdExList(AsBuildPcdExList
)
883 ## GenGuidProtocolPpis
885 # Gen Guids/Protocol/Ppis of INF
886 # <CName>=<GuidValue>
888 def _GenGuidProtocolPpis(self
, Type
):
889 Logger
.Debug(2, "Generate %s ..." % Type
)
891 # Get all Guid/Protocol/Ppis data
893 GuidObj
= self
.Parser
.InfGuidSection
.GetGuid()
894 ProtocolObj
= self
.Parser
.InfProtocolSection
.GetProtocol()
895 PpisObj
= self
.Parser
.InfPpiSection
.GetPpi()
897 GuidProtocolPpiList
= []
899 if Type
== DT
.TAB_GUIDS
:
900 GuidData
= GuidObj
.keys()
901 for Item
in GuidData
:
902 CommentList
= Item
.GetCommentList()
904 # Depend on CommentList content
905 # generate muti-guid-obj
908 for GuidComentItem
in CommentList
:
909 ListObject
= CommonObject
.GuidObject()
910 ListObject
.SetGuidTypeList([GuidComentItem
.GetGuidTypeItem()])
911 ListObject
.SetVariableName(GuidComentItem
.GetVariableNameItem())
912 ListObject
.SetUsage(GuidComentItem
.GetUsageItem())
913 ListObject
.SetName(Item
.GetName())
914 ListObject
.SetCName(Item
.GetName())
915 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
916 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
917 HelpString
= GuidComentItem
.GetHelpStringItem()
918 HelpTxtTailObj
= CommonObject
.TextObject()
919 HelpTxtTailObj
.SetString(HelpString
)
921 ListObject
.SetHelpTextList([HelpTxtTailObj
])
923 GuidProtocolPpiList
.append(ListObject
)
924 elif Type
== DT
.TAB_PROTOCOLS
:
925 ProtocolData
= ProtocolObj
.keys()
926 for Item
in ProtocolData
:
927 CommentList
= Item
.GetCommentList()
928 for CommentItem
in CommentList
:
929 ListObject
= CommonObject
.ProtocolObject()
930 ListObject
.SetCName(Item
.GetName())
931 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
932 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
933 ListObject
.SetNotify(CommentItem
.GetNotify())
934 ListObject
.SetUsage(CommentItem
.GetUsageItem())
935 HelpTxtObj
= CommonObject
.TextObject()
936 HelpString
= CommentItem
.GetHelpStringItem()
937 HelpTxtObj
.SetString(HelpString
)
938 ListObject
.SetHelpTextList([HelpTxtObj
])
939 GuidProtocolPpiList
.append(ListObject
)
940 elif Type
== DT
.TAB_PPIS
:
941 PpiData
= PpisObj
.keys()
943 CommentList
= Item
.GetCommentList()
944 for CommentItem
in CommentList
:
945 ListObject
= CommonObject
.PpiObject()
946 ListObject
.SetCName(Item
.GetName())
947 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
948 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
949 ListObject
.SetNotify(CommentItem
.GetNotify())
950 ListObject
.SetUsage(CommentItem
.GetUsage())
951 HelpTextObj
= CommonObject
.TextObject()
952 HelpString
= CommentItem
.GetHelpStringItem()
953 HelpTextObj
.SetString(HelpString
)
954 ListObject
.SetHelpTextList([HelpTextObj
])
955 GuidProtocolPpiList
.append(ListObject
)
957 if Type
== DT
.TAB_GUIDS
:
958 self
.SetGuidList(self
.GetGuidList() + GuidProtocolPpiList
)
959 elif Type
== DT
.TAB_PROTOCOLS
:
960 self
.SetProtocolList(self
.GetProtocolList() + GuidProtocolPpiList
)
961 elif Type
== DT
.TAB_PPIS
:
962 self
.SetPpiList(self
.GetPpiList() + GuidProtocolPpiList
)
966 # Gen MiscellaneousFiles of Inf
968 # @param ContainerFile: The Inf file full path
970 def _GenMiscFiles(self
, ContainerFile
, Skip
):