]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / GenMetaFile / GenInfFile.py
index b97b319e0956e7209484af0d77ca07805168e0be..dd6184e0471e5de11a26791d57f18e8178d977f4 100644 (file)
@@ -4,13 +4,7 @@
 #\r
 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
-# This program and the accompanying materials are licensed and made available \r
-# under the terms and conditions of the BSD License which accompanies this \r
-# distribution. The full text of the license may be found at \r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 '''\r
 GenInf\r
@@ -18,7 +12,7 @@ GenInf
 import os\r
 import stat\r
 import codecs\r
-import md5\r
+from hashlib import md5\r
 from Core.FileHook import __FileHookOpen__\r
 from Library.StringUtils import GetSplitValueList\r
 from Library.Parsing import GenSection\r
@@ -46,8 +40,8 @@ from Library.StringUtils import GetUniFileName
 \r
 ## Transfer Module Object to Inf files\r
 #\r
-# Transfer all contents of a standard Module Object to an Inf file \r
-# @param ModuleObject: A Module Object  \r
+# Transfer all contents of a standard Module Object to an Inf file\r
+# @param ModuleObject: A Module Object\r
 #\r
 def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):\r
     if not GlobalData.gWSPKG_LIST:\r
@@ -59,9 +53,9 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
 \r
     Content = ''\r
     #\r
-    # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing, \r
-    # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements \r
-    # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea, \r
+    # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing,\r
+    # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements\r
+    # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea,\r
     # use the abstract, description, copyright or license from the DistributionPackage.Header elements.\r
     #\r
     ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract())\r
@@ -107,15 +101,15 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
 \r
     #\r
     # Generate header comment section of INF file\r
-    #        \r
+    #\r
     Content += GenHeaderCommentSection(ModuleAbstract,\r
                                        ModuleDescription,\r
                                        ModuleCopyright,\r
                                        ModuleLicense).replace('\r\n', '\n')\r
 \r
     #\r
-    # Generate Binary Header \r
-    # \r
+    # Generate Binary Header\r
+    #\r
     for UserExtension in ModuleObject.GetUserExtensionList():\r
         if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r
         and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r
@@ -152,10 +146,10 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
     else:\r
         GlobalData.gIS_BINARY_INF = False\r
     #\r
-    # for each section, maintain a dict, sorted arch will be its key, \r
+    # for each section, maintain a dict, sorted arch will be its key,\r
     # statement list will be its data\r
     # { 'Arch1 Arch2 Arch3': [statement1, statement2],\r
-    #   'Arch1' : [statement1, statement3] \r
+    #   'Arch1' : [statement1, statement3]\r
     #  }\r
     #\r
     # Gen section contents\r
@@ -197,7 +191,7 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
     BinaryAbstract = []\r
     BinaryDescription = []\r
     #\r
-    # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE, \r
+    # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,\r
     # then the MODULE_UNI_FILE must be created.\r
     #\r
     for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription():\r
@@ -255,8 +249,8 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
         File = codecs.open(ContainerFile, 'wb', Encoding)\r
         File.write(u'\uFEFF' + Content)\r
         File.stream.close()\r
-    Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())\r
-    Md5Sum = Md5Sigature.hexdigest()\r
+    Md5Signature = md5(__FileHookOpen__(str(ContainerFile), 'rb').read())\r
+    Md5Sum = Md5Signature.hexdigest()\r
     if (ContainerFile, Md5Sum) not in ModuleObject.FileList:\r
         ModuleObject.FileList.append((ContainerFile, Md5Sum))\r
 \r
@@ -274,7 +268,7 @@ def GenDefines(ModuleObject):
         if not DefinesDict:\r
             continue\r
         for Statement in DefinesDict:\r
-            if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:\r
+            if len(Statement.split(DT.TAB_EQUAL_SPLIT)) > 1:\r
                 Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \\r
                              + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()\r
             SortedArch = DT.TAB_ARCH_COMMON\r
@@ -300,11 +294,11 @@ def GenDefines(ModuleObject):
         BaseName = '_' + BaseName\r
     Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) + u'= %s' % BaseName\r
     SpecialStatementList.append(Statement)\r
