SCons: Colorize warnings/errors during generation
This commit is contained in:
@ -1,10 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
import atexit
|
||||
import os
|
||||
import sys
|
||||
import methods
|
||||
import time
|
||||
|
||||
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
|
||||
# <https://github.com/python/cpython/issues/73245>
|
||||
if sys.platform == "win32":
|
||||
from ctypes import windll, c_int, byref
|
||||
|
||||
stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
|
||||
mode = c_int(0)
|
||||
windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
|
||||
mode = c_int(mode.value | 4)
|
||||
windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
|
||||
|
||||
# For the reference:
|
||||
# - CCFLAGS are compilation flags shared between C and C++
|
||||
# - CFLAGS are for C-specific compilation flags
|
||||
@ -28,7 +38,7 @@ opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", Fa
|
||||
opts.Update(env)
|
||||
|
||||
if not env["verbose"]:
|
||||
methods.no_verbose(sys, env)
|
||||
methods.no_verbose(env)
|
||||
|
||||
# ThorVG
|
||||
if env["thorvg_enabled"] and env["freetype_enabled"]:
|
||||
@ -311,9 +321,16 @@ Default(library)
|
||||
|
||||
|
||||
def print_elapsed_time():
|
||||
elapsed_time_sec = round(time.time() - time_at_start, 3)
|
||||
time_ms = round((elapsed_time_sec % 1) * 1000)
|
||||
print("[Time elapsed: {}.{:03}]".format(time.strftime("%H:%M:%S", time.gmtime(elapsed_time_sec)), time_ms))
|
||||
elapsed_time_sec = round(time.time() - time_at_start, 2)
|
||||
time_centiseconds = round((elapsed_time_sec % 1) * 100)
|
||||
print(
|
||||
"{}[Time elapsed: {}.{:02}]{}".format(
|
||||
methods.ANSI.GRAY,
|
||||
time.strftime("%H:%M:%S", time.gmtime(elapsed_time_sec)),
|
||||
time_centiseconds,
|
||||
methods.ANSI.RESET,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
atexit.register(print_elapsed_time)
|
||||
|
||||
@ -1,66 +1,73 @@
|
||||
import os
|
||||
import sys
|
||||
from enum import Enum
|
||||
|
||||
# Colors are disabled in non-TTY environments such as pipes. This means
|
||||
# that if output is redirected to a file, it won't contain color codes.
|
||||
# Colors are always enabled on continuous integration.
|
||||
_colorize = bool(sys.stdout.isatty() or os.environ.get("CI"))
|
||||
|
||||
|
||||
def no_verbose(sys, env):
|
||||
colors = {}
|
||||
class ANSI(Enum):
|
||||
"""
|
||||
Enum class for adding ansi colorcodes directly into strings.
|
||||
Automatically converts values to strings representing their
|
||||
internal value, or an empty string in a non-colorized scope.
|
||||
"""
|
||||
|
||||
# Colors are disabled in non-TTY environments such as pipes. This means
|
||||
# that if output is redirected to a file, it will not contain color codes
|
||||
if sys.stdout.isatty():
|
||||
colors["blue"] = "\033[0;94m"
|
||||
colors["bold_blue"] = "\033[1;94m"
|
||||
colors["reset"] = "\033[0m"
|
||||
else:
|
||||
colors["blue"] = ""
|
||||
colors["bold_blue"] = ""
|
||||
colors["reset"] = ""
|
||||
GRAY = "\x1b[0;30m"
|
||||
RED = "\x1b[0;31m"
|
||||
GREEN = "\x1b[0;32m"
|
||||
YELLOW = "\x1b[0;33m"
|
||||
BLUE = "\x1b[0;34m"
|
||||
PURPLE = "\x1b[0;35m"
|
||||
CYAN = "\x1b[0;36m"
|
||||
WHITE = "\x1b[0;37m"
|
||||
|
||||
BOLD_GRAY = "\x1b[1;90m"
|
||||
BOLD_RED = "\x1b[1;91m"
|
||||
BOLD_GREEN = "\x1b[1;92m"
|
||||
BOLD_YELLOW = "\x1b[1;93m"
|
||||
BOLD_BLUE = "\x1b[1;94m"
|
||||
BOLD_PURPLE = "\x1b[1;95m"
|
||||
BOLD_CYAN = "\x1b[1;96m"
|
||||
BOLD_WHITE = "\x1b[1;97m"
|
||||
|
||||
RESET = "\x1b[0m"
|
||||
|
||||
def __str__(self):
|
||||
global _colorize
|
||||
return self.value if _colorize else ""
|
||||
|
||||
|
||||
def no_verbose(env):
|
||||
colors = [ANSI.BLUE, ANSI.BOLD_BLUE, ANSI.RESET]
|
||||
|
||||
# There is a space before "..." to ensure that source file names can be
|
||||
# Ctrl + clicked in the VS Code terminal.
|
||||
compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
java_compile_source_message = "{}Compiling {}$SOURCE{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
compile_shared_source_message = "{}Compiling shared {}$SOURCE{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
link_program_message = "{}Linking Program {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
link_library_message = "{}Linking Static Library {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
ranlib_library_message = "{}Ranlib Library {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
link_shared_library_message = "{}Linking Shared Library {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
java_library_message = "{}Creating Java Archive {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
compiled_resource_message = "{}Creating Compiled Resource {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
generated_file_message = "{}Generating {}$TARGET{} ...{}".format(
|
||||
colors["blue"], colors["bold_blue"], colors["blue"], colors["reset"]
|
||||
)
|
||||
compile_source_message = "{0}Compiling {1}$SOURCE{0} ...{2}".format(*colors)
|
||||
java_compile_source_message = "{0}Compiling {1}$SOURCE{0} ...{2}".format(*colors)
|
||||
compile_shared_source_message = "{0}Compiling shared {1}$SOURCE{0} ...{2}".format(*colors)
|
||||
link_program_message = "{0}Linking Program {1}$TARGET{0} ...{2}".format(*colors)
|
||||
link_library_message = "{0}Linking Static Library {1}$TARGET{0} ...{2}".format(*colors)
|
||||
ranlib_library_message = "{0}Ranlib Library {1}$TARGET{0} ...{2}".format(*colors)
|
||||
link_shared_library_message = "{0}Linking Shared Library {1}$TARGET{0} ...{2}".format(*colors)
|
||||
java_library_message = "{0}Creating Java Archive {1}$TARGET{0} ...{2}".format(*colors)
|
||||
compiled_resource_message = "{0}Creating Compiled Resource {1}$TARGET{0} ...{2}".format(*colors)
|
||||
generated_file_message = "{0}Generating {1}$TARGET{0} ...{2}".format(*colors)
|
||||
|
||||
env.Append(CXXCOMSTR=[compile_source_message])
|
||||
env.Append(CCCOMSTR=[compile_source_message])
|
||||
env.Append(SHCCCOMSTR=[compile_shared_source_message])
|
||||
env.Append(SHCXXCOMSTR=[compile_shared_source_message])
|
||||
env.Append(ARCOMSTR=[link_library_message])
|
||||
env.Append(RANLIBCOMSTR=[ranlib_library_message])
|
||||
env.Append(SHLINKCOMSTR=[link_shared_library_message])
|
||||
env.Append(LINKCOMSTR=[link_program_message])
|
||||
env.Append(JARCOMSTR=[java_library_message])
|
||||
env.Append(JAVACCOMSTR=[java_compile_source_message])
|
||||
env.Append(RCCOMSTR=[compiled_resource_message])
|
||||
env.Append(GENCOMSTR=[generated_file_message])
|
||||
env.Append(CXXCOMSTR=compile_source_message)
|
||||
env.Append(CCCOMSTR=compile_source_message)
|
||||
env.Append(SHCCCOMSTR=compile_shared_source_message)
|
||||
env.Append(SHCXXCOMSTR=compile_shared_source_message)
|
||||
env.Append(ARCOMSTR=link_library_message)
|
||||
env.Append(RANLIBCOMSTR=ranlib_library_message)
|
||||
env.Append(SHLINKCOMSTR=link_shared_library_message)
|
||||
env.Append(LINKCOMSTR=link_program_message)
|
||||
env.Append(JARCOMSTR=java_library_message)
|
||||
env.Append(JAVACCOMSTR=java_compile_source_message)
|
||||
env.Append(RCCOMSTR=compiled_resource_message)
|
||||
env.Append(GENCOMSTR=generated_file_message)
|
||||
|
||||
|
||||
def disable_warnings(self):
|
||||
|
||||
Reference in New Issue
Block a user