interpreter: add cm_interpreter to SubprojectHolder

This is used in the cmake module, as an extra attribute we just tack on.
Instead, let's actually define and type it.
pull/10043/head
Dylan Baker 3 years ago
parent 4a2058cb83
commit 5787f81615
  1. 5
      mesonbuild/interpreter/interpreterobjects.py
  2. 7
      mesonbuild/modules/cmake.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,
})

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

Loading…
Cancel
Save