modules: Add methods dict everywhere

This fix calling random internal methods from meson.build as long as
they were not prefixed by underscore.
pull/8811/head
Xavier Claessens 4 years ago committed by Xavier Claessens
parent a734bcfc83
commit 2e02ef6592
  1. 7
      mesonbuild/interpreter/interpreterobjects.py
  2. 4
      mesonbuild/modules/__init__.py
  3. 6
      mesonbuild/modules/cmake.py
  4. 3
      mesonbuild/modules/dlang.py
  5. 17
      mesonbuild/modules/fs.py
  6. 14
      mesonbuild/modules/gnome.py
  7. 4
      mesonbuild/modules/hotdoc.py
  8. 6
      mesonbuild/modules/i18n.py
  9. 3
      mesonbuild/modules/keyval.py
  10. 5
      mesonbuild/modules/modtest.py
  11. 5
      mesonbuild/modules/pkgconfig.py
  12. 3
      mesonbuild/modules/python.py
  13. 6
      mesonbuild/modules/python3.py
  14. 5
      mesonbuild/modules/qt.py
  15. 26
      mesonbuild/modules/rpm.py
  16. 3
      mesonbuild/modules/sourceset.py
  17. 3
      mesonbuild/modules/unstable_icestorm.py
  18. 4
      mesonbuild/modules/unstable_rust.py
  19. 3
      mesonbuild/modules/unstable_simd.py
  20. 5
      mesonbuild/modules/windows.py

@ -789,13 +789,8 @@ class ModuleObjectHolder(InterpreterObject, ObjectHolder['ModuleObject']):
def method_call(self, method_name, args, kwargs):
modobj = self.held_object
method = modobj.methods.get(method_name)
if not method and not modobj.methods:
# FIXME: Port all modules to use the methods dict.
method = getattr(modobj, method_name, None)
if method_name.startswith('_'):
raise InvalidArguments(f'Method {method_name!r} is private.')
if not method:
raise InvalidCode('Unknown method "%s" in object.' % method_name)
raise InvalidCode(f'Unknown method {method_name!r} in object.')
if not getattr(method, 'no-args-flattening', False):
args = flatten(args)
state = ModuleState(self.interpreter)

@ -87,7 +87,7 @@ class ModuleObject:
"""Base class for all objects returned by modules
"""
def __init__(self) -> None:
self.methods = {} # type: T.Dict[str, T.Callable[[T.List[TYPE_nvar], TYPE_nkwargs], TYPE_var]]
self.methods = {} # type: T.Dict[str, T.Callable[[ModuleState, T.List[TYPE_nvar], TYPE_nkwargs], T.Union[ModuleReturnValue, TYPE_var]]]
class MutableModuleObject(ModuleObject):
pass
@ -112,7 +112,7 @@ def is_module_library(fname):
class ModuleReturnValue:
def __init__(self, return_value: 'TYPE_var', new_objects: T.List['TYPE_var']) -> None:
def __init__(self, return_value: T.Optional['TYPE_var'], new_objects: T.List['TYPE_var']) -> None:
self.return_value = return_value
assert(isinstance(new_objects, list))
self.new_objects = new_objects

@ -212,6 +212,12 @@ class CmakeModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'write_basic_package_version_file': self.write_basic_package_version_file,
'configure_package_config_file': self.configure_package_config_file,
'subproject': self.subproject,
'subproject_options': self.subproject_options,
})
def detect_voidp_size(self, env):
compilers = env.coredata.compilers.host

@ -36,6 +36,9 @@ class DlangModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'generate_dub_file': self.generate_dub_file,
})
def _init_dub(self):
if DlangModule.class_dubbin is None:

