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.
Details
Diff Detail
Event Timeline
But what if Lit isn't running in a device capable of color output? Won't
this add a bunch of ugly ASCII codes?
I think what tools like Ninja do is to also optionally strip the color
codes in that case (
https://github.com/martine/ninja/blob/master/src/util.cc#L384).
- Daniel
But what if Lit isn't running in a device capable of color output? Won't
this add a bunch of ugly ASCII codes?
Wouldn't clang refrain from outputting color codes to begin with?
Do you know of any way to detect this?
I think what tools like Ninja do is to also optionally strip the color
codes in that case (
https://github.com/martine/ninja/blob/master/src/util.cc#L384).
Not much you can do about that. At least the colored output makes it one step further.
Thanks for the input.
Only use pseudo-terminal if sys.stdout.isatty() is true. Otherwise fall back to the old method.
FWIW, Ninja found that it wasn't tenable to use this approach. Some discussion here: https://github.com/martine/ninja/issues/174
Not sure if any of the concerns apply to lit.
Their main concern was that providing a pseudo-terminal might confuse some commands like SVN it if tries to spin up an editor.
Since we know exactly what types of command will be run this isn't a concern.
Thanks for the input.
Ok, so on the structure of the patch:
- It would be nice if this functionality wasn't in the Libcxx test format,
but a utility that was part of lit proper.
- This: --
+ out = LibcxxTestFormat._read_and_close_pty(out_pty)
+ err = LibcxxTestFormat._read_and_close_pty(err_pty)
is not safe, if a command writes enough output to stderr that the pipe is
full it will block, and then the system will be deadlocked since it will
never finish writing to stdout. Also, you probably shouldn't assume that
all data is returned in a single .read() call (even though that is likely
true). See notes in subprocess module, e.g.,
https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate
.
- Daniel
I'm abandoning this revision because I'm going to try and put this functionality in LIT proper. I have a working implementation that addresses @ddunbar's concerns that I will submit next week.