]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/AutoGen: move functions
authorCarsey, Jaben <jaben.carsey@intel.com>
Thu, 10 Jan 2019 18:39:48 +0000 (02:39 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Mon, 21 Jan 2019 10:03:33 +0000 (18:03 +0800)
Move SplitOption and ConvertStringToByteArray from
Common.Misc to this file.
There were no other consumers of the functions.

Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/Common/Misc.py

index 13d49bd3fbc8de6332f2e6da1ca14898ec64612d..f4cfb0830d4627ef7068683046c7e4be1740497c 100644 (file)
@@ -31,7 +31,7 @@ from io import BytesIO
 \r
 from .StrGather import *\r
 from .BuildEngine import BuildRule\r
-\r
+import shutil\r
 from Common.LongFilePathSupport import CopyLongFilePath\r
 from Common.BuildToolError import *\r
 from Common.DataType import *\r
@@ -171,6 +171,73 @@ ${tail_comments}
 ## @AsBuilt${BEGIN}\r
 ##   ${flags_item}${END}\r
 """)\r
+## Split command line option string to list\r
+#\r
+# subprocess.Popen needs the args to be a sequence. Otherwise there's problem\r
+# in non-windows platform to launch command\r
+#\r
+def _SplitOption(OptionString):\r
+    OptionList = []\r
+    LastChar = " "\r
+    OptionStart = 0\r
+    QuotationMark = ""\r
+    for Index in range(0, len(OptionString)):\r
+        CurrentChar = OptionString[Index]\r
+        if CurrentChar in ['"', "'"]:\r
+            if QuotationMark == CurrentChar:\r
+                QuotationMark = ""\r
+            elif QuotationMark == "":\r
+                QuotationMark = CurrentChar\r
+            continue\r
+        elif QuotationMark:\r
+            continue\r
+\r
+        if CurrentChar in ["/", "-"] and LastChar in [" ", "\t", "\r", "\n"]:\r
+            if Index > OptionStart:\r
+                OptionList.append(OptionString[OptionStart:Index - 1])\r
+            OptionStart = Index\r
+        LastChar = CurrentChar\r
+    OptionList.append(OptionString[OptionStart:])\r
+    return OptionList\r
+\r
+#\r
+# Convert string to C format array\r
+#\r
+def _ConvertStringToByteArray(Value):\r
+    Value = Value.strip()\r
+    if not Value:\r
+        return None\r
+    if Value[0] == '{':\r
+        if not Value.endswith('}'):\r
+            return None\r
+        Value = Value.replace(' ', '').replace('{', '').replace('}', '')\r
+        ValFields = Value.split(',')\r
+        try:\r
+            for Index in range(len(ValFields)):\r
+                ValFields[Index] = str(int(ValFields[Index], 0))\r
+        except ValueError:\r
+            return None\r
+        Value = '{' + ','.join(ValFields) + '}'\r
+        return Value\r
+\r
+    Unicode = False\r
+    if Value.startswith('L"'):\r
+        if not Value.endswith('"'):\r
+            return None\r
+        Value = Value[1:]\r
+        Unicode = True\r
+    elif not Value.startswith('"') or not Value.endswith('"'):\r
+        return None\r
+\r
+    Value = eval(Value)         # translate escape character\r
+    NewValue = '{'\r
+    for Index in range(0, len(Value)):\r
+        if Unicode:\r
+            NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ','\r
+        else:\r
+            NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ','\r
+    Value = NewValue + '0}'\r
+    return Value\r
 \r
 ## Base class for AutoGen\r
 #\r
@@ -1769,11 +1836,11 @@ class PlatformAutoGen(AutoGen):
     def BuildCommand(self):\r
         RetVal = []\r
         if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
-            RetVal += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
+            RetVal += _SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
             if "FLAGS" in self.ToolDefinition["MAKE"]:\r
                 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
                 if NewOption != '':\r
-                    RetVal += SplitOption(NewOption)\r
+                    RetVal += _SplitOption(NewOption)\r
             if "MAKE" in self.EdkIIBuildOption:\r
                 if "FLAGS" in self.EdkIIBuildOption["MAKE"]:\r
                     Flags = self.EdkIIBuildOption["MAKE"]["FLAGS"]\r
@@ -3417,7 +3484,7 @@ class ModuleAutoGen(AutoGen):
                 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r
                 if not Guid:\r
                     break\r
-                NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
+                NameArray = _ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
                 NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
                 Pos = Content.find('efivarstore', Name.end())\r
         if not NameGuids:\r
@@ -3430,7 +3497,7 @@ class ModuleAutoGen(AutoGen):
                 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r
                 if not Value:\r
                     continue\r
-                Name = ConvertStringToByteArray(SkuInfo.VariableName)\r
+                Name = _ConvertStringToByteArray(SkuInfo.VariableName)\r
                 Guid = GuidStructureStringToGuidString(Value)\r
                 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r
                     HiiExPcds.append(Pcd)\r
index 4c6660b844d6b79c51768aa4272676b9a32dfdc9..d2cbece894a3092710cf916241dcfcbba7d792c0 100644 (file)
@@ -1512,35 +1512,6 @@ def CheckPcdDatum(Type, Value):
 \r
     return True, ""\r
 \r
-## Split command line option string to list\r
-#\r
-# subprocess.Popen needs the args to be a sequence. Otherwise there's problem\r
-# in non-windows platform to launch command\r
-#\r
-def SplitOption(OptionString):\r
-    OptionList = []\r
-    LastChar = " "\r
-    OptionStart = 0\r
-    QuotationMark = ""\r
-    for Index in range(0, len(OptionString)):\r
-        CurrentChar = OptionString[Index]\r
-        if CurrentChar in ['"', "'"]:\r
-            if QuotationMark == CurrentChar:\r
-                QuotationMark = ""\r
-            elif QuotationMark == "":\r
-                QuotationMark = CurrentChar\r
-            continue\r
-        elif QuotationMark:\r
-            continue\r
-\r
-        if CurrentChar in ["/", "-"] and LastChar in [" ", "\t", "\r", "\n"]:\r
-            if Index > OptionStart:\r
-                OptionList.append(OptionString[OptionStart:Index - 1])\r
-            OptionStart = Index\r
-        LastChar = CurrentChar\r
-    OptionList.append(OptionString[OptionStart:])\r
-    return OptionList\r
-\r
 def CommonPath(PathList):\r
     P1 = min(PathList).split(os.path.sep)\r
     P2 = max(PathList).split(os.path.sep)\r
@@ -1549,45 +1520,6 @@ def CommonPath(PathList):
             return os.path.sep.join(P1[:Index])\r
     return os.path.sep.join(P1)\r
 \r
-#\r
-# Convert string to C format array\r
-#\r
-def ConvertStringToByteArray(Value):\r
-    Value = Value.strip()\r
-    if not Value:\r
-        return None\r
-    if Value[0] == '{':\r
-        if not Value.endswith('}'):\r
-            return None\r
-        Value = Value.replace(' ', '').replace('{', '').replace('}', '')\r
-        ValFields = Value.split(',')\r
-        try:\r
-            for Index in range(len(ValFields)):\r
-                ValFields[Index] = str(int(ValFields[Index], 0))\r
-        except ValueError:\r
-            return None\r
-        Value = '{' + ','.join(ValFields) + '}'\r
-        return Value\r
-\r
-    Unicode = False\r
-    if Value.startswith('L"'):\r
-        if not Value.endswith('"'):\r
-            return None\r
-        Value = Value[1:]\r
-        Unicode = True\r
-    elif not Value.startswith('"') or not Value.endswith('"'):\r
-        return None\r
-\r
-    Value = eval(Value)         # translate escape character\r
-    NewValue = '{'\r
-    for Index in range(0, len(Value)):\r
-        if Unicode:\r
-            NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ','\r
-        else:\r
-            NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ','\r
-    Value = NewValue + '0}'\r
-    return Value\r
-\r
 class PathClass(object):\r
     def __init__(self, File='', Root='', AlterRoot='', Type='', IsBinary=False,\r
                  Arch='COMMON', ToolChainFamily='', Target='', TagName='', ToolCode=''):\r