diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py index c7ddb382b..eed750e54 100644 --- a/mesonbuild/interpreter/interpreterobjects.py +++ b/mesonbuild/interpreter/interpreterobjects.py @@ -1,3 +1,4 @@ +from __future__ import annotations import os import shlex import subprocess @@ -29,9 +30,10 @@ import typing as T if T.TYPE_CHECKING: from . import kwargs - from .interpreter import Interpreter + from ..cmake.interpreter import CMakeInterpreter from ..envconfig import MachineInfo from ..interpreterbase import SubProject + from .interpreter import Interpreter from typing_extensions import TypedDict @@ -678,6 +680,7 @@ class SubprojectHolder(MesonInterpreterObject): self.disabled_feature = disabled_feature self.exception = exception self.subdir = PurePath(subdir).as_posix() + self.cm_interpreter: T.Optional[CMakeInterpreter] = None self.methods.update({'get_variable': self.get_variable_method, 'found': self.found_method, }) diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index a58ad54c0..0f54d30fa 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -104,9 +104,10 @@ endmacro() class CMakeSubproject(ModuleObject): def __init__(self, subp: SubprojectHolder): assert isinstance(subp, SubprojectHolder) - assert hasattr(subp, 'cm_interpreter') + assert subp.cm_interpreter is not None super().__init__() self.subp = subp + self.cm_interpreter = subp.cm_interpreter self.methods.update({'get_variable': self.get_variable, 'dependency': self.dependency, 'include_directories': self.include_directories, @@ -121,7 +122,7 @@ class CMakeSubproject(ModuleObject): raise InterpreterException('Exactly one argument is required.') tgt = args[0] - res = self.subp.cm_interpreter.target_info(tgt) + res = self.cm_interpreter.target_info(tgt) if res is None: raise InterpreterException(f'The CMake target {tgt} does not exist\n' + ' Use the following command in your meson.build to list all available targets:\n\n' + @@ -172,7 +173,7 @@ class CMakeSubproject(ModuleObject): @noPosargs @noKwargs def target_list(self, state, args, kwargs): - return self.subp.cm_interpreter.target_list() + return self.cm_interpreter.target_list() @noPosargs @noKwargs