Hi mclow.lists, danalbert, jroelofs, ddunbar,

Change LibcxxTestFormat's execute_command method so it uses a pseudo-terminal 
when invoking the compiler commands. This means that clang will output color 
diagnostics and LIT will capture these diagnostics.

http://reviews.llvm.org/D6010

Files:
  test/lit.cfg
Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -13,6 +13,7 @@
 import sys
 import tempfile
 import time
+import pty
 
 import lit.Test
 import lit.formats
@@ -36,17 +37,44 @@
         self.ld_flags = list(ld_flags)
         self.exec_env = dict(exec_env)
 
+    @staticmethod
+    def _close_raw_fd(fd):
+        try:
+            os.close(fd)
+        except:
+            pass
+
+    @staticmethod
+    def _read_and_close_pty(p):
+        os.close(p[1])
+        with os.fdopen(p[0], 'r') as f:
+            out = ''
+            try:
+                out = f.read()
+            except IOError:
+                pass
+            return out
+
     def execute_command(self, command, in_dir=None):
-        kwargs = {
-            'stdin' :subprocess.PIPE,
-            'stdout':subprocess.PIPE,
-            'stderr':subprocess.PIPE,
-        }
-        if in_dir:
-            kwargs['cwd'] = in_dir
-        p = subprocess.Popen(command, **kwargs)
-        out,err = p.communicate()
-        exitCode = p.wait()
+        try:
+            out_pty = tuple(pty.openpty())
+            err_pty = tuple(pty.openpty())
+            kwargs = {
+                'stdin' :subprocess.PIPE,
+                'stdout':out_pty[1],
+                'stderr':err_pty[1],
+                'close_fds':True,
+            }
+            if in_dir:
+                kwargs['cwd'] = in_dir
+            p = subprocess.Popen(command, **kwargs)
+            exitCode = p.wait()
+            out = self._read_and_close_pty(out_pty)
+            err = self._read_and_close_pty(err_pty)
+        except:
+            for fd in out_pty + err_pty:
+                self._close_raw_fd(fd)
+            raise
 
         # Detect Ctrl-C in subprocess.
         if exitCode == -signal.SIGINT:
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to