]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/StrGather.py
BaseTools: Add a checking for Sources section in INF file
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / StrGather.py
index 73b2d0a3da14079d74b01f35570c24f048936a60..2e4671a4331d2f91f14f9b9fc20883590ac0b1a0 100644 (file)
@@ -3,17 +3,12 @@
 # file.\r
 #\r
 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this 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
 # Import Modules\r
 #\r
+from __future__ import absolute_import\r
 import re\r
 import Common.EdkLogger as EdkLogger\r
 from Common.BuildToolError import *\r
@@ -122,9 +117,10 @@ def DecToHexList(Dec, Digit = 8):
 # @retval:       A list for formatted hex string\r
 #\r
 def AscToHexList(Ascii):\r
-    if isinstance(Ascii, bytes):\r
+    try:\r
         return ['0x{0:02X}'.format(Item) for Item in Ascii]\r
-    return ['0x{0:02X}'.format(ord(Item)) for Item in Ascii]\r
+    except:\r
+        return ['0x{0:02X}'.format(ord(Item)) for Item in Ascii]\r
 \r
 ## Create content of .h file\r
 #\r
@@ -138,7 +134,7 @@ def AscToHexList(Ascii):
 # @retval Str:           A string of .h file content\r
 #\r
 def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):\r
-    Str = ''\r
+    Str = []\r
     ValueStartPtr = 60\r
     Line = COMMENT_DEFINE_STR + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(0, 4) + COMMENT_NOT_REFERENCED\r
     Str = WriteLine(Str, Line)\r
@@ -167,12 +163,12 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):
                     Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED\r
                 UnusedStr = WriteLine(UnusedStr, Line)\r
 \r
-    Str = ''.join([Str, UnusedStr])\r
+    Str.extend( UnusedStr)\r
 \r
     Str = WriteLine(Str, '')\r
     if IsCompatibleMode or UniGenCFlag:\r
         Str = WriteLine(Str, 'extern unsigned char ' + BaseName + 'Strings[];')\r
-    return Str\r
+    return "".join(Str)\r
 \r
 ## Create a complete .h file\r
 #\r
@@ -188,7 +184,7 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):
 def CreateHFile(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):\r
     HFile = WriteLine('', CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag))\r
 \r
-    return HFile\r
+    return "".join(HFile)\r
 \r
 ## Create a buffer to store all items in an array\r
 #\r
@@ -212,7 +208,7 @@ def CreateArrayItem(Array, Width = 16):
     MaxLength = Width\r
     Index = 0\r
     Line = '  '\r
-    ArrayItem = ''\r
+    ArrayItem = []\r
 \r
     for Item in Array:\r
         if Index < MaxLength:\r
@@ -224,7 +220,7 @@ def CreateArrayItem(Array, Width = 16):
             Index = 1\r
     ArrayItem = Write(ArrayItem, Line.rstrip())\r
 \r
-    return ArrayItem\r
+    return "".join(ArrayItem)\r
 \r
 ## CreateCFileStringValue\r
 #\r
@@ -239,7 +235,7 @@ def CreateCFileStringValue(Value):
     Value = [StringBlockType] + Value\r
     Str = WriteLine('', CreateArrayItem(Value))\r
 \r
-    return Str\r
+    return "".join(Str)\r
 \r
 ## GetFilteredLanguage\r
 #\r
@@ -441,7 +437,7 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer,
     #\r
     AllStr = Write(AllStr, Str)\r
 \r
-    return AllStr\r
+    return "".join(AllStr)\r
 \r
 ## Create end of .c file\r
 #\r
@@ -468,7 +464,7 @@ def CreateCFile(BaseName, UniObjectClass, IsCompatibleMode, FilterInfo):
     CFile = ''\r
     CFile = WriteLine(CFile, CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, None, FilterInfo))\r
     CFile = WriteLine(CFile, CreateCFileEnd())\r
-    return CFile\r
+    return "".join(CFile)\r
 \r
 ## GetFileList\r
 #\r
@@ -552,9 +548,9 @@ def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, Ski
             #\r
             # support ISO 639-2 codes in .UNI files of EDK Shell\r
             #\r
-            Uni = UniFileClassObject(sorted (UniFilList, key=lambda x: x.File), True, IncludePathList)\r
+            Uni = UniFileClassObject(sorted(UniFilList, key=lambda x: x.File), True, IncludePathList)\r
         else:\r
-            Uni = UniFileClassObject(sorted (UniFilList, key=lambda x: x.File), IsCompatibleMode, IncludePathList)\r
+            Uni = UniFileClassObject(sorted(UniFilList, key=lambda x: x.File), IsCompatibleMode, IncludePathList)\r
     else:\r
         EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, 'No unicode files given')\r
 \r
@@ -575,13 +571,30 @@ def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, Ski
 # Write an item\r
 #\r
 def Write(Target, Item):\r
-    return ''.join([Target, Item])\r
+    if isinstance(Target,str):\r
+        Target = [Target]\r
+    if not Target:\r
+        Target = []\r
+    if isinstance(Item,list):\r
+        Target.extend(Item)\r
+    else:\r
+        Target.append(Item)\r
+    return Target\r
 \r
 #\r
 # Write an item with a break line\r
 #\r
 def WriteLine(Target, Item):\r
-    return ''.join([Target, Item, '\n'])\r
+    if isinstance(Target,str):\r
+        Target = [Target]\r
+    if not Target:\r
+        Target = []\r
+    if isinstance(Item, list):\r
+        Target.extend(Item)\r
+    else:\r
+        Target.append(Item)\r
+    Target.append('\n')\r
+    return Target\r
 \r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r