interpreter: Add FileHolder and remove specical case for File

pull/8903/head
Daniel Mensinger 3 years ago
parent 7be172fe16
commit d601227cb2
  1. 10
      mesonbuild/interpreter/interpreter.py
  2. 4
      mesonbuild/interpreter/interpreterobjects.py
  3. 4
      mesonbuild/interpreterbase/interpreterbase.py

@ -46,7 +46,7 @@ from .interpreterobjects import (SubprojectHolder, MachineHolder, EnvironmentVar
SharedModuleHolder, HeadersHolder, BothLibrariesHolder,
BuildTargetHolder, DataHolder, JarHolder, Test, RunProcess,
ManHolder, GeneratorHolder, InstallDirHolder, extract_required_kwarg,
extract_search_dirs, MutableModuleObjectHolder)
extract_search_dirs, MutableModuleObjectHolder, FileHolder)
from .dependencyfallbacks import DependencyFallbacksHolder
from pathlib import Path
@ -64,7 +64,7 @@ if T.TYPE_CHECKING:
from . import kwargs
# Input source types passed to Targets
SourceInputs = T.Union[mesonlib.File, GeneratedListHolder, TargetHolder,
SourceInputs = T.Union[FileHolder, GeneratedListHolder, TargetHolder,
CustomTargetIndexHolder, GeneratedObjectsHolder, str]
# Input source types passed to the build.Target5 classes
SourceOutputs = T.Union[mesonlib.File, build.GeneratedList,
@ -394,7 +394,7 @@ class Interpreter(InterpreterBase):
if isinstance(item, build.CustomTarget):
return CustomTargetHolder(item, self)
elif isinstance(item, (int, str, bool, InterpreterObject, mesonlib.File)) or item is None:
elif isinstance(item, (int, str, bool, InterpreterObject)) or item is None:
return item
elif isinstance(item, build.Executable):
return ExecutableHolder(item, self)
@ -414,8 +414,8 @@ class Interpreter(InterpreterBase):
return MutableModuleObjectHolder(item, self)
elif isinstance(item, ModuleObject):
return ModuleObjectHolder(item, self)
elif isinstance(item, InterpreterObject):
return item
elif isinstance(item, mesonlib.File):
return FileHolder(item)
else:
raise InterpreterException('Module returned a value of unknown type.')

@ -662,6 +662,10 @@ class IncludeDirsHolder(ObjectHolder[build.IncludeDirs]):
def __init__(self, idobj: build.IncludeDirs):
super().__init__(idobj)
class FileHolder(ObjectHolder[mesonlib.File]):
def __init__(self, fobj: mesonlib.File):
super().__init__(fobj)
class HeadersHolder(ObjectHolder[build.Headers]):
def __init__(self, obj: build.Headers):
super().__init__(obj)

@ -545,8 +545,6 @@ The result of this is undefined and will become a hard error in a future Meson r
return self.array_method_call(obj, method_name, args, kwargs)
if isinstance(obj, dict):
return self.dict_method_call(obj, method_name, args, kwargs)
if isinstance(obj, mesonlib.File):
raise InvalidArguments('File object "%s" is not callable.' % obj)
if not isinstance(obj, InterpreterObject):
raise InvalidArguments('Variable "%s" is not callable.' % object_name)
# Special case. This is the only thing you can do with a disabler
@ -867,7 +865,7 @@ To specify a keyword argument, use : instead of =.''')
def is_assignable(self, value: T.Any) -> bool:
return isinstance(value, (InterpreterObject, dependencies.Dependency,
str, int, list, dict, mesonlib.File))
str, int, list, dict))
def validate_extraction(self, buildtarget: InterpreterObject) -> None:
raise InterpreterException('validate_extraction is not implemented in this context (please file a bug)')

Loading…
Cancel
Save