diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
commit | f215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch) | |
tree | 6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter | |
parent | Initial commit. (diff) | |
download | virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip |
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter')
4 files changed, 2340 insertions, 0 deletions
diff --git a/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py new file mode 100755 index 00000000..354e493d --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py @@ -0,0 +1,1000 @@ +## @file DecPomAlignment.py +# This file contained the adapter for convert INF parser object to POM Object +# +# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' +DecPomAlignment +''' +from __future__ import print_function + +## +# Import Modules +# +import os.path +from os import sep +import platform + +import re +import Logger.Log as Logger +from Logger import StringTable as ST +from Logger.ToolError import UPT_MUL_DEC_ERROR +from Logger.ToolError import FORMAT_INVALID + +from Library.Parsing import NormPath +from Library.DataType import ARCH_LIST +from Library.DataType import TAB_GUIDS +from Library.DataType import TAB_PROTOCOLS +from Library.DataType import TAB_PPIS +from Library.DataType import TAB_DEC_DEFINES_PACKAGE_NAME +from Library.DataType import TAB_DEC_DEFINES_PACKAGE_GUID +from Library.DataType import TAB_DEC_DEFINES_PACKAGE_VERSION +from Library.DataType import TAB_DEC_DEFINES_DEC_SPECIFICATION +from Library.DataType import TAB_DEC_DEFINES_PKG_UNI_FILE +from Library.DataType import TAB_ARCH_COMMON +from Library.DataType import TAB_INCLUDES +from Library.DataType import TAB_LIBRARY_CLASSES +from Library.DataType import TAB_PCDS +from Library.DataType import TAB_PCDS_FIXED_AT_BUILD_NULL +from Library.DataType import TAB_PCDS_PATCHABLE_IN_MODULE_NULL +from Library.DataType import TAB_PCDS_FEATURE_FLAG_NULL +from Library.DataType import TAB_PCDS_DYNAMIC_EX_NULL +from Library.DataType import TAB_PCDS_DYNAMIC_NULL +from Library.DataType import TAB_PTR_TYPE_PCD +from Library.DataType import ITEM_UNDEFINED +from Library.DataType import TAB_DEC_BINARY_ABSTRACT +from Library.DataType import TAB_DEC_BINARY_DESCRIPTION +from Library.DataType import TAB_LANGUAGE_EN_US +from Library.DataType import TAB_BINARY_HEADER_IDENTIFIER +from Library.DataType import TAB_BINARY_HEADER_USERID +from Library.DataType import TAB_LANGUAGE_EN_X +from Library.DataType import TAB_LANGUAGE_EN +from Library.DataType import TAB_STR_TOKENCNAME +from Library.DataType import TAB_STR_TOKENPROMPT +from Library.DataType import TAB_STR_TOKENHELP +from Library.DataType import TAB_STR_TOKENERR +from Library.DataType import TAB_HEX_START +from Library.DataType import TAB_SPLIT +import Library.DataType as DT +from Library.CommentParsing import ParseHeaderCommentSection +from Library.CommentParsing import ParseGenericComment +from Library.CommentParsing import ParseDecPcdGenericComment +from Library.CommentParsing import ParseDecPcdTailComment +from Library.Misc import GetFiles +from Library.Misc import Sdict +from Library.Misc import GetRelativePath +from Library.Misc import PathClass +from Library.Misc import ValidateUNIFilePath +from Library.UniClassObject import UniFileClassObject +from Library.UniClassObject import ConvertSpecialUnicodes +from Library.UniClassObject import GetLanguageCode1766 +from Library.ParserValidate import IsValidPath +from Parser.DecParser import Dec +from Object.POM.PackageObject import PackageObject +from Object.POM.CommonObject import UserExtensionObject +from Object.POM.CommonObject import IncludeObject +from Object.POM.CommonObject import GuidObject +from Object.POM.CommonObject import ProtocolObject +from Object.POM.CommonObject import PpiObject +from Object.POM.CommonObject import LibraryClassObject +from Object.POM.CommonObject import PcdObject +from Object.POM.CommonObject import TextObject +from Object.POM.CommonObject import MiscFileObject +from Object.POM.CommonObject import FileObject + + +## DecPomAlignment +# +# Inherited from PackageObject +# +class DecPomAlignment(PackageObject): + def __init__(self, Filename, WorkspaceDir = None, CheckMulDec = False): + PackageObject.__init__(self) + self.UserExtensions = '' + self.WorkspaceDir = WorkspaceDir + self.SupArchList = ARCH_LIST + self.CheckMulDec = CheckMulDec + self.DecParser = None + self.UniFileClassObject = None + self.PcdDefaultValueDict = {} + + # + # Load Dec file + # + self.LoadDecFile(Filename) + + # + # Transfer to Package Object if IsToPackage is True + # + self.DecToPackage() + + ## Load Dec file + # + # Load the file if it exists + # + # @param Filename: Input value for filename of Dec file + # + def LoadDecFile(self, Filename): + # + # Insert a record for file + # + Filename = NormPath(Filename) + (Path, Name) = os.path.split(Filename) + self.SetFullPath(Filename) + self.SetRelaPath(Path) + self.SetFileName(Name) + self.SetPackagePath(GetRelativePath(Path, self.WorkspaceDir)) + self.SetCombinePath(GetRelativePath(Filename, self.WorkspaceDir)) + + self.DecParser = Dec(Filename) + + ## Transfer to Package Object + # + # Transfer all contents of a Dec file to a standard Package Object + # + def DecToPackage(self): + # + # Init global information for the file + # + ContainerFile = self.GetFullPath() + + # + # Generate Package Header + # + self.GenPackageHeader(ContainerFile) + + # + # Generate Includes + # + self.GenIncludes(ContainerFile) + + # + # Generate Guids + # + self.GenGuidProtocolPpis(TAB_GUIDS, ContainerFile) + + # + # Generate Protocols + # + self.GenGuidProtocolPpis(TAB_PROTOCOLS, ContainerFile) + + # + # Generate Ppis + # + self.GenGuidProtocolPpis(TAB_PPIS, ContainerFile) + + # + # Generate LibraryClasses + # + self.GenLibraryClasses(ContainerFile) + + # + # Generate Pcds + # + self.GenPcds(ContainerFile) + + # + # Generate Module File list, will be used later on to generate + # distribution + # + self.GenModuleFileList(ContainerFile) + + # + # Generate user extensions + # + self.GenUserExtensions() + + ## Generate user extension + # + # + def GenUserExtensions(self): + UEObj = self.DecParser.GetUserExtensionSectionObject() + UEList = UEObj.GetAllUserExtensions() + for Item in UEList: + if not Item.UserString: + continue + UserExtension = UserExtensionObject() + UserId = Item.UserId + if UserId.startswith('"') and UserId.endswith('"'): + UserId = UserId[1:-1] + UserExtension.SetUserID(UserId) + Identifier = Item.IdString + if Identifier.startswith('"') and Identifier.endswith('"'): + Identifier = Identifier[1:-1] + # + # Generate miscellaneous files of DEC file + # + if UserId == 'TianoCore' and Identifier == 'ExtraFiles': + self.GenMiscFiles(Item.UserString) + UserExtension.SetIdentifier(Identifier) + UserExtension.SetStatement(Item.UserString) + UserExtension.SetSupArchList( + Item.ArchAndModuleType + ) + self.SetUserExtensionList( + self.GetUserExtensionList() + [UserExtension] + ) + + # Add Private sections to UserExtension + if self.DecParser.GetPrivateSections(): + PrivateUserExtension = UserExtensionObject() + PrivateUserExtension.SetStatement(self.DecParser.GetPrivateSections()) + PrivateUserExtension.SetIdentifier(DT.TAB_PRIVATE) + PrivateUserExtension.SetUserID(DT.TAB_INTEL) + self.SetUserExtensionList(self.GetUserExtensionList() + [PrivateUserExtension]) + + ## Generate miscellaneous files on DEC file + # + # + def GenMiscFiles(self, Content): + MiscFileObj = MiscFileObject() + for Line in Content.splitlines(): + FileName = '' + if '#' in Line: + FileName = Line[:Line.find('#')] + else: + FileName = Line + if FileName: + if IsValidPath(FileName, self.GetRelaPath()): + FileObj = FileObject() + FileObj.SetURI(FileName) + MiscFileObj.SetFileList(MiscFileObj.GetFileList()+[FileObj]) + else: + Logger.Error("InfParser", + FORMAT_INVALID, + ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Line), + File=self.GetFileName(), + ExtraData=Line) + self.SetMiscFileList(self.GetMiscFileList()+[MiscFileObj]) + + ## Generate Package Header + # + # Gen Package Header of Dec as <Key> = <Value> + # + # @param ContainerFile: The Dec file full path + # + def GenPackageHeader(self, ContainerFile): + Logger.Debug(2, "Generate PackageHeader ...") + DefinesDict = {} + + # + # Update all defines item in database + # + DefObj = self.DecParser.GetDefineSectionObject() + for Item in DefObj.GetDefines(): + # + # put items into Dict except for PackageName, Guid, Version, DEC_SPECIFICATION + # + SkipItemList = [TAB_DEC_DEFINES_PACKAGE_NAME, \ + TAB_DEC_DEFINES_PACKAGE_GUID, TAB_DEC_DEFINES_PACKAGE_VERSION, \ + TAB_DEC_DEFINES_DEC_SPECIFICATION, TAB_DEC_DEFINES_PKG_UNI_FILE] + if Item.Key in SkipItemList: + continue + DefinesDict['%s = %s' % (Item.Key, Item.Value)] = TAB_ARCH_COMMON + + self.SetBaseName(DefObj.GetPackageName()) + self.SetVersion(DefObj.GetPackageVersion()) +# self.SetName(DefObj.GetPackageName() + ' Version ' + \ +# DefObj.GetPackageVersion()) + self.SetName(os.path.splitext(self.GetFileName())[0]) + self.SetGuid(DefObj.GetPackageGuid()) + if DefObj.GetPackageUniFile(): + ValidateUNIFilePath(DefObj.GetPackageUniFile()) + self.UniFileClassObject = \ + UniFileClassObject([PathClass(os.path.join(DefObj.GetPackagePath(), DefObj.GetPackageUniFile()))]) + else: + self.UniFileClassObject = None + + if DefinesDict: + UserExtension = UserExtensionObject() + UserExtension.SetDefinesDict(DefinesDict) + UserExtension.SetIdentifier('DefineModifiers') + UserExtension.SetUserID('EDK2') + self.SetUserExtensionList( + self.GetUserExtensionList() + [UserExtension] + ) + + # + # Get File header information + # + if self.UniFileClassObject: + Lang = TAB_LANGUAGE_EN_X + else: + Lang = TAB_LANGUAGE_EN_US + Abstract, Description, Copyright, License = \ + ParseHeaderCommentSection(self.DecParser.GetHeadComment(), + ContainerFile) + if Abstract: + self.SetAbstract((Lang, Abstract)) + if Description: + self.SetDescription((Lang, Description)) + if Copyright: + self.SetCopyright(('', Copyright)) + if License: + self.SetLicense(('', License)) + + # + # Get Binary header information + # + if self.DecParser.BinaryHeadComment: + Abstract, Description, Copyright, License = \ + ParseHeaderCommentSection(self.DecParser.BinaryHeadComment, + ContainerFile, True) + + if not Abstract or not Description or not Copyright or not License: + Logger.Error('MkPkg', + FORMAT_INVALID, + ST.ERR_INVALID_BINARYHEADER_FORMAT, + ContainerFile) + else: + self.SetBinaryHeaderAbstract((Lang, Abstract)) + self.SetBinaryHeaderDescription((Lang, Description)) + self.SetBinaryHeaderCopyright(('', Copyright)) + self.SetBinaryHeaderLicense(('', License)) + + BinaryAbstractList = [] + BinaryDescriptionList = [] + + #Get Binary header from UNI file + # Initialize the UniStrDict dictionary, top keys are language codes + UniStrDict = {} + if self.UniFileClassObject: + UniStrDict = self.UniFileClassObject.OrderedStringList + for Lang in UniStrDict: + for StringDefClassObject in UniStrDict[Lang]: + Lang = GetLanguageCode1766(Lang) + if StringDefClassObject.StringName == TAB_DEC_BINARY_ABSTRACT: + if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \ + not in self.GetBinaryHeaderAbstract(): + BinaryAbstractList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue))) + if StringDefClassObject.StringName == TAB_DEC_BINARY_DESCRIPTION: + if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \ + not in self.GetBinaryHeaderDescription(): + BinaryDescriptionList.append((Lang, + ConvertSpecialUnicodes(StringDefClassObject.StringValue))) + #Combine Binary header from DEC file and UNI file + BinaryAbstractList = self.GetBinaryHeaderAbstract() + BinaryAbstractList + BinaryDescriptionList = self.GetBinaryHeaderDescription() + BinaryDescriptionList + BinaryCopyrightList = self.GetBinaryHeaderCopyright() + BinaryLicenseList = self.GetBinaryHeaderLicense() + #Generate the UserExtensionObject for TianoCore."BinaryHeader" + if BinaryAbstractList or BinaryDescriptionList or BinaryCopyrightList or BinaryLicenseList: + BinaryUserExtension = UserExtensionObject() + BinaryUserExtension.SetBinaryAbstract(BinaryAbstractList) + BinaryUserExtension.SetBinaryDescription(BinaryDescriptionList) + BinaryUserExtension.SetBinaryCopyright(BinaryCopyrightList) + BinaryUserExtension.SetBinaryLicense(BinaryLicenseList) + BinaryUserExtension.SetIdentifier(TAB_BINARY_HEADER_IDENTIFIER) + BinaryUserExtension.SetUserID(TAB_BINARY_HEADER_USERID) + self.SetUserExtensionList(self.GetUserExtensionList() + [BinaryUserExtension]) + + + ## GenIncludes + # + # Gen Includes of Dec + # + # @param ContainerFile: The Dec file full path + # + def GenIncludes(self, ContainerFile): + if ContainerFile: + pass + Logger.Debug(2, "Generate %s ..." % TAB_INCLUDES) + IncludesDict = Sdict() + + IncObj = self.DecParser.GetIncludeSectionObject() + for Item in IncObj.GetAllIncludes(): + IncludePath = os.path.normpath(Item.File) + if platform.system() != 'Windows' and platform.system() != 'Microsoft': + IncludePath = IncludePath.replace('\\', '/') + if IncludePath in IncludesDict: + if Item.GetArchList() == [TAB_ARCH_COMMON] or IncludesDict[IncludePath] == [TAB_ARCH_COMMON]: + IncludesDict[IncludePath] = [TAB_ARCH_COMMON] + else: + IncludesDict[IncludePath] = IncludesDict[IncludePath] + Item.GetArchList() + else: + IncludesDict[IncludePath] = Item.GetArchList() + + # + # get the standardIncludeFileList(industry), packageIncludeFileList + # (others) for PackageObject + # + PackagePath = os.path.split(self.GetFullPath())[0] + IncludePathList = \ + sorted([os.path.normpath(Path) + sep for Path in IncludesDict.keys()]) + + # + # get a non-overlap set of include path, IncludePathList should be + # sorted, and path should be end with path separator '\' + # + NonOverLapList = [] + for Path1 in IncludePathList: + for Path2 in NonOverLapList: + if Path1.startswith(Path2): + break + else: + NonOverLapList.append(Path1) + # + # revert the list so the longest path shown first in list, also need + # to remove the extra path separator '\' + # as this list is used to search the supported Arch info + # + for IndexN in range (0, len(IncludePathList)): + IncludePathList[IndexN] = os.path.normpath(IncludePathList[IndexN]) + IncludePathList.sort() + IncludePathList.reverse() + # + # save the include path list for later usage + # + self.SetIncludePathList(IncludePathList) + StandardIncludeFileList = [] + PackageIncludeFileList = [] + + IncludeFileList = [] + for Path in NonOverLapList: + FileList = GetFiles(os.path.join(PackagePath, Path), ['CVS', '.svn'], False) + IncludeFileList += [os.path.normpath(os.path.join(Path, File)) for File in FileList] + for Includefile in IncludeFileList: + ExtName = os.path.splitext(Includefile)[1] + if ExtName.upper() == '.DEC' and self.CheckMulDec: + Logger.Error('MkPkg', + UPT_MUL_DEC_ERROR, + ST.ERR_MUL_DEC_ERROR%(os.path.dirname(ContainerFile), + os.path.basename(ContainerFile), + Includefile)) + + FileCombinePath = os.path.dirname(Includefile) + Include = IncludeObject() + for Path in IncludePathList: + if FileCombinePath.startswith(Path): + SupArchList = IncludesDict[Path] + break + Include.SetFilePath(Includefile) + Include.SetSupArchList(SupArchList) + if Includefile.find('IndustryStandard') != -1: + StandardIncludeFileList.append(Include) + else: + PackageIncludeFileList.append(Include) + + self.SetStandardIncludeFileList(StandardIncludeFileList) + + # + # put include path into the PackageIncludeFileList + # + PackagePathList = [] + IncObj = self.DecParser.GetIncludeSectionObject() + for Item in IncObj.GetAllIncludes(): + IncludePath = Item.File + Include = IncludeObject() + Include.SetFilePath(IncludePath) + Include.SetSupArchList(Item.GetArchList()) + PackagePathList.append(Include) + self.SetPackageIncludeFileList(PackagePathList + PackageIncludeFileList) + + ## GenPpis + # + # Gen Ppis of Dec + # <CName>=<GuidValue> + # + # @param ContainerFile: The Dec file full path + # + def GenGuidProtocolPpis(self, Type, ContainerFile): + if ContainerFile: + pass + Logger.Debug(2, "Generate %s ..." % Type) + + Obj = None + Factory = None + if Type == TAB_GUIDS: + Obj = self.DecParser.GetGuidSectionObject() + def CreateGuidObject(): + Object = GuidObject() + Object.SetGuidTypeList([]) + Object.SetUsage(None) + Object.SetName(None) + return Object + Factory = CreateGuidObject + elif Type == TAB_PROTOCOLS: + Obj = self.DecParser.GetProtocolSectionObject() + + def CreateProtocolObject(): + return ProtocolObject() + Factory = CreateProtocolObject + elif Type == TAB_PPIS: + Obj = self.DecParser.GetPpiSectionObject() + + def CreatePpiObject(): + return PpiObject() + Factory = CreatePpiObject + else: + # + # Should not be here + # + return + + DeclarationsList = [] + + # + # Go through each arch + # + for Item in Obj.GetGuidStyleAllItems(): + Name = Item.GuidCName + Value = Item.GuidString + HelpTxt = ParseGenericComment(Item.GetHeadComment() + \ + Item.GetTailComment()) + + ListObject = Factory() + ListObject.SetCName(Name) + ListObject.SetGuid(Value) + ListObject.SetSupArchList(Item.GetArchList()) + if HelpTxt: + if self.UniFileClassObject: + HelpTxt.SetLang(TAB_LANGUAGE_EN_X) + ListObject.SetHelpTextList([HelpTxt]) + + DeclarationsList.append(ListObject) + + # + #GuidTypeList is abstracted from help + # + if Type == TAB_GUIDS: + self.SetGuidList(self.GetGuidList() + DeclarationsList) + elif Type == TAB_PROTOCOLS: + self.SetProtocolList(self.GetProtocolList() + DeclarationsList) + elif Type == TAB_PPIS: + self.SetPpiList(self.GetPpiList() + DeclarationsList) + + ## GenLibraryClasses + # + # Gen LibraryClasses of Dec + # <CName>=<GuidValue> + # + # @param ContainerFile: The Dec file full path + # + def GenLibraryClasses(self, ContainerFile): + if ContainerFile: + pass + Logger.Debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES) + LibraryClassDeclarations = [] + + LibObj = self.DecParser.GetLibraryClassSectionObject() + for Item in LibObj.GetAllLibraryclasses(): + LibraryClass = LibraryClassObject() + LibraryClass.SetLibraryClass(Item.Libraryclass) + LibraryClass.SetSupArchList(Item.GetArchList()) + LibraryClass.SetIncludeHeader(Item.File) + HelpTxt = ParseGenericComment(Item.GetHeadComment() + \ + Item.GetTailComment(), None, '@libraryclass') + if HelpTxt: + if self.UniFileClassObject: + HelpTxt.SetLang(TAB_LANGUAGE_EN_X) + LibraryClass.SetHelpTextList([HelpTxt]) + LibraryClassDeclarations.append(LibraryClass) + + self.SetLibraryClassList(self.GetLibraryClassList() + \ + LibraryClassDeclarations) + + ## GenPcds + # + # Gen Pcds of Dec + # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token> + # + # @param ContainerFile: The Dec file full path + # + def GenPcds(self, ContainerFile): + Logger.Debug(2, "Generate %s ..." % TAB_PCDS) + PcdObj = self.DecParser.GetPcdSectionObject() + # + # Get all Pcds + # + PcdDeclarations = [] + IterList = [ + (TAB_PCDS_FIXED_AT_BUILD_NULL, 'FixedPcd'), + (TAB_PCDS_PATCHABLE_IN_MODULE_NULL, 'PatchPcd'), + (TAB_PCDS_FEATURE_FLAG_NULL, 'FeaturePcd'), + (TAB_PCDS_DYNAMIC_EX_NULL, 'PcdEx'), + (TAB_PCDS_DYNAMIC_NULL, 'Pcd')] + + PromptStrList = [] + HelpStrList = [] + PcdErrStrList = [] + # Initialize UniStrDict dictionary, top keys are language codes + UniStrDict = {} + StrList = [] + + Language = '' + if self.UniFileClassObject: + Language = TAB_LANGUAGE_EN_X + else: + Language = TAB_LANGUAGE_EN_US + + if self.UniFileClassObject: + UniStrDict = self.UniFileClassObject.OrderedStringList + for Lang in UniStrDict: + for StringDefClassObject in UniStrDict[Lang]: + StrList = StringDefClassObject.StringName.split('_') + # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_PROMPT + if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[3] == TAB_STR_TOKENPROMPT: + PromptStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ + StringDefClassObject.StringValue)) + # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_HELP + if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[3] == TAB_STR_TOKENHELP: + HelpStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ + StringDefClassObject.StringValue)) + # StringName format is STR_<TOKENSPACECNAME>_ERR_## + if len(StrList) == 4 and StrList[0] == TAB_STR_TOKENCNAME and StrList[2] == TAB_STR_TOKENERR: + PcdErrStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ + StringDefClassObject.StringValue)) + # + # For each PCD type + # + for PcdType, Type in IterList: + # + # Go through all archs + # + # for Arch in self.SupArchList + [TAB_ARCH_COMMON]: + # + for Item in PcdObj.GetPcdsByType(PcdType.upper()): + PcdDeclaration = GenPcdDeclaration( + ContainerFile, + (Item.TokenSpaceGuidCName, Item.TokenCName, + Item.DefaultValue, Item.DatumType, Item.TokenValue, + Type, Item.GetHeadComment(), Item.GetTailComment(), ''), + Language, + self.DecParser.GetDefineSectionMacro() + ) + PcdDeclaration.SetSupArchList(Item.GetArchListOfType(PcdType)) + + # + # Get PCD error message from PCD error comment section in DEC file + # + for PcdErr in PcdDeclaration.GetPcdErrorsList(): + if (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) \ + in self.DecParser.PcdErrorCommentDict: + Key = (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) + PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ + [(Language, self.DecParser.PcdErrorCommentDict[Key])]) + + for Index in range(0, len(PromptStrList)): + StrNameList = PromptStrList[Index][1].split('_') + if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ + StrNameList[2].lower() == Item.TokenCName.lower(): + TxtObj = TextObject() + TxtObj.SetLang(PromptStrList[Index][0]) + TxtObj.SetString(PromptStrList[Index][2]) + for Prompt in PcdDeclaration.GetPromptList(): + if Prompt.GetLang() == TxtObj.GetLang() and \ + Prompt.GetString() == TxtObj.GetString(): + break + else: + PcdDeclaration.SetPromptList(PcdDeclaration.GetPromptList() + [TxtObj]) + + for Index in range(0, len(HelpStrList)): + StrNameList = HelpStrList[Index][1].split('_') + if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ + StrNameList[2].lower() == Item.TokenCName.lower(): + TxtObj = TextObject() + TxtObj.SetLang(HelpStrList[Index][0]) + TxtObj.SetString(HelpStrList[Index][2]) + for HelpStrObj in PcdDeclaration.GetHelpTextList(): + if HelpStrObj.GetLang() == TxtObj.GetLang() and \ + HelpStrObj.GetString() == TxtObj.GetString(): + break + else: + PcdDeclaration.SetHelpTextList(PcdDeclaration.GetHelpTextList() + [TxtObj]) + + # + # Get PCD error message from UNI file + # + for Index in range(0, len(PcdErrStrList)): + StrNameList = PcdErrStrList[Index][1].split('_') + if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ + StrNameList[2].lower() == TAB_STR_TOKENERR.lower(): + for PcdErr in PcdDeclaration.GetPcdErrorsList(): + if PcdErr.GetErrorNumber().lower() == (TAB_HEX_START + StrNameList[3]).lower() and \ + (PcdErrStrList[Index][0], PcdErrStrList[Index][2]) not in PcdErr.GetErrorMessageList(): + PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ + [(PcdErrStrList[Index][0], PcdErrStrList[Index][2])]) + + # + # Check to prevent missing error message if a Pcd has the error code. + # + for PcdErr in PcdDeclaration.GetPcdErrorsList(): + if PcdErr.GetErrorNumber().strip(): + if not PcdErr.GetErrorMessageList(): + Logger.Error('UPT', + FORMAT_INVALID, + ST.ERR_DECPARSE_PCD_UNMATCHED_ERRORCODE % PcdErr.GetErrorNumber(), + ContainerFile, + PcdErr.GetLineNum(), + PcdErr.GetFileLine()) + + PcdDeclarations.append(PcdDeclaration) + self.SetPcdList(self.GetPcdList() + PcdDeclarations) + self.CheckPcdValue() + + ## + # Get error message via language + # @param ErrorMessageList: Error message tuple list the language and its message + # @param Lang: the language of setting + # @return: the error message described in the related UNI file + def GetEnErrorMessage(self, ErrorMessageList): + if self.FullPath: + pass + Lang = TAB_LANGUAGE_EN_US + for (Language, Message) in ErrorMessageList: + if Language == Lang: + return Message + for (Language, Message) in ErrorMessageList: + if Language.find(TAB_LANGUAGE_EN) >= 0: + return Message + else: + try: + return ErrorMessageList[0][1] + except IndexError: + return '' + return '' + + ## + # Replace the strings for Python eval function. + # @param ReplaceValue: The string that needs to be replaced. + # @return: The string was replaced, then eval function is always making out it. + def ReplaceForEval(self, ReplaceValue, IsRange=False, IsExpr=False): + if self.FullPath: + pass + # + # deal with "NOT EQ", "NOT LT", "NOT GT", "NOT LE", "NOT GE", "NOT NOT" + # + NOTNOT_Pattern = '[\t\s]*NOT[\t\s]+NOT[\t\s]*' + NOTGE_Pattern = '[\t\s]*NOT[\t\s]+GE[\t\s]*' + NOTLE_Pattern = '[\t\s]*NOT[\t\s]+LE[\t\s]*' + NOTGT_Pattern = '[\t\s]*NOT[\t\s]+GT[\t\s]*' + NOTLT_Pattern = '[\t\s]*NOT[\t\s]+LT[\t\s]*' + NOTEQ_Pattern = '[\t\s]*NOT[\t\s]+EQ[\t\s]*' + ReplaceValue = re.compile(NOTNOT_Pattern).sub('', ReplaceValue) + ReplaceValue = re.compile(NOTLT_Pattern).sub('x >= ', ReplaceValue) + ReplaceValue = re.compile(NOTGT_Pattern).sub('x <= ', ReplaceValue) + ReplaceValue = re.compile(NOTLE_Pattern).sub('x > ', ReplaceValue) + ReplaceValue = re.compile(NOTGE_Pattern).sub('x < ', ReplaceValue) + ReplaceValue = re.compile(NOTEQ_Pattern).sub('x != ', ReplaceValue) + + if IsRange: + ReplaceValue = ReplaceValue.replace('EQ', 'x ==') + ReplaceValue = ReplaceValue.replace('LT', 'x <') + ReplaceValue = ReplaceValue.replace('LE', 'x <=') + ReplaceValue = ReplaceValue.replace('GT', 'x >') + ReplaceValue = ReplaceValue.replace('GE', 'x >=') + ReplaceValue = ReplaceValue.replace('XOR', 'x ^') + elif IsExpr: + ReplaceValue = ReplaceValue.replace('EQ', '==') + ReplaceValue = ReplaceValue.replace('NE', '!=') + ReplaceValue = ReplaceValue.replace('LT', '<') + ReplaceValue = ReplaceValue.replace('LE', '<=') + ReplaceValue = ReplaceValue.replace('GT', '>') + ReplaceValue = ReplaceValue.replace('GE', '>=') + ReplaceValue = ReplaceValue.replace('XOR', '^') + + ReplaceValue = ReplaceValue.replace('AND', 'and') + ReplaceValue = ReplaceValue.replace('&&', ' and ') + ReplaceValue = ReplaceValue.replace('xor', '^') + ReplaceValue = ReplaceValue.replace('OR', 'or') + ReplaceValue = ReplaceValue.replace('||', ' or ') + ReplaceValue = ReplaceValue.replace('NOT', 'not') + if ReplaceValue.find('!') >= 0 and ReplaceValue[ReplaceValue.index('!') + 1] != '=': + ReplaceValue = ReplaceValue.replace('!', ' not ') + if '.' in ReplaceValue: + Pattern = '[a-zA-Z0-9]{1,}\.[a-zA-Z0-9]{1,}' + MatchedList = re.findall(Pattern, ReplaceValue) + for MatchedItem in MatchedList: + if MatchedItem not in self.PcdDefaultValueDict: + Logger.Error("Dec File Parser", FORMAT_INVALID, Message=ST.ERR_DECPARSE_PCD_NODEFINED % MatchedItem, + File=self.FullPath) + + ReplaceValue = ReplaceValue.replace(MatchedItem, self.PcdDefaultValueDict[MatchedItem]) + + return ReplaceValue + + ## + # Check pcd's default value according to the pcd's description + # + def CheckPcdValue(self): + for Pcd in self.GetPcdList(): + self.PcdDefaultValueDict[TAB_SPLIT.join((Pcd.GetTokenSpaceGuidCName(), Pcd.GetCName())).strip()] = \ + Pcd.GetDefaultValue() + + for Pcd in self.GetPcdList(): + ValidationExpressions = [] + PcdGuidName = TAB_SPLIT.join((Pcd.GetTokenSpaceGuidCName(), Pcd.GetCName())) + Valids = Pcd.GetPcdErrorsList() + for Valid in Valids: + Expression = Valid.GetExpression() + if Expression: + # + # Delete the 'L' prefix of a quoted string, this operation is for eval() + # + QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' + QuotedMatchedObj = re.search(QUOTED_PATTERN, Expression) + if QuotedMatchedObj: + MatchedStr = QuotedMatchedObj.group().strip() + if MatchedStr.startswith('L'): + Expression = Expression.replace(MatchedStr, MatchedStr[1:].strip()) + + Expression = self.ReplaceForEval(Expression, IsExpr=True) + Expression = Expression.replace(PcdGuidName, 'x') + Message = self.GetEnErrorMessage(Valid.GetErrorMessageList()) + ValidationExpressions.append((Expression, Message)) + + ValidList = Valid.GetValidValue() + if ValidList: + ValidValue = 'x in %s' % [eval(v) for v in ValidList.split(' ') if v] + Message = self.GetEnErrorMessage(Valid.GetErrorMessageList()) + ValidationExpressions.append((ValidValue, Message)) + + ValidValueRange = Valid.GetValidValueRange() + if ValidValueRange: + ValidValueRange = self.ReplaceForEval(ValidValueRange, IsRange=True) + if ValidValueRange.find('-') >= 0: + ValidValueRange = ValidValueRange.replace('-', '<= x <=') + elif not ValidValueRange.startswith('x ') and not ValidValueRange.startswith('not ') \ + and not ValidValueRange.startswith('not(') and not ValidValueRange.startswith('('): + ValidValueRange = 'x %s' % ValidValueRange + Message = self.GetEnErrorMessage(Valid.GetErrorMessageList()) + ValidationExpressions.append((ValidValueRange, Message)) + + DefaultValue = self.PcdDefaultValueDict[PcdGuidName.strip()] + # + # Delete the 'L' prefix of a quoted string, this operation is for eval() + # + QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' + QuotedMatchedObj = re.search(QUOTED_PATTERN, DefaultValue) + if QuotedMatchedObj: + MatchedStr = QuotedMatchedObj.group().strip() + if MatchedStr.startswith('L'): + DefaultValue = DefaultValue.replace(MatchedStr, MatchedStr[1:].strip()) + + try: + DefaultValue = eval(DefaultValue.replace('TRUE', 'True').replace('true', 'True') + .replace('FALSE', 'False').replace('false', 'False')) + except BaseException: + pass + + for (Expression, Msg) in ValidationExpressions: + try: + if not eval(Expression, {'x':DefaultValue}): + Logger.Error("Dec File Parser", FORMAT_INVALID, ExtraData='%s, value = %s' %\ + (PcdGuidName, DefaultValue), Message=Msg, File=self.FullPath) + except TypeError: + Logger.Error("Dec File Parser", FORMAT_INVALID, ExtraData=PcdGuidName, \ + Message=Msg, File=self.FullPath) + + ## GenModuleFileList + # + def GenModuleFileList(self, ContainerFile): + ModuleFileList = [] + ContainerFileName = os.path.basename(ContainerFile) + ContainerFilePath = os.path.dirname(ContainerFile) + for Item in GetFiles(ContainerFilePath, + ['CVS', '.svn'] + self.GetIncludePathList(), False): + ExtName = os.path.splitext(Item)[1] + if ExtName.lower() == '.inf': + ModuleFileList.append(Item) + elif ExtName.upper() == '.DEC' and self.CheckMulDec: + if Item == ContainerFileName: + continue + Logger.Error('MkPkg', + UPT_MUL_DEC_ERROR, + ST.ERR_MUL_DEC_ERROR%(ContainerFilePath, + ContainerFileName, + Item)) + + self.SetModuleFileList(ModuleFileList) + + ## Show detailed information of Package + # + # Print all members and their values of Package class + # + def ShowPackage(self): + print('\nName =', self.GetName()) + print('\nBaseName =', self.GetBaseName()) + print('\nVersion =', self.GetVersion()) + print('\nGuid =', self.GetGuid()) + + print('\nStandardIncludes = %d ' \ + % len(self.GetStandardIncludeFileList()), end=' ') + for Item in self.GetStandardIncludeFileList(): + print(Item.GetFilePath(), ' ', Item.GetSupArchList()) + print('\nPackageIncludes = %d \n' \ + % len(self.GetPackageIncludeFileList()), end=' ') + for Item in self.GetPackageIncludeFileList(): + print(Item.GetFilePath(), ' ', Item.GetSupArchList()) + + print('\nGuids =', self.GetGuidList()) + for Item in self.GetGuidList(): + print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()) + print('\nProtocols =', self.GetProtocolList()) + for Item in self.GetProtocolList(): + print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()) + print('\nPpis =', self.GetPpiList()) + for Item in self.GetPpiList(): + print(Item.GetCName(), Item.GetGuid(), Item.GetSupArchList()) + print('\nLibraryClasses =', self.GetLibraryClassList()) + for Item in self.GetLibraryClassList(): + print(Item.GetLibraryClass(), Item.GetRecommendedInstance(), \ + Item.GetSupArchList()) + print('\nPcds =', self.GetPcdList()) + for Item in self.GetPcdList(): + print('CName=', Item.GetCName(), 'TokenSpaceGuidCName=', \ + Item.GetTokenSpaceGuidCName(), \ + 'DefaultValue=', Item.GetDefaultValue(), \ + 'ValidUsage=', Item.GetValidUsage(), \ + 'SupArchList', Item.GetSupArchList(), \ + 'Token=', Item.GetToken(), 'DatumType=', Item.GetDatumType()) + + for Item in self.GetMiscFileList(): + print(Item.GetName()) + for FileObjectItem in Item.GetFileList(): + print(FileObjectItem.GetURI()) + print('****************\n') + +## GenPcdDeclaration +# +# @param ContainerFile: File name of the DEC file +# @param PcdInfo: Pcd information, of format (TokenGuidCName, +# TokenName, Value, DatumType, Token, Type, +# GenericComment, TailComment, Arch) +# @param Language: The language of HelpText, Prompt +# +def GenPcdDeclaration(ContainerFile, PcdInfo, Language, MacroReplaceDict): + HelpStr = '' + PromptStr = '' + TailHelpStr = '' + TokenGuidCName, TokenName, Value, DatumType, Token, Type, \ + GenericComment, TailComment, Arch = PcdInfo + Pcd = PcdObject() + Pcd.SetCName(TokenName) + Pcd.SetToken(Token) + Pcd.SetTokenSpaceGuidCName(TokenGuidCName) + Pcd.SetDatumType(DatumType) + Pcd.SetDefaultValue(Value) + Pcd.SetValidUsage(Type) + # + # MaxDatumSize is required field for 'VOID*' PCD + # + if DatumType == TAB_PTR_TYPE_PCD: + Pcd.SetMaxDatumSize(ITEM_UNDEFINED) + + SupArchList = [Arch] + Pcd.SetSupArchList(SupArchList) + + if GenericComment: + HelpStr, PcdErrList, PromptStr = ParseDecPcdGenericComment(GenericComment, + ContainerFile, + TokenGuidCName, + TokenName, + MacroReplaceDict) + if PcdErrList: + Pcd.SetPcdErrorsList(PcdErrList) + + if TailComment: + SupModuleList, TailHelpStr = ParseDecPcdTailComment(TailComment, + ContainerFile) + if SupModuleList: + Pcd.SetSupModuleList(SupModuleList) + + if HelpStr and (not HelpStr.endswith('\n')) and TailHelpStr: + HelpStr += '\n' + HelpStr += TailHelpStr + if HelpStr: + HelpTxtObj = TextObject() + HelpTxtObj.SetLang(Language) + HelpTxtObj.SetString(HelpStr) + Pcd.SetHelpTextList([HelpTxtObj]) + if PromptStr: + TxtObj = TextObject() + TxtObj.SetLang(Language) + TxtObj.SetString(PromptStr) + Pcd.SetPromptList([TxtObj]) + + return Pcd diff --git a/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py new file mode 100755 index 00000000..184c36c6 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py @@ -0,0 +1,1071 @@ +## @file InfPomAlignment.py +# This file contained the adapter for convert INF parser object to POM Object +# +# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +''' +InfPomAlignment +''' +## +# Import modules +# +import os.path +from Logger import StringTable as ST +import Logger.Log as Logger +from Library.StringUtils import FORMAT_INVALID +from Library.StringUtils import PARSER_ERROR +from Library.StringUtils import NormPath +from Library.StringUtils import GetSplitValueList +from Library.Misc import ConvertVersionToDecimal +from Library.Misc import GetHelpStringByRemoveHashKey +from Library.Misc import ConvertArchList +from Library.Misc import GetRelativePath +from Library.Misc import PathClass +from Library.Parsing import GetPkgInfoFromDec +from Library.UniClassObject import UniFileClassObject +from Library.UniClassObject import ConvertSpecialUnicodes +from Library.UniClassObject import GetLanguageCode1766 +from Library import DataType as DT +from Library import GlobalData +from Library.ParserValidate import IsValidPath +from Object.POM import CommonObject +from Object.POM.ModuleObject import ModuleObject +from Object.POM.ModuleObject import ExternObject +from Object.POM.ModuleObject import HobObject +from Object.POM.ModuleObject import EventObject +from Object.POM.ModuleObject import BootModeObject +from Object.POM.ModuleObject import PackageDependencyObject +from Object.POM.ModuleObject import SourceFileObject +from Object.POM.ModuleObject import DepexObject +from Object.POM.ModuleObject import AsBuildLibraryClassObject +from Object.POM.ModuleObject import AsBuiltObject +from PomAdapter.InfPomAlignmentMisc import GenModuleHeaderUserExt +from PomAdapter.InfPomAlignmentMisc import GenBinaryData +from Parser import InfParser +from PomAdapter.DecPomAlignment import DecPomAlignment +from Common.MultipleWorkspace import MultipleWorkspace as mws + +## InfPomAlignment +# +# Inherit from ModuleObject +# +class InfPomAlignment(ModuleObject): + ## Construct of InfPomAlignment + # Skip means that UPT don't care the syntax of INF, this may be the not + # distributed INF files during creation or the INF files checked for + # dependency rule during remove. + # + def __init__(self, FileName, WorkSpace=None, PackagePath='', Skip=False): + ModuleObject.__init__(self) + self.Parser = None + self.FileName = FileName + self.WorkSpace = WorkSpace + self.CombinePath = '' + self.LibModuleTypeList = [] + self.FullPath = '' + self.ModulePath = '' + self.WorkspaceDir = " " + self.CustomMakefile = [] + self.UniFileClassObject = None + self.SetPackagePath(PackagePath) + # + # Call GenInfPomObjects function to fill POM object. + # + if Skip: + OrigConfig = Logger.SUPRESS_ERROR + Logger.SUPRESS_ERROR = True + try: + self._GenInfPomObjects(Skip) + finally: + Logger.SUPRESS_ERROR = OrigConfig + else: + self._GenInfPomObjects(Skip) + + ## + # Generate all POM objects, the original input comes + # from INF parser's output + # + def _GenInfPomObjects(self, Skip): + # + # Call INF Parser to get information from INF file + # + self.Parser = InfParser.InfParser(self.FileName, self.WorkSpace) + self.FullPath = self.Parser.FullPath + self.GetFullPath() + self._GenModuleHeader() + # + # Call GenBinaries after Module Header for Binary INF consideration. + # + self._GenBinaries() + self._GenBuildOptions() + self._GenLibraryClasses() + self._GenPackages(Skip) + self._GenPcds() + self._GenSources() + self._GenUserExtensions() + self._GenGuidProtocolPpis(DT.TAB_GUIDS) + self._GenGuidProtocolPpis(DT.TAB_PROTOCOLS) + self._GenGuidProtocolPpis(DT.TAB_PPIS) + self._GenDepexes() + + ## Convert [Defines] section content to InfDefObject + # + # Convert [Defines] section content to InfDefObject + # + # @param Defines The content under [Defines] section + # @param ModuleHeader An object of ModuleHeaderClass + # @param Arch The supported ARCH + # + def _GenModuleHeader(self): + Logger.Debug(2, "Generate ModuleHeader ...") + # + # Get all defines information form InfParser Object + # + RecordSet = self.Parser.InfDefSection.Defines + # + # Should only have one ArchString Item. + # + ArchString = list(RecordSet.keys())[0] + ArchList = GetSplitValueList(ArchString, ' ') + ArchList = ConvertArchList(ArchList) + HasCalledFlag = False + # + # Get data from Sdict() + # + ValueList = RecordSet[ArchString] + self.SetFileName(self.FileName) + self.SetFullPath(self.FullPath) + # + # The INF's filename (without the directory path or the extension) + # must be used for the value of the + # ModuleSurfaceArea.Header.Name element + # + self.SetName(os.path.splitext(os.path.basename(self.FileName))[0]) + self.WorkspaceDir = " " + # + # CombinePath and ModulePath + # + CombinePath = GetRelativePath(self.FullPath, self.WorkSpace) + self.SetCombinePath(CombinePath) + ModulePath = os.path.split(CombinePath)[0] + ModuleRelativePath = ModulePath + if self.GetPackagePath() != '': + ModuleRelativePath = GetRelativePath(ModulePath, self.GetPackagePath()) + self.SetModulePath(ModuleRelativePath) + # + # For Define Seciton Items. + # + DefineObj = ValueList + # + # Convert UEFI/PI version to decimal number + # + if DefineObj.GetUefiSpecificationVersion() is not None: + __UefiVersion = DefineObj.GetUefiSpecificationVersion().GetValue() + __UefiVersion = ConvertVersionToDecimal(__UefiVersion) + self.SetUefiSpecificationVersion(str(__UefiVersion)) + if DefineObj.GetPiSpecificationVersion() is not None: + __PiVersion = DefineObj.GetPiSpecificationVersion().GetValue() + __PiVersion = ConvertVersionToDecimal(__PiVersion) + + self.SetPiSpecificationVersion(str(__PiVersion)) + SpecList = DefineObj.GetSpecification() + NewSpecList = [] + for SpecItem in SpecList: + NewSpecList.append((SpecItem[0], ConvertVersionToDecimal(SpecItem[1]))) + self.SetSpecList(NewSpecList) + + # + # must exist items in INF define section + # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING + # + if DefineObj.GetModuleType() is None: + Logger.Error("InfParser", FORMAT_INVALID, + ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("MODULE_TYPE"), File=self.FullPath) + else: + self.SetModuleType(DefineObj.GetModuleType().GetValue()) + ModuleType = DefineObj.GetModuleType().GetValue() + if ModuleType: + # + # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only + # libraries are permitted to a have a MODULE_TYPE of "BASE". + # + if len(DefineObj.LibraryClass) == 0 and ModuleType == 'BASE': + Logger.Error("InfParser", + FORMAT_INVALID, + ST.ERR_INF_PARSER_MODULETYPE_INVALID, + File=self.FullPath, + Line=DefineObj.ModuleType.CurrentLine.LineNo, + ExtraData=DefineObj.ModuleType.CurrentLine.LineString) + self.LibModuleTypeList.append(ModuleType) + if DefineObj.GetBaseName() is None: + Logger.Error("InfParser", FORMAT_INVALID, + ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("BASE_NAME"), File=self.FullPath) + else: + self.SetBaseName(DefineObj.GetBaseName().GetValue()) + if DefineObj.GetModuleUniFileName(): + self.UniFileClassObject = UniFileClassObject([PathClass(DefineObj.GetModuleUniFileName())]) + else: + self.UniFileClassObject = None + if DefineObj.GetInfVersion() is None: + Logger.Error("InfParser", FORMAT_INVALID, + ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("INF_VERSION"), File=self.FullPath) + else: + self.SetVersion(DefineObj.GetInfVersion().GetValue()) + if DefineObj.GetFileGuid() is None: + Logger.Error("InfParser", FORMAT_INVALID, + ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("FILE_GUID"), File=self.FullPath) + else: + self.SetGuid(DefineObj.GetFileGuid().GetValue()) + if DefineObj.GetVersionString() is None: + # + # VERSION_STRING is missing from the [Defines] section, tools must assume that the module's version is 0. + # + self.SetVersion('0') + else: + # + # Get version of INF + # + if DefineObj.GetVersionString().GetValue() != "": + # + # EDK2 inf + # + VersionString = DefineObj.GetVersionString().GetValue() + if len(VersionString) > 0: + VersionString = ConvertVersionToDecimal(VersionString) + self.SetVersion(VersionString) + else: + # + # EDK1 inf + # + Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ExtraData=self.FullPath, + RaiseError=Logger.IS_RAISE_ERROR) + # + # if there is Shadow, Should judge the MODULE_TYPE in + # SEC, PEI_CORE and PEIM + # + if DefineObj.GetShadow(): + ModuleTypeValue = DefineObj.GetModuleType().GetValue() + if not (ModuleTypeValue == 'SEC' or ModuleTypeValue == 'PEI_CORE' or ModuleTypeValue == 'PEIM'): + Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SHADOW_INVALID, File=self.FullPath) + + if DefineObj.GetPcdIsDriver() is not None: + self.SetPcdIsDriver(DefineObj.GetPcdIsDriver().GetValue()) + # + # LIBRARY_CLASS + # + self._GenModuleHeaderLibClass(DefineObj, ArchList) + # + # CUSTOM_MAKEFILE + # + self.CustomMakefile = DefineObj.GetCustomMakefile() + # + # Externs in Defines section + # Only one define section, so just call once. + # + if not HasCalledFlag: + self._GenModuleHeaderExterns(DefineObj) + HasCalledFlag = True + # + # each module has only one module header + # + self.SetSupArchList(ArchList) + # + # Get Hob/BootMode/EventList information + # + self._GenSpecialComments() + # + # put all define statement into user-extension sections + # + DefinesDictNew = GenModuleHeaderUserExt(DefineObj, ArchString) + if DefinesDictNew: + UserExtension = CommonObject.UserExtensionObject() + UserExtension.SetDefinesDict(DefinesDictNew) + UserExtension.SetIdentifier('DefineModifiers') + UserExtension.SetUserID('EDK2') + self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) + # + # Get all meta-file header information + # the record is list of items formatted: + # [LineValue, Arch, StartLine, ID, Third] + # + InfHeaderObj = self.Parser.InfHeader + # + # Put header information into POM object + # + if self.UniFileClassObject: + Lang = DT.TAB_LANGUAGE_EN_X + else: + Lang = DT.TAB_LANGUAGE_EN_US + if InfHeaderObj.GetAbstract(): + self.SetAbstract((Lang, InfHeaderObj.GetAbstract())) + if InfHeaderObj.GetDescription(): + self.SetDescription((Lang, InfHeaderObj.GetDescription())) + if InfHeaderObj.GetCopyright(): + self.SetCopyright(('', InfHeaderObj.GetCopyright())) + if InfHeaderObj.GetLicense(): + self.SetLicense(('', InfHeaderObj.GetLicense())) + # + # Put Binary header information into POM object + # + InfBinaryHeaderObj = self.Parser.InfBinaryHeader + if InfBinaryHeaderObj.GetAbstract(): + self.SetBinaryHeaderAbstract((Lang, InfBinaryHeaderObj.GetAbstract())) + if InfBinaryHeaderObj.GetDescription(): + self.SetBinaryHeaderDescription((Lang, InfBinaryHeaderObj.GetDescription())) + if InfBinaryHeaderObj.GetCopyright(): + self.SetBinaryHeaderCopyright(('', InfBinaryHeaderObj.GetCopyright())) + if InfBinaryHeaderObj.GetLicense(): + self.SetBinaryHeaderLicense(('', InfBinaryHeaderObj.GetLicense())) + + ## GenModuleHeaderLibClass + # + # + def _GenModuleHeaderLibClass(self, DefineObj, ArchList): + LibraryList = DefineObj.GetLibraryClass() + for LibraryItem in LibraryList: + Lib = CommonObject.LibraryClassObject() + Lib.SetLibraryClass(LibraryItem.GetLibraryName()) + Lib.SetUsage(DT.USAGE_ITEM_PRODUCES) + SupModuleList = LibraryItem.GetTypes() + self.LibModuleTypeList += SupModuleList + Lib.SetSupModuleList(SupModuleList) + Lib.SetSupArchList(ArchList) + self.SetLibraryClassList(self.GetLibraryClassList() + [Lib]) + self.SetIsLibrary(True) + self.SetIsLibraryModList(self.GetIsLibraryModList() + SupModuleList) + + ## GenModuleHeaderExterns + # + # + def _GenModuleHeaderExterns(self, DefineObj): + EntryPointList = DefineObj.GetEntryPoint() + for EntryPoint in EntryPointList: + Image = ExternObject() + Image.SetEntryPoint(EntryPoint.GetCName()) + # + # Future enhancement + # + self.SetExternList(self.GetExternList() + [Image]) + # + # UNLOAD_IMAGE + # + UnloadImageList = DefineObj.GetUnloadImages() + for UnloadImage in UnloadImageList: + Image = ExternObject() + # + # Future enhancement + # + Image.SetUnloadImage(UnloadImage.GetCName()) + self.SetExternList(self.GetExternList() + [Image]) + # + # CONSTRUCTOR + # + ConstructorList = DefineObj.GetConstructor() + for ConstructorItem in ConstructorList: + Image = ExternObject() + # + # Future enhancement + # + Image.SetConstructor(ConstructorItem.GetCName()) + self.SetExternList(self.GetExternList() + [Image]) + # + # DESTRUCTOR + # + DestructorList = DefineObj.GetDestructor() + for DestructorItem in DestructorList: + Image = ExternObject() + # + # Future enhancement + # + Image.SetDestructor(DestructorItem.GetCName()) + self.SetExternList(self.GetExternList() + [Image]) + + ## GenModuleHeaderExterns + # BootMode/HOB/Event + # + def _GenSpecialComments(self): + SpecialCommentsList = self.Parser.InfSpecialCommentSection.GetSpecialComments() + for Key in SpecialCommentsList: + if Key == DT.TYPE_HOB_SECTION: + HobList = [] + for Item in SpecialCommentsList[Key]: + Hob = HobObject() + Hob.SetHobType(Item.GetHobType()) + Hob.SetUsage(Item.GetUsage()) + Hob.SetSupArchList(Item.GetSupArchList()) + if Item.GetHelpString(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(Item.GetHelpString()) + Hob.SetHelpTextList([HelpTextObj]) + HobList.append(Hob) + self.SetHobList(HobList) + elif Key == DT.TYPE_EVENT_SECTION: + EventList = [] + for Item in SpecialCommentsList[Key]: + Event = EventObject() + Event.SetEventType(Item.GetEventType()) + Event.SetUsage(Item.GetUsage()) + if Item.GetHelpString(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(Item.GetHelpString()) + Event.SetHelpTextList([HelpTextObj]) + EventList.append(Event) + self.SetEventList(EventList) + elif Key == DT.TYPE_BOOTMODE_SECTION: + BootModeList = [] + for Item in SpecialCommentsList[Key]: + BootMode = BootModeObject() + BootMode.SetSupportedBootModes(Item.GetSupportedBootModes()) + BootMode.SetUsage(Item.GetUsage()) + if Item.GetHelpString(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(Item.GetHelpString()) + BootMode.SetHelpTextList([HelpTextObj]) + BootModeList.append(BootMode) + self.SetBootModeList(BootModeList) + + ## GenBuildOptions + # + # Gen BuildOptions of Inf + # [<Family>:]<ToolFlag>=Flag + # + # + def _GenBuildOptions(self): + Logger.Debug(2, "Generate %s ..." % DT.TAB_BUILD_OPTIONS) + # + # Get all BuildOptions + # + BuildOptionsList = self.Parser.InfBuildOptionSection.GetBuildOptions() + if not GlobalData.gIS_BINARY_INF: + BuildOptionDict = {} + for BuildOptionObj in BuildOptionsList: + ArchList = BuildOptionObj.GetSupArchList() + ArchList = ConvertArchList(ArchList) + BuildOptionsContent = BuildOptionObj.GetContent() + ArchString = ' '.join(ArchList) + if not BuildOptionsContent: + continue + BuildOptionDict[ArchString] = BuildOptionsContent + if not BuildOptionDict: + return + UserExtension = CommonObject.UserExtensionObject() + UserExtension.SetBuildOptionDict(BuildOptionDict) + UserExtension.SetIdentifier('BuildOptionModifiers') + UserExtension.SetUserID('EDK2') + self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) + else: + # + # Not process this information, will be processed in GenBinaries() + # + pass + + ## GenLibraryClasses + # + # Get LibraryClass of Inf + # <LibraryClassKeyWord>|<LibraryInstance> + # + # @param ContainerFile: The Inf file full path + # + def _GenLibraryClasses(self): + Logger.Debug(2, "Generate %s ..." % DT.TAB_LIBRARY_CLASSES) + if not GlobalData.gIS_BINARY_INF: + # + # Get all LibraryClasses + # + for LibraryClassData in self.Parser.InfLibraryClassSection.LibraryClasses.values(): + for Item in LibraryClassData: + LibraryClass = CommonObject.LibraryClassObject() + LibraryClass.SetUsage(DT.USAGE_ITEM_CONSUMES) + LibraryClass.SetLibraryClass(Item.GetLibName()) + LibraryClass.SetRecommendedInstance(None) + LibraryClass.SetFeatureFlag(Item.GetFeatureFlagExp()) + LibraryClass.SetSupArchList(ConvertArchList(Item.GetSupArchList())) + LibraryClass.SetSupModuleList(Item.GetSupModuleList()) + HelpStringObj = Item.GetHelpString() + if HelpStringObj is not None: + CommentString = GetHelpStringByRemoveHashKey(HelpStringObj.HeaderComments + + HelpStringObj.TailComments) + HelpTextHeaderObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextHeaderObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextHeaderObj.SetString(CommentString) + LibraryClass.SetHelpTextList([HelpTextHeaderObj]) + self.SetLibraryClassList(self.GetLibraryClassList() + [LibraryClass]) + + ## GenPackages + # + # Gen Packages of Inf + # + # + # @param ContainerFile: The Inf file full path + # + def _GenPackages(self, Skip): + Logger.Debug(2, "Generate %s ..." % DT.TAB_PACKAGES) + # + # Get all Packages + # + PackageObj = self.Parser.InfPackageSection.Packages + # + # Go through each arch + # + for PackageItemObj in PackageObj: + # + # Need package information for dependency check usage + # + PackageDependency = PackageDependencyObject() + PackageDependency.SetPackageFilePath(NormPath(PackageItemObj.GetPackageName())) + PackageDependency.SetSupArchList(ConvertArchList(PackageItemObj.GetSupArchList())) + PackageDependency.SetFeatureFlag(PackageItemObj.GetFeatureFlagExp()) + + PkgInfo = GetPkgInfoFromDec(mws.join(self.WorkSpace, NormPath(PackageItemObj.GetPackageName()))) + if PkgInfo[1] and PkgInfo[2]: + PackageDependency.SetGuid(PkgInfo[1]) + PackageDependency.SetVersion(PkgInfo[2]) + elif Skip: + continue + else: + Logger.Error("\nUPT", PARSER_ERROR, + ST.ERR_INF_GET_PKG_DEPENDENCY_FAIL % PackageItemObj.GetPackageName(), File=self.FullPath) + + PackageDependencyList = self.GetPackageDependencyList() + PackageDependencyList.append(PackageDependency) + self.SetPackageDependencyList(PackageDependencyList) + + ## GenPcds + # + # Gen Pcds of Inf + # <TokenSpaceGuidCName>.<PcdCName>[|<Value> [|<FFE>]] + # + # @param ContainerFile: The Inf file full path + # + def _GenPcds(self): + if not GlobalData.gIS_BINARY_INF: + Logger.Debug(2, "Generate %s ..." % DT.TAB_PCDS) + # + # Get all Pcds + # + PcdObj = self.Parser.InfPcdSection.Pcds + KeysList = PcdObj.keys() + # + # Go through each arch + # + for (PcdType, PcdKey) in KeysList: + PcdData = PcdObj[PcdType, PcdKey] + for PcdItemObj in PcdData: + CommentList = PcdItemObj.GetHelpStringList() + if CommentList: + for CommentItem in CommentList: + Pcd = CommonObject.PcdObject() + Pcd.SetCName(PcdItemObj.GetCName()) + Pcd.SetTokenSpaceGuidCName(PcdItemObj.GetTokenSpaceGuidCName()) + Pcd.SetDefaultValue(PcdItemObj.GetDefaultValue()) + Pcd.SetItemType(PcdType) + Pcd.SetValidUsage(CommentItem.GetUsageItem()) + Pcd.SetFeatureFlag(PcdItemObj.GetFeatureFlagExp()) + Pcd.SetSupArchList(ConvertArchList(PcdItemObj.GetSupportArchList())) + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(CommentItem.GetHelpStringItem()) + Pcd.SetHelpTextList([HelpTextObj]) + PcdList = self.GetPcdList() + PcdList.append(Pcd) + self.SetPcdList(PcdList) + + ## GenSources + # + # Gen Sources of Inf + # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]] + # + # @param ContainerFile: The Inf file full path + # + def _GenSources(self): + Logger.Debug(2, "Generate %s ..." % DT.TAB_SOURCES) + + # + # Get all SourceFiles + # + SourceObj = self.Parser.InfSourcesSection.Sources + DataList = SourceObj.keys() + # + # Go through each arch + # + SourceList = [] + for Key in DataList: + SourceData = SourceObj[Key] + for Item in SourceData: + SourceFile = Item.GetSourceFileName() + Family = Item.GetFamily() + FeatureFlag = Item.GetFeatureFlagExp() + SupArchList = sorted(ConvertArchList(Item.GetSupArchList())) + Source = SourceFileObject() + Source.SetSourceFile(SourceFile) + Source.SetFamily(Family) + Source.SetFeatureFlag(FeatureFlag) + Source.SetSupArchList(SupArchList) + SourceList.append(Source) + + self.SetSourceFileList(self.GetSourceFileList() + SourceList) + + + ## GenUserExtensions + # + # Gen UserExtensions of Inf + # + def _GenUserExtensions(self): + # + # UserExtensions + # + UserExtensionObj = self.Parser.InfUserExtensionSection.UserExtension + Keys = UserExtensionObj.keys() + + for Key in Keys: + UserExtensionData = UserExtensionObj[Key] + for UserExtensionDataObj in UserExtensionData: + UserExtension = CommonObject.UserExtensionObject() + UserId = UserExtensionDataObj.GetUserId() + if UserId.startswith('"') and UserId.endswith('"'): + UserId = UserId[1:-1] + UserExtension.SetUserID(UserId) + Identifier = UserExtensionDataObj.GetIdString() + if Identifier.startswith('"') and Identifier.endswith('"'): + Identifier = Identifier[1:-1] + # + # Generate miscellaneous files on INF file + # + if UserId == 'TianoCore' and Identifier == 'ExtraFiles': + self._GenMiscFiles(UserExtensionDataObj.GetContent()) + UserExtension.SetIdentifier(Identifier) + UserExtension.SetStatement(UserExtensionDataObj.GetContent()) + UserExtension.SetSupArchList(ConvertArchList(UserExtensionDataObj.GetSupArchList())) + self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) + + # + # Gen UserExtensions of TianoCore."BinaryHeader" + # + + #Get Binary header from INF file + BinaryAbstractList = self.BinaryHeaderAbstractList + BinaryDescriptionList = self.BinaryHeaderDescriptionList + BinaryCopyrightList = self.BinaryHeaderCopyrightList + BinaryLicenseList = self.BinaryHeaderLicenseList + #Get Binary header from UNI file + # Initialize UniStrDict, the top keys are language codes + UniStrDict = {} + if self.UniFileClassObject: + UniStrDict = self.UniFileClassObject.OrderedStringList + for Lang in UniStrDict: + for StringDefClassObject in UniStrDict[Lang]: + Lang = GetLanguageCode1766(Lang) + if StringDefClassObject.StringName == DT.TAB_INF_BINARY_ABSTRACT: + BinaryAbstractList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue))) + if StringDefClassObject.StringName == DT.TAB_INF_BINARY_DESCRIPTION: + BinaryDescriptionList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue))) + if BinaryAbstractList or BinaryDescriptionList or BinaryCopyrightList or BinaryLicenseList: + BinaryUserExtension = CommonObject.UserExtensionObject() + BinaryUserExtension.SetBinaryAbstract(BinaryAbstractList) + BinaryUserExtension.SetBinaryDescription(BinaryDescriptionList) + BinaryUserExtension.SetBinaryCopyright(BinaryCopyrightList) + BinaryUserExtension.SetBinaryLicense(BinaryLicenseList) + BinaryUserExtension.SetIdentifier(DT.TAB_BINARY_HEADER_IDENTIFIER) + BinaryUserExtension.SetUserID(DT.TAB_BINARY_HEADER_USERID) + self.SetUserExtensionList(self.GetUserExtensionList() + [BinaryUserExtension]) + + def _GenDepexesList(self, SmmDepexList, DxeDepexList, PeiDepexList): + if SmmDepexList: + self.SetSmmDepex(SmmDepexList) + if DxeDepexList: + self.SetDxeDepex(DxeDepexList) + if PeiDepexList: + self.SetPeiDepex(PeiDepexList) + + ## GenDepexes + # + # Gen Depex of Inf + # + # @param ContainerFile: The Inf file full path + # + def _GenDepexes(self): + Logger.Debug(2, "Generate %s ..." % DT.TAB_DEPEX) + + PEI_LIST = [DT.SUP_MODULE_PEIM] + SMM_LIST = [DT.SUP_MODULE_DXE_SMM_DRIVER] + DXE_LIST = [DT.SUP_MODULE_DXE_DRIVER, DT.SUP_MODULE_DXE_SAL_DRIVER, + DT.SUP_MODULE_DXE_RUNTIME_DRIVER] + + IsLibraryClass = self.GetIsLibrary() + # + # Get all Depexes + # + DepexData = self.Parser.InfDepexSection.GetDepex() + SmmDepexList = [] + DxeDepexList = [] + PeiDepexList = [] + for Depex in DepexData: + ModuleType = Depex.GetModuleType() + ModuleTypeList = [] + if IsLibraryClass: + if self.GetModuleType() == 'BASE' and not ModuleType: + Logger.Error("\nMkPkg", PARSER_ERROR, + ST.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS, + self.GetFullPath(), RaiseError=True) + if self.GetModuleType() != 'BASE' and not self.GetIsLibraryModList(): + Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS, + self.GetFullPath(), RaiseError=True) + if self.GetModuleType() != 'BASE' and ModuleType and ModuleType not in self.GetIsLibraryModList(): + Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, + self.GetFullPath(), RaiseError=True) + if ModuleType: + ModuleTypeList = [ModuleType] + else: + for ModuleTypeInList in self.GetIsLibraryModList(): + if ModuleTypeInList in DT.VALID_DEPEX_MODULE_TYPE_LIST: + ModuleTypeList.append(ModuleTypeInList) + if not ModuleTypeList: + Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, + self.GetFullPath(), RaiseError=True) + else: + if not ModuleType: + ModuleType = self.ModuleType + if ModuleType not in DT.VALID_DEPEX_MODULE_TYPE_LIST: + Logger.Error("\nMkPkg", PARSER_ERROR, + ST.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR % (ModuleType), + self.GetFullPath(), RaiseError=True) + if ModuleType != self.ModuleType: + Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, + self.GetFullPath(), RaiseError=True) + ModuleTypeList = [ModuleType] + for ModuleType in ModuleTypeList: + DepexIns = DepexObject() + DepexIns.SetDepex(Depex.GetDepexContent()) + if IsLibraryClass: + DepexIns.SetModuleType(ModuleType) + else: + if Depex.GetModuleType(): + DepexIns.SetModuleType(Depex.GetModuleType()) + DepexIns.SetSupArchList(ConvertArchList([Depex.GetSupArch()])) + DepexIns.SetFeatureFlag(Depex.GetFeatureFlagExp()) + if Depex.HelpString: + HelpIns = CommonObject.TextObject() + if self.UniFileClassObject: + HelpIns.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpIns.SetString(GetHelpStringByRemoveHashKey(Depex.HelpString)) + DepexIns.SetHelpText(HelpIns) + + if ModuleType in SMM_LIST: + SmmDepexList.append(DepexIns) + if ModuleType in DXE_LIST: + DxeDepexList.append(DepexIns) + if ModuleType in PEI_LIST: + PeiDepexList.append(DepexIns) + if ModuleType == DT.SUP_MODULE_UEFI_DRIVER: + if IsLibraryClass: + DxeDepexList.append(DepexIns) + else: + Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER, + self.GetFullPath(), RaiseError=True) + + #End of for ModuleType in ModuleTypeList + self._GenDepexesList(SmmDepexList, DxeDepexList, PeiDepexList) + #End of for Depex in DepexData + + ## GenBinaries + # + # Gen Binary of Inf, must be called after Pcd/Library is generated + # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>] + # + # @param ContainerFile: The Inf file full path + # + def _GenBinaries(self): + Logger.Debug(2, "Generate %s ..." % DT.TAB_BINARIES) + BinariesDict = {} + + # + # Get all Binary data + # + BinaryObj = self.Parser.InfBinariesSection.GetBinary() + + BinaryData = BinaryObj.keys() + + # + # If the INF file does not contain a [Sources] section, and the INF file does contain a [Binaries] section, + # then the ModuleSurfaceArea.BinaryModule attribute must be set to true. Otherwise, do not use the attribute + # + if BinaryObj and not self.Parser.InfSourcesSection.GetSources(): + self.BinaryModule = True + else: + self.BinaryModule = False + + BinaryFileObjectList = [] + AsBuildLibraryClassList = [] + AsBuildBuildOptionList = [] + AsBuildIns = AsBuiltObject() + # + # Library AsBuild Info + # + for LibItem in self.Parser.InfLibraryClassSection.GetLibraryClasses(): + AsBuildLibIns = AsBuildLibraryClassObject() + AsBuildLibIns.SetLibGuid(LibItem.GetFileGuid()) + AsBuildLibIns.SetLibVersion(LibItem.GetVersion()) + AsBuildLibIns.SetSupArchList(LibItem.GetSupArchList()) + AsBuildLibraryClassList.append(AsBuildLibIns) + AsBuildIns.SetLibraryInstancesList(AsBuildLibraryClassList) + + # + # BuildOption AsBuild Info + # + for BuildOptionItem in self.Parser.InfBuildOptionSection.GetBuildOptions(): + AsBuildBuildOptionList.append(BuildOptionItem) + AsBuildIns.SetBuildFlagsList(AsBuildBuildOptionList) + + # + # PatchPcd and PcdEx + # + AsBuildIns = self._GenAsBuiltPcds(self.Parser.InfPcdSection.GetPcds(), AsBuildIns) + + # + # Parse the DEC file that contains the GUID value of the GUID CName which is used by + # SUBTYPE_GUID type binary file in the Binaries section in the INF file + # + DecObjList = [] + if not self.PackagePath: + WorkSpace = os.path.normpath(self.WorkSpace) + TempPath = ModulePath = os.path.normpath(self.ModulePath) + while ModulePath: + TempPath = ModulePath + ModulePath = os.path.dirname(ModulePath) + PackageName = TempPath + DecFilePath = os.path.normpath(os.path.join(WorkSpace, PackageName)) + if DecFilePath: + for File in os.listdir(DecFilePath): + if File.upper().endswith('.DEC'): + DecFileFullPath = os.path.normpath(os.path.join(DecFilePath, File)) + DecObjList.append(DecPomAlignment(DecFileFullPath, self.WorkSpace)) + + + BinariesDict, AsBuildIns, BinaryFileObjectList = GenBinaryData(BinaryData, BinaryObj, + BinariesDict, + AsBuildIns, + BinaryFileObjectList, + self.GetSupArchList(), + self.BinaryModule, + DecObjList) + + BinariesDict2 = {} + for Key in BinariesDict: + ValueList = BinariesDict[Key] + if len(ValueList) > 1: + BinariesDict2[Key] = ValueList + else: + # + # if there is no TagName, ToolCode, HelpStr, + # then do not need to put them into userextension + # + (Target, Family, TagName, HelpStr) = ValueList[0] + if not (Target or Family or TagName or HelpStr): + continue + else: + BinariesDict2[Key] = ValueList + + self.SetBinaryFileList(self.GetBinaryFileList() + BinaryFileObjectList) + + if BinariesDict2: + UserExtension = CommonObject.UserExtensionObject() + UserExtension.SetBinariesDict(BinariesDict2) + UserExtension.SetIdentifier('BinaryFileModifiers') + UserExtension.SetUserID('EDK2') + self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) + + ## GenAsBuiltPcds + # + # + def _GenAsBuiltPcds(self, PcdList, AsBuildIns): + AsBuildPatchPcdList = [] + AsBuildPcdExList = [] + # + # Pcd AsBuild Info + # + for PcdItem in PcdList: + if PcdItem[0].upper() == DT.TAB_INF_PATCH_PCD.upper(): + PcdItemObj = PcdItem[1] + Pcd = CommonObject.PcdObject() + Pcd.SetCName(PcdItemObj.GetCName()) + Pcd.SetTokenSpaceGuidCName(PcdItemObj.GetTokenSpaceGuidCName()) + if PcdItemObj.GetTokenSpaceGuidValue() == '' and self.BinaryModule: + Logger.Error("\nMkPkg", + PARSER_ERROR, + ST.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS % \ + (PcdItemObj.GetTokenSpaceGuidCName()), + self.GetFullPath(), RaiseError=True) + else: + Pcd.SetTokenSpaceGuidValue(PcdItemObj.GetTokenSpaceGuidValue()) + if (PcdItemObj.GetToken() == '' or PcdItemObj.GetDatumType() == '') and self.BinaryModule: + Logger.Error("\nMkPkg", + PARSER_ERROR, + ST.ERR_ASBUILD_PCD_DECLARITION_MISS % \ + (PcdItemObj.GetTokenSpaceGuidCName() + '.' + PcdItemObj.GetCName()), + self.GetFullPath(), RaiseError=True) + Pcd.SetToken(PcdItemObj.GetToken()) + Pcd.SetDatumType(PcdItemObj.GetDatumType()) + Pcd.SetMaxDatumSize(PcdItemObj.GetMaxDatumSize()) + Pcd.SetDefaultValue(PcdItemObj.GetDefaultValue()) + Pcd.SetOffset(PcdItemObj.GetOffset()) + Pcd.SetItemType(PcdItem[0]) + Pcd.SetFeatureFlag(PcdItemObj.GetFeatureFlagExp()) + Pcd.SetSupArchList(ConvertArchList(PcdItemObj.GetSupportArchList())) + Pcd.SetValidUsage(PcdItemObj.GetValidUsage()) + for CommentItem in PcdItemObj.GetHelpStringList(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(CommentItem.GetHelpStringItem()) + Pcd.SetHelpTextList(Pcd.GetHelpTextList() + [HelpTextObj]) + AsBuildPatchPcdList.append(Pcd) + elif PcdItem[0].upper() == DT.TAB_INF_PCD_EX.upper(): + PcdItemObj = PcdItem[1] + Pcd = CommonObject.PcdObject() + Pcd.SetTokenSpaceGuidValue(PcdItemObj.GetTokenSpaceGuidValue()) + Pcd.SetToken(PcdItemObj.GetToken()) + Pcd.SetDatumType(PcdItemObj.GetDatumType()) + Pcd.SetMaxDatumSize(PcdItemObj.GetMaxDatumSize()) + Pcd.SetDefaultValue(PcdItemObj.GetDefaultValue()) + Pcd.SetItemType(PcdItem[0]) + Pcd.SetFeatureFlag(PcdItemObj.GetFeatureFlagExp()) + Pcd.SetSupArchList(ConvertArchList(PcdItemObj.GetSupportArchList())) + Pcd.SetValidUsage(PcdItemObj.GetValidUsage()) + for CommentItem in PcdItemObj.GetHelpStringList(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(CommentItem.GetHelpStringItem()) + Pcd.SetHelpTextList(Pcd.GetHelpTextList() + [HelpTextObj]) + AsBuildPcdExList.append(Pcd) + AsBuildIns.SetPatchPcdList(AsBuildPatchPcdList) + AsBuildIns.SetPcdExList(AsBuildPcdExList) + + return AsBuildIns + + ## GenGuidProtocolPpis + # + # Gen Guids/Protocol/Ppis of INF + # <CName>=<GuidValue> + # + def _GenGuidProtocolPpis(self, Type): + Logger.Debug(2, "Generate %s ..." % Type) + # + # Get all Guid/Protocol/Ppis data + # + GuidObj = self.Parser.InfGuidSection.GetGuid() + ProtocolObj = self.Parser.InfProtocolSection.GetProtocol() + PpisObj = self.Parser.InfPpiSection.GetPpi() + + GuidProtocolPpiList = [] + + if Type == DT.TAB_GUIDS: + GuidData = GuidObj.keys() + for Item in GuidData: + CommentList = Item.GetCommentList() + # + # Depend on CommentList content + # generate muti-guid-obj + # + if CommentList: + for GuidComentItem in CommentList: + ListObject = CommonObject.GuidObject() + ListObject.SetGuidTypeList([GuidComentItem.GetGuidTypeItem()]) + ListObject.SetVariableName(GuidComentItem.GetVariableNameItem()) + ListObject.SetUsage(GuidComentItem.GetUsageItem()) + ListObject.SetName(Item.GetName()) + ListObject.SetCName(Item.GetName()) + ListObject.SetSupArchList(ConvertArchList(Item.GetSupArchList())) + ListObject.SetFeatureFlag(Item.GetFeatureFlagExp()) + HelpString = GuidComentItem.GetHelpStringItem() + if HelpString.strip(): + HelpTxtTailObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTxtTailObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTxtTailObj.SetString(HelpString) + ListObject.SetHelpTextList([HelpTxtTailObj]) + + GuidProtocolPpiList.append(ListObject) + elif Type == DT.TAB_PROTOCOLS: + ProtocolData = ProtocolObj.keys() + for Item in ProtocolData: + CommentList = Item.GetCommentList() + for CommentItem in CommentList: + ListObject = CommonObject.ProtocolObject() + ListObject.SetCName(Item.GetName()) + ListObject.SetSupArchList(ConvertArchList(Item.GetSupArchList())) + ListObject.SetFeatureFlag(Item.GetFeatureFlagExp()) + ListObject.SetNotify(CommentItem.GetNotify()) + ListObject.SetUsage(CommentItem.GetUsageItem()) + HelpString = CommentItem.GetHelpStringItem() + if HelpString.strip(): + HelpTxtObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTxtObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTxtObj.SetString(HelpString) + ListObject.SetHelpTextList([HelpTxtObj]) + GuidProtocolPpiList.append(ListObject) + elif Type == DT.TAB_PPIS: + PpiData = PpisObj.keys() + for Item in PpiData: + CommentList = Item.GetCommentList() + for CommentItem in CommentList: + ListObject = CommonObject.PpiObject() + ListObject.SetCName(Item.GetName()) + ListObject.SetSupArchList(ConvertArchList(Item.GetSupArchList())) + ListObject.SetFeatureFlag(Item.GetFeatureFlagExp()) + ListObject.SetNotify(CommentItem.GetNotify()) + ListObject.SetUsage(CommentItem.GetUsage()) + HelpString = CommentItem.GetHelpStringItem() + if HelpString.strip(): + HelpTextObj = CommonObject.TextObject() + if self.UniFileClassObject: + HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) + HelpTextObj.SetString(HelpString) + ListObject.SetHelpTextList([HelpTextObj]) + GuidProtocolPpiList.append(ListObject) + + if Type == DT.TAB_GUIDS: + self.SetGuidList(self.GetGuidList() + GuidProtocolPpiList) + elif Type == DT.TAB_PROTOCOLS: + self.SetProtocolList(self.GetProtocolList() + GuidProtocolPpiList) + elif Type == DT.TAB_PPIS: + self.SetPpiList(self.GetPpiList() + GuidProtocolPpiList) + + ## GenMiscFiles + # + # Gen MiscellaneousFiles of Inf + # + # @param ContainerFile: The Inf file full path + # + def _GenMiscFiles(self, Content): + MiscFileObj = CommonObject.MiscFileObject() + for Line in Content.splitlines(): + FileName = '' + if '#' in Line: + FileName = Line[:Line.find('#')] + else: + FileName = Line + if FileName: + if IsValidPath(FileName, GlobalData.gINF_MODULE_DIR): + FileObj = CommonObject.FileObject() + FileObj.SetURI(FileName) + MiscFileObj.SetFileList(MiscFileObj.GetFileList()+[FileObj]) + else: + Logger.Error("InfParser", + FORMAT_INVALID, + ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Line), + File=GlobalData.gINF_MODULE_NAME, + ExtraData=Line) + self.SetMiscFileList(self.GetMiscFileList()+[MiscFileObj]) + diff --git a/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py new file mode 100755 index 00000000..c422de26 --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py @@ -0,0 +1,255 @@ +## @file InfPomAlignmentMisc.py +# This file contained the routines for InfPomAlignment +# +# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' +InfPomAlignmentMisc +''' + +## +# Import modules +# +import Logger.Log as Logger +from Library import DataType as DT +from Library.Misc import ConvertArchList +from Object.POM.ModuleObject import BinaryFileObject +from Object.POM import CommonObject +from Library.StringUtils import FORMAT_INVALID +from Library.Misc import CheckGuidRegFormat +from Logger import StringTable as ST + + +## GenModuleHeaderUserExt +# +# +def GenModuleHeaderUserExt(DefineObj, ArchString): + DefinesDictNew = {} + EdkReleaseVersion = DefineObj.GetEdkReleaseVersion() + Shadow = DefineObj.GetShadow() + DpxSource = DefineObj.GetDpxSource() + PciVendorId = DefineObj.GetPciVendorId() + PciDeviceId = DefineObj.GetPciDeviceId() + PciClassCode = DefineObj.GetPciClassCode() + PciRevision = DefineObj.GetPciRevision() + PciCompress = DefineObj.GetPciCompress() + CustomMakefile = DefineObj.GetCustomMakefile() + UefiHiiResourceSection = DefineObj.GetUefiHiiResourceSection() + + if EdkReleaseVersion is not None: + Name = DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION + Value = EdkReleaseVersion.GetValue() + Statement = _GenInfDefineStateMent(EdkReleaseVersion.Comments.GetHeaderComments(), + Name, + Value, + EdkReleaseVersion.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if Shadow is not None: + Name = DT.TAB_INF_DEFINES_SHADOW + Value = Shadow.GetValue() + Statement = _GenInfDefineStateMent(Shadow.Comments.GetHeaderComments(), + Name, + Value, + Shadow.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if DpxSource is not None: + Name = DT.TAB_INF_DEFINES_DPX_SOURCE + for DpxSourceItem in DpxSource: + Value = DpxSourceItem[0] + Statement = _GenInfDefineStateMent(DpxSourceItem[1].GetHeaderComments(), + Name, + Value, + DpxSourceItem[1].GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if PciVendorId is not None: + Name = DT.TAB_INF_DEFINES_PCI_VENDOR_ID + Value = PciVendorId.GetValue() + Statement = _GenInfDefineStateMent(PciVendorId.Comments.GetHeaderComments(), + Name, + Value, + PciVendorId.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if PciDeviceId is not None: + Name = DT.TAB_INF_DEFINES_PCI_DEVICE_ID + Value = PciDeviceId.GetValue() + Statement = _GenInfDefineStateMent(PciDeviceId.Comments.GetHeaderComments(), + Name, + Value, + PciDeviceId.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if PciClassCode is not None: + Name = DT.TAB_INF_DEFINES_PCI_CLASS_CODE + Value = PciClassCode.GetValue() + Statement = _GenInfDefineStateMent(PciClassCode.Comments.GetHeaderComments(), + Name, + Value, + PciClassCode.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if PciRevision is not None: + Name = DT.TAB_INF_DEFINES_PCI_REVISION + Value = PciRevision.GetValue() + Statement = _GenInfDefineStateMent(PciRevision.Comments.GetHeaderComments(), + Name, + Value, + PciRevision.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if PciCompress is not None: + Name = DT.TAB_INF_DEFINES_PCI_COMPRESS + Value = PciCompress.GetValue() + Statement = _GenInfDefineStateMent(PciCompress.Comments.GetHeaderComments(), + Name, + Value, + PciCompress.Comments.GetTailComments()) + DefinesDictNew[Statement] = ArchString + + if len(CustomMakefile) >= 1: + for CustomMakefileItem in CustomMakefile: + Name = DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE + # + # Not with Feature Flag Expression + # + if len(CustomMakefileItem) == 3: + if CustomMakefileItem[0] != '': + Value = CustomMakefileItem[0] + ' | ' + CustomMakefileItem[1] + else: + Value = CustomMakefileItem[1] + + Comments = CustomMakefileItem[2] + Statement = _GenInfDefineStateMent(Comments.GetHeaderComments(), + Name, + Value, + Comments.GetTailComments()) + + DefinesDictNew[Statement] = ArchString + + if UefiHiiResourceSection is not None: + Name = DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION + Value = UefiHiiResourceSection.GetValue() + HeaderComment = UefiHiiResourceSection.Comments.GetHeaderComments() + TailComment = UefiHiiResourceSection.Comments.GetTailComments() + Statement = _GenInfDefineStateMent(HeaderComment, + Name, + Value, + TailComment) + DefinesDictNew[Statement] = "" + + return DefinesDictNew + + +## Generate the define statement that will be put into userextension +# Not support comments. +# +# @param HeaderComment: the original header comment (# not removed) +# @param Name: the definition keyword, should not be empty or none +# @param Value: the definition keyword value +# @param TailComment: the original Tail comment (# not removed) +# +# @return: the regenerated define statement +# +def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment): + Logger.Debug(5, HeaderComment + TailComment) + Statement = '%s = %s' % (Name, Value) + + return Statement + +## GenBinaryData +# +# +def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \ + SupArchList, BinaryModule, DecObjList=None): + if BinaryModule: + pass + OriSupArchList = SupArchList + for Item in BinaryData: + ItemObj = BinaryObj[Item][0][0] + if ItemObj.GetType() not in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST: + TagName = ItemObj.GetTagName() + Family = ItemObj.GetFamily() + else: + TagName = '' + Family = '' + + FFE = ItemObj.GetFeatureFlagExp() + + # + # If have architecturie specified, then use the specified architecturie; + # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive), + # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment + # can be used for the attribute. + # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty. + # + SupArchList = sorted(ConvertArchList(ItemObj.GetSupArchList())) + if len(SupArchList) == 1 and SupArchList[0] == 'COMMON': + if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'): + SupArchList = OriSupArchList + else: + SupArchList = ['COMMON'] + + FileNameObj = CommonObject.FileNameObject() + FileNameObj.SetFileType(ItemObj.GetType()) + FileNameObj.SetFilename(ItemObj.GetFileName()) + FileNameObj.SetFeatureFlag(FFE) + # + # Get GUID value of the GUID CName in the DEC file + # + if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE: + if not CheckGuidRegFormat(ItemObj.GetGuidValue()): + if not DecObjList: + if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \ + DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue(): + Logger.Error("\nMkPkg", + FORMAT_INVALID, + ST.ERR_DECPARSE_DEFINE_PKGGUID, + ExtraData=ItemObj.GetGuidValue(), + RaiseError=True) + else: + Logger.Error("\nMkPkg", + FORMAT_INVALID, + ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \ + (ItemObj.GetGuidValue()), + RaiseError=True) + else: + for DecObj in DecObjList: + for GuidObj in DecObj.GetGuidList(): + if GuidObj.GetCName() == ItemObj.GetGuidValue(): + FileNameObj.SetGuidValue(GuidObj.GetGuid()) + break + + if not FileNameObj.GetGuidValue(): + Logger.Error("\nMkPkg", + FORMAT_INVALID, + ST.ERR_DECPARSE_CGUID_NOT_FOUND % \ + (ItemObj.GetGuidValue()), + RaiseError=True) + else: + FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip()) + + FileNameObj.SetSupArchList(SupArchList) + FileNameList = [FileNameObj] + + BinaryFile = BinaryFileObject() + BinaryFile.SetFileNameList(FileNameList) + BinaryFile.SetAsBuiltList(AsBuildIns) + BinaryFileObjectList.append(BinaryFile) + + SupArchStr = ' '.join(SupArchList) + Key = (ItemObj.GetFileName(), ItemObj.GetType(), FFE, SupArchStr) + ValueItem = (ItemObj.GetTarget(), Family, TagName, '') + if Key in BinariesDict: + ValueList = BinariesDict[Key] + ValueList.append(ValueItem) + BinariesDict[Key] = ValueList + else: + BinariesDict[Key] = [ValueItem] + + return BinariesDict, AsBuildIns, BinaryFileObjectList diff --git a/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/__init__.py b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/__init__.py new file mode 100644 index 00000000..0df484ce --- /dev/null +++ b/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/UPT/PomAdapter/__init__.py @@ -0,0 +1,14 @@ +## @file +# Python 'Parser' package initialization file. +# +# This file is required to make Python interpreter treat the directory +# as containing package. +# +# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# + +''' +PomAdapter +''' |