]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenDepex.py
BaseTool: Fixed the incorrect cache key.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenDepex.py
index 23b289500e014a8f6f395c6bb1c28930390a8c6b..d3b1eae181c234912f641edf06979c841128bc2b 100644 (file)
@@ -17,7 +17,7 @@ import Common.LongFilePathOs as os
 import re\r
 import traceback\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
-from StringIO import StringIO\r
+from io import BytesIO\r
 from struct import pack\r
 from Common.BuildToolError import *\r
 from Common.Misc import SaveFileOnChange\r
@@ -140,7 +140,7 @@ class DependencyExpression:
     def __init__(self, Expression, ModuleType, Optimize=False):\r
         self.ModuleType = ModuleType\r
         self.Phase = gType2Phase[ModuleType]\r
-        if type(Expression) == type([]):\r
+        if isinstance(Expression, type([])):\r
             self.ExpressionString = " ".join(Expression)\r
             self.TokenList = Expression\r
         else:\r
@@ -271,10 +271,14 @@ class DependencyExpression:
 \r
     ## Simply optimize the dependency expression by removing duplicated operands\r
     def Optimize(self):\r
-        ValidOpcode = list(set(self.OpcodeList))\r
-        if len(ValidOpcode) != 1 or ValidOpcode[0] not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:\r
+        OpcodeSet = set(self.OpcodeList)\r
+        # if there are isn't one in the set, return\r
+        if len(OpcodeSet) != 1:\r
+          return\r
+        Op = OpcodeSet.pop()\r
+        #if Op isn't either OR or AND, return\r
+        if Op not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]:\r
             return\r
-        Op = ValidOpcode[0]\r
         NewOperand = []\r
         AllOperand = set()\r
         for Token in self.PostfixNotation:\r
@@ -341,7 +345,7 @@ class DependencyExpression:
     #   @retval False   If file exists and is not changed.\r
     #\r
     def Generate(self, File=None):\r
-        Buffer = StringIO()\r
+        Buffer = BytesIO()\r
         if len(self.PostfixNotation) == 0:\r
             return False\r
 \r
@@ -445,7 +449,7 @@ def Main():
                     os.utime(Option.OutputFile, None)\r
         else:\r
             Dpx.Generate()\r
-    except BaseException, X:\r
+    except BaseException as X:\r
         EdkLogger.quiet("")\r
         if Option is not None and Option.debug is not None:\r
             EdkLogger.quiet(traceback.format_exc())\r