Debian Codegraph @

mesonbuild/munstable_coredata.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2019 The Meson development team
3
4 from __future__ import annotations
5
6 from . import coredata as cdata
7 from .mesonlib import MachineChoice
8 from .options import OptionKey
9 import typing as T
10
11 import os.path
12 import pprint
13 import textwrap
14
15 if T.TYPE_CHECKING:
16 import argparse
17
18 from .import dependencies
19 from .compilers.compilers import CompilerDict
20 from .dependencies.detect import TV_DepID
21
22 class Arguments(T.Protocol):
23
24 builddir: str
25 all: bool
26
27 # Note: when adding arguments, please also add them to the completion
28 # scripts in $MESONSRC/data/shell-completions/
29 def add_arguments(parser: argparse.ArgumentParser) -> None:
30 parser.add_argument('--all', action='store_true', dest='all', default=False,
31 help='Show data not used by current backend.')
32
33 parser.add_argument('builddir', nargs='?', default='.', help='The build directory')
34
35
36 def dump_compilers(compilers: CompilerDict) -> None:
37 for lang, compiler in compilers.items():
38 print(' ' + lang + ':')
39 print(' Id: ' + compiler.id)
40 print(' Command: ' + ' '.join(compiler.exelist))
41 if compiler.full_version:
42 print(' Full version: ' + compiler.full_version)
43 if compiler.version:
44 print(' Detected version: ' + compiler.version)
45
46
47 def dump_guids(d: dict[str, str]) -> None:
48 for name, value in d.items():
49 print(' ' + name + ': ' + value)
50
51
52 def run(options: Arguments) -> int:
53 datadir = 'meson-private'
54 if options.builddir is not None:
55 datadir = os.path.join(options.builddir, datadir)
56 if not os.path.isdir(datadir):
57 print('Current directory is not a build dir. Please specify it or '
58 'change the working directory to it.')
59 return 1
60
61 all_backends = options.all
62
63 print('This is a dump of the internal unstable cache of meson. This is for debugging only.')
64 print('Do NOT parse, this will change from version to version in incompatible ways')
65 print('')
66
67 coredata = cdata.load(options.builddir)
68 backend = coredata.optstore.get_value_for(OptionKey('backend'))
69 assert isinstance(backend, str), 'for mypy'
70 for k, v in sorted(coredata.__dict__.items()):
71 if k in {'backend_options', 'base_options', 'builtins', 'compiler_options', 'user_options'}:
72 # use `meson configure` to view these
73 pass
74 elif k in {'install_guid', 'test_guid', 'regen_guid'}:
75 if all_backends or backend.startswith('vs'):
76 print(k + ': ' + v)
77 elif k == 'target_guids':
78 if all_backends or backend.startswith('vs'):
79 print(k + ':')
80 dump_guids(v)
81 elif k == 'lang_guids':
82 if all_backends or backend.startswith('vs') or backend == 'xcode':
83 print(k + ':')
84 dump_guids(v)
85 elif k == 'meson_command':
86 if all_backends or backend.startswith('vs'):
87 print('Meson command used in build file regeneration: ' + ' '.join(v))
88 elif k == 'pkgconf_envvar':
89 print('Last seen PKGCONFIG environment variable value: ' + v)
90 elif k == 'version':
91 print('Meson version: ' + v)
92 elif k == 'cross_files':
93 if v:
94 print('Cross File: ' + ' '.join(v))
95 elif k == 'config_files':
96 if v:
97 print('Native File: ' + ' '.join(v))
98 elif k == 'compilers':
99 for for_machine in MachineChoice:
100 print('Cached {} machine compilers:'.format(
101 for_machine.get_lower_case_name()))
102 dump_compilers(v[for_machine])
103 elif k == 'deps':
104 def print_dep(dep_key: TV_DepID, dep: dependencies.Dependency) -> None:
105 print(' ' + str(dep_key[0][1]) + ": ")
106 print(' compile args: ' + repr(dep.get_compile_args()))
107 print(' link args: ' + repr(dep.get_link_args()))
108 if dep.get_sources():
109 print(' sources: ' + repr(dep.get_sources()))
110 print(' version: ' + repr(dep.get_version()))
111
112 for for_machine in iter(MachineChoice):
113 items_list = sorted(v[for_machine].items())
114 if items_list:
115 print(f'Cached dependencies for {for_machine.get_lower_case_name()} machine')
116 for dep_key, deps in items_list:
117 for dep in deps:
118 print_dep(dep_key, dep)
119 else:
120 print(k + ':')
121 print(textwrap.indent(pprint.pformat(v), ' '))
122 return 0