Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable colors when compiling foreign stubs. #3263

Closed
MisterDA opened this issue Mar 14, 2020 · 5 comments
Closed

Enable colors when compiling foreign stubs. #3263

MisterDA opened this issue Mar 14, 2020 · 5 comments
Milestone

Comments

@MisterDA
Copy link
Contributor

Hi!
I’m compiling C++ foreign stubs, and there are errors in it. I noticed that the G++ output doesn’t have colors, so I added the -fdiagnostics-color=always of G++ flag in the dune configuration. However, ansi escape codes are not interpreted and are outputted raw (the output is also messed up):

required fro;01;K
error: static assertion failed: co;01;31;Kis_invocable_v<const _Compare&, const _Key&, const _Key&>

I’d suggest to find a work-around to let processes in foreign stubs output ansi escape code that are correctly interpreted by the terminal, especially when using the --verbose option of Dune.

@ghost
Copy link

ghost commented Mar 16, 2020

Dune is parsing the ansi sequences in the output of commands and re-printing them. In this case it seems that it doesn't understand the output of G++. Can you pipe the output of G++ into hexdump -C and report the result here? I'd like to see what the ansi sequences G++ produces look like.

@MisterDA
Copy link
Contributor Author

Sorry, I should have added means to reproduce the bug. In this particular case, I get a compilation error when enabling C++17. Theses are the steps I took, but one could craft a smaller example.
Using dune version 2.4.0, g++ version (Arch Linux 9.3.0-1) 9.3.0

git clone git@github.com:AltGr/ocaml-mccs.git
cd ocaml-mccs
git checkout 93cd3b25878c1a2bde5cab0a5c85a376936dc183

patch -p1 << EOF
diff --git a/src/dune b/src/dune
index dde1111..b495213 100644
--- a/src/dune
+++ b/src/dune
@@ -9,6 +9,7 @@
   :standard
   -I
   .
+  -std=c++17
   (:include cxxflags.sexp))
  (c_library_flags
   :standard
EOF
dune build	# output is correct, but uncoloured

patch -p1 << EOF
diff --git a/src/dune b/src/dune
index b495213..ff4c528 100644
--- a/src/dune
+++ b/src/dune
@@ -10,6 +10,7 @@
   -I
   .
   -std=c++17
+  -fdiagnostics-color=always
   (:include cxxflags.sexp))
  (c_library_flags
   :standard
EOF
dune build	# output is not correct, and uncoloured

dune build 2>&1 | hexdump -C

I have the feeling that the two last outputs differ, maybe it has something to do with the piping?

@ghost
Copy link

ghost commented Mar 16, 2020

Piping the output of dune won't tell us much, we need to capture the output of G++ directly if we want to see what it sends to stdout. What you can do is look in _build/log the exact g++ command emitted by dune, copy&paste this command in your terminal, add the relevant argument and pipe its output.

@MisterDA
Copy link
Contributor Author

MisterDA commented Dec 10, 2020

Ran into this issue again, and you were right, GCC emits a special ANSI code that Dune does not seem to understand. clang doesn't emit this code.

From https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-VT52-Mode:

ESC K Erase from the cursor to the end of the line.

$ echo '#warning "this is a warning"' > warning.c
$ gcc -fdiagnostics-color=always -c warning.c -o warning.o 2>&1 | hexdump -C 
00000000  1b 5b 30 31 6d 1b 5b 4b  77 61 72 6e 69 6e 67 2e  |.[01m.[Kwarning.|
00000010  63 3a 31 3a 32 3a 1b 5b  6d 1b 5b 4b 20 1b 5b 30  |c:1:2:.[m.[K .[0|
00000020  31 3b 33 35 6d 1b 5b 4b  61 74 74 65 6e 74 69 6f  |1;35m.[Kattentio|
00000030  6e 3a 20 1b 5b 6d 1b 5b  4b 23 77 61 72 6e 69 6e  |n: .[m.[K#warnin|
00000040  67 20 22 74 68 69 73 20  69 73 20 61 20 77 61 72  |g "this is a war|
00000050  6e 69 6e 67 22 20 5b 1b  5b 30 31 3b 33 35 6d 1b  |ning" [.[01;35m.|
00000060  5b 4b 2d 57 63 70 70 1b  5b 6d 1b 5b 4b 5d 0a 20  |[K-Wcpp.[m.[K]. |
00000070  20 20 20 31 20 7c 20 23  1b 5b 30 31 3b 33 35 6d  |   1 | #.[01;35m|
00000080  1b 5b 4b 77 61 72 6e 69  6e 67 1b 5b 6d 1b 5b 4b  |.[Kwarning.[m.[K|
00000090  20 22 74 68 69 73 20 69  73 20 61 20 77 61 72 6e  | "this is a warn|
000000a0  69 6e 67 22 0a 20 20 20  20 20 20 7c 20 20 1b 5b  |ing".      |  .[|
000000b0  30 31 3b 33 35 6d 1b 5b  4b 5e 7e 7e 7e 7e 7e 7e  |01;35m.[K^~~~~~~|
000000c0  1b 5b 6d 1b 5b 4b 0a                              |.[m.[K.|
000000c7

MisterDA added a commit to MisterDA/dune that referenced this issue Jan 5, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Jan 5, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Jan 6, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Jan 15, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Jan 19, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Feb 2, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue May 10, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
MisterDA added a commit to MisterDA/dune that referenced this issue Sep 2, 2021
GCC emits coloured output when it's printing to a tty, and coloured
output is disabled e.g., when the output is piped.
When GCC is called by Dune, it doesn't output ANSI sequences.

However, that behaviour can be forced with the
`-fdiagnostics-color=always` flag. GCC has the particularity that
after each color sequence, it will also emit a ESC K "erase from the
cursor the end of line".

Dune did not support this sequence, and this messes up the output. The
sequence does not seem important; clang doesn't use it, and it
clearing the line means that it would already have been written to,
which seems unlikely. So, this patch simply ignores that sequence.

Closes ocaml#3263.

Signed-off-by: Antonin Décimo <antonin@tarides.com>
@MisterDA
Copy link
Contributor Author

The issue with the K escape code was fixed in #6214 and colors support for C/C++ stubs was added in #4083.

@rgrinberg rgrinberg added this to the 3.5.0 milestone Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants