X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FUPT%2FGenMetaFile%2FGenInfFile.py;h=c2a240a88410c965715c9b6a4958abab315f432d;hb=1ccc4d895dd8d659d016efcd6ef8a48749aba1d0;hp=bfd422b196ba0f6abe977be825d333e9221bdc7f;hpb=64285f15264906c761b5a6772b5b590b32caa03c;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py index bfd422b196..c2a240a884 100644 --- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py +++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py @@ -4,9 +4,9 @@ # # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
# -# This program and the accompanying materials are licensed and made available -# under the terms and conditions of the BSD License which accompanies this -# distribution. The full text of the license may be found at +# This program and the accompanying materials are licensed and made available +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at # http://opensource.org/licenses/bsd-license.php # # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, @@ -18,7 +18,7 @@ GenInf import os import stat import codecs -import md5 +from hashlib import md5 from Core.FileHook import __FileHookOpen__ from Library.StringUtils import GetSplitValueList from Library.Parsing import GenSection @@ -46,8 +46,8 @@ from Library.StringUtils import GetUniFileName ## Transfer Module Object to Inf files # -# Transfer all contents of a standard Module Object to an Inf file -# @param ModuleObject: A Module Object +# Transfer all contents of a standard Module Object to an Inf file +# @param ModuleObject: A Module Object # def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None): if not GlobalData.gWSPKG_LIST: @@ -59,9 +59,9 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None): Content = '' # - # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing, - # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements - # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea, + # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing, + # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements + # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea, # use the abstract, description, copyright or license from the DistributionPackage.Header elements. # ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract()) @@ -107,15 +107,15 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None): # # Generate header comment section of INF file - # + # Content += GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense).replace('\r\n', '\n') # - # Generate Binary Header - # + # Generate Binary Header + # for UserExtension in ModuleObject.GetUserExtensionList(): if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \ and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER: @@ -152,10 +152,10 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None): else: GlobalData.gIS_BINARY_INF = False # - # for each section, maintain a dict, sorted arch will be its key, + # for each section, maintain a dict, sorted arch will be its key, # statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], - # 'Arch1' : [statement1, statement3] + # 'Arch1' : [statement1, statement3] # } # # Gen section contents @@ -197,7 +197,7 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD BinaryAbstract = [] BinaryDescription = [] # - # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE, + # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE, # then the MODULE_UNI_FILE must be created. # for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription(): @@ -255,7 +255,7 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD File = codecs.open(ContainerFile, 'wb', Encoding) File.write(u'\uFEFF' + Content) File.stream.close() - Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read()) + Md5Sigature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if (ContainerFile, Md5Sum) not in ModuleObject.FileList: ModuleObject.FileList.append((ContainerFile, Md5Sum)) @@ -300,11 +300,11 @@ def GenDefines(ModuleObject): BaseName = '_' + BaseName Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) + u'= %s' % BaseName SpecialStatementList.append(Statement) - + # TAB_INF_DEFINES_FILE_GUID Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) + u'= %s' % ModuleObject.GetGuid() SpecialStatementList.append(Statement) - + # TAB_INF_DEFINES_VERSION_STRING Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset) + u'= %s' % ModuleObject.GetVersion() SpecialStatementList.append(Statement) @@ -438,14 +438,14 @@ def GenLibraryClasses(ModuleObject): Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version if len(BinaryFile.SupArchList) == 0: - if LibraryClassDict.has_key('COMMON') and Statement not in LibraryClassDict['COMMON']: + if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']: LibraryClassDict['COMMON'].append(Statement) else: LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES'] LibraryClassDict['COMMON'].append(Statement) else: for Arch in BinaryFile.SupArchList: - if LibraryClassDict.has_key(Arch): + if Arch in LibraryClassDict: if Statement not in LibraryClassDict[Arch]: LibraryClassDict[Arch].append(Statement) else: @@ -480,7 +480,7 @@ def GenPackages(ModuleObject): Path = '' # # find package path/name - # + # for PkgInfo in GlobalData.gWSPKG_LIST: if Guid == PkgInfo[1]: if (not Version) or (Version == PkgInfo[2]): @@ -493,8 +493,7 @@ def GenPackages(ModuleObject): Statement += RelaPath.replace('\\', '/') if FFE: Statement += '|' + FFE - ArchList = PackageDependency.GetSupArchList() - ArchList.sort() + ArchList = sorted(PackageDependency.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement] @@ -513,8 +512,7 @@ def GenSources(ModuleObject): SourceFile = Source.GetSourceFile() Family = Source.GetFamily() FeatureFlag = Source.GetFeatureFlag() - SupArchList = Source.GetSupArchList() - SupArchList.sort() + SupArchList = sorted(Source.GetSupArchList()) SortedArch = ' '.join(SupArchList) Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag) if SortedArch in NewSectionDict: @@ -555,7 +553,7 @@ def GenDepex(ModuleObject): else: NewSectionDict[Key] = [Statement] Content += GenSection('Depex', NewSectionDict, False) - + return Content ## GenUserExtensions # @@ -675,7 +673,7 @@ def GenBinaryStatement(Key, Value, SubTypeGuidValue=None): Statement += '|' + Target return Statement ## GenGuidSections -# +# # @param GuidObjList: List of GuidObject # @retVal Content: The generated section contents # @@ -722,8 +720,7 @@ def GenGuidSections(GuidObjList): # # merge duplicate items # - ArchList = Guid.GetSupArchList() - ArchList.sort() + ArchList = sorted(Guid.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in GuidDict: PreviousComment = GuidDict[Statement, SortedArch] @@ -739,7 +736,7 @@ def GenGuidSections(GuidObjList): return Content ## GenProtocolPPiSections -# +# # @param ObjList: List of ProtocolObject or Ppi Object # @retVal Content: The generated section contents # @@ -782,8 +779,7 @@ def GenProtocolPPiSections(ObjList, IsProtocol): # # merge duplicate items # - ArchList = Object.GetSupArchList() - ArchList.sort() + ArchList = sorted(Object.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] @@ -808,7 +804,7 @@ def GenPcdSections(ModuleObject): Content = '' if not GlobalData.gIS_BINARY_INF: # - # for each Pcd Itemtype, maintain a dict so the same type will be grouped + # for each Pcd Itemtype, maintain a dict so the same type will be grouped # together # ItemTypeDict = {} @@ -857,8 +853,7 @@ def GenPcdSections(ModuleObject): # # Merge duplicate entries # - ArchList = Pcd.GetSupArchList() - ArchList.sort() + ArchList = sorted(Pcd.GetSupArchList()) SortedArch = ' '.join(ArchList) if (Statement, SortedArch) in Dict: PreviousComment = Dict[Statement, SortedArch] @@ -871,7 +866,7 @@ def GenPcdSections(ModuleObject): if NewSectionDict: Content += GenSection(ItemType, NewSectionDict) # - # For AsBuild INF files + # For AsBuild INF files # else: Content += GenAsBuiltPacthPcdSections(ModuleObject) @@ -910,21 +905,21 @@ def GenAsBuiltPacthPcdSections(ModuleObject): Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \ PcdOffset + DT.TAB_SPACE_SPLIT # - # Use binary file's Arch to be Pcd's Arch + # Use binary file's Arch to be Pcd's Arch # ArchList = [] FileNameObjList = BinaryFile.GetFileNameList() if FileNameObjList: ArchList = FileNameObjList[0].GetSupArchList() if len(ArchList) == 0: - if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON): + if DT.TAB_ARCH_COMMON in PatchPcdDict: if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]: PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement) else: PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement] else: for Arch in ArchList: - if PatchPcdDict.has_key(Arch): + if Arch in PatchPcdDict: if Statement not in PatchPcdDict[Arch]: PatchPcdDict[Arch].append(Statement) else: @@ -959,7 +954,7 @@ def GenAsBuiltPcdExSections(ModuleObject): Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT # - # Use binary file's Arch to be Pcd's Arch + # Use binary file's Arch to be Pcd's Arch # ArchList = [] FileNameObjList = BinaryFile.GetFileNameList() @@ -967,13 +962,13 @@ def GenAsBuiltPcdExSections(ModuleObject): ArchList = FileNameObjList[0].GetSupArchList() if len(ArchList) == 0: - if PcdExDict.has_key('COMMON'): + if 'COMMON' in PcdExDict: PcdExDict['COMMON'].append(Statement) else: PcdExDict['COMMON'] = [Statement] else: for Arch in ArchList: - if PcdExDict.has_key(Arch): + if Arch in PcdExDict: if Statement not in PcdExDict[Arch]: PcdExDict[Arch].append(Statement) else: @@ -1025,8 +1020,7 @@ def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''): if CommentStr and not CommentStr.endswith('\n#\n'): CommentStr = CommentStr + '#\n' NewStateMent = CommentStr + Statement - SupArch = Obj.GetSupArchList() - SupArch.sort() + SupArch = sorted(Obj.GetSupArchList()) SortedArch = ' '.join(SupArch) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent] @@ -1039,7 +1033,7 @@ def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''): Content = Content.lstrip() # # add a return to differentiate it between other possible sections - # + # if Content: Content += '\n' return Content @@ -1071,7 +1065,7 @@ def GenBuildOptions(ModuleObject): for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList: Statement = '#' + BuilOptionItem.AsBuiltOptionFlags if len(BinaryFile.SupArchList) == 0: - if BuildOptionDict.has_key('COMMON'): + if 'COMMON' in BuildOptionDict: if Statement not in BuildOptionDict['COMMON']: BuildOptionDict['COMMON'].append(Statement) else: @@ -1079,7 +1073,7 @@ def GenBuildOptions(ModuleObject): BuildOptionDict['COMMON'].append(Statement) else: for Arch in BinaryFile.SupArchList: - if BuildOptionDict.has_key(Arch): + if Arch in BuildOptionDict: if Statement not in BuildOptionDict[Arch]: BuildOptionDict[Arch].append(Statement) else: @@ -1104,8 +1098,7 @@ def GenBinaries(ModuleObject): FileName = ConvertPath(FileNameObj.GetFilename()) FileType = FileNameObj.GetFileType() FFE = FileNameObj.GetFeatureFlag() - ArchList = FileNameObj.GetSupArchList() - ArchList.sort() + ArchList = sorted(FileNameObj.GetSupArchList()) SortedArch = ' '.join(ArchList) Key = (FileName, FileType, FFE, SortedArch) if Key in BinariesDict: @@ -1117,7 +1110,7 @@ def GenBinaries(ModuleObject): else: NewSectionDict[SortedArch] = [Statement] # - # as we already generated statement for this DictKey here set the Valuelist to be empty + # as we already generated statement for this DictKey here set the Valuelist to be empty # to avoid generate duplicate entries as the DictKey may have multiple entries # BinariesDict[Key] = []