mintro: redirect stdout to stderr

pull/11483/head
Charles Brunet 2 years ago committed by Xavier Claessens
parent a3f4f6c88f
commit a0d0fb5492
  1. 5
      docs/markdown/snippets/mintro_outputs.md
  2. 17
      mesonbuild/mintro.py

@ -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.

@ -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 Currently only works for the Ninja backend. Others use generated
project files and don't need this info.""" project files and don't need this info."""
from contextlib import redirect_stdout
import collections import collections
import json import json
import os import os
from pathlib import Path, PurePath from pathlib import Path, PurePath
import sys
import typing as T 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 .ast import IntrospectionInterpreter, BUILD_TARGET_FUNCTIONS, AstConditionLevel, AstIDGenerator, AstIndentationGenerator, AstJSONPrinter
from .backend import backends from .backend import backends
from .mesonlib import OptionKey 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]: 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 # Make sure that log entries in other parts of meson don't interfere with the JSON output
mlog.disable() with redirect_stdout(sys.stderr):
backend = backends.get_backend_from_name(options.backend) backend = backends.get_backend_from_name(options.backend)
assert backend is not None assert backend is not None
intr = IntrospectionInterpreter(sourcedir, '', backend.name, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()]) intr = IntrospectionInterpreter(sourcedir, '', backend.name, visitors = [AstIDGenerator(), AstIndentationGenerator(), AstConditionLevel()])
intr.analyze() intr.analyze()
# Re-enable logging just in case
mlog.enable()
for key, val in intro_types.items(): for key, val in intro_types.items():
if (not options.all and not getattr(options, key, False)) or not val.no_bd: if (not options.all and not getattr(options, key, False)) or not val.no_bd:
continue continue

Loading…
Cancel
Save