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
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
= 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 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
is not 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(mws
.join(self
.WorkSpace
, NormPath(PackageItemObj
.GetPackageName())))
538 if PkgInfo
[1] and PkgInfo
[2]:
539 PackageDependency
.SetGuid(PkgInfo
[1])
540 PackageDependency
.SetVersion(PkgInfo
[2])
544 Logger
.Error("\nUPT", PARSER_ERROR
,
545 ST
.ERR_INF_GET_PKG_DEPENDENCY_FAIL
% PackageItemObj
.GetPackageName(), File
=self
.FullPath
)
547 PackageDependencyList
= self
.GetPackageDependencyList()
548 PackageDependencyList
.append(PackageDependency
)
549 self
.SetPackageDependencyList(PackageDependencyList
)
554 # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]]
556 # @param ContainerFile: The Inf file full path
559 if not GlobalData
.gIS_BINARY_INF
:
560 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_PCDS
)
564 PcdObj
= self
.Parser
.InfPcdSection
.Pcds
565 KeysList
= PcdObj
.keys()
567 # Go through each arch
569 for (PcdType
, PcdKey
) in KeysList
:
570 PcdData
= PcdObj
[PcdType
, PcdKey
]
571 for PcdItemObj
in PcdData
:
572 CommentList
= PcdItemObj
.GetHelpStringList()
574 for CommentItem
in CommentList
:
575 Pcd
= CommonObject
.PcdObject()
576 Pcd
.SetCName(PcdItemObj
.GetCName())
577 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
578 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
579 Pcd
.SetItemType(PcdType
)
580 Pcd
.SetValidUsage(CommentItem
.GetUsageItem())
581 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
582 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
583 HelpTextObj
= CommonObject
.TextObject()
584 if self
.UniFileClassObject
:
585 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
586 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
587 Pcd
.SetHelpTextList([HelpTextObj
])
588 PcdList
= self
.GetPcdList()
590 self
.SetPcdList(PcdList
)
595 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]
597 # @param ContainerFile: The Inf file full path
599 def _GenSources(self
):
600 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_SOURCES
)
603 # Get all SourceFiles
605 SourceObj
= self
.Parser
.InfSourcesSection
.Sources
606 DataList
= SourceObj
.keys()
608 # Go through each arch
612 SourceData
= SourceObj
[Key
]
613 for Item
in SourceData
:
614 SourceFile
= Item
.GetSourceFileName()
615 Family
= Item
.GetFamily()
616 FeatureFlag
= Item
.GetFeatureFlagExp()
617 SupArchList
= ConvertArchList(Item
.GetSupArchList())
619 Source
= SourceFileObject()
620 Source
.SetSourceFile(SourceFile
)
621 Source
.SetFamily(Family
)
622 Source
.SetFeatureFlag(FeatureFlag
)
623 Source
.SetSupArchList(SupArchList
)
624 SourceList
.append(Source
)
626 self
.SetSourceFileList(self
.GetSourceFileList() + SourceList
)
631 # Gen UserExtensions of Inf
633 def _GenUserExtensions(self
):
637 UserExtensionObj
= self
.Parser
.InfUserExtensionSection
.UserExtension
638 Keys
= UserExtensionObj
.keys()
641 UserExtensionData
= UserExtensionObj
[Key
]
642 for UserExtensionDataObj
in UserExtensionData
:
643 UserExtension
= CommonObject
.UserExtensionObject()
644 UserId
= UserExtensionDataObj
.GetUserId()
645 if UserId
.startswith('"') and UserId
.endswith('"'):
646 UserId
= UserId
[1:-1]
647 UserExtension
.SetUserID(UserId
)
648 Identifier
= UserExtensionDataObj
.GetIdString()
649 if Identifier
.startswith('"') and Identifier
.endswith('"'):
650 Identifier
= Identifier
[1:-1]
652 # Generate miscellaneous files on INF file
654 if UserId
== 'TianoCore' and Identifier
== 'ExtraFiles':
655 self
._GenMiscFiles
(UserExtensionDataObj
.GetContent())
656 UserExtension
.SetIdentifier(Identifier
)
657 UserExtension
.SetStatement(UserExtensionDataObj
.GetContent())
658 UserExtension
.SetSupArchList(ConvertArchList(UserExtensionDataObj
.GetSupArchList()))
659 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
662 # Gen UserExtensions of TianoCore."BinaryHeader"
665 #Get Binary header from INF file
666 BinaryAbstractList
= self
.BinaryHeaderAbstractList
667 BinaryDescriptionList
= self
.BinaryHeaderDescriptionList
668 BinaryCopyrightList
= self
.BinaryHeaderCopyrightList
669 BinaryLicenseList
= self
.BinaryHeaderLicenseList
670 #Get Binary header from UNI file
671 # Initialize UniStrDict, the top keys are language codes
673 if self
.UniFileClassObject
:
674 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
675 for Lang
in UniStrDict
:
676 for StringDefClassObject
in UniStrDict
[Lang
]:
677 Lang
= GetLanguageCode1766(Lang
)
678 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_ABSTRACT
:
679 BinaryAbstractList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
680 if StringDefClassObject
.StringName
== DT
.TAB_INF_BINARY_DESCRIPTION
:
681 BinaryDescriptionList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
682 if BinaryAbstractList
or BinaryDescriptionList
or BinaryCopyrightList
or BinaryLicenseList
:
683 BinaryUserExtension
= CommonObject
.UserExtensionObject()
684 BinaryUserExtension
.SetBinaryAbstract(BinaryAbstractList
)
685 BinaryUserExtension
.SetBinaryDescription(BinaryDescriptionList
)
686 BinaryUserExtension
.SetBinaryCopyright(BinaryCopyrightList
)
687 BinaryUserExtension
.SetBinaryLicense(BinaryLicenseList
)
688 BinaryUserExtension
.SetIdentifier(DT
.TAB_BINARY_HEADER_IDENTIFIER
)
689 BinaryUserExtension
.SetUserID(DT
.TAB_BINARY_HEADER_USERID
)
690 self
.SetUserExtensionList(self
.GetUserExtensionList() + [BinaryUserExtension
])
692 def _GenDepexesList(self
, SmmDepexList
, DxeDepexList
, PeiDepexList
):
694 self
.SetSmmDepex(SmmDepexList
)
696 self
.SetDxeDepex(DxeDepexList
)
698 self
.SetPeiDepex(PeiDepexList
)
704 # @param ContainerFile: The Inf file full path
706 def _GenDepexes(self
):
707 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_DEPEX
)
709 PEI_LIST
= [DT
.SUP_MODULE_PEIM
]
710 SMM_LIST
= [DT
.SUP_MODULE_DXE_SMM_DRIVER
]
711 DXE_LIST
= [DT
.SUP_MODULE_DXE_DRIVER
, DT
.SUP_MODULE_DXE_SAL_DRIVER
,
712 DT
.SUP_MODULE_DXE_RUNTIME_DRIVER
]
714 IsLibraryClass
= self
.GetIsLibrary()
718 DepexData
= self
.Parser
.InfDepexSection
.GetDepex()
722 for Depex
in DepexData
:
723 ModuleType
= Depex
.GetModuleType()
726 if self
.GetModuleType() == 'BASE' and not ModuleType
:
727 Logger
.Error("\nMkPkg", PARSER_ERROR
,
728 ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS
,
729 self
.GetFullPath(), RaiseError
=True)
730 if self
.GetModuleType() != 'BASE' and not self
.GetIsLibraryModList():
731 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS
,
732 self
.GetFullPath(), RaiseError
=True)
733 if self
.GetModuleType() != 'BASE' and ModuleType
and ModuleType
not in self
.GetIsLibraryModList():
734 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
735 self
.GetFullPath(), RaiseError
=True)
737 ModuleTypeList
= [ModuleType
]
739 for ModuleTypeInList
in self
.GetIsLibraryModList():
740 if ModuleTypeInList
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
741 ModuleTypeList
.append(ModuleTypeInList
)
742 if not ModuleTypeList
:
743 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
744 self
.GetFullPath(), RaiseError
=True)
747 ModuleType
= self
.ModuleType
748 if ModuleType
not in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
749 Logger
.Error("\nMkPkg", PARSER_ERROR
,
750 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
751 self
.GetFullPath(), RaiseError
=True)
752 if ModuleType
!= self
.ModuleType
:
753 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED
,
754 self
.GetFullPath(), RaiseError
=True)
755 ModuleTypeList
= [ModuleType
]
756 for ModuleType
in ModuleTypeList
:
757 DepexIns
= DepexObject()
758 DepexIns
.SetDepex(Depex
.GetDepexContent())
760 DepexIns
.SetModuleType(ModuleType
)
762 if Depex
.GetModuleType():
763 DepexIns
.SetModuleType(Depex
.GetModuleType())
764 DepexIns
.SetSupArchList(ConvertArchList([Depex
.GetSupArch()]))
765 DepexIns
.SetFeatureFlag(Depex
.GetFeatureFlagExp())
767 HelpIns
= CommonObject
.TextObject()
768 if self
.UniFileClassObject
:
769 HelpIns
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
770 HelpIns
.SetString(GetHelpStringByRemoveHashKey(Depex
.HelpString
))
771 DepexIns
.SetHelpText(HelpIns
)
773 if ModuleType
in SMM_LIST
:
774 SmmDepexList
.append(DepexIns
)
775 if ModuleType
in DXE_LIST
:
776 DxeDepexList
.append(DepexIns
)
777 if ModuleType
in PEI_LIST
:
778 PeiDepexList
.append(DepexIns
)
779 if ModuleType
== DT
.SUP_MODULE_UEFI_DRIVER
:
781 DxeDepexList
.append(DepexIns
)
783 Logger
.Error("\nMkPkg", PARSER_ERROR
, ST
.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER
,
784 self
.GetFullPath(), RaiseError
=True)
786 #End of for ModuleType in ModuleTypeList
787 self
._GenDepexesList
(SmmDepexList
, DxeDepexList
, PeiDepexList
)
788 #End of for Depex in DepexData
792 # Gen Binary of Inf, must be called after Pcd/Library is generated
793 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]
795 # @param ContainerFile: The Inf file full path
797 def _GenBinaries(self
):
798 Logger
.Debug(2, "Generate %s ..." % DT
.TAB_BINARIES
)
802 # Get all Binary data
804 BinaryObj
= self
.Parser
.InfBinariesSection
.GetBinary()
806 BinaryData
= BinaryObj
.keys()
809 # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section,
810 # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute
812 if BinaryObj
and not self
.Parser
.InfSourcesSection
.GetSources():
813 self
.BinaryModule
= True
815 self
.BinaryModule
= False
817 BinaryFileObjectList
= []
818 AsBuildLibraryClassList
= []
819 AsBuildBuildOptionList
= []
820 AsBuildIns
= AsBuiltObject()
822 # Library AsBuild Info
824 for LibItem
in self
.Parser
.InfLibraryClassSection
.GetLibraryClasses():
825 AsBuildLibIns
= AsBuildLibraryClassObject()
826 AsBuildLibIns
.SetLibGuid(LibItem
.GetFileGuid())
827 AsBuildLibIns
.SetLibVersion(LibItem
.GetVersion())
828 AsBuildLibIns
.SetSupArchList(LibItem
.GetSupArchList())
829 AsBuildLibraryClassList
.append(AsBuildLibIns
)
830 AsBuildIns
.SetLibraryInstancesList(AsBuildLibraryClassList
)
833 # BuildOption AsBuild Info
835 for BuildOptionItem
in self
.Parser
.InfBuildOptionSection
.GetBuildOptions():
836 AsBuildBuildOptionList
.append(BuildOptionItem
)
837 AsBuildIns
.SetBuildFlagsList(AsBuildBuildOptionList
)
842 AsBuildIns
= self
._GenAsBuiltPcds
(self
.Parser
.InfPcdSection
.GetPcds(), AsBuildIns
)
845 # Parse the DEC file that contains the GUID value of the GUID CName which is used by
846 # SUBTYPE_GUID type binary file in the Binaries section in the INF file
849 if not self
.PackagePath
:
850 WorkSpace
= os
.path
.normpath(self
.WorkSpace
)
851 TempPath
= ModulePath
= os
.path
.normpath(self
.ModulePath
)
853 TempPath
= ModulePath
854 ModulePath
= os
.path
.dirname(ModulePath
)
855 PackageName
= TempPath
856 DecFilePath
= os
.path
.normpath(os
.path
.join(WorkSpace
, PackageName
))
858 for File
in os
.listdir(DecFilePath
):
859 if File
.upper().endswith('.DEC'):
860 DecFileFullPath
= os
.path
.normpath(os
.path
.join(DecFilePath
, File
))
861 DecObjList
.append(DecPomAlignment(DecFileFullPath
, self
.WorkSpace
))
864 BinariesDict
, AsBuildIns
, BinaryFileObjectList
= GenBinaryData(BinaryData
, BinaryObj
,
867 BinaryFileObjectList
,
868 self
.GetSupArchList(),
873 for Key
in BinariesDict
:
874 ValueList
= BinariesDict
[Key
]
875 if len(ValueList
) > 1:
876 BinariesDict2
[Key
] = ValueList
879 # if there is no TagName, ToolCode, HelpStr,
880 # then do not need to put them into userextension
882 (Target
, Family
, TagName
, HelpStr
) = ValueList
[0]
883 if not (Target
or Family
or TagName
or HelpStr
):
886 BinariesDict2
[Key
] = ValueList
888 self
.SetBinaryFileList(self
.GetBinaryFileList() + BinaryFileObjectList
)
891 UserExtension
= CommonObject
.UserExtensionObject()
892 UserExtension
.SetBinariesDict(BinariesDict2
)
893 UserExtension
.SetIdentifier('BinaryFileModifiers')
894 UserExtension
.SetUserID('EDK2')
895 self
.SetUserExtensionList(self
.GetUserExtensionList() + [UserExtension
])
900 def _GenAsBuiltPcds(self
, PcdList
, AsBuildIns
):
901 AsBuildPatchPcdList
= []
902 AsBuildPcdExList
= []
906 for PcdItem
in PcdList
:
907 if PcdItem
[0].upper() == DT
.TAB_INF_PATCH_PCD
.upper():
908 PcdItemObj
= PcdItem
[1]
909 Pcd
= CommonObject
.PcdObject()
910 Pcd
.SetCName(PcdItemObj
.GetCName())
911 Pcd
.SetTokenSpaceGuidCName(PcdItemObj
.GetTokenSpaceGuidCName())
912 if PcdItemObj
.GetTokenSpaceGuidValue() == '' and self
.BinaryModule
:
913 Logger
.Error("\nMkPkg",
915 ST
.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS
% \
916 (PcdItemObj
.GetTokenSpaceGuidCName()),
917 self
.GetFullPath(), RaiseError
=True)
919 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
920 if (PcdItemObj
.GetToken() == '' or PcdItemObj
.GetDatumType() == '') and self
.BinaryModule
:
921 Logger
.Error("\nMkPkg",
923 ST
.ERR_ASBUILD_PCD_DECLARITION_MISS
% \
924 (PcdItemObj
.GetTokenSpaceGuidCName() + '.' + PcdItemObj
.GetCName()),
925 self
.GetFullPath(), RaiseError
=True)
926 Pcd
.SetToken(PcdItemObj
.GetToken())
927 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
928 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
929 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
930 Pcd
.SetOffset(PcdItemObj
.GetOffset())
931 Pcd
.SetItemType(PcdItem
[0])
932 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
933 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
934 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
935 for CommentItem
in PcdItemObj
.GetHelpStringList():
936 HelpTextObj
= CommonObject
.TextObject()
937 if self
.UniFileClassObject
:
938 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
939 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
940 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
941 AsBuildPatchPcdList
.append(Pcd
)
942 elif PcdItem
[0].upper() == DT
.TAB_INF_PCD_EX
.upper():
943 PcdItemObj
= PcdItem
[1]
944 Pcd
= CommonObject
.PcdObject()
945 Pcd
.SetTokenSpaceGuidValue(PcdItemObj
.GetTokenSpaceGuidValue())
946 Pcd
.SetToken(PcdItemObj
.GetToken())
947 Pcd
.SetDatumType(PcdItemObj
.GetDatumType())
948 Pcd
.SetMaxDatumSize(PcdItemObj
.GetMaxDatumSize())
949 Pcd
.SetDefaultValue(PcdItemObj
.GetDefaultValue())
950 Pcd
.SetItemType(PcdItem
[0])
951 Pcd
.SetFeatureFlag(PcdItemObj
.GetFeatureFlagExp())
952 Pcd
.SetSupArchList(ConvertArchList(PcdItemObj
.GetSupportArchList()))
953 Pcd
.SetValidUsage(PcdItemObj
.GetValidUsage())
954 for CommentItem
in PcdItemObj
.GetHelpStringList():
955 HelpTextObj
= CommonObject
.TextObject()
956 if self
.UniFileClassObject
:
957 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
958 HelpTextObj
.SetString(CommentItem
.GetHelpStringItem())
959 Pcd
.SetHelpTextList(Pcd
.GetHelpTextList() + [HelpTextObj
])
960 AsBuildPcdExList
.append(Pcd
)
961 AsBuildIns
.SetPatchPcdList(AsBuildPatchPcdList
)
962 AsBuildIns
.SetPcdExList(AsBuildPcdExList
)
966 ## GenGuidProtocolPpis
968 # Gen Guids/Protocol/Ppis of INF
969 # <CName>=<GuidValue>
971 def _GenGuidProtocolPpis(self
, Type
):
972 Logger
.Debug(2, "Generate %s ..." % Type
)
974 # Get all Guid/Protocol/Ppis data
976 GuidObj
= self
.Parser
.InfGuidSection
.GetGuid()
977 ProtocolObj
= self
.Parser
.InfProtocolSection
.GetProtocol()
978 PpisObj
= self
.Parser
.InfPpiSection
.GetPpi()
980 GuidProtocolPpiList
= []
982 if Type
== DT
.TAB_GUIDS
:
983 GuidData
= GuidObj
.keys()
984 for Item
in GuidData
:
985 CommentList
= Item
.GetCommentList()
987 # Depend on CommentList content
988 # generate muti-guid-obj
991 for GuidComentItem
in CommentList
:
992 ListObject
= CommonObject
.GuidObject()
993 ListObject
.SetGuidTypeList([GuidComentItem
.GetGuidTypeItem()])
994 ListObject
.SetVariableName(GuidComentItem
.GetVariableNameItem())
995 ListObject
.SetUsage(GuidComentItem
.GetUsageItem())
996 ListObject
.SetName(Item
.GetName())
997 ListObject
.SetCName(Item
.GetName())
998 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
999 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1000 HelpString
= GuidComentItem
.GetHelpStringItem()
1001 if HelpString
.strip():
1002 HelpTxtTailObj
= CommonObject
.TextObject()
1003 if self
.UniFileClassObject
:
1004 HelpTxtTailObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1005 HelpTxtTailObj
.SetString(HelpString
)
1006 ListObject
.SetHelpTextList([HelpTxtTailObj
])
1008 GuidProtocolPpiList
.append(ListObject
)
1009 elif Type
== DT
.TAB_PROTOCOLS
:
1010 ProtocolData
= ProtocolObj
.keys()
1011 for Item
in ProtocolData
:
1012 CommentList
= Item
.GetCommentList()
1013 for CommentItem
in CommentList
:
1014 ListObject
= CommonObject
.ProtocolObject()
1015 ListObject
.SetCName(Item
.GetName())
1016 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1017 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1018 ListObject
.SetNotify(CommentItem
.GetNotify())
1019 ListObject
.SetUsage(CommentItem
.GetUsageItem())
1020 HelpString
= CommentItem
.GetHelpStringItem()
1021 if HelpString
.strip():
1022 HelpTxtObj
= CommonObject
.TextObject()
1023 if self
.UniFileClassObject
:
1024 HelpTxtObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1025 HelpTxtObj
.SetString(HelpString
)
1026 ListObject
.SetHelpTextList([HelpTxtObj
])
1027 GuidProtocolPpiList
.append(ListObject
)
1028 elif Type
== DT
.TAB_PPIS
:
1029 PpiData
= PpisObj
.keys()
1030 for Item
in PpiData
:
1031 CommentList
= Item
.GetCommentList()
1032 for CommentItem
in CommentList
:
1033 ListObject
= CommonObject
.PpiObject()
1034 ListObject
.SetCName(Item
.GetName())
1035 ListObject
.SetSupArchList(ConvertArchList(Item
.GetSupArchList()))
1036 ListObject
.SetFeatureFlag(Item
.GetFeatureFlagExp())
1037 ListObject
.SetNotify(CommentItem
.GetNotify())
1038 ListObject
.SetUsage(CommentItem
.GetUsage())
1039 HelpString
= CommentItem
.GetHelpStringItem()
1040 if HelpString
.strip():
1041 HelpTextObj
= CommonObject
.TextObject()
1042 if self
.UniFileClassObject
:
1043 HelpTextObj
.SetLang(DT
.TAB_LANGUAGE_EN_X
)
1044 HelpTextObj
.SetString(HelpString
)
1045 ListObject
.SetHelpTextList([HelpTextObj
])
1046 GuidProtocolPpiList
.append(ListObject
)
1048 if Type
== DT
.TAB_GUIDS
:
1049 self
.SetGuidList(self
.GetGuidList() + GuidProtocolPpiList
)
1050 elif Type
== DT
.TAB_PROTOCOLS
:
1051 self
.SetProtocolList(self
.GetProtocolList() + GuidProtocolPpiList
)
1052 elif Type
== DT
.TAB_PPIS
:
1053 self
.SetPpiList(self
.GetPpiList() + GuidProtocolPpiList
)
1057 # Gen MiscellaneousFiles of Inf
1059 # @param ContainerFile: The Inf file full path
1061 def _GenMiscFiles(self
, Content
):
1062 MiscFileObj
= CommonObject
.MiscFileObject()
1063 for Line
in Content
.splitlines():
1066 FileName
= Line
[:Line
.find('#')]
1070 if IsValidPath(FileName
, GlobalData
.gINF_MODULE_DIR
):
1071 FileObj
= CommonObject
.FileObject()
1072 FileObj
.SetURI(FileName
)
1073 MiscFileObj
.SetFileList(MiscFileObj
.GetFileList()+[FileObj
])
1075 Logger
.Error("InfParser",
1077 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Line),
1078 File
=GlobalData
.gINF_MODULE_NAME
,
1080 self
.SetMiscFileList(self
.GetMiscFileList()+[MiscFileObj
])