Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter cleanups #13857

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion mesonbuild/ast/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self,
subproject: SubProject = SubProject(''),
subproject_dir: str = 'subprojects',
env: T.Optional[environment.Environment] = None):
visitors = visitors if visitors is not None else []
super().__init__(source_root, subdir, subproject, visitors=visitors)

options = IntrospectionHelper(cross_file)
Expand Down
6 changes: 5 additions & 1 deletion mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ def __init__(self, environment: environment.Environment):
self.dependency_overrides: PerMachine[T.Dict[T.Tuple, DependencyOverride]] = PerMachineDefaultable.default(
environment.is_cross_build(), {}, {})
self.devenv: T.List[EnvironmentVariables] = []
self.modules: T.List[str] = []
self.modules: T.Set[str] = set()
"""Used to track which modules are enabled in all subprojects.

Needed for tracking whether a modules options needs to be exposed to the user.
"""

def get_build_targets(self):
build_targets = OrderedDict()
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/interpreter/dependencyfallbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2021-2024 The Meson Developers
# Copyright © 2021-2024 Intel Corporation

from __future__ import annotations

from .interpreterobjects import extract_required_kwarg
Expand Down
38 changes: 13 additions & 25 deletions mesonbuild/interpreter/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ def __init__(
subproject_dir: str = 'subprojects',
default_project_options: T.Optional[T.Dict[OptionKey, str]] = None,
ast: T.Optional[mparser.CodeBlockNode] = None,
is_translated: bool = False,
relaxations: T.Optional[T.Set[InterpreterRuleRelaxation]] = None,
user_defined_options: T.Optional[coredata.SharedCMDOptions] = None,
) -> None:
Expand All @@ -281,18 +280,15 @@ def __init__(
self.backend = backend
self.summary: T.Dict[str, 'Summary'] = {}
self.modules: T.Dict[str, NewExtensionModule] = {}
# Subproject directory is usually the name of the subproject, but can
# be different for dependencies provided by wrap files.
self.subproject_directory_name = subdir.split(os.path.sep)[-1]
self.subproject_dir = subproject_dir
self.relaxations = relaxations or set()
self.build_def_files: mesonlib.OrderedSet[str] = mesonlib.OrderedSet()
if ast is None:
self.load_root_meson_file()
else:
self.ast = ast
self.sanity_check_ast()
self.builtin.update({'meson': MesonMain(self.build, self)})
self.generators: T.List[build.Generator] = []
self.processed_buildfiles: T.Set[str] = set()
self.project_args_frozen = False
self.global_args_frozen = False # implies self.project_args_frozen
Expand All @@ -309,16 +305,6 @@ def __init__(
self.build_holder_map()
self.user_defined_options = user_defined_options
self.compilers: PerMachine[T.Dict[str, 'compilers.Compiler']] = PerMachine({}, {})

# build_def_files needs to be defined before parse_project is called
#
# For non-meson subprojects, we'll be using the ast. Even if it does
# exist we don't want to add a dependency on it, it's autogenerated
# from the actual build files, and is just for reference.
self.build_def_files: mesonlib.OrderedSet[str] = mesonlib.OrderedSet()
build_filename = os.path.join(self.subdir, environment.build_filename)
if not is_translated:
self.build_def_files.add(build_filename)
self.parse_project()
self._redetect_machines()

Expand All @@ -343,6 +329,11 @@ def _redetect_machines(self) -> None:
self.builtin['target_machine'] = \
OBJ.MachineHolder(self.build.environment.machines.target, self)

def load_root_meson_file(self) -> None:
build_filename = os.path.join(self.subdir, environment.build_filename)
self.build_def_files.add(build_filename)
super().load_root_meson_file()

def build_func_dict(self) -> None:
self.funcs.update({'add_global_arguments': self.func_add_global_arguments,
'add_global_link_arguments': self.func_add_global_link_arguments,
Expand Down Expand Up @@ -636,8 +627,8 @@ def func_import(self, node: mparser.BaseNode, args: T.Tuple[str],
ext_module = NotFoundExtensionModule(real_modname)
else:
ext_module = module.initialize(self)
assert isinstance(ext_module, (ExtensionModule, NewExtensionModule)), 'for mypy'
self.build.modules.append(real_modname)
assert isinstance(ext_module, (ExtensionModule, NewExtensionModule))
self.build.modules.add(real_modname)
if ext_module.INFO.added:
FeatureNew.single_use(f'module {ext_module.INFO.name}', ext_module.INFO.added, self.subproject, location=node)
if ext_module.INFO.deprecated:
Expand Down Expand Up @@ -972,8 +963,7 @@ def _do_subproject_meson(self, subp_name: str, subdir: str,

new_build = self.build.copy()
subi = Interpreter(new_build, self.backend, subp_name, subdir, self.subproject_dir,
default_options, ast=ast, is_translated=(ast is not None),
relaxations=relaxations,
default_options, ast=ast, relaxations=relaxations,
user_defined_options=self.user_defined_options)
# Those lists are shared by all interpreters. That means that
# even if the subproject fails, any modification that the subproject
Expand Down Expand Up @@ -1131,7 +1121,7 @@ def set_backend(self) -> None:
return
from ..backend import backends

if OptionKey('genvslite') in self.user_defined_options.cmd_line_options.keys():
if OptionKey('genvslite') in self.user_defined_options.cmd_line_options:
# Use of the '--genvslite vsxxxx' option ultimately overrides any '--backend xxx'
# option the user may specify.
backend_name = self.coredata.get_option(OptionKey('genvslite'))
Expand Down Expand Up @@ -2203,9 +2193,7 @@ def func_generator(self, node: mparser.FunctionNode,
if '@OUTPUT@' in o:
raise InvalidArguments('Tried to use @OUTPUT@ in a rule with more than one output.')

gen = build.Generator(args[0], **kwargs)
self.generators.append(gen)
return gen
return build.Generator(args[0], **kwargs)

@typed_pos_args('benchmark', str, (build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex))
@typed_kwargs('benchmark', *TEST_KWS)
Expand Down Expand Up @@ -2686,11 +2674,11 @@ def func_configure_file(self, node: mparser.BaseNode, args: T.List[TYPE_var],
ofile_rpath = os.path.join(self.subdir, output)
if ofile_rpath in self.configure_file_outputs:
mesonbuildfile = os.path.join(self.subdir, 'meson.build')
current_call = f"{mesonbuildfile}:{self.current_lineno}"
current_call = f"{mesonbuildfile}:{self.current_node.lineno}"
first_call = "{}:{}".format(mesonbuildfile, self.configure_file_outputs[ofile_rpath])
mlog.warning('Output file', mlog.bold(ofile_rpath, True), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call)
else:
self.configure_file_outputs[ofile_rpath] = self.current_lineno
self.configure_file_outputs[ofile_rpath] = self.current_node.lineno
(ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output))
ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname)

Expand Down
3 changes: 1 addition & 2 deletions mesonbuild/interpreterbase/interpreterbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, source_root: str, subdir: str, subproject: 'SubProject'):
self.current_lineno = -1
# Current node set during a function call. This can be used as location
# when printing a warning message during a method call.
self.current_node: mparser.BaseNode = None
self.current_node = mparser.BaseNode(-1, -1, 'sentinel')
# This is set to `version_string` when this statement is evaluated:
# meson.version().compare_version(version_string)
# If it was part of a if-clause, it is used to temporally override the
Expand Down Expand Up @@ -183,7 +183,6 @@ def evaluate_codeblock(self, node: mparser.CodeBlockNode, start: int = 0, end: T
while i < len(statements):
cur = statements[i]
try:
self.current_lineno = cur.lineno
self.evaluate_statement(cur)
except Exception as e:
if getattr(e, 'lineno', None) is None:
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, interpreter: 'Interpreter') -> None:
self.subproject = interpreter.subproject
self.subdir = interpreter.subdir
self.root_subdir = interpreter.root_subdir
self.current_lineno = interpreter.current_lineno
self.current_lineno = interpreter.current_node.lineno
self.environment = interpreter.environment
self.project_name = interpreter.build.project_name
self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version
Expand Down
Loading