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 # 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.
21 from Logger
import StringTable
as ST
22 import Logger
.Log
as Logger
23 from Library
.StringUtils
import FORMAT_INVALID
24 from Library
.StringUtils
import PARSER_ERROR
25 from Library
.StringUtils
import NormPath
26 from Library
.StringUtils
import GetSplitValueList
27 from Library
.Misc
import ConvertVersionToDecimal
28 from Library
.Misc
import GetHelpStringByRemoveHashKey
29 from Library
.Misc
import ConvertArchList
30 from Library
.Misc
import GetRelativePath
31 from Library
.Misc
import PathClass
32 from Library
.Parsing
import GetPkgInfoFromDec
33 from Library
.UniClassObject
import UniFileClassObject
34 from Library
.UniClassObject
import ConvertSpecialUnicodes
35 from Library
.UniClassObject
import GetLanguageCode1766
36 from Library
import DataType
as DT
37 from Library
import GlobalData
38 from Library
.ParserValidate
import IsValidPath
39 from Object
.POM
import CommonObject
40 from Object
.POM
.ModuleObject
import ModuleObject
41 from Object
.POM
.ModuleObject
import ExternObject
42 from Object
.POM
.ModuleObject
import HobObject
43 from Object
.POM
.ModuleObject
import EventObject
44 from Object
.POM
.ModuleObject
import BootModeObject
45 from Object
.POM
.ModuleObject
import PackageDependencyObject
46 from Object
.POM
.ModuleObject
import SourceFileObject
47 from Object
.POM
.ModuleObject
import DepexObject
48 from Object
.POM
.ModuleObject
import AsBuildLibraryClassObject
49 from Object
.POM
.ModuleObject
import AsBuiltObject
50 from PomAdapter
.InfPomAlignmentMisc
import GenModuleHeaderUserExt
51 from PomAdapter
.InfPomAlignmentMisc
import GenBinaryData
52 from Parser
import InfParser
53 from PomAdapter
.DecPomAlignment
import DecPomAlignment
54 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
58 # Inherit from ModuleObject
60 class InfPomAlignment(ModuleObject
):
61 ## Construct of InfPomAlignment
62 # Skip means that UPT don't care the syntax of INF, this may be the not
63 # distributed INF files during creation or the INF files checked for
64 # dependency rule during remove.
66 def __init__(self
, FileName
, WorkSpace
=None, PackagePath
='', Skip
=False):
67 ModuleObject
.__init
__(self
)
69 self
.FileName
= FileName
70 self
.WorkSpace
= WorkSpace
72 self
.LibModuleTypeList
= []
75 self
.WorkspaceDir
= " "
76 self
.CustomMakefile
= []
77 self
.UniFileClassObject
= None
78 self
.SetPackagePath(PackagePath
)
80 # Call GenInfPomObjects function to fill POM object.
83 OrigConfig
= Logger
.SUPRESS_ERROR
84 Logger
.SUPRESS_ERROR
= True
86 self
._GenInfPomObjects
(Skip
)
88 Logger
.SUPRESS_ERROR
= OrigConfig
90 self
._GenInfPomObjects
(Skip
)
93 # Generate all POM objects, the original input comes
94 # from INF parser's output
96 def _GenInfPomObjects(self
, Skip
):
98 # Call INF Parser to get information from INF file
100 self
.Parser
= InfParser
.InfParser(self
.FileName
, self
.WorkSpace
)
101 self
.FullPath
= self
.Parser
.FullPath
103 self
._GenModuleHeader
()
105 # Call GenBinaries after Module Header for Binary INF consideration.
108 self
._GenBuildOptions
()
109 self
._GenLibraryClasses
()
110 self
._GenPackages
(Skip
)
113 self
._GenUserExtensions
()
114 self
._GenGuidProtocolPpis
(DT
.TAB_GUIDS
)
115 self
._GenGuidProtocolPpis
(DT
.TAB_PROTOCOLS
)
116 self
._GenGuidProtocolPpis
(DT
.TAB_PPIS
)
119 ## Convert [Defines] section content to InfDefObject
121 # Convert [Defines] section content to InfDefObject
123 # @param Defines The content under [Defines] section
124 # @param ModuleHeader An object of ModuleHeaderClass
125 # @param Arch The supported ARCH
127 def _GenModuleHeader(self
):
128 Logger
.Debug(2, "Generate ModuleHeader ...")
130 # Get all defines information form InfParser Object
132 RecordSet
= self
.Parser
.InfDefSection
.Defines
134 # Should only have one ArchString Item.
136 ArchString
= list(RecordSet
.keys())[0]
137 ArchList
= GetSplitValueList(ArchString
, ' ')
138 ArchList
= ConvertArchList(ArchList
)
139 HasCalledFlag
= False
141 # Get data from Sdict()
143 ValueList
= RecordSet
[ArchString
]
144 self
.SetFileName(self
.FileName
)
145 self
.SetFullPath(self
.FullPath
)
147 # The INF's filename (without the directory path or the extension)
148 # must be used for the value of the
149 # ModuleSurfaceArea.Header.Name element
151 self
.SetName(os
.path
.splitext(os
.path
.basename(self
.FileName
))[0])
152 self
.WorkspaceDir
= " "
154 # CombinePath and ModulePath
156 CombinePath
= GetRelativePath(self
.FullPath
, self
.WorkSpace
)
157 self
.SetCombinePath(CombinePath
)
158 ModulePath
= os
.path
.split(CombinePath
)[0]
159 ModuleRelativePath
= ModulePath
160 if self
.GetPackagePath() != '':
161 ModuleRelativePath
= GetRelativePath(ModulePath
, self
.GetPackagePath())
162 self
.SetModulePath(ModuleRelativePath
)
164 # For Define Seciton Items.
166 DefineObj
= ValueList
168 # Convert UEFI/PI version to decimal number
170 if DefineObj
.GetUefiSpecificationVersion() is not None:
171 __UefiVersion
= DefineObj
.GetUefiSpecificationVersion().GetValue()
172 __UefiVersion
= ConvertVersionToDecimal(__UefiVersion
)
173 self
.SetUefiSpecificationVersion(str(__UefiVersion
))
174 if DefineObj
.GetPiSpecificationVersion() is not None:
175 __PiVersion
= DefineObj
.GetPiSpecificationVersion().GetValue()
176 __PiVersion
= ConvertVersionToDecimal(__PiVersion
)
178 self
.SetPiSpecificationVersion(str(__PiVersion
))
179 SpecList
= DefineObj
.GetSpecification()
181 for SpecItem
in SpecList
:
182 NewSpecList
.append((SpecItem
[0], ConvertVersionToDecimal(SpecItem
[1])))
183 self
.SetSpecList(NewSpecList
)
186 # must exist items in INF define section
187 # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING
189 if DefineObj
.GetModuleType() is None:
190 Logger
.Error("InfParser", FORMAT_INVALID
,
191 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("MODULE_TYPE"), File
=self
.FullPath
)
193 self
.SetModuleType(DefineObj
.GetModuleType().GetValue())
194 ModuleType
= DefineObj
.GetModuleType().GetValue()
197 # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only
198 # libraries are permitted to a have a MODULE_TYPE of "BASE".
200 if len(DefineObj
.LibraryClass
) == 0 and ModuleType
== 'BASE':
201 Logger
.Error("InfParser",
203 ST
.ERR_INF_PARSER_MODULETYPE_INVALID
,
205 Line
=DefineObj
.ModuleType
.CurrentLine
.LineNo
,
206 ExtraData
=DefineObj
.ModuleType
.CurrentLine
.LineString
)
207 self
.LibModuleTypeList
.append(ModuleType
)
208 if DefineObj
.GetBaseName() is None:
209 Logger
.Error("InfParser", FORMAT_INVALID
,
210 ST
.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST
% ("BASE_NAME"), File
=self
.FullPath
)
212 self
.SetBaseName(DefineObj
.GetBaseName().GetValue())
213 if DefineObj
.GetModuleUniFileName():
214 self
.UniFileClassObject
= UniFileClassObject([PathClass(DefineObj
.GetModuleUniFileName())])
216 self
.UniFileClassObject
= None
217 if DefineObj
.GetInfVersion() is 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() is 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() is 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
)
251 # if there is Shadow, Should judge the MODULE_TYPE in
252 # SEC, PEI_CORE and PEIM
254 if DefineObj
.GetShadow():
255 ModuleTypeValue
= DefineObj
.GetModuleType().GetValue()
256 if not (ModuleTypeValue
== 'SEC' or ModuleTypeValue
== 'PEI_CORE' or ModuleTypeValue
== 'PEIM'):
257 Logger
.Error("InfParser", FORMAT_INVALID
, ST
.ERR_INF_PARSER_DEFINE_SHADOW_INVALID
, File
=self
.FullPath
)
259 if DefineObj
.GetPcdIsDriver() is not None:
260 self
.SetPcdIsDriver(DefineObj
.GetPcdIsDriver().GetValue())
264 self
._GenModuleHeaderLibClass
(DefineObj
, ArchList
)
268 self
.CustomMakefile
= DefineObj
.GetCustomMakefile()
270 # Externs in Defines section
271 # Only one define section, so just call once.
273 if not HasCalledFlag
:
274 self
._GenModuleHeaderExterns
(DefineObj
)
277 # each module has only one module header
279 self
.SetSupArchList(ArchList
)
281 # Get Hob/BootMode/EventList information
283 self
._GenSpecialComments
()
285 # put all define statement into user-extension sections
287 DefinesDictNew
= GenModuleHeaderUserExt(DefineObj
, ArchString
)
289 UserExtension
= CommonObject
.UserExtensionObject()
290 UserExtension
.SetDefinesDict(DefinesDictNew
)
291 UserExtension
.SetIdentifier('DefineModifiers')
292 UserExtension
.SetUserID('EDK2')
293 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
295 # Get all meta-file header information
296 # the record is list of items formatted:
297 # [LineValue, Arch, StartLine, ID, Third]
299 InfHeaderObj
= self
.Parser
.InfHeader
301 # Put header information into POM object
303 if self
.UniFileClassObject
:
304 Lang
= DT
.TAB_LANGUAGE_EN_X
306 Lang
= DT
.TAB_LANGUAGE_EN_US
307 if InfHeaderObj
.GetAbstract():
308 self
.SetAbstract((Lang
, InfHeaderObj
.GetAbstract()))
309 if InfHeaderObj
.GetDescription():
310 self
.SetDescription((Lang
, InfHeaderObj
.GetDescription()))
311 if InfHeaderObj
.GetCopyright():
312 self
.SetCopyright(('', InfHeaderObj
.GetCopyright()))
313 if InfHeaderObj
.GetLicense():
314 self
.SetLicense(('', InfHeaderObj
.GetLicense()))
316 # Put Binary header information into POM object
318 InfBinaryHeaderObj
= self
.Parser
.InfBinaryHeader
319 if InfBinaryHeaderObj
.GetAbstract():
320 self
.SetBinaryHeaderAbstract((Lang
, InfBinaryHeaderObj
.GetAbstract()))
321 if InfBinaryHeaderObj
.GetDescription():
322 self
.SetBinaryHeaderDescription((Lang
, InfBinaryHeaderObj
.GetDescription()))
323 if InfBinaryHeaderObj
.GetCopyright():
324 self
.SetBinaryHeaderCopyright(('', InfBinaryHeaderObj
.GetCopyright()))
325 if InfBinaryHeaderObj
.GetLicense():
326 self
.SetBinaryHeaderLicense(('', InfBinaryHeaderObj
.GetLicense()))
328 ## GenModuleHeaderLibClass
331 def _GenModuleHeaderLibClass(self
, DefineObj
, ArchList
):
332 LibraryList
= DefineObj
.GetLibraryClass()
333 for LibraryItem
in LibraryList
:
334 Lib
= CommonObject
.LibraryClassObject()
335 Lib
.SetLibraryClass(LibraryItem
.GetLibraryName())
336 Lib
.SetUsage(DT
.USAGE_ITEM_PRODUCES
)
337 SupModuleList
= LibraryItem
.GetTypes()
338 self
.LibModuleTypeList
+= SupModuleList
339 Lib
.SetSupModuleList(SupModuleList
)
340 Lib
.SetSupArchList(ArchList
)
341 self
.SetLibraryClassList(self
.GetLibraryClassList() + [Lib
])
342 self
.SetIsLibrary(True)
343 self
.SetIsLibraryModList(self
.GetIsLibraryModList() + SupModuleList
)
345 ## GenModuleHeaderExterns
348 def _GenModuleHeaderExterns(self
, DefineObj
):
349 EntryPointList
= DefineObj
.GetEntryPoint()
350 for EntryPoint
in EntryPointList
:
351 Image
= ExternObject()
352 Image
.SetEntryPoint(EntryPoint
.GetCName())
356 self
.SetExternList(self
.GetExternList() + [Image
])
360 UnloadImageList
= DefineObj
.GetUnloadImages()
361 for UnloadImage
in UnloadImageList
:
362 Image
= ExternObject()
366 Image
.SetUnloadImage(UnloadImage
.GetCName())
367 self
.SetExternList(self
.GetExternList() + [Image
])
371 ConstructorList
= DefineObj
.GetConstructor()
372 for ConstructorItem
in ConstructorList
:
373 Image
= ExternObject()
377 Image
.SetConstructor(ConstructorItem
.GetCName())
378 self
.SetExternList(self
.GetExternList() + [Image
])
382 DestructorList
= DefineObj
.GetDestructor()
383 for DestructorItem
in DestructorList
:
384 Image
= ExternObject()
388 Image
.SetDestructor(DestructorItem
.GetCName())
389 self
.SetExternList(self
.GetExternList() + [Image
])
391 ## GenModuleHeaderExterns
394 def _GenSpecialComments(self
):
395 SpecialCommentsList
= self
.Parser
.InfSpecialCommentSection
.GetSpecialComments()
396 for Key
in SpecialCommentsList
:
397 if Key
== DT
.TYPE_HOB_SECTION
:
399 for Item
in SpecialCommentsList
[Key
]:
401 Hob
.SetHobType(Item
.GetHobType())
402 Hob
.SetUsage(Item
.GetUsage())
403 Hob
.SetSupArchList(Item
.GetSupArchList())
404 if Item
.GetHelpString():
405 HelpTextObj
= CommonObject
.TextObject()
406 if self
.UniFileClassObject
:
407 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
408 HelpTextObj
.SetString(Item
.GetHelpString())
409 Hob
.SetHelpTextList([HelpTextObj
])
411 self
.SetHobList(HobList
)
412 elif Key
== DT
.TYPE_EVENT_SECTION
:
414 for Item
in SpecialCommentsList
[Key
]:
415 Event
= EventObject()
416 Event
.SetEventType(Item
.GetEventType())
417 Event
.SetUsage(Item
.GetUsage())
418 if Item
.GetHelpString():
419 HelpTextObj
= CommonObject
.TextObject()
420 if self
.UniFileClassObject
:
421 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
422 HelpTextObj
.SetString(Item
.GetHelpString())
423 Event
.SetHelpTextList([HelpTextObj
])
424 EventList
.append(Event
)
425 self
.SetEventList(EventList
)
426 elif Key
== DT
.TYPE_BOOTMODE_SECTION
:
428 for Item
in SpecialCommentsList
[Key
]:
429 BootMode
= BootModeObject()
430 BootMode
.SetSupportedBootModes(Item
.GetSupportedBootModes())
431 BootMode
.SetUsage(Item
.GetUsage())
432 if Item
.GetHelpString():
433 HelpTextObj
= CommonObject
.TextObject()
434 if self
.UniFileClassObject
:
435 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
436 HelpTextObj
.SetString(Item
.GetHelpString())
437 BootMode
.SetHelpTextList([HelpTextObj
])
438 BootModeList
.append(BootMode
)
439 self
.SetBootModeList(BootModeList
)
443 # Gen BuildOptions of Inf
444 # [<Family>:]<ToolFlag>=Flag
447 def _GenBuildOptions(self
):
448 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BUILD_OPTIONS
)
450 # Get all BuildOptions
452 BuildOptionsList
= self
.Parser
.InfBuildOptionSection
.GetBuildOptions()
453 if not GlobalData
.gIS_BINARY_INF
:
455 for BuildOptionObj
in BuildOptionsList
:
456 ArchList
= BuildOptionObj
.GetSupArchList()
457 ArchList
= ConvertArchList(ArchList
)
458 BuildOptionsContent
= BuildOptionObj
.GetContent()
459 ArchString
= ' '.join(ArchList
)
460 if not BuildOptionsContent
:
462 BuildOptionDict
[ArchString
] = BuildOptionsContent
463 if not BuildOptionDict
:
465 UserExtension
= CommonObject
.UserExtensionObject()
466 UserExtension
.SetBuildOptionDict(BuildOptionDict
)
467 UserExtension
.SetIdentifier('BuildOptionModifiers')
468 UserExtension
.SetUserID('EDK2')
469 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
472 # Not process this information, will be processed in GenBinaries()
478 # Get LibraryClass of Inf
479 # <LibraryClassKeyWord>|<LibraryInstance>
481 # @param ContainerFile: The Inf file full path
483 def _GenLibraryClasses(self
):
484 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_LIBRARY_CLASSES
)
485 if not GlobalData
.gIS_BINARY_INF
:
487 # Get all LibraryClasses
489 for LibraryClassData
in self
.Parser
.InfLibraryClassSection
.LibraryClasses
.values():
490 for Item
in LibraryClassData
:
491 LibraryClass
= CommonObject
.LibraryClassObject()
492 LibraryClass
.SetUsage(DT
.USAGE_ITEM_CONSUMES
)
493 LibraryClass
.SetLibraryClass(Item
.GetLibName())
494 LibraryClass
.SetRecommendedInstance(None)
495 LibraryClass
.SetFeatureFlag(Item
.GetFeatureFlagExp())
496 LibraryClass
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
497 LibraryClass
.SetSupModuleList(Item
.GetSupModuleList())
498 HelpStringObj
= Item
.GetHelpString()
499 if HelpStringObj
is not None:
500 CommentString
= GetHelpStringByRemoveHashKey(HelpStringObj
.HeaderComments
+
501 HelpStringObj
.TailComments
)
502 HelpTextHeaderObj
= CommonObject
.TextObject()
503 if self
.UniFileClassObject
:
504 HelpTextHeaderObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
505 HelpTextHeaderObj
.SetString(CommentString
)
506 LibraryClass
.SetHelpTextList([HelpTextHeaderObj
])
507 self
.SetLibraryClassList(self
.GetLibraryClassList() + [LibraryClass
])
511 # Gen Packages of Inf
514 # @param ContainerFile: The Inf file full path
516 def _GenPackages(self
, Skip
):
517 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PACKAGES
)
521 PackageObj
= self
.Parser
.InfPackageSection
.Packages
523 # Go through each arch
525 for PackageItemObj
in PackageObj
:
527 # Need package information for dependency check usage
529 PackageDependency
= PackageDependencyObject()
530 PackageDependency
.SetPackageFilePath(NormPath(PackageItemObj
.GetPackageName()))
531 PackageDependency
.SetSupArchList(ConvertArchList(PackageItemObj
.GetSupArchList()))
532 PackageDependency
.SetFeatureFlag(PackageItemObj
.GetFeatureFlagExp())
534 PkgInfo
= GetPkgInfoFromDec(mws
.join(self
.WorkSpace
, NormPath(PackageItemObj
.GetPackageName())))
535 if PkgInfo
[1] and PkgInfo
[2]:
536 PackageDependency
.SetGuid(PkgInfo
[1])
537 PackageDependency
.SetVersion(PkgInfo
[2])
541 Logger
.Error("\nUPT", PARSER_ERROR
,
542 ST
.ERR_INF_GET_PKG_DEPENDENCY_FAIL
% PackageItemObj
.GetPackageName(), File
=self
.FullPath
)
544 PackageDependencyList
= self
.GetPackageDependencyList()
545 PackageDependencyList
.append(PackageDependency
)
546 self
.SetPackageDependencyList(PackageDependencyList
)
551 # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]]
553 # @param ContainerFile: The Inf file full path
556 if not GlobalData
.gIS_BINARY_INF
:
557 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PCDS
)
561 PcdObj
= self
.Parser
.InfPcdSection
.Pcds
562 KeysList
= PcdObj
.keys()
564 # Go through each arch
566 for (PcdType
, PcdKey
) in KeysList
:
567 PcdData
= PcdObj
[PcdType
, PcdKey
]
568 for PcdItemObj
in PcdData
:
569 CommentList
= PcdItemObj
.GetHelpStringList()
571 for CommentItem
in CommentList
:
572 Pcd
= CommonObject
.PcdObject()
573 Pcd
.SetCName(PcdItemObj
.GetCName())
574 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
575 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
576 Pcd
.SetItemType(PcdType
)
577 Pcd
.SetValidUsage(CommentItem
.GetUsageItem())
578 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
579 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
580 HelpTextObj
= CommonObject
.TextObject()
581 if self
.UniFileClassObject
:
582 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
583 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
584 Pcd
.SetHelpTextList([HelpTextObj
])
585 PcdList
= self
.GetPcdList()
587 self
.SetPcdList(PcdList
)
592 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
594 # @param ContainerFile: The Inf file full path
596 def _GenSources(self
):
597 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_SOURCES
)
600 # Get all SourceFiles
602 SourceObj
= self
.Parser
.InfSourcesSection
.Sources
603 DataList
= SourceObj
.keys()
605 # Go through each arch
609 SourceData
= SourceObj
[Key
]
610 for Item
in SourceData
:
611 SourceFile
= Item
.GetSourceFileName()
612 Family
= Item
.GetFamily()
613 FeatureFlag
= Item
.GetFeatureFlagExp()
614 SupArchList
= sorted(ConvertArchList(Item
.GetSupArchList()))
615 Source
= SourceFileObject()
616 Source
.SetSourceFile(SourceFile
)
617 Source
.SetFamily(Family
)
618 Source
.SetFeatureFlag(FeatureFlag
)
619 Source
.SetSupArchList(SupArchList
)
620 SourceList
.append(Source
)
622 self
.SetSourceFileList(self
.GetSourceFileList() + SourceList
)
627 # Gen UserExtensions of Inf
629 def _GenUserExtensions(self
):
633 UserExtensionObj
= self
.Parser
.InfUserExtensionSection
.UserExtension
634 Keys
= UserExtensionObj
.keys()
637 UserExtensionData
= UserExtensionObj
[Key
]
638 for UserExtensionDataObj
in UserExtensionData
:
639 UserExtension
= CommonObject
.UserExtensionObject()
640 UserId
= UserExtensionDataObj
.GetUserId()
641 if UserId
.startswith('"') and UserId
.endswith('"'):
642 UserId
= UserId
[1:-1]
643 UserExtension
.SetUserID(UserId
)
644 Identifier
= UserExtensionDataObj
.GetIdString()
645 if Identifier
.startswith('"') and Identifier
.endswith('"'):
646 Identifier
= Identifier
[1:-1]
648 # Generate miscellaneous files on INF file
650 if UserId
== 'TianoCore' and Identifier
== 'ExtraFiles':
651 self
._GenMiscFiles
(UserExtensionDataObj
.GetContent())
652 UserExtension
.SetIdentifier(Identifier
)
653 UserExtension
.SetStatement(UserExtensionDataObj
.GetContent())
654 UserExtension
.SetSupArchList(ConvertArchList(UserExtensionDataObj
.GetSupArchList()))
655 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
658 # Gen UserExtensions of TianoCore."BinaryHeader"
661 #Get Binary header from INF file
662 BinaryAbstractList
= self
.BinaryHeaderAbstractList
663 BinaryDescriptionList
= self
.BinaryHeaderDescriptionList
664 BinaryCopyrightList
= self
.BinaryHeaderCopyrightList
665 BinaryLicenseList
= self
.BinaryHeaderLicenseList
666 #Get Binary header from UNI file
667 # Initialize UniStrDict, the top keys are language codes
669 if self
.UniFileClassObject
:
670 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
671 for Lang
in UniStrDict
:
672 for StringDefClassObject
in UniStrDict
[Lang
]:
673 Lang
= GetLanguageCode1766(Lang
)
674 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_ABSTRACT
:
675 BinaryAbstractList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
676 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_DESCRIPTION
:
677 BinaryDescriptionList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
678 if BinaryAbstractList
or BinaryDescriptionList
or BinaryCopyrightList
or BinaryLicenseList
:
679 BinaryUserExtension
= CommonObject
.UserExtensionObject()
680 BinaryUserExtension
.SetBinaryAbstract(BinaryAbstractList
)
681 BinaryUserExtension
.SetBinaryDescription(BinaryDescriptionList
)
682 BinaryUserExtension
.SetBinaryCopyright(BinaryCopyrightList
)
683 BinaryUserExtension
.SetBinaryLicense(BinaryLicenseList
)
684 BinaryUserExtension
.SetIdentifier(DT
.TAB_BINARY_HEADER_IDENTIFIER
)
685 BinaryUserExtension
.SetUserID(DT
.TAB_BINARY_HEADER_USERID
)
686 self
.SetUserExtensionList(self
.GetUserExtensionList() + [BinaryUserExtension
])
688 def _GenDepexesList(self
, SmmDepexList
, DxeDepexList
, PeiDepexList
):
690 self
.SetSmmDepex(SmmDepexList
)
692 self
.SetDxeDepex(DxeDepexList
)
694 self
.SetPeiDepex(PeiDepexList
)
700 # @param ContainerFile: The Inf file full path
702 def _GenDepexes(self
):
703 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_DEPEX
)
705 PEI_LIST
= [DT
.SUP_MODULE_PEIM
]
706 SMM_LIST
= [DT
.SUP_MODULE_DXE_SMM_DRIVER
]
707 DXE_LIST
= [DT
.SUP_MODULE_DXE_DRIVER
, DT
.SUP_MODULE_DXE_SAL_DRIVER
,
708 DT
.SUP_MODULE_DXE_RUNTIME_DRIVER
]
710 IsLibraryClass
= self
.GetIsLibrary()
714 DepexData
= self
.Parser
.InfDepexSection
.GetDepex()
718 for Depex
in DepexData
:
719 ModuleType
= Depex
.GetModuleType()
722 if self
.GetModuleType() == 'BASE' and not ModuleType
:
723 Logger
.Error("\nMkPkg", PARSER_ERROR
,
724 ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS
,
725 self
.GetFullPath(), RaiseError
=True)
726 if self
.GetModuleType() != 'BASE' and not self
.GetIsLibraryModList():
727 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS
,
728 self
.GetFullPath(), RaiseError
=True)
729 if self
.GetModuleType() != 'BASE' and ModuleType
and ModuleType
not in self
.GetIsLibraryModList():
730 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
731 self
.GetFullPath(), RaiseError
=True)
733 ModuleTypeList
= [ModuleType
]
735 for ModuleTypeInList
in self
.GetIsLibraryModList():
736 if ModuleTypeInList
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
737 ModuleTypeList
.append(ModuleTypeInList
)
738 if not ModuleTypeList
:
739 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
740 self
.GetFullPath(), RaiseError
=True)
743 ModuleType
= self
.ModuleType
744 if ModuleType
not in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
745 Logger
.Error("\nMkPkg", PARSER_ERROR
,
746 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
747 self
.GetFullPath(), RaiseError
=True)
748 if ModuleType
!= self
.ModuleType
:
749 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
750 self
.GetFullPath(), RaiseError
=True)
751 ModuleTypeList
= [ModuleType
]
752 for ModuleType
in ModuleTypeList
:
753 DepexIns
= DepexObject()
754 DepexIns
.SetDepex(Depex
.GetDepexContent())
756 DepexIns
.SetModuleType(ModuleType
)
758 if Depex
.GetModuleType():
759 DepexIns
.SetModuleType(Depex
.GetModuleType())
760 DepexIns
.SetSupArchList(ConvertArchList([Depex
.GetSupArch()]))
761 DepexIns
.SetFeatureFlag(Depex
.GetFeatureFlagExp())
763 HelpIns
= CommonObject
.TextObject()
764 if self
.UniFileClassObject
:
765 HelpIns
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
766 HelpIns
.SetString(GetHelpStringByRemoveHashKey(Depex
.HelpString
))
767 DepexIns
.SetHelpText(HelpIns
)
769 if ModuleType
in SMM_LIST
:
770 SmmDepexList
.append(DepexIns
)
771 if ModuleType
in DXE_LIST
:
772 DxeDepexList
.append(DepexIns
)
773 if ModuleType
in PEI_LIST
:
774 PeiDepexList
.append(DepexIns
)
775 if ModuleType
== DT
.SUP_MODULE_UEFI_DRIVER
:
777 DxeDepexList
.append(DepexIns
)
779 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER
,
780 self
.GetFullPath(), RaiseError
=True)
782 #End of for ModuleType in ModuleTypeList
783 self
._GenDepexesList
(SmmDepexList
, DxeDepexList
, PeiDepexList
)
784 #End of for Depex in DepexData
788 # Gen Binary of Inf, must be called after Pcd/Library is generated
789 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
791 # @param ContainerFile: The Inf file full path
793 def _GenBinaries(self
):
794 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BINARIES
)
798 # Get all Binary data
800 BinaryObj
= self
.Parser
.InfBinariesSection
.GetBinary()
802 BinaryData
= BinaryObj
.keys()
805 # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section,
806 # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute
808 if BinaryObj
and not self
.Parser
.InfSourcesSection
.GetSources():
809 self
.BinaryModule
= True
811 self
.BinaryModule
= False
813 BinaryFileObjectList
= []
814 AsBuildLibraryClassList
= []
815 AsBuildBuildOptionList
= []
816 AsBuildIns
= AsBuiltObject()
818 # Library AsBuild Info
820 for LibItem
in self
.Parser
.InfLibraryClassSection
.GetLibraryClasses():
821 AsBuildLibIns
= AsBuildLibraryClassObject()
822 AsBuildLibIns
.SetLibGuid(LibItem
.GetFileGuid())
823 AsBuildLibIns
.SetLibVersion(LibItem
.GetVersion())
824 AsBuildLibIns
.SetSupArchList(LibItem
.GetSupArchList())
825 AsBuildLibraryClassList
.append(AsBuildLibIns
)
826 AsBuildIns
.SetLibraryInstancesList(AsBuildLibraryClassList
)
829 # BuildOption AsBuild Info
831 for BuildOptionItem
in self
.Parser
.InfBuildOptionSection
.GetBuildOptions():
832 AsBuildBuildOptionList
.append(BuildOptionItem
)
833 AsBuildIns
.SetBuildFlagsList(AsBuildBuildOptionList
)
838 AsBuildIns
= self
._GenAsBuiltPcds
(self
.Parser
.InfPcdSection
.GetPcds(), AsBuildIns
)
841 # Parse the DEC file that contains the GUID value of the GUID CName which is used by
842 # SUBTYPE_GUID type binary file in the Binaries section in the INF file
845 if not self
.PackagePath
:
846 WorkSpace
= os
.path
.normpath(self
.WorkSpace
)
847 TempPath
= ModulePath
= os
.path
.normpath(self
.ModulePath
)
849 TempPath
= ModulePath
850 ModulePath
= os
.path
.dirname(ModulePath
)
851 PackageName
= TempPath
852 DecFilePath
= os
.path
.normpath(os
.path
.join(WorkSpace
, PackageName
))
854 for File
in os
.listdir(DecFilePath
):
855 if File
.upper().endswith('.DEC'):
856 DecFileFullPath
= os
.path
.normpath(os
.path
.join(DecFilePath
, File
))
857 DecObjList
.append(DecPomAlignment(DecFileFullPath
, self
.WorkSpace
))
860 BinariesDict
, AsBuildIns
, BinaryFileObjectList
= GenBinaryData(BinaryData
, BinaryObj
,
863 BinaryFileObjectList
,
864 self
.GetSupArchList(),
869 for Key
in BinariesDict
:
870 ValueList
= BinariesDict
[Key
]
871 if len(ValueList
) > 1:
872 BinariesDict2
[Key
] = ValueList
875 # if there is no TagName, ToolCode, HelpStr,
876 # then do not need to put them into userextension
878 (Target
, Family
, TagName
, HelpStr
) = ValueList
[0]
879 if not (Target
or Family
or TagName
or HelpStr
):
882 BinariesDict2
[Key
] = ValueList
884 self
.SetBinaryFileList(self
.GetBinaryFileList() + BinaryFileObjectList
)
887 UserExtension
= CommonObject
.UserExtensionObject()
888 UserExtension
.SetBinariesDict(BinariesDict2
)
889 UserExtension
.SetIdentifier('BinaryFileModifiers')
890 UserExtension
.SetUserID('EDK2')
891 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
896 def _GenAsBuiltPcds(self
, PcdList
, AsBuildIns
):
897 AsBuildPatchPcdList
= []
898 AsBuildPcdExList
= []
902 for PcdItem
in PcdList
:
903 if PcdItem
[0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
904 PcdItemObj
= PcdItem
[1]
905 Pcd
= CommonObject
.PcdObject()
906 Pcd
.SetCName(PcdItemObj
.GetCName())
907 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
908 if PcdItemObj
.GetTokenSpaceGuidValue() == '' and self
.BinaryModule
:
909 Logger
.Error("\nMkPkg",
911 ST
.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS
% \
912 (PcdItemObj
.GetTokenSpaceGuidCName()),
913 self
.GetFullPath(), RaiseError
=True)
915 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
916 if (PcdItemObj
.GetToken() == '' or PcdItemObj
.GetDatumType() == '') and self
.BinaryModule
:
917 Logger
.Error("\nMkPkg",
919 ST
.ERR_ASBUILD_PCD_DECLARITION_MISS
% \
920 (PcdItemObj
.GetTokenSpaceGuidCName() + '.' + PcdItemObj
.GetCName()),
921 self
.GetFullPath(), RaiseError
=True)
922 Pcd
.SetToken(PcdItemObj
.GetToken())
923 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
924 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
925 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
926 Pcd
.SetOffset(PcdItemObj
.GetOffset())
927 Pcd
.SetItemType(PcdItem
[0])
928 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
929 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
930 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
931 for CommentItem
in PcdItemObj
.GetHelpStringList():
932 HelpTextObj
= CommonObject
.TextObject()
933 if self
.UniFileClassObject
:
934 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
935 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
936 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
937 AsBuildPatchPcdList
.append(Pcd
)
938 elif PcdItem
[0].upper() == DT
.TAB_INF_PCD_EX
.upper():
939 PcdItemObj
= PcdItem
[1]
940 Pcd
= CommonObject
.PcdObject()
941 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
942 Pcd
.SetToken(PcdItemObj
.GetToken())
943 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
944 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
945 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
946 Pcd
.SetItemType(PcdItem
[0])
947 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
948 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
949 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
950 for CommentItem
in PcdItemObj
.GetHelpStringList():
951 HelpTextObj
= CommonObject
.TextObject()
952 if self
.UniFileClassObject
:
953 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
954 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
955 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
956 AsBuildPcdExList
.append(Pcd
)
957 AsBuildIns
.SetPatchPcdList(AsBuildPatchPcdList
)
958 AsBuildIns
.SetPcdExList(AsBuildPcdExList
)
962 ## GenGuidProtocolPpis
964 # Gen Guids/Protocol/Ppis of INF
965 # <CName>=<GuidValue>
967 def _GenGuidProtocolPpis(self
, Type
):
968 Logger
.Debug(2, "Generate %s ..." % Type
)
970 # Get all Guid/Protocol/Ppis data
972 GuidObj
= self
.Parser
.InfGuidSection
.GetGuid()
973 ProtocolObj
= self
.Parser
.InfProtocolSection
.GetProtocol()
974 PpisObj
= self
.Parser
.InfPpiSection
.GetPpi()
976 GuidProtocolPpiList
= []
978 if Type
== DT
.TAB_GUIDS
:
979 GuidData
= GuidObj
.keys()
980 for Item
in GuidData
:
981 CommentList
= Item
.GetCommentList()
983 # Depend on CommentList content
984 # generate muti-guid-obj
987 for GuidComentItem
in CommentList
:
988 ListObject
= CommonObject
.GuidObject()
989 ListObject
.SetGuidTypeList([GuidComentItem
.GetGuidTypeItem()])
990 ListObject
.SetVariableName(GuidComentItem
.GetVariableNameItem())
991 ListObject
.SetUsage(GuidComentItem
.GetUsageItem())
992 ListObject
.SetName(Item
.GetName())
993 ListObject
.SetCName(Item
.GetName())
994 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
995 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
996 HelpString
= GuidComentItem
.GetHelpStringItem()
997 if HelpString
.strip():
998 HelpTxtTailObj
= CommonObject
.TextObject()
999 if self
.UniFileClassObject
:
1000 HelpTxtTailObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1001 HelpTxtTailObj
.SetString(HelpString
)
1002 ListObject
.SetHelpTextList([HelpTxtTailObj
])
1004 GuidProtocolPpiList
.append(ListObject
)
1005 elif Type
== DT
.TAB_PROTOCOLS
:
1006 ProtocolData
= ProtocolObj
.keys()
1007 for Item
in ProtocolData
:
1008 CommentList
= Item
.GetCommentList()
1009 for CommentItem
in CommentList
:
1010 ListObject
= CommonObject
.ProtocolObject()
1011 ListObject
.SetCName(Item
.GetName())
1012 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1013 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1014 ListObject
.SetNotify(CommentItem
.GetNotify())
1015 ListObject
.SetUsage(CommentItem
.GetUsageItem())
1016 HelpString
= CommentItem
.GetHelpStringItem()
1017 if HelpString
.strip():
1018 HelpTxtObj
= CommonObject
.TextObject()
1019 if self
.UniFileClassObject
:
1020 HelpTxtObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1021 HelpTxtObj
.SetString(HelpString
)
1022 ListObject
.SetHelpTextList([HelpTxtObj
])
1023 GuidProtocolPpiList
.append(ListObject
)
1024 elif Type
== DT
.TAB_PPIS
:
1025 PpiData
= PpisObj
.keys()
1026 for Item
in PpiData
:
1027 CommentList
= Item
.GetCommentList()
1028 for CommentItem
in CommentList
:
1029 ListObject
= CommonObject
.PpiObject()
1030 ListObject
.SetCName(Item
.GetName())
1031 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1032 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1033 ListObject
.SetNotify(CommentItem
.GetNotify())
1034 ListObject
.SetUsage(CommentItem
.GetUsage())
1035 HelpString
= CommentItem
.GetHelpStringItem()
1036 if HelpString
.strip():
1037 HelpTextObj
= CommonObject
.TextObject()
1038 if self
.UniFileClassObject
:
1039 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1040 HelpTextObj
.SetString(HelpString
)
1041 ListObject
.SetHelpTextList([HelpTextObj
])
1042 GuidProtocolPpiList
.append(ListObject
)
1044 if Type
== DT
.TAB_GUIDS
:
1045 self
.SetGuidList(self
.GetGuidList() + GuidProtocolPpiList
)
1046 elif Type
== DT
.TAB_PROTOCOLS
:
1047 self
.SetProtocolList(self
.GetProtocolList() + GuidProtocolPpiList
)
1048 elif Type
== DT
.TAB_PPIS
:
1049 self
.SetPpiList(self
.GetPpiList() + GuidProtocolPpiList
)
1053 # Gen MiscellaneousFiles of Inf
1055 # @param ContainerFile: The Inf file full path
1057 def _GenMiscFiles(self
, Content
):
1058 MiscFileObj
= CommonObject
.MiscFileObject()
1059 for Line
in Content
.splitlines():
1062 FileName
= Line
[:Line
.find('#')]
1066 if IsValidPath(FileName
, GlobalData
.gINF_MODULE_DIR
):
1067 FileObj
= CommonObject
.FileObject()
1068 FileObj
.SetURI(FileName
)
1069 MiscFileObj
.SetFileList(MiscFileObj
.GetFileList()+[FileObj
])
1071 Logger
.Error("InfParser",
1073 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Line),
1074 File
=GlobalData
.gINF_MODULE_NAME
,
1076 self
.SetMiscFileList(self
.GetMiscFileList()+[MiscFileObj
])