-    \r
+\r
     # TAB_INF_DEFINES_FILE_GUID\r
     Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) + u'= %s' % ModuleObject.GetGuid()\r
     SpecialStatementList.append(Statement)\r
-    \r
+\r
     # TAB_INF_DEFINES_VERSION_STRING\r
     Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset) + u'= %s' % ModuleObject.GetVersion()\r
     SpecialStatementList.append(Statement)\r
@@ -409,7 +403,7 @@ def GenLibraryClasses(ModuleObject):
                 Statement += '|' + FFE\r
             ModuleList = LibraryClass.GetSupModuleList()\r
             ArchList = LibraryClass.GetSupArchList()\r
-            for Index in xrange(0, len(ArchList)):\r
+            for Index in range(0, len(ArchList)):\r
                 ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
             ArchList.sort()\r
             SortedArch = ' '.join(ArchList)\r
@@ -480,7 +474,7 @@ def GenPackages(ModuleObject):
         Path = ''\r
         #\r
         # find package path/name\r
-        # \r
+        #\r
         for PkgInfo in GlobalData.gWSPKG_LIST:\r
             if Guid == PkgInfo[1]:\r
                 if (not Version) or (Version == PkgInfo[2]):\r
@@ -493,8 +487,7 @@ def GenPackages(ModuleObject):
         Statement += RelaPath.replace('\\', '/')\r
         if FFE:\r
             Statement += '|' + FFE\r
-        ArchList = PackageDependency.GetSupArchList()\r
-        ArchList.sort()\r
+        ArchList = sorted(PackageDependency.GetSupArchList())\r
         SortedArch = ' '.join(ArchList)\r
         if SortedArch in NewSectionDict:\r
             NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r
@@ -513,8 +506,7 @@ def GenSources(ModuleObject):
         SourceFile = Source.GetSourceFile()\r
         Family = Source.GetFamily()\r
         FeatureFlag = Source.GetFeatureFlag()\r
-        SupArchList = Source.GetSupArchList()\r
-        SupArchList.sort()\r
+        SupArchList = sorted(Source.GetSupArchList())\r
         SortedArch = ' '.join(SupArchList)\r
         Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag)\r
         if SortedArch in NewSectionDict:\r
@@ -555,7 +547,7 @@ def GenDepex(ModuleObject):
             else:\r
                 NewSectionDict[Key] = [Statement]\r
     Content += GenSection('Depex', NewSectionDict, False)\r
-    \r
+\r
     return Content\r
 ## GenUserExtensions\r
 #\r
@@ -574,7 +566,7 @@ def GenUserExtensions(ModuleObject):
 #         if not Statement:\r
 #             continue\r
         ArchList = UserExtension.GetSupArchList()\r
-        for Index in xrange(0, len(ArchList)):\r
+        for Index in range(0, len(ArchList)):\r
             ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
         ArchList.sort()\r
         KeyList = []\r
@@ -675,7 +667,7 @@ def GenBinaryStatement(Key, Value, SubTypeGuidValue=None):
             Statement += '|' + Target\r
     return Statement\r
 ## GenGuidSections\r
-# \r
+#\r
 #  @param GuidObjList: List of GuidObject\r
 #  @retVal Content: The generated section contents\r
 #\r
@@ -722,8 +714,7 @@ def GenGuidSections(GuidObjList):
         #\r
         # merge duplicate items\r
         #\r
-        ArchList = Guid.GetSupArchList()\r
-        ArchList.sort()\r
+        ArchList = sorted(Guid.GetSupArchList())\r
         SortedArch = ' '.join(ArchList)\r
         if (Statement, SortedArch) in GuidDict:\r
             PreviousComment = GuidDict[Statement, SortedArch]\r
@@ -739,7 +730,7 @@ def GenGuidSections(GuidObjList):
     return Content\r
 \r
 ## GenProtocolPPiSections\r
-# \r
+#\r
 #  @param ObjList: List of ProtocolObject or Ppi Object\r
 #  @retVal Content: The generated section contents\r
 #\r
@@ -782,8 +773,7 @@ def GenProtocolPPiSections(ObjList, IsProtocol):
         #\r
         # merge duplicate items\r
         #\r
