This bbclass turns on compiler color diagnostics to make it easier to
visually interpret compiler errors and warnings. It can be used
per-recipe or globally (via INHERIT in local.conf).

You can set the LOG_COLORIZER_SUPPRESS_COLORIZED_OUTPUT variable to turn
off color output - this is intended for usage in a CI environment.

log.do_compile and log.do_configure task logs will contain the colorized
output. Non-colorized versions (log.do_<task>.nocolor) and explicitly
colorized versions (log.do_<task>.color) are created as well, regardless
of LOG_COLORIZER_SUPPRESS_COLORIZED_OUTPUT.

Signed-off-by: Chris Laplante <[email protected]>
---
 meta/classes/log-colorizer.bbclass | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 meta/classes/log-colorizer.bbclass

diff --git a/meta/classes/log-colorizer.bbclass 
b/meta/classes/log-colorizer.bbclass
new file mode 100644
index 0000000000..4271957e28
--- /dev/null
+++ b/meta/classes/log-colorizer.bbclass
@@ -0,0 +1,49 @@
+# Copyright (C) 2020  Agilent Technologies, Inc.
+# Author: Chris Laplante <[email protected]>
+#
+# Released under the MIT license (see COPYING.MIT)
+
+LOG_COLORIZER_SUPPRESS_COLORIZED_OUTPUT ?= ""
+LOG_COLORIZER_SUPPRESS_COLORIZED_OUTPUT[doc] = "If set, then console output 
from the colorized tasks will be stripped of ANSI escape codes."
+
+LOG_COLORIZER_TASKS ?= " \
+    configure \
+    compile \
+"
+
+BB_SIGNATURE_EXCLUDE_FLAGS += "originalprogress"
+
+CFLAGS += "-fdiagnostics-color"
+
+python log_colorizer_eventhandler() {
+    def is_task_enabled(task):
+        return task in (d.getVar("__BBTASKS") or []) and "noexec" not in 
d.getVarFlags(task)
+
+    for task in set((d.getVar("LOG_COLORIZER_TASKS") or "").split()):
+        if not task.startswith("do_"):
+            task = "do_{0}".format(task)
+
+        if not is_task_enabled(task):
+            continue
+
+        ph = d.getVarFlag(task, "progress")
+        if ph:
+            # Stash away the original progress handler
+            d.setVarFlag(task, "originalprogress", ph)
+
+        d.setVarFlag(task, "progress", 
"custom:oe.log_colorizer.LogColorizerProxyProgressHandler")
+}
+
+addhandler log_colorizer_eventhandler
+log_colorizer_eventhandler[eventmask] = " \
+    bb.event.RecipeTaskPreProcess \
+"
+
+python __anonymous() {
+    if bb.data.inherits_class("cmake", d):
+        # Inject environment variable to ensure CMake/Ninja gives colorized 
output
+        func = d.getVar("cmake_do_compile", False)
+        if "export CLICOLOR_FORCE=1" not in [line.strip() for line in 
func.split("\n")]:
+            func = "\texport CLICOLOR_FORCE=1\n" + func
+            d.setVar("cmake_do_compile", func)
+}
--
2.17.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#141022): 
https://lists.openembedded.org/g/openembedded-core/message/141022
Mute This Topic: https://lists.openembedded.org/mt/75836420/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to