@ -36,6 +36,23 @@ class FSModule(ExtensionModule):
def __init__(self, interpreter: 'Interpreter') -> None:
super().__init__(interpreter)
self.methods.update({
'expanduser': self.expanduser,
'is_absolute': self.is_absolute,
'as_posix': self.as_posix,
'exists': self.exists,
'is_symlink': self.is_symlink,
'is_file': self.is_file,
'is_dir': self.is_dir,
'hash': self.hash,
'size': self.size,
'is_samepath': self.is_samepath,
'replace_suffix': self.replace_suffix,
'parent': self.parent,
'name': self.name,
'stem': self.stem,
'read': self.read,
})
def _absolute_dir(self, state: 'ModuleState', arg: 'FileOrString') -> Path:
"""

@ -57,6 +57,20 @@ class GnomeModule(ExtensionModule):
self.install_gio_querymodules = []
self.install_gtk_update_icon_cache = False
self.devenv = None
self.methods.update({
'post_install': self.post_install,
'compile_resources': self.compile_resources,
'generate_gir': self.generate_gir,
'compile_schemas': self.compile_schemas,
'yelp': self.yelp,
'gtkdoc': self.gtkdoc,
'gtkdoc_html_dir': self.gtkdoc_html_dir,
'gdbus_codegen': self.gdbus_codegen,
'mkenums': self.mkenums,
'mkenums_simple': self.mkenums_simple,
'genmarshal': self.genmarshal,
'generate_vapi': self.generate_vapi,
})
@staticmethod
def _get_native_glib_version(state):

@ -405,6 +405,10 @@ class HotDocModule(ExtensionModule):
except Exception as e:
raise MesonException('hotdoc {} required but not found. ({})'.format(
MIN_HOTDOC_VERSION, e))
self.methods.update({
'has_extensions': self.has_extensions,
'generate_doc': self.generate_doc,
})
@noKwargs
def has_extensions(self, state, args, kwargs):

@ -57,6 +57,12 @@ PRESET_ARGS = {
class I18nModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'merge_file': self.merge_file,
'gettext': self.gettext,
})
@staticmethod
def nogettext_warning():

@ -25,6 +25,9 @@ class KeyvalModule(ExtensionModule):
@FeatureNew('Keyval Module', '0.55.0')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.methods.update({
'load': self.load,
})
def _load_file(self, path_to_config):
result = dict()

@ -16,6 +16,11 @@ from . import ExtensionModule
from ..interpreterbase import noKwargs
class TestModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'print_hello': self.print_hello,
})
@noKwargs
def print_hello(self, state, args, kwargs):

@ -280,6 +280,11 @@ class DependenciesHelper:
self.cflags = _fn(self.cflags)
class PkgConfigModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'generate': self.generate,
})
def _get_lname(self, l, msg, pcfile, is_custom_target):
if is_custom_target:

@ -473,6 +473,9 @@ class PythonModule(ExtensionModule):
@FeatureNew('Python Module', '0.46.0')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.methods.update({
'find_installation': self.find_installation,
})
# https://www.python.org/dev/peps/pep-0397/
def _get_win_pythonpath(self, name_or_path):

@ -25,6 +25,12 @@ class Python3Module(ExtensionModule):
@FeatureDeprecated('python3 module', '0.48.0')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.methods.update({
'extension_module': self.extension_module,
'find_python': self.find_python,
'language_version': self.language_version,
'sysconfig_path': self.sysconfig_path,
})
@permittedKwargs(known_shmod_kwargs)
def extension_module(self, state, args, kwargs):

@ -46,6 +46,11 @@ class QtBaseModule(ExtensionModule):
self.uic: 'ExternalProgram' = NonExistingExternalProgram('uic')
self.rcc: 'ExternalProgram' = NonExistingExternalProgram('rcc')
self.lrelease: 'ExternalProgram' = NonExistingExternalProgram('lrelease')
self.methods.update({
'has_tools': self.has_tools,
'preprocess': self.preprocess,
'compile_translations': self.compile_translations,
})
def compilers_detect(self, qt_dep: 'QtBaseDependency') -> None:
"""Detect Qt (4 or 5) moc, uic, rcc in the specified bindir or in PATH"""

@ -26,18 +26,22 @@ from ..interpreterbase import noKwargs
import os
class RPMModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'generate_spec_template': self.generate_spec_template,
})
@noKwargs
def generate_spec_template(self, coredata, args, kwargs):
self.coredata = coredata
required_compilers = self.__get_required_compilers()
proj = coredata.project_name.replace(' ', '_').replace('\t', '_')
def generate_spec_template(self, state, args, kwargs):
required_compilers = self.__get_required_compilers(state)
proj = state.project_name.replace(' ', '_').replace('\t', '_')
so_installed = False
devel_subpkg = False
files = set()
files_devel = set()
to_delete = set()
for target in coredata.targets.values():
for target in state.targets.values():
if isinstance(target, build.Executable) and target.need_install:
files.add('%%{_bindir}/%s' % target.get_filename())
elif isinstance(target, build.SharedLibrary) and target.need_install:
@ -56,13 +60,13 @@ class RPMModule(ExtensionModule):
files_devel.add('%%{_datadir}/gir-1.0/%s' % target.get_filename()[0])
elif isinstance(target, TypelibTarget) and target.should_install():
files.add('%%{_libdir}/girepository-1.0/%s' % target.get_filename()[0])
for header in coredata.headers:
for header in state.headers:
if header.get_install_subdir():
files_devel.add('%%{_includedir}/%s/' % header.get_install_subdir())
else:
for hdr_src in header.get_sources():
files_devel.add('%%{_includedir}/%s' % hdr_src)
for man in coredata.man:
for man in state.man:
for man_file in man.get_sources():
if man.locale:
files.add('%%{_mandir}/%s/man%u/%s.*' % (man.locale, int(man_file.split('.')[-1]), man_file))
@ -71,7 +75,7 @@ class RPMModule(ExtensionModule):
if files_devel:
devel_subpkg = True
filename = os.path.join(coredata.environment.get_build_dir(),
filename = os.path.join(state.environment.get_build_dir(),
'%s.spec' % proj)
with open(filename, 'w+') as fn:
fn.write('Name: %s\n' % proj)
@ -85,7 +89,7 @@ class RPMModule(ExtensionModule):
fn.write('BuildRequires: meson\n')
for compiler in required_compilers:
fn.write('BuildRequires: %s\n' % compiler)
for dep in coredata.environment.coredata.deps.host:
for dep in state.environment.coredata.deps.host:
fn.write('BuildRequires: pkgconfig(%s)\n' % dep[0])
# ext_libs and ext_progs have been removed from coredata so the following code
# no longer works. It is kept as a reminder of the idea should anyone wish
@ -150,9 +154,9 @@ class RPMModule(ExtensionModule):
fn.write('\n')
mlog.log('RPM spec template written to %s.spec.\n' % proj)
def __get_required_compilers(self):
def __get_required_compilers(self, state):
required_compilers = set()
for compiler in self.coredata.environment.coredata.compilers.host.values():
for compiler in state.environment.coredata.compilers.host.values():
# Elbrus has one 'lcc' package for every compiler
if isinstance(compiler, compilers.GnuCCompiler):
required_compilers.add('gcc')

@ -189,6 +189,9 @@ class SourceSetModule(ExtensionModule):
@FeatureNew('SourceSet module', '0.51.0')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.methods.update({
'source_set': self.source_set,
})
@noKwargs
@noPosargs

@ -24,6 +24,9 @@ class IceStormModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.yosys_bin = None
self.methods.update({
'project': self.project,
})
def detect_binaries(self, interpreter):
self.yosys_bin = interpreter.find_program_impl(['yosys'])

@ -38,6 +38,10 @@ class RustModule(ExtensionModule):
def __init__(self, interpreter: 'Interpreter') -> None:
super().__init__(interpreter)
self._bindgen_bin: T.Optional['ExternalProgram'] = None
self.methods.update({
'test': self.test,
'bindgen': self.bindgen,
})
@permittedKwargs(permitted_test_kwargs | {'dependencies'} ^ {'protocol'})
@typed_pos_args('rust.test', str, BuildTargetHolder)

@ -35,6 +35,9 @@ class SimdModule(ExtensionModule):
'avx2',
'neon',
)
self.methods.update({
'check': self.check,
})
def check(self, state, args, kwargs):
result = []

@ -30,6 +30,11 @@ class ResourceCompilerType(enum.Enum):
rc = 2
class WindowsModule(ExtensionModule):
def __init__(self, interpreter):
super().__init__(interpreter)
self.methods.update({
'compile_resources': self.compile_resources,
})
def detect_compiler(self, compilers):
for l in ('c', 'cpp'):

Loading…
Cancel
Save