diff options
author | Charles Brunet <charles.brunet@optelgroup.com> | 2023-02-23 11:46:20 -0500 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-03-02 10:10:03 -0500 |
commit | a0d0fb549212f6140323a7988e457ebda6e0b56d (patch) | |
tree | 0225a45a6799a057a7b1d453cad333e618448827 | |
parent | a3f4f6c88f14ba9f176721bace861d705a11189c (diff) | |
download | meson-a0d0fb549212f6140323a7988e457ebda6e0b56d.zip meson-a0d0fb549212f6140323a7988e457ebda6e0b56d.tar.gz meson-a0d0fb549212f6140323a7988e457ebda6e0b56d.tar.bz2 |
mintro: redirect stdout to stderr
-rw-r--r-- | docs/markdown/snippets/mintro_outputs.md | 5 | ||||
-rw-r--r-- | mesonbuild/mintro.py | 17 |
2 files changed, 14 insertions, 8 deletions
diff --git a/docs/markdown/snippets/mintro_outputs.md b/docs/markdown/snippets/mintro_outputs.md new file mode 100644 index 0000000..cfc7f8c --- /dev/null +++ b/docs/markdown/snippets/mintro_outputs.md @@ -0,0 +1,5 @@ +## Redirect introspection outputs to stderr + +`meson introspect` used to disable logging to `stdout` to not interfere with generated json. +It now redirect outputs to `stderr` to allow printing warnings to the console +while keeping `stdout` clean for json outputs. diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index 1fd0f3d..68820d6 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -20,13 +20,15 @@ tests and so on. All output is in JSON for simple parsing. Currently only works for the Ninja backend. Others use generated project files and don't need this info.""" +from contextlib import redirect_stdout import collections import json import os from pathlib import Path, PurePath +import sys import typing as T -from . import build, mesonlib, mlog, coredata as cdata +from . import build, mesonlib, coredata as cdata from .ast import IntrospectionInterpreter, BUILD_TARGET_FUNCTIONS, AstConditionLevel, AstIDGenerator, AstIndentationGenerator, AstJSONPrinter from .backend import backends from .mesonlib import OptionKey @@ -461,13 +463,12 @@ def run(options: argparse.Namespace) -> int: if 'meson.build' in [os.path.basename(options.builddir), options.builddir]: # Make sure that log entries in other parts of meson don't interfere with the JSON output - mlog.disable() - backend = backends.get_backend_from_name(options.backend) - assert backend is not None - intr = IntrospectionInterpreter(sourcedir, '', backend.name, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()]) - intr.analyze() - # Re-enable logging just in case - mlog.enable() + with redirect_stdout(sys.stderr): + backend = backends.get_backend_from_name(options.backend) + assert backend is not None + intr = IntrospectionInterpreter(sourcedir, '', backend.name, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()]) + intr.analyze() + for key, val in intro_types.items(): if (not options.all and not getattr(options, key, False)) or not val.no_bd: continue |