1 ## @file InfPomAlignment.py
2 # This file contained the adapter for convert INF parser object to POM Object
4 # Copyright (c) 2011 - 2014, 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
.String
import FORMAT_INVALID
24 from Library
.String
import PARSER_ERROR
25 from Library
.String
import NormPath
26 from Library
.String
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
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
= 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() != None:
171 __UefiVersion
= DefineObj
.GetUefiSpecificationVersion().GetValue()
172 __UefiVersion
= ConvertVersionToDecimal(__UefiVersion
)
173 self
.SetUefiSpecificationVersion(str(__UefiVersion
))
174 if DefineObj
.GetPiSpecificationVersion() != 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() == 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() == 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() == 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
)
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() != 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 formated:
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 LibClassObj
= self
.Parser
.InfLibraryClassSection
.LibraryClasses
490 Keys
= LibClassObj
.keys()
492 LibraryClassData
= LibClassObj
[Key
]
493 for Item
in LibraryClassData
:
494 LibraryClass
= CommonObject
.LibraryClassObject()
495 LibraryClass
.SetUsage(DT
.USAGE_ITEM_CONSUMES
)
496 LibraryClass
.SetLibraryClass(Item
.GetLibName())
497 LibraryClass
.SetRecommendedInstance(None)
498 LibraryClass
.SetFeatureFlag(Item
.GetFeatureFlagExp())
499 LibraryClass
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
500 LibraryClass
.SetSupModuleList(Item
.GetSupModuleList())
501 HelpStringObj
= Item
.GetHelpString()
502 if HelpStringObj
!= None:
503 CommentString
= GetHelpStringByRemoveHashKey(HelpStringObj
.HeaderComments
+
504 HelpStringObj
.TailComments
)
505 HelpTextHeaderObj
= CommonObject
.TextObject()
506 if self
.UniFileClassObject
:
507 HelpTextHeaderObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
508 HelpTextHeaderObj
.SetString(CommentString
)
509 LibraryClass
.SetHelpTextList([HelpTextHeaderObj
])
510 self
.SetLibraryClassList(self
.GetLibraryClassList() + [LibraryClass
])
514 # Gen Packages of Inf
517 # @param ContainerFile: The Inf file full path
519 def _GenPackages(self
, Skip
):
520 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PACKAGES
)
524 PackageObj
= self
.Parser
.InfPackageSection
.Packages
526 # Go through each arch
528 for PackageItemObj
in PackageObj
:
530 # Need package information for dependency check usage
532 PackageDependency
= PackageDependencyObject()
533 PackageDependency
.SetPackageFilePath(NormPath(PackageItemObj
.GetPackageName()))
534 PackageDependency
.SetSupArchList(ConvertArchList(PackageItemObj
.GetSupArchList()))
535 PackageDependency
.SetFeatureFlag(PackageItemObj
.GetFeatureFlagExp())
537 PkgInfo
= GetPkgInfoFromDec(os
.path
.normpath(os
.path
.join(self
.WorkSpace
,
538 NormPath(PackageItemObj
.GetPackageName()))))
539 if PkgInfo
[1] and PkgInfo
[2]:
540 PackageDependency
.SetGuid(PkgInfo
[1])
541 PackageDependency
.SetVersion(PkgInfo
[2])
545 Logger
.Error("\nUPT", PARSER_ERROR
,
546 ST
.ERR_INF_GET_PKG_DEPENDENCY_FAIL
% PackageItemObj
.GetPackageName(), File
=self
.FullPath
)
548 PackageDependencyList
= self
.GetPackageDependencyList()
549 PackageDependencyList
.append(PackageDependency
)
550 self
.SetPackageDependencyList(PackageDependencyList
)
555 # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]]
557 # @param ContainerFile: The Inf file full path
560 if not GlobalData
.gIS_BINARY_INF
:
561 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PCDS
)
565 PcdObj
= self
.Parser
.InfPcdSection
.Pcds
566 KeysList
= PcdObj
.keys()
568 # Go through each arch
570 for (PcdType
, PcdKey
) in KeysList
:
571 PcdData
= PcdObj
[PcdType
, PcdKey
]
572 for PcdItemObj
in PcdData
:
573 CommentList
= PcdItemObj
.GetHelpStringList()
575 for CommentItem
in CommentList
:
576 Pcd
= CommonObject
.PcdObject()
577 Pcd
.SetCName(PcdItemObj
.GetCName())
578 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
579 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
580 Pcd
.SetItemType(PcdType
)
581 Pcd
.SetValidUsage(CommentItem
.GetUsageItem())
582 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
583 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
584 HelpTextObj
= CommonObject
.TextObject()
585 if self
.UniFileClassObject
:
586 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
587 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
588 Pcd
.SetHelpTextList([HelpTextObj
])
589 PcdList
= self
.GetPcdList()
591 self
.SetPcdList(PcdList
)
596 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
598 # @param ContainerFile: The Inf file full path
600 def _GenSources(self
):
601 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_SOURCES
)
604 # Get all SourceFiles
606 SourceObj
= self
.Parser
.InfSourcesSection
.Sources
607 DataList
= SourceObj
.keys()
609 # Go through each arch
613 SourceData
= SourceObj
[Key
]
614 for Item
in SourceData
:
615 SourceFile
= Item
.GetSourceFileName()
616 Family
= Item
.GetFamily()
617 FeatureFlag
= Item
.GetFeatureFlagExp()
618 SupArchList
= ConvertArchList(Item
.GetSupArchList())
620 Source
= SourceFileObject()
621 Source
.SetSourceFile(SourceFile
)
622 Source
.SetFamily(Family
)
623 Source
.SetFeatureFlag(FeatureFlag
)
624 Source
.SetSupArchList(SupArchList
)
625 SourceList
.append(Source
)
627 self
.SetSourceFileList(self
.GetSourceFileList() + SourceList
)
632 # Gen UserExtensions of Inf
634 def _GenUserExtensions(self
):
638 UserExtensionObj
= self
.Parser
.InfUserExtensionSection
.UserExtension
639 Keys
= UserExtensionObj
.keys()
642 UserExtensionData
= UserExtensionObj
[Key
]
643 for UserExtensionDataObj
in UserExtensionData
:
644 UserExtension
= CommonObject
.UserExtensionObject()
645 UserId
= UserExtensionDataObj
.GetUserId()
646 if UserId
.startswith('"') and UserId
.endswith('"'):
647 UserId
= UserId
[1:-1]
648 UserExtension
.SetUserID(UserId
)
649 Identifier
= UserExtensionDataObj
.GetIdString()
650 if Identifier
.startswith('"') and Identifier
.endswith('"'):
651 Identifier
= Identifier
[1:-1]
653 # Generate miscellaneous files on INF file
655 if UserId
== 'TianoCore' and Identifier
== 'ExtraFiles':
656 self
._GenMiscFiles
(UserExtensionDataObj
.GetContent())
657 UserExtension
.SetIdentifier(Identifier
)
658 UserExtension
.SetStatement(UserExtensionDataObj
.GetContent())
659 UserExtension
.SetSupArchList(ConvertArchList(UserExtensionDataObj
.GetSupArchList()))
660 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
663 # Gen UserExtensions of TianoCore."BinaryHeader"
666 #Get Binary header from INF file
667 BinaryAbstractList
= self
.BinaryHeaderAbstractList
668 BinaryDescriptionList
= self
.BinaryHeaderDescriptionList
669 BinaryCopyrightList
= self
.BinaryHeaderCopyrightList
670 BinaryLicenseList
= self
.BinaryHeaderLicenseList
671 #Get Binary header from UNI file
672 # Initialize UniStrDict, the top keys are language codes
674 if self
.UniFileClassObject
:
675 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
676 for Lang
in UniStrDict
:
677 for StringDefClassObject
in UniStrDict
[Lang
]:
678 Lang
= GetLanguageCode1766(Lang
)
679 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_ABSTRACT
:
680 BinaryAbstractList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
681 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_DESCRIPTION
:
682 BinaryDescriptionList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
683 if BinaryAbstractList
or BinaryDescriptionList
or BinaryCopyrightList
or BinaryLicenseList
:
684 BinaryUserExtension
= CommonObject
.UserExtensionObject()
685 BinaryUserExtension
.SetBinaryAbstract(BinaryAbstractList
)
686 BinaryUserExtension
.SetBinaryDescription(BinaryDescriptionList
)
687 BinaryUserExtension
.SetBinaryCopyright(BinaryCopyrightList
)
688 BinaryUserExtension
.SetBinaryLicense(BinaryLicenseList
)
689 BinaryUserExtension
.SetIdentifier(DT
.TAB_BINARY_HEADER_IDENTIFIER
)
690 BinaryUserExtension
.SetUserID(DT
.TAB_BINARY_HEADER_USERID
)
691 self
.SetUserExtensionList(self
.GetUserExtensionList() + [BinaryUserExtension
])
693 def _GenDepexesList(self
, SmmDepexList
, DxeDepexList
, PeiDepexList
):
695 self
.SetSmmDepex(SmmDepexList
)
697 self
.SetDxeDepex(DxeDepexList
)
699 self
.SetPeiDepex(PeiDepexList
)
705 # @param ContainerFile: The Inf file full path
707 def _GenDepexes(self
):
708 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_DEPEX
)
710 PEI_LIST
= [DT
.SUP_MODULE_PEIM
]
711 SMM_LIST
= [DT
.SUP_MODULE_DXE_SMM_DRIVER
]
712 DXE_LIST
= [DT
.SUP_MODULE_DXE_DRIVER
, DT
.SUP_MODULE_DXE_SAL_DRIVER
,
713 DT
.SUP_MODULE_DXE_RUNTIME_DRIVER
]
715 IsLibraryClass
= self
.GetIsLibrary()
719 DepexData
= self
.Parser
.InfDepexSection
.GetDepex()
723 for Depex
in DepexData
:
724 ModuleType
= Depex
.GetModuleType()
727 if self
.GetModuleType() == 'BASE' and not ModuleType
:
728 Logger
.Error("\nMkPkg", PARSER_ERROR
,
729 ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS
,
730 self
.GetFullPath(), RaiseError
=True)
731 if self
.GetModuleType() != 'BASE' and not self
.GetIsLibraryModList():
732 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS
,
733 self
.GetFullPath(), RaiseError
=True)
734 if self
.GetModuleType() != 'BASE' and ModuleType
and ModuleType
not in self
.GetIsLibraryModList():
735 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
736 self
.GetFullPath(), RaiseError
=True)
738 ModuleTypeList
= [ModuleType
]
740 for ModuleTypeInList
in self
.GetIsLibraryModList():
741 if ModuleTypeInList
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
742 ModuleTypeList
.append(ModuleTypeInList
)
743 if not ModuleTypeList
:
744 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
745 self
.GetFullPath(), RaiseError
=True)
748 ModuleType
= self
.ModuleType
749 if ModuleType
not in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
750 Logger
.Error("\nMkPkg", PARSER_ERROR
,
751 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
752 self
.GetFullPath(), RaiseError
=True)
753 if ModuleType
!= self
.ModuleType
:
754 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
755 self
.GetFullPath(), RaiseError
=True)
756 ModuleTypeList
= [ModuleType
]
757 for ModuleType
in ModuleTypeList
:
758 DepexIns
= DepexObject()
759 DepexIns
.SetDepex(Depex
.GetDepexContent())
761 DepexIns
.SetModuleType(ModuleType
)
763 if Depex
.GetModuleType():
764 DepexIns
.SetModuleType(Depex
.GetModuleType())
765 DepexIns
.SetSupArchList(ConvertArchList([Depex
.GetSupArch()]))
766 DepexIns
.SetFeatureFlag(Depex
.GetFeatureFlagExp())
768 HelpIns
= CommonObject
.TextObject()
769 if self
.UniFileClassObject
:
770 HelpIns
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
771 HelpIns
.SetString(GetHelpStringByRemoveHashKey(Depex
.HelpString
))
772 DepexIns
.SetHelpText(HelpIns
)
774 if ModuleType
in SMM_LIST
:
775 SmmDepexList
.append(DepexIns
)
776 if ModuleType
in DXE_LIST
:
777 DxeDepexList
.append(DepexIns
)
778 if ModuleType
in PEI_LIST
:
779 PeiDepexList
.append(DepexIns
)
780 if ModuleType
== DT
.SUP_MODULE_UEFI_DRIVER
:
782 DxeDepexList
.append(DepexIns
)
784 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER
,
785 self
.GetFullPath(), RaiseError
=True)
787 #End of for ModuleType in ModuleTypeList
788 self
._GenDepexesList
(SmmDepexList
, DxeDepexList
, PeiDepexList
)
789 #End of for Depex in DepexData
793 # Gen Binary of Inf, must be called after Pcd/Library is generated
794 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
796 # @param ContainerFile: The Inf file full path
798 def _GenBinaries(self
):
799 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BINARIES
)
803 # Get all Binary data
805 BinaryObj
= self
.Parser
.InfBinariesSection
.GetBinary()
807 BinaryData
= BinaryObj
.keys()
810 # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section,
811 # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute
813 if BinaryObj
and not self
.Parser
.InfSourcesSection
.GetSources():
814 self
.BinaryModule
= True
816 self
.BinaryModule
= False
818 BinaryFileObjectList
= []
819 AsBuildLibraryClassList
= []
820 AsBuildBuildOptionList
= []
821 AsBuildIns
= AsBuiltObject()
823 # Library AsBuild Info
825 for LibItem
in self
.Parser
.InfLibraryClassSection
.GetLibraryClasses():
826 AsBuildLibIns
= AsBuildLibraryClassObject()
827 AsBuildLibIns
.SetLibGuid(LibItem
.GetFileGuid())
828 AsBuildLibIns
.SetLibVersion(LibItem
.GetVersion())
829 AsBuildLibIns
.SetSupArchList(LibItem
.GetSupArchList())
830 AsBuildLibraryClassList
.append(AsBuildLibIns
)
831 AsBuildIns
.SetLibraryInstancesList(AsBuildLibraryClassList
)
834 # BuildOption AsBuild Info
836 for BuildOptionItem
in self
.Parser
.InfBuildOptionSection
.GetBuildOptions():
837 AsBuildBuildOptionList
.append(BuildOptionItem
)
838 AsBuildIns
.SetBuildFlagsList(AsBuildBuildOptionList
)
843 AsBuildIns
= self
._GenAsBuiltPcds
(self
.Parser
.InfPcdSection
.GetPcds(), AsBuildIns
)
846 # Parse the DEC file that contains the GUID value of the GUID CName which is used by
847 # SUBTYPE_GUID type binary file in the Binaries section in the INF file
850 if not self
.PackagePath
:
851 WorkSpace
= os
.path
.normpath(self
.WorkSpace
)
852 TempPath
= ModulePath
= os
.path
.normpath(self
.ModulePath
)
854 TempPath
= ModulePath
855 ModulePath
= os
.path
.dirname(ModulePath
)
856 PackageName
= TempPath
857 DecFilePath
= os
.path
.normpath(os
.path
.join(WorkSpace
, PackageName
))
859 for File
in os
.listdir(DecFilePath
):
860 if File
.upper().endswith('.DEC'):
861 DecFileFullPath
= os
.path
.normpath(os
.path
.join(DecFilePath
, File
))
862 DecObjList
.append(DecPomAlignment(DecFileFullPath
, self
.WorkSpace
))
865 BinariesDict
, AsBuildIns
, BinaryFileObjectList
= GenBinaryData(BinaryData
, BinaryObj
,
868 BinaryFileObjectList
,
869 self
.GetSupArchList(),
874 for Key
in BinariesDict
:
875 ValueList
= BinariesDict
[Key
]
876 if len(ValueList
) > 1:
877 BinariesDict2
[Key
] = ValueList
880 # if there is no TagName, ToolCode, HelpStr,
881 # then do not need to put them into userextension
883 (Target
, Family
, TagName
, HelpStr
) = ValueList
[0]
884 if not (Target
or Family
or TagName
or HelpStr
):
887 BinariesDict2
[Key
] = ValueList
889 self
.SetBinaryFileList(self
.GetBinaryFileList() + BinaryFileObjectList
)
892 UserExtension
= CommonObject
.UserExtensionObject()
893 UserExtension
.SetBinariesDict(BinariesDict2
)
894 UserExtension
.SetIdentifier('BinaryFileModifiers')
895 UserExtension
.SetUserID('EDK2')
896 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
901 def _GenAsBuiltPcds(self
, PcdList
, AsBuildIns
):
902 AsBuildPatchPcdList
= []
903 AsBuildPcdExList
= []
907 for PcdItem
in PcdList
:
908 if PcdItem
[0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
909 PcdItemObj
= PcdItem
[1]
910 Pcd
= CommonObject
.PcdObject()
911 Pcd
.SetCName(PcdItemObj
.GetCName())
912 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
913 if PcdItemObj
.GetTokenSpaceGuidValue() == '' and self
.BinaryModule
:
914 Logger
.Error("\nMkPkg",
916 ST
.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS
% \
917 (PcdItemObj
.GetTokenSpaceGuidCName()),
918 self
.GetFullPath(), RaiseError
=True)
920 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
921 if (PcdItemObj
.GetToken() == '' or PcdItemObj
.GetDatumType() == '') and self
.BinaryModule
:
922 Logger
.Error("\nMkPkg",
924 ST
.ERR_ASBUILD_PCD_DECLARITION_MISS
% \
925 (PcdItemObj
.GetTokenSpaceGuidCName() + '.' + PcdItemObj
.GetCName()),
926 self
.GetFullPath(), RaiseError
=True)
927 Pcd
.SetToken(PcdItemObj
.GetToken())
928 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
929 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
930 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
931 Pcd
.SetOffset(PcdItemObj
.GetOffset())
932 Pcd
.SetItemType(PcdItem
[0])
933 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
934 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
935 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
936 for CommentItem
in PcdItemObj
.GetHelpStringList():
937 HelpTextObj
= CommonObject
.TextObject()
938 if self
.UniFileClassObject
:
939 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
940 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
941 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
942 AsBuildPatchPcdList
.append(Pcd
)
944 PcdItemObj
= PcdItem
[1]
945 Pcd
= CommonObject
.PcdObject()
946 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
947 Pcd
.SetToken(PcdItemObj
.GetToken())
948 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
949 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
950 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
951 Pcd
.SetItemType(PcdItem
[0])
952 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
953 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
954 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
955 for CommentItem
in PcdItemObj
.GetHelpStringList():
956 HelpTextObj
= CommonObject
.TextObject()
957 if self
.UniFileClassObject
:
958 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
959 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
960 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
961 AsBuildPcdExList
.append(Pcd
)
962 AsBuildIns
.SetPatchPcdList(AsBuildPatchPcdList
)
963 AsBuildIns
.SetPcdExList(AsBuildPcdExList
)
967 ## GenGuidProtocolPpis
969 # Gen Guids/Protocol/Ppis of INF
970 # <CName>=<GuidValue>
972 def _GenGuidProtocolPpis(self
, Type
):
973 Logger
.Debug(2, "Generate %s ..." % Type
)
975 # Get all Guid/Protocol/Ppis data
977 GuidObj
= self
.Parser
.InfGuidSection
.GetGuid()
978 ProtocolObj
= self
.Parser
.InfProtocolSection
.GetProtocol()
979 PpisObj
= self
.Parser
.InfPpiSection
.GetPpi()
981 GuidProtocolPpiList
= []
983 if Type
== DT
.TAB_GUIDS
:
984 GuidData
= GuidObj
.keys()
985 for Item
in GuidData
:
986 CommentList
= Item
.GetCommentList()
988 # Depend on CommentList content
989 # generate muti-guid-obj
992 for GuidComentItem
in CommentList
:
993 ListObject
= CommonObject
.GuidObject()
994 ListObject
.SetGuidTypeList([GuidComentItem
.GetGuidTypeItem()])
995 ListObject
.SetVariableName(GuidComentItem
.GetVariableNameItem())
996 ListObject
.SetUsage(GuidComentItem
.GetUsageItem())
997 ListObject
.SetName(Item
.GetName())
998 ListObject
.SetCName(Item
.GetName())
999 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1000 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1001 HelpString
= GuidComentItem
.GetHelpStringItem()
1002 if HelpString
.strip():
1003 HelpTxtTailObj
= CommonObject
.TextObject()
1004 if self
.UniFileClassObject
:
1005 HelpTxtTailObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1006 HelpTxtTailObj
.SetString(HelpString
)
1007 ListObject
.SetHelpTextList([HelpTxtTailObj
])
1009 GuidProtocolPpiList
.append(ListObject
)
1010 elif Type
== DT
.TAB_PROTOCOLS
:
1011 ProtocolData
= ProtocolObj
.keys()
1012 for Item
in ProtocolData
:
1013 CommentList
= Item
.GetCommentList()
1014 for CommentItem
in CommentList
:
1015 ListObject
= CommonObject
.ProtocolObject()
1016 ListObject
.SetCName(Item
.GetName())
1017 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1018 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1019 ListObject
.SetNotify(CommentItem
.GetNotify())
1020 ListObject
.SetUsage(CommentItem
.GetUsageItem())
1021 HelpString
= CommentItem
.GetHelpStringItem()
1022 if HelpString
.strip():
1023 HelpTxtObj
= CommonObject
.TextObject()
1024 if self
.UniFileClassObject
:
1025 HelpTxtObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1026 HelpTxtObj
.SetString(HelpString
)
1027 ListObject
.SetHelpTextList([HelpTxtObj
])
1028 GuidProtocolPpiList
.append(ListObject
)
1029 elif Type
== DT
.TAB_PPIS
:
1030 PpiData
= PpisObj
.keys()
1031 for Item
in PpiData
:
1032 CommentList
= Item
.GetCommentList()
1033 for CommentItem
in CommentList
:
1034 ListObject
= CommonObject
.PpiObject()
1035 ListObject
.SetCName(Item
.GetName())
1036 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1037 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1038 ListObject
.SetNotify(CommentItem
.GetNotify())
1039 ListObject
.SetUsage(CommentItem
.GetUsage())
1040 HelpString
= CommentItem
.GetHelpStringItem()
1041 if HelpString
.strip():
1042 HelpTextObj
= CommonObject
.TextObject()
1043 if self
.UniFileClassObject
:
1044 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1045 HelpTextObj
.SetString(HelpString
)
1046 ListObject
.SetHelpTextList([HelpTextObj
])
1047 GuidProtocolPpiList
.append(ListObject
)
1049 if Type
== DT
.TAB_GUIDS
:
1050 self
.SetGuidList(self
.GetGuidList() + GuidProtocolPpiList
)
1051 elif Type
== DT
.TAB_PROTOCOLS
:
1052 self
.SetProtocolList(self
.GetProtocolList() + GuidProtocolPpiList
)
1053 elif Type
== DT
.TAB_PPIS
:
1054 self
.SetPpiList(self
.GetPpiList() + GuidProtocolPpiList
)
1058 # Gen MiscellaneousFiles of Inf
1060 # @param ContainerFile: The Inf file full path
1062 def _GenMiscFiles(self
, Content
):
1063 MiscFileObj
= CommonObject
.MiscFileObject()
1064 for Line
in Content
.splitlines():
1067 FileName
= Line
[:Line
.find('#')]
1071 if IsValidPath(FileName
, GlobalData
.gINF_MODULE_DIR
):
1072 FileObj
= CommonObject
.FileObject()
1073 FileObj
.SetURI(FileName
)
1074 MiscFileObj
.SetFileList(MiscFileObj
.GetFileList()+[FileObj
])
1076 Logger
.Error("InfParser",
1078 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Line),
1079 File
=GlobalData
.gINF_MODULE_NAME
,
1081 self
.SetMiscFileList(self
.GetMiscFileList()+[MiscFileObj
])