-        ArchList = Object.GetSupArchList()\r
-        ArchList.sort()\r
+        ArchList = sorted(Object.GetSupArchList())\r
         SortedArch = ' '.join(ArchList)\r
         if (Statement, SortedArch) in Dict:\r
             PreviousComment = Dict[Statement, SortedArch]\r
@@ -808,7 +798,7 @@ def GenPcdSections(ModuleObject):
     Content = ''\r
     if not GlobalData.gIS_BINARY_INF:\r
         #\r
-        # for each Pcd Itemtype, maintain a dict so the same type will be grouped \r
+        # for each Pcd Itemtype, maintain a dict so the same type will be grouped\r
         # together\r
         #\r
         ItemTypeDict = {}\r
@@ -857,8 +847,7 @@ def GenPcdSections(ModuleObject):
             #\r
             # Merge duplicate entries\r
             #\r
-            ArchList = Pcd.GetSupArchList()\r
-            ArchList.sort()\r
+            ArchList = sorted(Pcd.GetSupArchList())\r
             SortedArch = ' '.join(ArchList)\r
             if (Statement, SortedArch) in Dict:\r
                 PreviousComment = Dict[Statement, SortedArch]\r
@@ -871,7 +860,7 @@ def GenPcdSections(ModuleObject):
             if NewSectionDict:\r
                 Content += GenSection(ItemType, NewSectionDict)\r
     #\r
-    # For AsBuild INF files   \r
+    # For AsBuild INF files\r
     #\r
     else:\r
         Content += GenAsBuiltPacthPcdSections(ModuleObject)\r
@@ -910,7 +899,7 @@ def GenAsBuiltPacthPcdSections(ModuleObject):
             Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \\r
                          PcdOffset + DT.TAB_SPACE_SPLIT\r
             #\r
-            # Use binary file's Arch to be Pcd's Arch \r
+            # Use binary file's Arch to be Pcd's Arch\r
             #\r
             ArchList = []\r
             FileNameObjList = BinaryFile.GetFileNameList()\r
@@ -959,7 +948,7 @@ def GenAsBuiltPcdExSections(ModuleObject):
             Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT\r
 \r
             #\r
-            # Use binary file's Arch to be Pcd's Arch \r
+            # Use binary file's Arch to be Pcd's Arch\r
             #\r
             ArchList = []\r
             FileNameObjList = BinaryFile.GetFileNameList()\r
@@ -1025,8 +1014,7 @@ def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):
         if CommentStr and not CommentStr.endswith('\n#\n'):\r
             CommentStr = CommentStr + '#\n'\r
         NewStateMent = CommentStr + Statement\r
-        SupArch = Obj.GetSupArchList()\r
-        SupArch.sort()\r
+        SupArch = sorted(Obj.GetSupArchList())\r
         SortedArch = ' '.join(SupArch)\r
         if SortedArch in NewSectionDict:\r
             NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r
@@ -1039,7 +1027,7 @@ def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):
         Content = Content.lstrip()\r
     #\r
     # add a return to differentiate it between other possible sections\r
-    # \r
+    #\r
     if Content:\r
         Content += '\n'\r
     return Content\r
@@ -1104,8 +1092,7 @@ def GenBinaries(ModuleObject):
             FileName = ConvertPath(FileNameObj.GetFilename())\r
             FileType = FileNameObj.GetFileType()\r
             FFE = FileNameObj.GetFeatureFlag()\r
-            ArchList = FileNameObj.GetSupArchList()\r
-            ArchList.sort()\r
+            ArchList = sorted(FileNameObj.GetSupArchList())\r
             SortedArch = ' '.join(ArchList)\r
             Key = (FileName, FileType, FFE, SortedArch)\r
             if Key in BinariesDict:\r
@@ -1117,7 +1104,7 @@ def GenBinaries(ModuleObject):
                     else:\r
                         NewSectionDict[SortedArch] = [Statement]\r
                 #\r
-                # as we already generated statement for this DictKey here set the Valuelist to be empty \r
+                # as we already generated statement for this DictKey here set the Valuelist to be empty\r
                 # to avoid generate duplicate entries as the DictKey may have multiple entries\r
                 #\r
                 BinariesDict[Key] = []\r