diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 1f3989d8b..f3c07591f 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -65,8 +65,7 @@ def git(cmd: T.List[str], workingdir: str, **kwargs) -> subprocess.CompletedProc # Sometimes git calls git recursively, such as `git submodule update # --recursive` which will be without the above workaround, so set the # console mode again just in case. - if platform.system().lower() == 'windows': - mlog._windows_ansi() + mlog.setup_console() return pc diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index a30d6b9c0..b28eca12a 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -40,13 +40,15 @@ def _windows_ansi() -> bool: # original behavior return bool(kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')) -try: - if platform.system().lower() == 'windows': - colorize_console = os.isatty(sys.stdout.fileno()) and _windows_ansi() # type: bool - else: - colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb' -except Exception: - colorize_console = False +def setup_console() -> bool: + try: + if platform.system().lower() == 'windows': + return os.isatty(sys.stdout.fileno()) and _windows_ansi() + return os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb' + except Exception: + return False + +colorize_console = setup_console() log_dir = None # type: T.Optional[str] log_file = None # type: T.Optional[T.TextIO] log_fname = 'meson-log.txt' # type: str