interpreter: Add a new MesonInterpreterObject for non-elementary objects

pull/8903/head
Daniel Mensinger 4 years ago
parent 202e345dfb
commit 63ade7d937
  1. 30
      mesonbuild/ast/interpreter.py
  2. 4
      mesonbuild/interpreter/interpreter.py
  3. 10
      mesonbuild/interpreter/interpreterobjects.py
  4. 9
      mesonbuild/interpreter/mesonmain.py
  5. 2
      mesonbuild/interpreterbase/__init__.py
  6. 7
      mesonbuild/interpreterbase/baseobjects.py
  7. 4
      mesonbuild/interpreterbase/disabler.py

@ -16,10 +16,20 @@
# or an interpreter-based tool.
from .visitor import AstVisitor
from .. import interpreterbase, mparser, mesonlib
from .. import mparser, mesonlib
from .. import environment
from ..interpreterbase import InvalidArguments, BreakRequest, ContinueRequest, TYPE_nvar, TYPE_nkwargs
from ..interpreterbase import (
MesonInterpreterObject,
InterpreterBase,
InvalidArguments,
BreakRequest,
ContinueRequest,
default_resolve_key,
TYPE_nvar,
TYPE_nkwargs,
)
from ..mparser import (
AndNode,
ArgumentNode,
@ -45,28 +55,28 @@ from ..mparser import (
import os, sys
import typing as T
class DontCareObject(interpreterbase.InterpreterObject):
class DontCareObject(MesonInterpreterObject):
pass
class MockExecutable(interpreterbase.InterpreterObject):
class MockExecutable(MesonInterpreterObject):
pass
class MockStaticLibrary(interpreterbase.InterpreterObject):
class MockStaticLibrary(MesonInterpreterObject):
pass
class MockSharedLibrary(interpreterbase.InterpreterObject):
class MockSharedLibrary(MesonInterpreterObject):
pass
class MockCustomTarget(interpreterbase.InterpreterObject):
class MockCustomTarget(MesonInterpreterObject):
pass
class MockRunTarget(interpreterbase.InterpreterObject):
class MockRunTarget(MesonInterpreterObject):
pass
ADD_SOURCE = 0
REMOVE_SOURCE = 1
class AstInterpreter(interpreterbase.InterpreterBase):
class AstInterpreter(InterpreterBase):
def __init__(self, source_root: str, subdir: str, subproject: str, visitors: T.Optional[T.List[AstVisitor]] = None):
super().__init__(source_root, subdir, subproject)
self.visitors = visitors if visitors is not None else []
@ -224,7 +234,7 @@ class AstInterpreter(interpreterbase.InterpreterBase):
def reduce_arguments(
self,
args: mparser.ArgumentNode,
key_resolver: T.Callable[[mparser.BaseNode], str] = interpreterbase.default_resolve_key,
key_resolver: T.Callable[[mparser.BaseNode], str] = default_resolve_key,
duplicate_key_error: T.Optional[str] = None,
) -> T.Tuple[T.List[TYPE_nvar], TYPE_nkwargs]:
if isinstance(args, ArgumentNode):

@ -394,7 +394,7 @@ class Interpreter(InterpreterBase):
if isinstance(item, build.CustomTarget):
return CustomTargetHolder(item, self)
elif isinstance(item, (int, str, bool, Disabler, InterpreterObject, mesonlib.File)) or item is None:
elif isinstance(item, (int, str, bool, InterpreterObject, mesonlib.File)) or item is None:
return item
elif isinstance(item, build.Executable):
return ExecutableHolder(item, self)
@ -414,7 +414,7 @@ class Interpreter(InterpreterBase):
return MutableModuleObjectHolder(item, self)
elif isinstance(item, ModuleObject):
return ModuleObjectHolder(item, self)
elif isinstance(item, (InterpreterObject, ObjectHolder)):
elif isinstance(item, InterpreterObject):
return item
else:
raise InterpreterException('Module returned a value of unknown type.')

@ -13,8 +13,8 @@ from .. import mlog
from ..modules import ModuleReturnValue, ModuleObject, ModuleState, ExtensionModule
from ..backend.backends import TestProtocol
from ..interpreterbase import (ContainerTypeInfo, InterpreterObject, KwargInfo,
ObjectHolder, MutableInterpreterObject,
from ..interpreterbase import (ContainerTypeInfo, KwargInfo,
MesonInterpreterObject, ObjectHolder, MutableInterpreterObject,
FeatureNewKwargs, FeatureNew, FeatureDeprecated,
typed_kwargs, typed_pos_args, stringArgs,
permittedKwargs, noArgsFlattening, noPosargs,
@ -145,7 +145,7 @@ class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]):
return self if self.value != 'auto' or not args[0] else self.as_disabled()
class RunProcess(InterpreterObject):
class RunProcess(MesonInterpreterObject):
def __init__(self, cmd, args, env, source_dir, build_dir, subdir, mesonintrospect, in_builddir=False, check=False, capture=True):
super().__init__()
@ -718,13 +718,13 @@ class GeneratedObjectsHolder(ObjectHolder[build.ExtractedObjects]):
def __init__(self, held_object: build.ExtractedObjects):
super().__init__(held_object)
class Test(InterpreterObject):
class Test(MesonInterpreterObject):
def __init__(self, name: str, project: str, suite: T.List[str], exe: build.Executable,
depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]],
is_parallel: bool, cmd_args: T.List[str], env: build.EnvironmentVariables,
should_fail: bool, timeout: int, workdir: T.Optional[str], protocol: str,
priority: int):
InterpreterObject.__init__(self)
super().__init__()
self.name = name
self.suite = suite
self.project_name = project

