Add --color command line argument to control colored console output#77261
Add --color command line argument to control colored console output#77261Calinou wants to merge 1 commit intogodotengine:masterfrom
--color command line argument to control colored console output#77261Conversation
dfafc67 to
4dd89b4
Compare
|
I've tried to fix the build on Windows, but am not sure how to fix the heap-use-after-free in the Linux build: ==7218==ERROR: AddressSanitizer: heap-use-after-free on address 0x612000009650 at pc 0x5577491682f7 bp 0x7fff032db4d0 sp 0x7fff032db4c0
READ of size 8 at 0x612000009650 thread T0
#0 0x5577491682f6 in UnixTerminalLogger::log_error(char const*, char const*, int, char const*, char const*, bool, Logger::ErrorType) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x45dfb2f6)
#1 0x55775ada11f3 in CompositeLogger::log_error(char const*, char const*, int, char const*, char const*, bool, Logger::ErrorType) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x57a341f3)
#2 0x55775a71fe05 in OS::print_error(char const*, char const*, int, char const*, char const*, bool, Logger::ErrorType) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x573b2e05)
#3 0x55775c1f4cf9 in _err_print_error(char const*, char const*, int, char const*, char const*, bool, ErrorHandlerType) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x58e87cf9)
#4 0x55775c1f49ab in _err_print_error(char const*, char const*, int, char const*, bool, ErrorHandlerType) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x58e879ab)
#5 0x55775bf1c1ca in ObjectDB::cleanup() (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x58baf1ca)
#6 0x55775a5520bd in unregister_core_types() (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x571e50bd)
#7 0x55773fd09e89 in Main::test_cleanup() (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99ce89)
#8 0x55773fd0a29d in Main::test_entrypoint(int, char**, bool&) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99d29d)
#9 0x55773fa8be31 in main (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c71ee31)
#10 0x7f861c5b0082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
#11 0x55773fa8bbad in _start (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c71ebad)
0x612000009650 is located 16 bytes inside of 264-byte region [0x612000009640,0x612000009748)
freed by thread T0 here:
#0 0x7f861d37040f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
#1 0x55775a71a7c8 in Memory::free_static(void*, bool) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x573ad7c8)
#2 0x55773fd8c5c4 in void memdelete<Engine>(Engine*) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3ca1f5c4)
#3 0x55773fd09e70 in Main::test_cleanup() (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99ce70)
#4 0x55773fd0a29d in Main::test_entrypoint(int, char**, bool&) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99d29d)
#5 0x55773fa8be31 in main (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c71ee31)
#6 0x7f861c5b0082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)
previously allocated by thread T0 here:
#0 0x7f861d370808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
#1 0x55775a71976d in Memory::alloc_static(unsigned long, bool) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x573ac76d)
#2 0x55775a71967e in operator new(unsigned long, char const*) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x573ac67e)
#3 0x55773fd079a1 in Main::test_setup() (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99a9a1)
#4 0x55773fd0a284 in Main::test_entrypoint(int, char**, bool&) (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c99d284)
#5 0x55773fa8be31 in main (/home/runner/work/godot/godot/bin/godot.linuxbsd.editor.dev.double.x86_64.san+0x3c71ee31)
#6 0x7f861c5b0082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082)The problematic line is https://github.com/Calinou/godot/blob/4dd89b440234c8e1b4d7e6da748d20d859049f0f/drivers/unix/os_unix.cpp#L794. I'm just not sure how to avoid having to query the Engine singleton here, while keeping the solution as local as possible. |
Am I wrong or is this is simple as not blindly dereferencing the |
|
Not that I want to throw out this PR, but the API feels like it should be a part of So, if I was to propose an alternate API, move |
|
Rebased and tested again, it works as expected. I've also added CLI argument validation for
That works, thanks 🙂 |
99e2102 to
52abd35
Compare
52abd35 to
2c2c876
Compare
|
Rebased and tested again, it works as expected. I've added support for |
There was a problem hiding this comment.
This is more thorough than my own implementation in #106868, but the end result should be the same, with one exception in my testing: this PR actively suppresses colors from print_rich, where mine keeps them (see example screenshot in godotengine/godot-proposals#12507) - one could argue stripping colors there would be the expected behavior.
Other than that, I'm just not entirely convinced by --color auto, given that it is the default value, but I guess the same can be said of other shell commands (ls for instance).
|
The remaining CI errors should be easy to fix by just replacing the 5 |
This also adds support for the `NO_COLOR`, `CLICOLOR_FORCE` and `CI` environment variables, and harmonizes checks for colored console output by using a unique Engine method. The default mode should now behave in the same manner as Godot's SCons setup when it comes to coloring output. - `auto` (default): Only color if output is a TTY (interactive session), or if either `CLICOLOR_FORCE` or `CI` is `1` (continuous integration). Color is disabled if the `NO_COLOR` environment variable is set to a non-empty string, as per <https://no-color.org>. `NO_COLOR` takes priority over `CLICOLOR_FORCE` and `CI`. - `always`: Always color, even if output is a file or is non-interactive. This also bypasses `NO_COLOR` as per its specification. - `never`: Never color command line output. This takes priority over `CLICOLOR_FORCE` and `CI`.
2c2c876 to
ada5637
Compare
Done.
I'll keep those as-is for now, given this PR only aims to change whether to use ANSI escape codes in output. Ideally, |
|
Any chance this could get a rebase? It's a pretty handy feature to have when looking through CI logs, especially when you get a long list of import prints and a few errors thrown in the mix, which don't really pop out without colors. |
This also adds support for the
NO_COLOR,CLICOLOR_FORCEandCIenvironment variables, and harmonizes checks for colored console output by using a unique Engine method.The default mode should now behave in the same manner as Godot's SCons setup when it comes to coloring output.
auto(default): Only color if output is a TTY (interactive session), or if eitherCLICOLOR_FORCEorCIis1(continuous integration). Color is disabled if theNO_COLORenvironment variable is set to a non-empty string, as per https://no-color.org.NO_COLORtakes priority overCLICOLOR_FORCEandCI.always: Always color, even if output is a file or is non-interactive. This also bypassesNO_COLORas per its specification.never: Never color command line output. This takes priority overCLICOLOR_FORCEandCI.Preview