]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
BaseTools/UPT: Update the import statement to use StringUtils
[mirror_edk2.git] / BaseTools / Source / Python / UPT / GenMetaFile / GenInfFile.py
index 2a11204f7d203ac9859a6fc2265786fc473f12fd..bfd422b196ba0f6abe977be825d333e9221bdc7f 100644 (file)
@@ -2,7 +2,7 @@
 #\r
 # This file contained the logical of transfer package object to INF files.\r
 #\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\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
@@ -20,7 +20,7 @@ import stat
 import codecs\r
 import md5\r
 from Core.FileHook import __FileHookOpen__\r
-from Library.String import GetSplitValueList\r
+from Library.StringUtils import GetSplitValueList\r
 from Library.Parsing import GenSection\r
 from Library.Parsing import GetWorkspacePackage\r
 from Library.Parsing import ConvertArchForInstall\r
@@ -41,6 +41,7 @@ import Logger.Log as Logger
 from Library import DataType as DT\r
 from GenMetaFile import GenMetaFileMisc\r
 from Library.UniClassObject import FormatUniEntry\r
+from Library.StringUtils import GetUniFileName\r
 \r
 \r
 ## Transfer Module Object to Inf files\r
@@ -110,7 +111,7 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
     Content += GenHeaderCommentSection(ModuleAbstract,\r
                                        ModuleDescription,\r
                                        ModuleCopyright,\r
-                                       ModuleLicense)\r
+                                       ModuleLicense).replace('\r\n', '\n')\r
 \r
     #\r
     # Generate Binary Header \r
@@ -139,7 +140,9 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
     #\r
     FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense, False, \\r
                                          DT.TAB_COMMENT_EDK1_SPLIT)\r
-    GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
+    ModuleUniFile = GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r
+    if ModuleUniFile:\r
+        ModuleObject.SetModuleUniFile(os.path.basename(ModuleUniFile))\r
 \r
     #\r
     # Judge whether the INF file is an AsBuild INF.\r
@@ -168,15 +171,16 @@ def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
     Content += GenGuidSections(ModuleObject.GetGuidList())\r
     Content += GenBinaries(ModuleObject)\r
     Content += GenDepex(ModuleObject)\r
-    Content += GenUserExtensions(ModuleObject)\r
+    __UserExtensionsContent = GenUserExtensions(ModuleObject)\r
+    Content += __UserExtensionsContent\r
     if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or ModuleObject.GetHobList():\r
         Content += '\n'\r
     #\r
     # generate [Event], [BootMode], [Hob] section\r
     #\r
-    Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event')\r
-    Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode')\r
-    Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob')\r
+    Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event', __UserExtensionsContent)\r
+    Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode', __UserExtensionsContent)\r
+    Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob', __UserExtensionsContent)\r
     SaveFileOnChange(ContainerFile, Content, False)\r
     if DistHeader.ReadOnly:\r
         os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r
@@ -225,8 +229,8 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
         return\r
     else:\r
         ModuleObject.UNIFlag = True\r
-    ContainerFile = os.path.normpath(os.path.join(os.path.dirname(ModuleObject.GetFullPath()),\r
-                                                  (ModuleObject.GetBaseName() + '.uni')))\r
+    ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r
+\r
     if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r
         os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r
 \r
@@ -261,13 +265,18 @@ def GenDefines(ModuleObject):
     #\r
     # generate [Defines] section\r
     #\r
+    LeftOffset = 31\r
     Content = ''\r
     NewSectionDict = {}\r
+\r
     for UserExtension in ModuleObject.GetUserExtensionList():\r
         DefinesDict = UserExtension.GetDefinesDict()\r
         if not DefinesDict:\r
             continue\r
         for Statement in DefinesDict:\r
+            if 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
             if Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):\r
                 pos = Statement.find(DT.TAB_VALUE_SPLIT)\r
@@ -280,11 +289,7 @@ def GenDefines(ModuleObject):
             else:\r
                 NewSectionDict[SortedArch] = [Statement]\r
     SpecialStatementList = []\r
-    #\r
-    # Add INF_VERSION statement firstly\r
-    #\r
-    \r
-    LeftOffset = 31\r
+\r
     # TAB_INF_DEFINES_INF_VERSION\r
     Statement = (u'%s ' % DT.TAB_INF_DEFINES_INF_VERSION).ljust(LeftOffset) + u'= %s' % '0x00010017'\r
     SpecialStatementList.append(Statement)\r
@@ -307,7 +312,7 @@ def GenDefines(ModuleObject):
     # TAB_INF_DEFINES_VERSION_STRING\r
     if ModuleObject.UNIFlag:\r
         Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \\r
-                    u'= %s' % ModuleObject.GetBaseName() + '.uni'\r
+                    u'= %s' % ModuleObject.GetModuleUniFile()\r
         SpecialStatementList.append(Statement)\r
 \r
     # TAB_INF_DEFINES_MODULE_TYPE\r
@@ -565,8 +570,9 @@ def GenUserExtensions(ModuleObject):
         if UserExtension.GetIdentifier() == 'Depex':\r
             continue\r
         Statement = UserExtension.GetStatement()\r
-        if not Statement:\r
-            continue\r
+# Comment the code to support user extension without any statement just the section header in []\r
+#         if not Statement:\r
+#             continue\r
         ArchList = UserExtension.GetSupArchList()\r
         for Index in xrange(0, len(ArchList)):\r
             ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
@@ -612,11 +618,11 @@ def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,
     # format of SourceFile|Family|TagName|ToolCode|FeatureFlag\r
     #\r
     Statement += SourceFile\r
-    if TagName == None:\r
+    if TagName is None:\r
         TagName = ''\r
-    if ToolCode == None:\r
+    if ToolCode is None:\r
         ToolCode = ''\r
-    if HelpStr == None:\r
+    if HelpStr is None:\r
         HelpStr = ''\r
     if FeatureFlag:\r
         Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' + FeatureFlag\r
@@ -705,7 +711,7 @@ def GenGuidSections(GuidObjList):
             else:\r
                 Comment = ''\r
             if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r
-                Comment = '## ' + Usage + ' ## GUID ' + Comment\r
+                Comment = '## ' + Usage + Comment\r
             elif GuidType == 'Variable':\r
                 Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment\r
             else:\r
@@ -977,7 +983,7 @@ def GenAsBuiltPcdExSections(ModuleObject):
 ## GenSpecialSections\r
 #  generate special sections for Event/BootMode/Hob\r
 #\r
-def GenSpecialSections(ObjectList, SectionName):\r
+def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r
     #\r
     # generate section\r
     #\r
@@ -1000,6 +1006,11 @@ def GenSpecialSections(ObjectList, SectionName):
         else:\r
             assert(SectionName)\r
         Usage = Obj.GetUsage()\r
+\r
+        # If the content already in UserExtensionsContent then ignore\r
+        if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r
+            return ''\r
+\r
         Statement = ' ' + Type + ' ## ' + Usage\r
         if CommentStr in ['#\n', '#\n#\n']:\r
             CommentStr = '#\n#\n#\n'\r
@@ -1027,10 +1038,10 @@ def GenSpecialSections(ObjectList, SectionName):
         Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n'))\r
         Content = Content.lstrip()\r
     #\r
-    # add two empty line after the generated section content to differentiate it between other possible sections\r
+    # add a return to differentiate it between other possible sections\r
     # \r
     if Content:\r
-        Content += '\n#\n#\n'\r
+        Content += '\n'\r
     return Content\r
 ## GenBuildOptions\r
 #\r