@ -7,7 +7,7 @@ from .. import mlog
from ..mesonlib import unholder, MachineChoice, OptionKey
from ..programs import OverrideProgram, ExternalProgram
from ..interpreterbase import (InterpreterObject, FeatureNewKwargs, FeatureNew, FeatureDeprecated,
from ..interpreterbase import (MesonInterpreterObject, FeatureNewKwargs, FeatureNew, FeatureDeprecated,
typed_pos_args, permittedKwargs, noArgsFlattening, noPosargs, noKwargs,
MesonVersionString, InterpreterException)
@ -18,9 +18,12 @@ from .interpreterobjects import (ExecutableHolder, ExternalProgramHolder,
import typing as T
class MesonMain(InterpreterObject):
if T.TYPE_CHECKING:
from .interpreter import Interpreter
class MesonMain(MesonInterpreterObject):
def __init__(self, build: 'build.Build', interpreter: 'Interpreter'):
InterpreterObject.__init__(self)
super().__init__()
self.build = build
self.interpreter = interpreter
self.methods.update({'get_compiler': self.get_compiler_method,

@ -14,6 +14,7 @@
__all__ = [
'InterpreterObject',
'MesonInterpreterObject',
'ObjectHolder',
'RangeHolder',
'MesonVersionString',
@ -64,6 +65,7 @@ __all__ = [
from .baseobjects import (
InterpreterObject,
MesonInterpreterObject,
ObjectHolder,
RangeHolder,
MutableInterpreterObject,

@ -51,12 +51,15 @@ class InterpreterObject:
return method(args, kwargs)
raise InvalidCode('Unknown method "%s" in object.' % method_name)
class MesonInterpreterObject(InterpreterObject):
''' All non-elementary objects should be derived from this '''
class MutableInterpreterObject:
''' Dummy class to mark the object type as mutable '''
TV_InterpreterObject = T.TypeVar('TV_InterpreterObject')
class ObjectHolder(InterpreterObject, T.Generic[TV_InterpreterObject]):
class ObjectHolder(MesonInterpreterObject, T.Generic[TV_InterpreterObject]):
def __init__(self, obj: TV_InterpreterObject, *, subproject: T.Optional[str] = None) -> None:
super().__init__(subproject=subproject)
self.held_object = obj
@ -64,7 +67,7 @@ class ObjectHolder(InterpreterObject, T.Generic[TV_InterpreterObject]):
def __repr__(self) -> str:
return f'<Holder: {self.held_object!r}>'
class RangeHolder(InterpreterObject):
class RangeHolder(MesonInterpreterObject):
def __init__(self, start: int, stop: int, step: int, *, subproject: T.Optional[str] = None) -> None:
super().__init__(subproject=subproject)
self.range = range(start, stop, step)

@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .baseobjects import InterpreterObject
from .baseobjects import MesonInterpreterObject
import typing as T
class Disabler(InterpreterObject):
class Disabler(MesonInterpreterObject):
def __init__(self) -> None:
super().__init__()
self.methods.update({'found': self.found_method})

Loading…
Cancel
Save