aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/modules/__init__.py7
-rw-r--r--mesonbuild/modules/gnome.py20
-rw-r--r--mesonbuild/modules/qt.py21
-rw-r--r--mesonbuild/modules/unstable_external_project.py37
-rw-r--r--mesonbuild/modules/unstable_icestorm.py14
-rw-r--r--mesonbuild/modules/unstable_rust.py2
6 files changed, 47 insertions, 54 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py
index 5bae3a0..e95b9c6 100644
--- a/mesonbuild/modules/__init__.py
+++ b/mesonbuild/modules/__init__.py
@@ -33,6 +33,9 @@ class ModuleState:
"""
def __init__(self, interpreter: 'Interpreter') -> None:
+ # Keep it private, it should be accessed only through methods.
+ self._interpreter = interpreter
+
self.source_root = interpreter.environment.get_source_dir()
self.build_to_src = relpath(interpreter.environment.get_source_dir(),
interpreter.environment.get_build_dir())
@@ -82,6 +85,10 @@ class ModuleState:
return dirs_str
+ def find_program(self, prog: T.Union[str, T.List[str]], required: bool = True,
+ version_func: T.Optional[T.Callable[['ExternalProgram'], str]] = None,
+ wanted: T.Optional[str] = None) -> 'ExternalProgramHolder':
+ return self._interpreter.find_program_impl(prog, required=required)
class ModuleObject:
"""Base class for all objects returned by modules
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index d2b64dd..95860d6 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -125,7 +125,7 @@ class GnomeModule(ExtensionModule):
return ExternalProgram(name, value)
# Normal program lookup
- return unholder(self.interpreter.find_program_impl(name, required=required))
+ return unholder(state.find_program(name, required=required))
@permittedKwargs({'glib_compile_schemas', 'gio_querymodules', 'gtk_update_icon_cache'})
@noPosargs
@@ -167,7 +167,7 @@ class GnomeModule(ExtensionModule):
self.__print_gresources_warning(state)
glib_version = self._get_native_glib_version(state)
- glib_compile_resources = self.interpreter.find_program_impl('glib-compile-resources')
+ glib_compile_resources = state.find_program('glib-compile-resources')
cmd = [glib_compile_resources, '@INPUT@']
source_dirs, dependencies = [mesonlib.extract_as_list(kwargs, c, pop=True) for c in ['source_dir', 'dependencies']]
@@ -925,7 +925,7 @@ class GnomeModule(ExtensionModule):
srcdir = os.path.join(state.build_to_src, state.subdir)
outdir = state.subdir
- cmd = [self.interpreter.find_program_impl('glib-compile-schemas')]
+ cmd = [state.find_program('glib-compile-schemas')]
cmd += ['--targetdir', outdir, srcdir]
kwargs['command'] = cmd
kwargs['input'] = []
@@ -1067,7 +1067,7 @@ class GnomeModule(ExtensionModule):
'--mode=' + mode]
for tool in ['scan', 'scangobj', 'mkdb', 'mkhtml', 'fixxref']:
program_name = 'gtkdoc-' + tool
- program = self.interpreter.find_program_impl(program_name)
+ program = state.find_program(program_name)
path = program.held_object.get_path()
args.append(f'--{program_name}={path}')
if namespace:
@@ -1119,7 +1119,7 @@ class GnomeModule(ExtensionModule):
custom_target = build.CustomTarget(targetname, state.subdir, state.subproject, custom_kwargs)
alias_target = build.AliasTarget(targetname, [custom_target], state.subdir, state.subproject)
if kwargs.get('check', False):
- check_cmd = self.interpreter.find_program_impl('gtkdoc-check')
+ check_cmd = state.find_program('gtkdoc-check')
check_env = ['DOC_MODULE=' + modulename,
'DOC_MAIN_SGML_FILE=' + main_file]
check_args = [targetname + '-check', check_cmd]
@@ -1223,7 +1223,7 @@ class GnomeModule(ExtensionModule):
raise MesonException('gdbus_codegen takes at most two arguments, name and xml file.')
namebase = args[0]
xml_files = args[1:]
- cmd = [self.interpreter.find_program_impl('gdbus-codegen')]
+ cmd = [state.find_program('gdbus-codegen')]
extra_args = mesonlib.stringlistify(kwargs.pop('extra_args', []))
cmd += extra_args
# Autocleanup supported?
@@ -1393,7 +1393,7 @@ class GnomeModule(ExtensionModule):
elif arg not in known_custom_target_kwargs:
raise MesonException(
f'Mkenums does not take a {arg} keyword argument.')
- cmd = [self.interpreter.find_program_impl(['glib-mkenums', 'mkenums'])] + cmd
+ cmd = [state.find_program(['glib-mkenums', 'mkenums'])] + cmd
custom_kwargs = {}
for arg in known_custom_target_kwargs:
if arg in kwargs:
@@ -1590,7 +1590,7 @@ G_END_DECLS'''
new_genmarshal = mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.53.3')
- cmd = [self.interpreter.find_program_impl('glib-genmarshal')]
+ cmd = [state.find_program('glib-genmarshal')]
known_kwargs = ['internal', 'nostdinc', 'skip_source', 'stdinc',
'valist_marshallers', 'extra_args']
known_custom_target_kwargs = ['build_always', 'depends',
@@ -1733,9 +1733,9 @@ G_END_DECLS'''
source_dir = os.path.join(state.environment.get_source_dir(), state.subdir)
pkg_cmd, vapi_depends, vapi_packages, vapi_includes = self._extract_vapi_packages(state, kwargs)
if 'VAPIGEN' in os.environ:
- cmd = [self.interpreter.find_program_impl(os.environ['VAPIGEN'])]
+ cmd = [state.find_program(os.environ['VAPIGEN'])]
else:
- cmd = [self.interpreter.find_program_impl('vapigen')]
+ cmd = [state.find_program('vapigen')]
cmd += ['--quiet', '--library=' + library, '--directory=' + build_dir]
cmd += self._vapi_args_to_command('--vapidir=', 'vapi_dirs', kwargs)
cmd += self._vapi_args_to_command('--metadatadir=', 'metadata_dirs', kwargs)
diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py
index b03e750..dd69611 100644
--- a/mesonbuild/modules/qt.py
+++ b/mesonbuild/modules/qt.py
@@ -52,7 +52,7 @@ class QtBaseModule(ExtensionModule):
'compile_translations': self.compile_translations,
})
- def compilers_detect(self, qt_dep: 'QtBaseDependency') -> None:
+ def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None:
"""Detect Qt (4 or 5) moc, uic, rcc in the specified bindir or in PATH"""
# It is important that this list does not change order as the order of
# the returned ExternalPrograms will change as well
@@ -90,23 +90,22 @@ class QtBaseModule(ExtensionModule):
care = err
return care.split(' ')[-1].replace(')', '').strip()
- p = self.interpreter.find_program_impl(
- [b], required=False,
- version_func=get_version,
- wanted=wanted).held_object
+ p = state.find_program(b, required=False,
+ version_func=get_version,
+ wanted=wanted).held_object
if p.found():
setattr(self, name, p)
- def _detect_tools(self, env: 'Environment', method, required=True):
+ def _detect_tools(self, state, method, required=True):
if self.tools_detected:
return
self.tools_detected = True
mlog.log(f'Detecting Qt{self.qt_version} tools')
kwargs = {'required': required, 'modules': 'Core', 'method': method}
- qt = find_external_dependency(f'qt{self.qt_version}', env, kwargs)
+ qt = find_external_dependency(f'qt{self.qt_version}', state.environment, kwargs)
if qt.found():
# Get all tools and then make sure that they are the right version
- self.compilers_detect(qt)
+ self.compilers_detect(state, qt)
if version_compare(qt.version, '>=5.14.0'):
self.rcc_supports_depfiles = True
else:
@@ -180,7 +179,7 @@ class QtBaseModule(ExtensionModule):
if disabled:
mlog.log('qt.has_tools skipped: feature', mlog.bold(feature), 'disabled')
return False
- self._detect_tools(state.environment, method, required=False)
+ self._detect_tools(state, method, required=False)
for tool in (self.moc, self.uic, self.rcc, self.lrelease):
if not tool.found():
if required:
@@ -197,7 +196,7 @@ class QtBaseModule(ExtensionModule):
= [extract_as_list(kwargs, c, pop=True) for c in ['qresources', 'ui_files', 'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'sources', 'include_directories', 'dependencies']]
sources += args[1:]
method = kwargs.get('method', 'auto')
- self._detect_tools(state.environment, method)
+ self._detect_tools(state, method)
err_msg = "{0} sources specified and couldn't find {1}, " \
"please check your qt{2} installation"
if (moc_headers or moc_sources) and not self.moc.found():
@@ -297,7 +296,7 @@ class QtBaseModule(ExtensionModule):
else:
raise MesonException(f'qt.compile_translations: qresource can only contain qm files, found {c}')
results = self.preprocess(state, [], {'qresources': qresource, 'rcc_extra_arguments': kwargs.get('rcc_extra_arguments', [])})
- self._detect_tools(state.environment, kwargs.get('method', 'auto'))
+ self._detect_tools(state, kwargs.get('method', 'auto'))
translations = []
for ts in ts_files:
if not self.lrelease.found():
diff --git a/mesonbuild/modules/unstable_external_project.py b/mesonbuild/modules/unstable_external_project.py
index 18b1931..a721b30 100644
--- a/mesonbuild/modules/unstable_external_project.py
+++ b/mesonbuild/modules/unstable_external_project.py
@@ -30,13 +30,7 @@ from ..mesonlib import OptionKey
class ExternalProject(ModuleObject):
def __init__(self,
- interpreter: Interpreter,
- subdir: str,
- project_version: T.Dict[str, str],
- subproject: str,
- environment: Environment,
- build_machine: str,
- host_machine: str,
+ state: ModuleState,
configure_command: str,
configure_options: T.List[str],
cross_configure_options: T.List[str],
@@ -46,13 +40,12 @@ class ExternalProject(ModuleObject):
self.methods.update({'dependency': self.dependency_method,
})
- self.interpreter = interpreter
- self.subdir = Path(subdir)
- self.project_version = project_version
- self.subproject = subproject
- self.env = environment
- self.build_machine = build_machine
- self.host_machine = host_machine
+ self.subdir = Path(state.subdir)
+ self.project_version = state.project_version
+ self.subproject = state.subproject
+ self.env = state.environment
+ self.build_machine = state.build_machine
+ self.host_machine = state.host_machine
self.configure_command = configure_command
self.configure_options = configure_options
self.cross_configure_options = cross_configure_options
@@ -76,18 +69,18 @@ class ExternalProject(ModuleObject):
# self.prefix is an absolute path, so we cannot append it to another path.
self.rel_prefix = self.prefix.relative_to(self.prefix.root)
- self.make = self.interpreter.find_program_impl('make')
+ self.make = state.find_program('make')
self.make = self.make.get_command()[0]
- self._configure()
+ self._configure(state)
self.targets = self._create_targets()
- def _configure(self):
+ def _configure(self, state: ModuleState):
# Assume it's the name of a script in source dir, like 'configure',
# 'autogen.sh', etc).
configure_path = Path(self.src_dir, self.configure_command)
- configure_prog = self.interpreter.find_program_impl(configure_path.as_posix())
+ configure_prog = state.find_program(configure_path.as_posix())
configure_cmd = configure_prog.get_command()
d = [('PREFIX', '--prefix=@PREFIX@', self.prefix.as_posix()),
@@ -265,13 +258,7 @@ class ExternalProjectModule(ExtensionModule):
cross_configure_options = ['--host=@HOST@']
verbose = kwargs.get('verbose', False)
env = self.interpreter.unpack_env_kwarg(kwargs)
- project = ExternalProject(self.interpreter,
- state.subdir,
- state.project_version,
- state.subproject,
- state.environment,
- state.build_machine,
- state.host_machine,
+ project = ExternalProject(state,
configure_command,
configure_options,
cross_configure_options,
diff --git a/mesonbuild/modules/unstable_icestorm.py b/mesonbuild/modules/unstable_icestorm.py
index be83885..841e647 100644
--- a/mesonbuild/modules/unstable_icestorm.py
+++ b/mesonbuild/modules/unstable_icestorm.py
@@ -28,16 +28,16 @@ class IceStormModule(ExtensionModule):
'project': self.project,
})
- def detect_binaries(self, interpreter):
- self.yosys_bin = interpreter.find_program_impl(['yosys'])
- self.arachne_bin = interpreter.find_program_impl(['arachne-pnr'])
- self.icepack_bin = interpreter.find_program_impl(['icepack'])
- self.iceprog_bin = interpreter.find_program_impl(['iceprog'])
- self.icetime_bin = interpreter.find_program_impl(['icetime'])
+ def detect_binaries(self, state):
+ self.yosys_bin = state.find_program('yosys')
+ self.arachne_bin = state.find_program('arachne-pnr')
+ self.icepack_bin = state.find_program('icepack')
+ self.iceprog_bin = state.find_program('iceprog')
+ self.icetime_bin = state.find_program('icetime')
def project(self, state, args, kwargs):
if not self.yosys_bin:
- self.detect_binaries(self.interpreter)
+ self.detect_binaries(state)
if not args:
raise mesonlib.MesonException('Project requires at least one argument, which is the project name.')
proj_name = args[0]
diff --git a/mesonbuild/modules/unstable_rust.py b/mesonbuild/modules/unstable_rust.py
index 30dea9f..1418309 100644
--- a/mesonbuild/modules/unstable_rust.py
+++ b/mesonbuild/modules/unstable_rust.py
@@ -178,7 +178,7 @@ class RustModule(ExtensionModule):
if self._bindgen_bin is None:
# there's some bugs in the interpreter typeing.
- self._bindgen_bin = T.cast('ExternalProgram', self.interpreter.find_program_impl(['bindgen']).held_object)
+ self._bindgen_bin = T.cast('ExternalProgram', state.find_program('bindgen').held_object)
name: str
if isinstance(header, File):