Fix the issue that makefile could be created success in VS2008 environment. The root...
authorklu2 <klu2@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 14 Jan 2010 17:43:41 +0000 (17:43 +0000)
committerklu2 <klu2@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 14 Jan 2010 17:43:41 +0000 (17:43 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1807 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/build/build.py

index 539fd77..699be50 100644 (file)
@@ -22,6 +22,9 @@ import glob
 import time\r
 import platform\r
 import traceback\r
+import types\r
+if sys.platform == "win32":\r
+    from _subprocess import CreateProcess\r
 \r
 from threading import *\r
 from optparse import OptionParser\r
@@ -213,6 +216,43 @@ def ReadMessage(From, To, ExitFlag):
         if ExitFlag.isSet():\r
             break\r
 \r
+class WinPopen(Popen):\r
+    def _execute_child(self, args, executable, preexec_fn, close_fds,\r
+                       cwd, env, universal_newlines,\r
+                       startupinfo, creationflags, shell,\r
+                       p2cread, p2cwrite,\r
+                       c2pread, c2pwrite,\r
+                       errread, errwrite):\r
+            """Execute program (MS Windows version)"""\r
+\r
+        if not isinstance(args, types.StringTypes):\r
+            args = list2cmdline(args)\r
+\r
+            # Start the process\r
+            try:\r
+                hp, ht, pid, tid = CreateProcess(executable, args,\r
+                                         None, None,\r
+                                         0,\r
+                                         creationflags,\r
+                                         env,\r
+                                         cwd,\r
+                                         None)\r
+            except IOError, e:\r
+                raise WindowsError(*e.args)\r
+\r
+            # Retain the process handle, but close the thread handle\r
+            self._child_created = True\r
+            self._handle = hp\r
+            self.pid = pid\r
+            ht.Close()\r
+\r
+            if p2cread is not None:\r
+                p2cread.Close()\r
+            if c2pwrite is not None:\r
+                c2pwrite.Close()\r
+            if errwrite is not None:\r
+                errwrite.Close()\r
+\r
 ## Launch an external program\r
 #\r
 # This method will call subprocess.Popen to execute an external program with\r
@@ -232,7 +272,10 @@ def LaunchCommand(Command, WorkingDir):
     EndOfProcedure = None\r
     try:\r
         # launch the command\r
-        Proc = Popen(Command, stdout=PIPE, stderr=PIPE, env=os.environ, cwd=WorkingDir, bufsize=-1)\r
+        if sys.platform == "win32":\r
+          Proc = WinPopen(Command, stdout=PIPE, stderr=PIPE, env=os.environ, cwd=WorkingDir, bufsize=-1)\r
+        else:\r
+          Proc = Popen(Command, stdout=PIPE, stderr=PIPE, env=os.environ, cwd=WorkingDir, bufsize=-1)\r
 \r
         # launch two threads to read the STDOUT and STDERR\r
         EndOfProcedure = Event()\r