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

Compiler diagnostics no longer colored in arduino-cli compile output #2308

Open
3 tasks done
per1234 opened this issue Sep 10, 2023 · 0 comments
Open
3 tasks done

Compiler diagnostics no longer colored in arduino-cli compile output #2308

per1234 opened this issue Sep 10, 2023 · 0 comments
Labels
topic: CLI Related to the command line interface topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Sep 10, 2023

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

65915d8

Operating system

Linux

Operating system version

Ubuntu 22.04

Additional context

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


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

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project topic: CLI Related to the command line interface labels Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: CLI Related to the command line interface topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

1 participant