]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
BaseTools: Replace StringIO.StringIO with io.BytesIO
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 416aa73549d115b1acfe877c45aa836f73e7200f..08e81016de8b363fcddb67db8f011ce43a5e11de 100644 (file)
@@ -19,7 +19,7 @@
 from __future__ import print_function\r
 import Common.LongFilePathOs as os\r
 import re\r
-import StringIO\r
+from io import BytesIO\r
 import sys\r
 import glob\r
 import time\r
@@ -54,7 +54,7 @@ import Common.EdkLogger
 import Common.GlobalData as GlobalData\r
 from GenFds.GenFds import GenFds\r
 \r
-from collections import OrderedDict,defaultdict\r
+from collections import OrderedDict, defaultdict\r
 \r
 # Version and Copyright\r
 VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
@@ -77,7 +77,7 @@ TmpTableDict = {}
 #   Otherwise, False is returned\r
 #\r
 def IsToolInPath(tool):\r
-    if os.environ.has_key('PATHEXT'):\r
+    if 'PATHEXT' in os.environ:\r
         extns = os.environ['PATHEXT'].split(os.path.pathsep)\r
     else:\r
         extns = ('',)\r
@@ -305,7 +305,7 @@ def LaunchCommand(Command, WorkingDir):
         if EndOfProcedure is not None:\r
             EndOfProcedure.set()\r
         if Proc is None:\r
-            if type(Command) != type(""):\r
+            if not isinstance(Command, type("")):\r
                 Command = " ".join(Command)\r
             EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir))\r
 \r
@@ -316,7 +316,7 @@ def LaunchCommand(Command, WorkingDir):
 \r
     # check the return code of the program\r
     if Proc.returncode != 0:\r
-        if type(Command) != type(""):\r
+        if not isinstance(Command, type("")):\r
             Command = " ".join(Command)\r
         # print out the Response file and its content when make failure\r
         RespFile = os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt')\r
@@ -526,7 +526,7 @@ class BuildTask:
                     BuildTask._Thread.acquire(True)\r
 \r
                     # start a new build thread\r
-                    Bo,Bt = BuildTask._ReadyQueue.popitem()\r
+                    Bo, Bt = BuildTask._ReadyQueue.popitem()\r
 \r
                     # move into running queue\r
                     BuildTask._RunningQueueLock.acquire()\r
@@ -840,7 +840,7 @@ class Build():
         self.HashSkipModules = []\r
         self.Db_Flag = False\r
         self.LaunchPrebuildFlag = False\r
-        self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory,'.cache', '.PlatformBuild')\r
+        self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory, '.cache', '.PlatformBuild')\r
         if BuildOptions.CommandLength:\r
             GlobalData.gCommandMaxLength = BuildOptions.CommandLength\r
 \r
@@ -1133,7 +1133,7 @@ class Build():
             # and preserve them for the rest of the main build step, because the child process environment will\r
             # evaporate as soon as it exits, we cannot get it in build step.\r
             #\r
-            PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory,'.cache','.PrebuildEnv')\r
+            PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory, '.cache', '.PrebuildEnv')\r
             if os.path.isfile(PrebuildEnvFile):\r
                 os.remove(PrebuildEnvFile)\r
             if os.path.isfile(self.PlatformBuildPath):\r
@@ -1173,7 +1173,7 @@ class Build():
                 f = open(PrebuildEnvFile)\r
                 envs = f.readlines()\r
                 f.close()\r
-                envs = itertools.imap(lambda l: l.split('=',1), envs)\r
+                envs = itertools.imap(lambda l: l.split('=', 1), envs)\r
                 envs = itertools.ifilter(lambda l: len(l) == 2, envs)\r
                 envs = itertools.imap(lambda l: [i.strip() for i in l], envs)\r
                 os.environ.update(dict(envs))\r
@@ -1782,7 +1782,7 @@ class Build():
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
@@ -1940,7 +1940,7 @@ class Build():
                             if not Ma.IsLibrary:\r
                                 ModuleList[Ma.Guid.upper()] = Ma\r
 \r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         #\r
                         # Rebase module to the preferred memory address before GenFds\r
@@ -2127,7 +2127,7 @@ class Build():
                     #\r
                     # Rebase module to the preferred memory address before GenFds\r
                     #\r
-                    MapBuffer = StringIO('')\r
+                    MapBuffer = BytesIO('')\r
                     if self.LoadFixAddress != 0:\r
                         self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
 \r
@@ -2358,7 +2358,7 @@ def MyOptionParser():
     Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
 \r
     Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")\r
-    Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD','LIBRARY','FLASH','DEPEX','BUILD_FLAGS','FIXED_ADDRESS','HASH','EXECUTION_ORDER'], dest="ReportType", default=[],\r
+    Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED_ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
         help="Flags that control the type of build report to generate.  Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, HASH, EXECUTION_ORDER].  "\\r
              "To specify more than one flag, repeat this option on the command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, HASH, BUILD_FLAGS, FIXED_ADDRESS]")\r
     Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r