1 ## @file InfPomAlignment.py
2 # This file contained the adapter for convert INF parser object to POM Object
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 from Logger
import StringTable
as ST
16 import Logger
.Log
as Logger
17 from Library
.StringUtils
import FORMAT_INVALID
18 from Library
.StringUtils
import PARSER_ERROR
19 from Library
.StringUtils
import NormPath
20 from Library
.StringUtils
import GetSplitValueList
21 from Library
.Misc
import ConvertVersionToDecimal
22 from Library
.Misc
import GetHelpStringByRemoveHashKey
23 from Library
.Misc
import ConvertArchList
24 from Library
.Misc
import GetRelativePath
25 from Library
.Misc
import PathClass
26 from Library
.Parsing
import GetPkgInfoFromDec
27 from Library
.UniClassObject
import UniFileClassObject
28 from Library
.UniClassObject
import ConvertSpecialUnicodes
29 from Library
.UniClassObject
import GetLanguageCode1766
30 from Library
import DataType
as DT
31 from Library
import GlobalData
32 from Library
.ParserValidate
import IsValidPath
33 from Object
.POM
import CommonObject
34 from Object
.POM
.ModuleObject
import ModuleObject
35 from Object
.POM
.ModuleObject
import ExternObject
36 from Object
.POM
.ModuleObject
import HobObject
37 from Object
.POM
.ModuleObject
import EventObject
38 from Object
.POM
.ModuleObject
import BootModeObject
39 from Object
.POM
.ModuleObject
import PackageDependencyObject
40 from Object
.POM
.ModuleObject
import SourceFileObject
41 from Object
.POM
.ModuleObject
import DepexObject
42 from Object
.POM
.ModuleObject
import AsBuildLibraryClassObject
43 from Object
.POM
.ModuleObject
import AsBuiltObject
44 from PomAdapter
.InfPomAlignmentMisc
import GenModuleHeaderUserExt
45 from PomAdapter
.InfPomAlignmentMisc
import GenBinaryData
46 from Parser
import InfParser
47 from PomAdapter
.DecPomAlignment
import DecPomAlignment
48 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
52 # Inherit from ModuleObject
54 class InfPomAlignment(ModuleObject
):
55 ## Construct of InfPomAlignment
56 # Skip means that UPT don't care the syntax of INF, this may be the not
57 # distributed INF files during creation or the INF files checked for
58 # dependency rule during remove.
60 def __init__(self
, FileName
, WorkSpace
=None, PackagePath
='', Skip
=False):
61 ModuleObject
.__init
__(self
)
63 self
.FileName
= FileName
64 self
.WorkSpace
= WorkSpace
66 self
.LibModuleTypeList
= []
69 self
.WorkspaceDir
= " "
70 self
.CustomMakefile
= []
71 self
.UniFileClassObject
= None
72 self
.SetPackagePath(PackagePath
)
74 # Call GenInfPomObjects function to fill POM object.
77 OrigConfig
= Logger
.SUPRESS_ERROR
78 Logger
.SUPRESS_ERROR
= True
80 self
._GenInfPomObjects
(Skip
)
82 Logger
.SUPRESS_ERROR
= OrigConfig
84 self
._GenInfPomObjects
(Skip
)
87 # Generate all POM objects, the original input comes
88 # from INF parser's output
90 def _GenInfPomObjects(self
, Skip
):
92 # Call INF Parser to get information from INF file
94 self
.Parser
= InfParser
.InfParser(self
.FileName
, self
.WorkSpace
)
95 self
.FullPath
= self
.Parser
.FullPath
97 self
._GenModuleHeader
()
99 # Call GenBinaries after Module Header for Binary INF consideration.
102 self
._GenBuildOptions
()
103 self
._GenLibraryClasses
()
104 self
._GenPackages
(Skip
)
107 self
._GenUserExtensions
()
108 self
._GenGuidProtocolPpis
(DT
.TAB_GUIDS
)
109 self
._GenGuidProtocolPpis
(DT
.TAB_PROTOCOLS
)
110 self
._GenGuidProtocolPpis
(DT
.TAB_PPIS
)
113 ## Convert [Defines] section content to InfDefObject
115 # Convert [Defines] section content to InfDefObject
117 # @param Defines The content under [Defines] section
118 # @param ModuleHeader An object of ModuleHeaderClass
119 # @param Arch The supported ARCH
121 def _GenModuleHeader(self
):
122 Logger
.Debug(2, "Generate ModuleHeader ...")
124 # Get all defines information form InfParser Object
126 RecordSet
= self
.Parser
.InfDefSection
.Defines
128 # Should only have one ArchString Item.
130 ArchString
= list(RecordSet
.keys())[0]
131 ArchList
= GetSplitValueList(ArchString
, ' ')
132 ArchList
= ConvertArchList(ArchList
)
133 HasCalledFlag
= False
135 # Get data from Sdict()
137 ValueList
= RecordSet
[ArchString
]
138 self
.SetFileName(self
.FileName
)
139 self
.SetFullPath(self
.FullPath
)
141 # The INF's filename (without the directory path or the extension)
142 # must be used for the value of the
143 # ModuleSurfaceArea.Header.Name element
145 self
.SetName(os
.path
.splitext(os
.path
.basename(self
.FileName
))[0])
146 self
.WorkspaceDir
= " "
148 # CombinePath and ModulePath
150 CombinePath
= GetRelativePath(self
.FullPath
, self
.WorkSpace
)
151 self
.SetCombinePath(CombinePath
)
152 ModulePath
= os
.path
.split(CombinePath
)[0]
153 ModuleRelativePath
= ModulePath
154 if self
.GetPackagePath() != '':
155 ModuleRelativePath
= GetRelativePath(ModulePath
, self
.GetPackagePath())
156 self
.SetModulePath(ModuleRelativePath
)
158 # For Define Seciton Items.
160 DefineObj
= ValueList
162 # Convert UEFI/PI version to decimal number
164 if DefineObj
.GetUefiSpecificationVersion() is not None:
165 __UefiVersion
= DefineObj
.GetUefiSpecificationVersion().GetValue()
166 __UefiVersion
= ConvertVersionToDecimal(__UefiVersion
)
167 self
.SetUefiSpecificationVersion(str(__UefiVersion
))
168 if DefineObj
.GetPiSpecificationVersion() is not None:
169 __PiVersion
= DefineObj
.GetPiSpecificationVersion().GetValue()
170 __PiVersion
= ConvertVersionToDecimal(__PiVersion
)
172 self
.SetPiSpecificationVersion(str(__PiVersion
))
173 SpecList
= DefineObj
.GetSpecification()
175 for SpecItem
in SpecList
:
176 NewSpecList
.append((SpecItem
[0], ConvertVersionToDecimal(SpecItem
[1])))
177 self
.SetSpecList(NewSpecList
)
180 # must exist items in INF define section
181 # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING
183 if DefineObj
.GetModuleType() is None:
184 Logger
.Error("InfParser", FORMAT_INVALID
,
185 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("MODULE_TYPE"), File
=self
.FullPath
)
187 self
.SetModuleType(DefineObj
.GetModuleType().GetValue())
188 ModuleType
= DefineObj
.GetModuleType().GetValue()
191 # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only
192 # libraries are permitted to a have a MODULE_TYPE of "BASE".
194 if len(DefineObj
.LibraryClass
) == 0 and ModuleType
== 'BASE':
195 Logger
.Error("InfParser",
197 ST
.ERR_INF_PARSER_MODULETYPE_INVALID
,
199 Line
=DefineObj
.ModuleType
.CurrentLine
.LineNo
,
200 ExtraData
=DefineObj
.ModuleType
.CurrentLine
.LineString
)
201 self
.LibModuleTypeList
.append(ModuleType
)
202 if DefineObj
.GetBaseName() is None:
203 Logger
.Error("InfParser", FORMAT_INVALID
,
204 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("BASE_NAME"), File
=self
.FullPath
)
206 self
.SetBaseName(DefineObj
.GetBaseName().GetValue())
207 if DefineObj
.GetModuleUniFileName():
208 self
.UniFileClassObject
= UniFileClassObject([PathClass(DefineObj
.GetModuleUniFileName())])
210 self
.UniFileClassObject
= None
211 if DefineObj
.GetInfVersion() is None:
212 Logger
.Error("InfParser", FORMAT_INVALID
,
213 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("INF_VERSION"), File
=self
.FullPath
)
215 self
.SetVersion(DefineObj
.GetInfVersion().GetValue())
216 if DefineObj
.GetFileGuid() is None:
217 Logger
.Error("InfParser", FORMAT_INVALID
,
218 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("FILE_GUID"), File
=self
.FullPath
)
220 self
.SetGuid(DefineObj
.GetFileGuid().GetValue())
221 if DefineObj
.GetVersionString() is None:
223 # VERSION_STRING is missing from the [Defines] section, tools must assume that the module's version is 0.
230 if DefineObj
.GetVersionString().GetValue() != "":
234 VersionString
= DefineObj
.GetVersionString().GetValue()
235 if len(VersionString
) > 0:
236 VersionString
= ConvertVersionToDecimal(VersionString
)
237 self
.SetVersion(VersionString
)
242 Logger
.Error("Parser", PARSER_ERROR
, ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
, ExtraData
=self
.FullPath
,
243 RaiseError
=Logger
.IS_RAISE_ERROR
)
245 # if there is Shadow, Should judge the MODULE_TYPE in
246 # SEC, PEI_CORE and PEIM
248 if DefineObj
.GetShadow():
249 ModuleTypeValue
= DefineObj
.GetModuleType().GetValue()
250 if not (ModuleTypeValue
== 'SEC' or ModuleTypeValue
== 'PEI_CORE' or ModuleTypeValue
== 'PEIM'):
251 Logger
.Error("InfParser", FORMAT_INVALID
, ST
.ERR_INF_PARSER_DEFINE_SHADOW_INVALID
, File
=self
.FullPath
)
253 if DefineObj
.GetPcdIsDriver() is not None:
254 self
.SetPcdIsDriver(DefineObj
.GetPcdIsDriver().GetValue())
258 self
._GenModuleHeaderLibClass
(DefineObj
, ArchList
)
262 self
.CustomMakefile
= DefineObj
.GetCustomMakefile()
264 # Externs in Defines section
265 # Only one define section, so just call once.
267 if not HasCalledFlag
:
268 self
._GenModuleHeaderExterns
(DefineObj
)
271 # each module has only one module header
273 self
.SetSupArchList(ArchList
)
275 # Get Hob/BootMode/EventList information
277 self
._GenSpecialComments
()
279 # put all define statement into user-extension sections
281 DefinesDictNew
= GenModuleHeaderUserExt(DefineObj
, ArchString
)
283 UserExtension
= CommonObject
.UserExtensionObject()
284 UserExtension
.SetDefinesDict(DefinesDictNew
)
285 UserExtension
.SetIdentifier('DefineModifiers')
286 UserExtension
.SetUserID('EDK2')
287 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
289 # Get all meta-file header information
290 # the record is list of items formatted:
291 # [LineValue, Arch, StartLine, ID, Third]
293 InfHeaderObj
= self
.Parser
.InfHeader
295 # Put header information into POM object
297 if self
.UniFileClassObject
:
298 Lang
= DT
.TAB_LANGUAGE_EN_X
300 Lang
= DT
.TAB_LANGUAGE_EN_US
301 if InfHeaderObj
.GetAbstract():
302 self
.SetAbstract((Lang
, InfHeaderObj
.GetAbstract()))
303 if InfHeaderObj
.GetDescription():
304 self
.SetDescription((Lang
, InfHeaderObj
.GetDescription()))
305 if InfHeaderObj
.GetCopyright():
306 self
.SetCopyright(('', InfHeaderObj
.GetCopyright()))
307 if InfHeaderObj
.GetLicense():
308 self
.SetLicense(('', InfHeaderObj
.GetLicense()))
310 # Put Binary header information into POM object
312 InfBinaryHeaderObj
= self
.Parser
.InfBinaryHeader
313 if InfBinaryHeaderObj
.GetAbstract():
314 self
.SetBinaryHeaderAbstract((Lang
, InfBinaryHeaderObj
.GetAbstract()))
315 if InfBinaryHeaderObj
.GetDescription():
316 self
.SetBinaryHeaderDescription((Lang
, InfBinaryHeaderObj
.GetDescription()))
317 if InfBinaryHeaderObj
.GetCopyright():
318 self
.SetBinaryHeaderCopyright(('', InfBinaryHeaderObj
.GetCopyright()))
319 if InfBinaryHeaderObj
.GetLicense():
320 self
.SetBinaryHeaderLicense(('', InfBinaryHeaderObj
.GetLicense()))
322 ## GenModuleHeaderLibClass
325 def _GenModuleHeaderLibClass(self
, DefineObj
, ArchList
):
326 LibraryList
= DefineObj
.GetLibraryClass()
327 for LibraryItem
in LibraryList
:
328 Lib
= CommonObject
.LibraryClassObject()
329 Lib
.SetLibraryClass(LibraryItem
.GetLibraryName())
330 Lib
.SetUsage(DT
.USAGE_ITEM_PRODUCES
)
331 SupModuleList
= LibraryItem
.GetTypes()
332 self
.LibModuleTypeList
+= SupModuleList
333 Lib
.SetSupModuleList(SupModuleList
)
334 Lib
.SetSupArchList(ArchList
)
335 self
.SetLibraryClassList(self
.GetLibraryClassList() + [Lib
])
336 self
.SetIsLibrary(True)
337 self
.SetIsLibraryModList(self
.GetIsLibraryModList() + SupModuleList
)
339 ## GenModuleHeaderExterns
342 def _GenModuleHeaderExterns(self
, DefineObj
):
343 EntryPointList
= DefineObj
.GetEntryPoint()
344 for EntryPoint
in EntryPointList
:
345 Image
= ExternObject()
346 Image
.SetEntryPoint(EntryPoint
.GetCName())
350 self
.SetExternList(self
.GetExternList() + [Image
])
354 UnloadImageList
= DefineObj
.GetUnloadImages()
355 for UnloadImage
in UnloadImageList
:
356 Image
= ExternObject()
360 Image
.SetUnloadImage(UnloadImage
.GetCName())
361 self
.SetExternList(self
.GetExternList() + [Image
])
365 ConstructorList
= DefineObj
.GetConstructor()
366 for ConstructorItem
in ConstructorList
:
367 Image
= ExternObject()
371 Image
.SetConstructor(ConstructorItem
.GetCName())
372 self
.SetExternList(self
.GetExternList() + [Image
])
376 DestructorList
= DefineObj
.GetDestructor()
377 for DestructorItem
in DestructorList
:
378 Image
= ExternObject()
382 Image
.SetDestructor(DestructorItem
.GetCName())
383 self
.SetExternList(self
.GetExternList() + [Image
])
385 ## GenModuleHeaderExterns
388 def _GenSpecialComments(self
):
389 SpecialCommentsList
= self
.Parser
.InfSpecialCommentSection
.GetSpecialComments()
390 for Key
in SpecialCommentsList
:
391 if Key
== DT
.TYPE_HOB_SECTION
:
393 for Item
in SpecialCommentsList
[Key
]:
395 Hob
.SetHobType(Item
.GetHobType())
396 Hob
.SetUsage(Item
.GetUsage())
397 Hob
.SetSupArchList(Item
.GetSupArchList())
398 if Item
.GetHelpString():
399 HelpTextObj
= CommonObject
.TextObject()
400 if self
.UniFileClassObject
:
401 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
402 HelpTextObj
.SetString(Item
.GetHelpString())
403 Hob
.SetHelpTextList([HelpTextObj
])
405 self
.SetHobList(HobList
)
406 elif Key
== DT
.TYPE_EVENT_SECTION
:
408 for Item
in SpecialCommentsList
[Key
]:
409 Event
= EventObject()
410 Event
.SetEventType(Item
.GetEventType())
411 Event
.SetUsage(Item
.GetUsage())
412 if Item
.GetHelpString():
413 HelpTextObj
= CommonObject
.TextObject()
414 if self
.UniFileClassObject
:
415 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
416 HelpTextObj
.SetString(Item
.GetHelpString())
417 Event
.SetHelpTextList([HelpTextObj
])
418 EventList
.append(Event
)
419 self
.SetEventList(EventList
)
420 elif Key
== DT
.TYPE_BOOTMODE_SECTION
:
422 for Item
in SpecialCommentsList
[Key
]:
423 BootMode
= BootModeObject()
424 BootMode
.SetSupportedBootModes(Item
.GetSupportedBootModes())
425 BootMode
.SetUsage(Item
.GetUsage())
426 if Item
.GetHelpString():
427 HelpTextObj
= CommonObject
.TextObject()
428 if self
.UniFileClassObject
:
429 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
430 HelpTextObj
.SetString(Item
.GetHelpString())
431 BootMode
.SetHelpTextList([HelpTextObj
])
432 BootModeList
.append(BootMode
)
433 self
.SetBootModeList(BootModeList
)
437 # Gen BuildOptions of Inf
438 # [<Family>:]<ToolFlag>=Flag
441 def _GenBuildOptions(self
):
442 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BUILD_OPTIONS
)
444 # Get all BuildOptions
446 BuildOptionsList
= self
.Parser
.InfBuildOptionSection
.GetBuildOptions()
447 if not GlobalData
.gIS_BINARY_INF
:
449 for BuildOptionObj
in BuildOptionsList
:
450 ArchList
= BuildOptionObj
.GetSupArchList()
451 ArchList
= ConvertArchList(ArchList
)
452 BuildOptionsContent
= BuildOptionObj
.GetContent()
453 ArchString
= ' '.join(ArchList
)
454 if not BuildOptionsContent
:
456 BuildOptionDict
[ArchString
] = BuildOptionsContent
457 if not BuildOptionDict
:
459 UserExtension
= CommonObject
.UserExtensionObject()
460 UserExtension
.SetBuildOptionDict(BuildOptionDict
)
461 UserExtension
.SetIdentifier('BuildOptionModifiers')
462 UserExtension
.SetUserID('EDK2')
463 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
466 # Not process this information, will be processed in GenBinaries()
472 # Get LibraryClass of Inf
473 # <LibraryClassKeyWord>|<LibraryInstance>
475 # @param ContainerFile: The Inf file full path
477 def _GenLibraryClasses(self
):
478 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_LIBRARY_CLASSES
)
479 if not GlobalData
.gIS_BINARY_INF
:
481 # Get all LibraryClasses
483 for LibraryClassData
in self
.Parser
.InfLibraryClassSection
.LibraryClasses
.values():
484 for Item
in LibraryClassData
:
485 LibraryClass
= CommonObject
.LibraryClassObject()
486 LibraryClass
.SetUsage(DT
.USAGE_ITEM_CONSUMES
)
487 LibraryClass
.SetLibraryClass(Item
.GetLibName())
488 LibraryClass
.SetRecommendedInstance(None)
489 LibraryClass
.SetFeatureFlag(Item
.GetFeatureFlagExp())
490 LibraryClass
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
491 LibraryClass
.SetSupModuleList(Item
.GetSupModuleList())
492 HelpStringObj
= Item
.GetHelpString()
493 if HelpStringObj
is not None:
494 CommentString
= GetHelpStringByRemoveHashKey(HelpStringObj
.HeaderComments
+
495 HelpStringObj
.TailComments
)
496 HelpTextHeaderObj
= CommonObject
.TextObject()
497 if self
.UniFileClassObject
:
498 HelpTextHeaderObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
499 HelpTextHeaderObj
.SetString(CommentString
)
500 LibraryClass
.SetHelpTextList([HelpTextHeaderObj
])
501 self
.SetLibraryClassList(self
.GetLibraryClassList() + [LibraryClass
])
505 # Gen Packages of Inf
508 # @param ContainerFile: The Inf file full path
510 def _GenPackages(self
, Skip
):
511 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PACKAGES
)
515 PackageObj
= self
.Parser
.InfPackageSection
.Packages
517 # Go through each arch
519 for PackageItemObj
in PackageObj
:
521 # Need package information for dependency check usage
523 PackageDependency
= PackageDependencyObject()
524 PackageDependency
.SetPackageFilePath(NormPath(PackageItemObj
.GetPackageName()))
525 PackageDependency
.SetSupArchList(ConvertArchList(PackageItemObj
.GetSupArchList()))
526 PackageDependency
.SetFeatureFlag(PackageItemObj
.GetFeatureFlagExp())
528 PkgInfo
= GetPkgInfoFromDec(mws
.join(self
.WorkSpace
, NormPath(PackageItemObj
.GetPackageName())))
529 if PkgInfo
[1] and PkgInfo
[2]:
530 PackageDependency
.SetGuid(PkgInfo
[1])
531 PackageDependency
.SetVersion(PkgInfo
[2])
535 Logger
.Error("\nUPT", PARSER_ERROR
,
536 ST
.ERR_INF_GET_PKG_DEPENDENCY_FAIL
% PackageItemObj
.GetPackageName(), File
=self
.FullPath
)
538 PackageDependencyList
= self
.GetPackageDependencyList()
539 PackageDependencyList
.append(PackageDependency
)
540 self
.SetPackageDependencyList(PackageDependencyList
)
545 # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]]
547 # @param ContainerFile: The Inf file full path
550 if not GlobalData
.gIS_BINARY_INF
:
551 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PCDS
)
555 PcdObj
= self
.Parser
.InfPcdSection
.Pcds
556 KeysList
= PcdObj
.keys()
558 # Go through each arch
560 for (PcdType
, PcdKey
) in KeysList
:
561 PcdData
= PcdObj
[PcdType
, PcdKey
]
562 for PcdItemObj
in PcdData
:
563 CommentList
= PcdItemObj
.GetHelpStringList()
565 for CommentItem
in CommentList
:
566 Pcd
= CommonObject
.PcdObject()
567 Pcd
.SetCName(PcdItemObj
.GetCName())
568 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
569 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
570 Pcd
.SetItemType(PcdType
)
571 Pcd
.SetValidUsage(CommentItem
.GetUsageItem())
572 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
573 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
574 HelpTextObj
= CommonObject
.TextObject()
575 if self
.UniFileClassObject
:
576 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
577 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
578 Pcd
.SetHelpTextList([HelpTextObj
])
579 PcdList
= self
.GetPcdList()
581 self
.SetPcdList(PcdList
)
586 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
588 # @param ContainerFile: The Inf file full path
590 def _GenSources(self
):
591 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_SOURCES
)
594 # Get all SourceFiles
596 SourceObj
= self
.Parser
.InfSourcesSection
.Sources
597 DataList
= SourceObj
.keys()
599 # Go through each arch
603 SourceData
= SourceObj
[Key
]
604 for Item
in SourceData
:
605 SourceFile
= Item
.GetSourceFileName()
606 Family
= Item
.GetFamily()
607 FeatureFlag
= Item
.GetFeatureFlagExp()
608 SupArchList
= sorted(ConvertArchList(Item
.GetSupArchList()))
609 Source
= SourceFileObject()
610 Source
.SetSourceFile(SourceFile
)
611 Source
.SetFamily(Family
)
612 Source
.SetFeatureFlag(FeatureFlag
)
613 Source
.SetSupArchList(SupArchList
)
614 SourceList
.append(Source
)
616 self
.SetSourceFileList(self
.GetSourceFileList() + SourceList
)
621 # Gen UserExtensions of Inf
623 def _GenUserExtensions(self
):
627 UserExtensionObj
= self
.Parser
.InfUserExtensionSection
.UserExtension
628 Keys
= UserExtensionObj
.keys()
631 UserExtensionData
= UserExtensionObj
[Key
]
632 for UserExtensionDataObj
in UserExtensionData
:
633 UserExtension
= CommonObject
.UserExtensionObject()
634 UserId
= UserExtensionDataObj
.GetUserId()
635 if UserId
.startswith('"') and UserId
.endswith('"'):
636 UserId
= UserId
[1:-1]
637 UserExtension
.SetUserID(UserId
)
638 Identifier
= UserExtensionDataObj
.GetIdString()
639 if Identifier
.startswith('"') and Identifier
.endswith('"'):
640 Identifier
= Identifier
[1:-1]
642 # Generate miscellaneous files on INF file
644 if UserId
== 'TianoCore' and Identifier
== 'ExtraFiles':
645 self
._GenMiscFiles
(UserExtensionDataObj
.GetContent())
646 UserExtension
.SetIdentifier(Identifier
)
647 UserExtension
.SetStatement(UserExtensionDataObj
.GetContent())
648 UserExtension
.SetSupArchList(ConvertArchList(UserExtensionDataObj
.GetSupArchList()))
649 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
652 # Gen UserExtensions of TianoCore."BinaryHeader"
655 #Get Binary header from INF file
656 BinaryAbstractList
= self
.BinaryHeaderAbstractList
657 BinaryDescriptionList
= self
.BinaryHeaderDescriptionList
658 BinaryCopyrightList
= self
.BinaryHeaderCopyrightList
659 BinaryLicenseList
= self
.BinaryHeaderLicenseList
660 #Get Binary header from UNI file
661 # Initialize UniStrDict, the top keys are language codes
663 if self
.UniFileClassObject
:
664 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
665 for Lang
in UniStrDict
:
666 for StringDefClassObject
in UniStrDict
[Lang
]:
667 Lang
= GetLanguageCode1766(Lang
)
668 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_ABSTRACT
:
669 BinaryAbstractList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
670 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_DESCRIPTION
:
671 BinaryDescriptionList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
672 if BinaryAbstractList
or BinaryDescriptionList
or BinaryCopyrightList
or BinaryLicenseList
:
673 BinaryUserExtension
= CommonObject
.UserExtensionObject()
674 BinaryUserExtension
.SetBinaryAbstract(BinaryAbstractList
)
675 BinaryUserExtension
.SetBinaryDescription(BinaryDescriptionList
)
676 BinaryUserExtension
.SetBinaryCopyright(BinaryCopyrightList
)
677 BinaryUserExtension
.SetBinaryLicense(BinaryLicenseList
)
678 BinaryUserExtension
.SetIdentifier(DT
.TAB_BINARY_HEADER_IDENTIFIER
)
679 BinaryUserExtension
.SetUserID(DT
.TAB_BINARY_HEADER_USERID
)
680 self
.SetUserExtensionList(self
.GetUserExtensionList() + [BinaryUserExtension
])
682 def _GenDepexesList(self
, SmmDepexList
, DxeDepexList
, PeiDepexList
):
684 self
.SetSmmDepex(SmmDepexList
)
686 self
.SetDxeDepex(DxeDepexList
)
688 self
.SetPeiDepex(PeiDepexList
)
694 # @param ContainerFile: The Inf file full path
696 def _GenDepexes(self
):
697 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_DEPEX
)
699 PEI_LIST
= [DT
.SUP_MODULE_PEIM
]
700 SMM_LIST
= [DT
.SUP_MODULE_DXE_SMM_DRIVER
]
701 DXE_LIST
= [DT
.SUP_MODULE_DXE_DRIVER
, DT
.SUP_MODULE_DXE_SAL_DRIVER
,
702 DT
.SUP_MODULE_DXE_RUNTIME_DRIVER
]
704 IsLibraryClass
= self
.GetIsLibrary()
708 DepexData
= self
.Parser
.InfDepexSection
.GetDepex()
712 for Depex
in DepexData
:
713 ModuleType
= Depex
.GetModuleType()
716 if self
.GetModuleType() == 'BASE' and not ModuleType
:
717 Logger
.Error("\nMkPkg", PARSER_ERROR
,
718 ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS
,
719 self
.GetFullPath(), RaiseError
=True)
720 if self
.GetModuleType() != 'BASE' and not self
.GetIsLibraryModList():
721 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS
,
722 self
.GetFullPath(), RaiseError
=True)
723 if self
.GetModuleType() != 'BASE' and ModuleType
and ModuleType
not in self
.GetIsLibraryModList():
724 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
725 self
.GetFullPath(), RaiseError
=True)
727 ModuleTypeList
= [ModuleType
]
729 for ModuleTypeInList
in self
.GetIsLibraryModList():
730 if ModuleTypeInList
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
731 ModuleTypeList
.append(ModuleTypeInList
)
732 if not ModuleTypeList
:
733 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
734 self
.GetFullPath(), RaiseError
=True)
737 ModuleType
= self
.ModuleType
738 if ModuleType
not in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
739 Logger
.Error("\nMkPkg", PARSER_ERROR
,
740 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
741 self
.GetFullPath(), RaiseError
=True)
742 if ModuleType
!= self
.ModuleType
:
743 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
744 self
.GetFullPath(), RaiseError
=True)
745 ModuleTypeList
= [ModuleType
]
746 for ModuleType
in ModuleTypeList
:
747 DepexIns
= DepexObject()
748 DepexIns
.SetDepex(Depex
.GetDepexContent())
750 DepexIns
.SetModuleType(ModuleType
)
752 if Depex
.GetModuleType():
753 DepexIns
.SetModuleType(Depex
.GetModuleType())
754 DepexIns
.SetSupArchList(ConvertArchList([Depex
.GetSupArch()]))
755 DepexIns
.SetFeatureFlag(Depex
.GetFeatureFlagExp())
757 HelpIns
= CommonObject
.TextObject()
758 if self
.UniFileClassObject
:
759 HelpIns
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
760 HelpIns
.SetString(GetHelpStringByRemoveHashKey(Depex
.HelpString
))
761 DepexIns
.SetHelpText(HelpIns
)
763 if ModuleType
in SMM_LIST
:
764 SmmDepexList
.append(DepexIns
)
765 if ModuleType
in DXE_LIST
:
766 DxeDepexList
.append(DepexIns
)
767 if ModuleType
in PEI_LIST
:
768 PeiDepexList
.append(DepexIns
)
769 if ModuleType
== DT
.SUP_MODULE_UEFI_DRIVER
:
771 DxeDepexList
.append(DepexIns
)
773 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER
,
774 self
.GetFullPath(), RaiseError
=True)
776 #End of for ModuleType in ModuleTypeList
777 self
._GenDepexesList
(SmmDepexList
, DxeDepexList
, PeiDepexList
)
778 #End of for Depex in DepexData
782 # Gen Binary of Inf, must be called after Pcd/Library is generated
783 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
785 # @param ContainerFile: The Inf file full path
787 def _GenBinaries(self
):
788 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BINARIES
)
792 # Get all Binary data
794 BinaryObj
= self
.Parser
.InfBinariesSection
.GetBinary()
796 BinaryData
= BinaryObj
.keys()
799 # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section,
800 # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute
802 if BinaryObj
and not self
.Parser
.InfSourcesSection
.GetSources():
803 self
.BinaryModule
= True
805 self
.BinaryModule
= False
807 BinaryFileObjectList
= []
808 AsBuildLibraryClassList
= []
809 AsBuildBuildOptionList
= []
810 AsBuildIns
= AsBuiltObject()
812 # Library AsBuild Info
814 for LibItem
in self
.Parser
.InfLibraryClassSection
.GetLibraryClasses():
815 AsBuildLibIns
= AsBuildLibraryClassObject()
816 AsBuildLibIns
.SetLibGuid(LibItem
.GetFileGuid())
817 AsBuildLibIns
.SetLibVersion(LibItem
.GetVersion())
818 AsBuildLibIns
.SetSupArchList(LibItem
.GetSupArchList())
819 AsBuildLibraryClassList
.append(AsBuildLibIns
)
820 AsBuildIns
.SetLibraryInstancesList(AsBuildLibraryClassList
)
823 # BuildOption AsBuild Info
825 for BuildOptionItem
in self
.Parser
.InfBuildOptionSection
.GetBuildOptions():
826 AsBuildBuildOptionList
.append(BuildOptionItem
)
827 AsBuildIns
.SetBuildFlagsList(AsBuildBuildOptionList
)
832 AsBuildIns
= self
._GenAsBuiltPcds
(self
.Parser
.InfPcdSection
.GetPcds(), AsBuildIns
)
835 # Parse the DEC file that contains the GUID value of the GUID CName which is used by
836 # SUBTYPE_GUID type binary file in the Binaries section in the INF file
839 if not self
.PackagePath
:
840 WorkSpace
= os
.path
.normpath(self
.WorkSpace
)
841 TempPath
= ModulePath
= os
.path
.normpath(self
.ModulePath
)
843 TempPath
= ModulePath
844 ModulePath
= os
.path
.dirname(ModulePath
)
845 PackageName
= TempPath
846 DecFilePath
= os
.path
.normpath(os
.path
.join(WorkSpace
, PackageName
))
848 for File
in os
.listdir(DecFilePath
):
849 if File
.upper().endswith('.DEC'):
850 DecFileFullPath
= os
.path
.normpath(os
.path
.join(DecFilePath
, File
))
851 DecObjList
.append(DecPomAlignment(DecFileFullPath
, self
.WorkSpace
))
854 BinariesDict
, AsBuildIns
, BinaryFileObjectList
= GenBinaryData(BinaryData
, BinaryObj
,
857 BinaryFileObjectList
,
858 self
.GetSupArchList(),
863 for Key
in BinariesDict
:
864 ValueList
= BinariesDict
[Key
]
865 if len(ValueList
) > 1:
866 BinariesDict2
[Key
] = ValueList
869 # if there is no TagName, ToolCode, HelpStr,
870 # then do not need to put them into userextension
872 (Target
, Family
, TagName
, HelpStr
) = ValueList
[0]
873 if not (Target
or Family
or TagName
or HelpStr
):
876 BinariesDict2
[Key
] = ValueList
878 self
.SetBinaryFileList(self
.GetBinaryFileList() + BinaryFileObjectList
)
881 UserExtension
= CommonObject
.UserExtensionObject()
882 UserExtension
.SetBinariesDict(BinariesDict2
)
883 UserExtension
.SetIdentifier('BinaryFileModifiers')
884 UserExtension
.SetUserID('EDK2')
885 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
890 def _GenAsBuiltPcds(self
, PcdList
, AsBuildIns
):
891 AsBuildPatchPcdList
= []
892 AsBuildPcdExList
= []
896 for PcdItem
in PcdList
:
897 if PcdItem
[0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
898 PcdItemObj
= PcdItem
[1]
899 Pcd
= CommonObject
.PcdObject()
900 Pcd
.SetCName(PcdItemObj
.GetCName())
901 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
902 if PcdItemObj
.GetTokenSpaceGuidValue() == '' and self
.BinaryModule
:
903 Logger
.Error("\nMkPkg",
905 ST
.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS
% \
906 (PcdItemObj
.GetTokenSpaceGuidCName()),
907 self
.GetFullPath(), RaiseError
=True)
909 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
910 if (PcdItemObj
.GetToken() == '' or PcdItemObj
.GetDatumType() == '') and self
.BinaryModule
:
911 Logger
.Error("\nMkPkg",
913 ST
.ERR_ASBUILD_PCD_DECLARITION_MISS
% \
914 (PcdItemObj
.GetTokenSpaceGuidCName() + '.' + PcdItemObj
.GetCName()),
915 self
.GetFullPath(), RaiseError
=True)
916 Pcd
.SetToken(PcdItemObj
.GetToken())
917 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
918 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
919 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
920 Pcd
.SetOffset(PcdItemObj
.GetOffset())
921 Pcd
.SetItemType(PcdItem
[0])
922 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
923 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
924 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
925 for CommentItem
in PcdItemObj
.GetHelpStringList():
926 HelpTextObj
= CommonObject
.TextObject()
927 if self
.UniFileClassObject
:
928 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
929 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
930 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
931 AsBuildPatchPcdList
.append(Pcd
)
932 elif PcdItem
[0].upper() == DT
.TAB_INF_PCD_EX
.upper():
933 PcdItemObj
= PcdItem
[1]
934 Pcd
= CommonObject
.PcdObject()
935 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
936 Pcd
.SetToken(PcdItemObj
.GetToken())
937 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
938 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
939 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
940 Pcd
.SetItemType(PcdItem
[0])
941 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
942 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
943 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
944 for CommentItem
in PcdItemObj
.GetHelpStringList():
945 HelpTextObj
= CommonObject
.TextObject()
946 if self
.UniFileClassObject
:
947 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
948 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
949 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
950 AsBuildPcdExList
.append(Pcd
)
951 AsBuildIns
.SetPatchPcdList(AsBuildPatchPcdList
)
952 AsBuildIns
.SetPcdExList(AsBuildPcdExList
)
956 ## GenGuidProtocolPpis
958 # Gen Guids/Protocol/Ppis of INF
959 # <CName>=<GuidValue>
961 def _GenGuidProtocolPpis(self
, Type
):
962 Logger
.Debug(2, "Generate %s ..." % Type
)
964 # Get all Guid/Protocol/Ppis data
966 GuidObj
= self
.Parser
.InfGuidSection
.GetGuid()
967 ProtocolObj
= self
.Parser
.InfProtocolSection
.GetProtocol()
968 PpisObj
= self
.Parser
.InfPpiSection
.GetPpi()
970 GuidProtocolPpiList
= []
972 if Type
== DT
.TAB_GUIDS
:
973 GuidData
= GuidObj
.keys()
974 for Item
in GuidData
:
975 CommentList
= Item
.GetCommentList()
977 # Depend on CommentList content
978 # generate muti-guid-obj
981 for GuidComentItem
in CommentList
:
982 ListObject
= CommonObject
.GuidObject()
983 ListObject
.SetGuidTypeList([GuidComentItem
.GetGuidTypeItem()])
984 ListObject
.SetVariableName(GuidComentItem
.GetVariableNameItem())
985 ListObject
.SetUsage(GuidComentItem
.GetUsageItem())
986 ListObject
.SetName(Item
.GetName())
987 ListObject
.SetCName(Item
.GetName())
988 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
989 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
990 HelpString
= GuidComentItem
.GetHelpStringItem()
991 if HelpString
.strip():
992 HelpTxtTailObj
= CommonObject
.TextObject()
993 if self
.UniFileClassObject
:
994 HelpTxtTailObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
995 HelpTxtTailObj
.SetString(HelpString
)
996 ListObject
.SetHelpTextList([HelpTxtTailObj
])
998 GuidProtocolPpiList
.append(ListObject
)
999 elif Type
== DT
.TAB_PROTOCOLS
:
1000 ProtocolData
= ProtocolObj
.keys()
1001 for Item
in ProtocolData
:
1002 CommentList
= Item
.GetCommentList()
1003 for CommentItem
in CommentList
:
1004 ListObject
= CommonObject
.ProtocolObject()
1005 ListObject
.SetCName(Item
.GetName())
1006 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1007 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1008 ListObject
.SetNotify(CommentItem
.GetNotify())
1009 ListObject
.SetUsage(CommentItem
.GetUsageItem())
1010 HelpString
= CommentItem
.GetHelpStringItem()
1011 if HelpString
.strip():
1012 HelpTxtObj
= CommonObject
.TextObject()
1013 if self
.UniFileClassObject
:
1014 HelpTxtObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1015 HelpTxtObj
.SetString(HelpString
)
1016 ListObject
.SetHelpTextList([HelpTxtObj
])
1017 GuidProtocolPpiList
.append(ListObject
)
1018 elif Type
== DT
.TAB_PPIS
:
1019 PpiData
= PpisObj
.keys()
1020 for Item
in PpiData
:
1021 CommentList
= Item
.GetCommentList()
1022 for CommentItem
in CommentList
:
1023 ListObject
= CommonObject
.PpiObject()
1024 ListObject
.SetCName(Item
.GetName())
1025 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1026 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1027 ListObject
.SetNotify(CommentItem
.GetNotify())
1028 ListObject
.SetUsage(CommentItem
.GetUsage())
1029 HelpString
= CommentItem
.GetHelpStringItem()
1030 if HelpString
.strip():
1031 HelpTextObj
= CommonObject
.TextObject()
1032 if self
.UniFileClassObject
:
1033 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1034 HelpTextObj
.SetString(HelpString
)
1035 ListObject
.SetHelpTextList([HelpTextObj
])
1036 GuidProtocolPpiList
.append(ListObject
)
1038 if Type
== DT
.TAB_GUIDS
:
1039 self
.SetGuidList(self
.GetGuidList() + GuidProtocolPpiList
)
1040 elif Type
== DT
.TAB_PROTOCOLS
:
1041 self
.SetProtocolList(self
.GetProtocolList() + GuidProtocolPpiList
)
1042 elif Type
== DT
.TAB_PPIS
:
1043 self
.SetPpiList(self
.GetPpiList() + GuidProtocolPpiList
)
1047 # Gen MiscellaneousFiles of Inf
1049 # @param ContainerFile: The Inf file full path
1051 def _GenMiscFiles(self
, Content
):
1052 MiscFileObj
= CommonObject
.MiscFileObject()
1053 for Line
in Content
.splitlines():
1056 FileName
= Line
[:Line
.find('#')]
1060 if IsValidPath(FileName
, GlobalData
.gINF_MODULE_DIR
):
1061 FileObj
= CommonObject
.FileObject()
1062 FileObj
.SetURI(FileName
)
1063 MiscFileObj
.SetFileList(MiscFileObj
.GetFileList()+[FileObj
])
1065 Logger
.Error("InfParser",
1067 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Line),
1068 File
=GlobalData
.gINF_MODULE_NAME
,
1070 self
.SetMiscFileList(self
.GetMiscFileList()+[MiscFileObj
])