arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

Compiler diagnostics no longer colored in `arduino-cli compile` output

Open per1234 opened this issue 2 years ago β€’ 0 comments
trafficstars

Describe the problem

It is a common practice for command line tools to selectively color output text with the goal of enhancing the readability. This is done though ANSI escape codes.

The GCC tools used to compile Arduino sketches do such coloration of the diagnostic messages printed in their output:

https://gcc.gnu.org/onlinedocs/gcc-7.4.0/gcc/Diagnostic-Message-Formatting-Options.html#index-GCC_005fCOLORS-environment-variable

πŸ› Compiler diagnostics are not colored in the arduino-cli compile output.

To reproduce

$ git checkout b3e8f8a4c2544cbda60975153773652631253738^1  # Checkout the last commit before the regression

[...]

$ task build

[...]

$ mkdir "/tmp/SketchWithDiagnostics"

$ printf '#warning foo\nvoid setup() {}\nvoid loop() {}\n' > "/tmp/SketchWithDiagnostics/SketchWithDiagnostics.ino"

$ ./arduino-cli compile --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"

πŸ™‚ The diagnostics in the compiler output are colored:

image

$ git checkout master  # Checkout the version with the regression

[...]

$ task build

[...]

$ ./arduino-cli version

arduino-cli  Version: git-snapshot Commit: 65915d8a Date: 2023-09-10T21:35:05Z

$ ./arduino-cli compile --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"

πŸ› The diagnostics in the compiler output are not colored:

image

Expected behavior

Tool output is colored in the Arduino CLI output the same as it would be if the command was invoked directly from the terminal.

Arduino CLI version

65915d8a

Operating system

Linux

Operating system version

Ubuntu 22.04

Additional context

I bisected the regression to b3e8f8a4c2544cbda60975153773652631253738 (does not occur when using the build at the previous commit a735ddfdf6eca1ed60cfdfc2dafa9133b03b55bc).


The coloration returns if I force the compiler to add the escape codes to its output by adding the -fdiagnostics-color flag to the compilation commands:

$ ./arduino-cli compile --build-property "compiler.cpp.extra_flags=-fdiagnostics-color=always" --fqbn arduino:avr:uno --warnings all "/tmp/SketchWithDiagnostics"

So it is not a matter of Arduino CLI stripping the escape codes, but rather of the context in which the compiler commands are invoked causing the compiler to not add them in its default "auto" mode:

β€˜auto’ means to use color only when the standard error is a terminal


The diagnostics are colored if I invoke the same compiler command directly from the terminal.


I don't get any coloration even when invoking the compiler command directly on my Windows machine (likely done due to a lack of support for the ANSI codes by Windows terminals).


Originally reported by @myklemykle at https://forum.arduino.cc/t/in-ardino-cli-0-33-1-compiler-errs-warnings-are-no-longer-colorized/1150508

Issue checklist

  • [X] I searched for previous reports in the issue tracker
  • [X] I verified the problem still occurs when using the nightly build
  • [X] My report contains all necessary details

per1234 avatar Sep 10 '23 22:09 per1234