diff options
| author | Xavier Claessens <xclaessens@netflix.com> | 2025-10-11 18:03:31 -0400 |
|---|---|---|
| committer | Xavier Claessens <xclaesse@gmail.com> | 2025-10-15 12:15:39 -0400 |
| commit | 4795475595ef6b87074df9e38d09a3dff2690396 (patch) | |
| tree | 795cc50e4baffd80dbd2673407c590a8c6af78a6 /mesonbuild/modules | |
| parent | 76facd5f717e152d64bfeeadc6217686304c5000 (diff) | |
| download | meson-4795475595ef6b87074df9e38d09a3dff2690396.tar.gz | |
Add support for LocalProgram to override_find_program()
Diffstat (limited to 'mesonbuild/modules')
| -rw-r--r-- | mesonbuild/modules/__init__.py | 6 | ||||
| -rw-r--r-- | mesonbuild/modules/_qt.py | 34 | ||||
| -rw-r--r-- | mesonbuild/modules/dlang.py | 4 | ||||
| -rw-r--r-- | mesonbuild/modules/gnome.py | 19 | ||||
| -rw-r--r-- | mesonbuild/modules/i18n.py | 2 | ||||
| -rw-r--r-- | mesonbuild/modules/icestorm.py | 2 | ||||
| -rw-r--r-- | mesonbuild/modules/rust.py | 8 | ||||
| -rw-r--r-- | mesonbuild/modules/wayland.py | 4 |
8 files changed, 47 insertions, 32 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 87892e6d7..f306f3ca5 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -75,14 +75,14 @@ class ModuleState: required: bool = True, version_func: T.Optional[ProgramVersionFunc] = None, wanted: T.Union[str, T.List[str]] = '', silent: bool = False, - for_machine: MachineChoice = MachineChoice.HOST) -> T.Union[ExternalProgram, build.OverrideExecutable, OverrideProgram]: + for_machine: MachineChoice = MachineChoice.HOST) -> T.Union[ExternalProgram, build.OverrideExecutable, OverrideProgram, build.LocalProgram]: if not isinstance(prog, list): prog = [prog] return self._interpreter.find_program_impl(prog, required=required, version_func=version_func, wanted=wanted, silent=silent, for_machine=for_machine) def find_tool(self, name: str, depname: str, varname: str, required: bool = True, - wanted: T.Optional[str] = None) -> T.Union[build.OverrideExecutable, ExternalProgram, 'OverrideProgram']: + wanted: T.Optional[str] = None) -> T.Union[build.OverrideExecutable, ExternalProgram, OverrideProgram, build.LocalProgram]: # Look in overrides in case it's built as subproject progobj = self._interpreter.program_from_overrides([name], []) if progobj is not None: @@ -118,7 +118,7 @@ class ModuleState: # implementations of meson functions anyway. return self._interpreter.func_dependency(self.current_node, [depname], kwargs) # type: ignore - def test(self, args: T.Tuple[str, T.Union[build.Executable, build.Jar, 'ExternalProgram', mesonlib.File]], + def test(self, args: T.Tuple[str, T.Union[build.Executable, build.Jar, ExternalProgram, build.LocalProgram, mesonlib.File]], workdir: T.Optional[str] = None, env: T.Union[T.List[str], T.Dict[str, str], str] = None, depends: T.List[T.Union[build.CustomTarget, build.BuildTarget]] = None) -> None: diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index 675c174a7..85aab1829 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py @@ -208,7 +208,7 @@ class QtBaseModule(ExtensionModule): self.qt_version = qt_version # It is important that this list does not change order as the order of # the returned ExternalPrograms will change as well - self.tools: T.Dict[str, T.Union[ExternalProgram, build.Executable]] = { + self.tools: T.Dict[str, T.Union[ExternalProgram, build.Executable, build.LocalProgram]] = { tool: NonExistingExternalProgram(tool) for tool in self._set_of_qt_tools } self.methods.update({ @@ -445,12 +445,17 @@ class QtBaseModule(ExtensionModule): for s in sources: qrc_deps.extend(self._parse_qrc_deps(state, s)) + cmd: T.List[T.Union[ExternalProgram, build.Executable, build.LocalProgram, str]] + cmd = [self.tools['rcc'], '-name', name, '-o', '@OUTPUT@'] + cmd.extend(extra_args) + cmd.append('@INPUT@') + cmd.extend(DEPFILE_ARGS) res_target = build.CustomTarget( name, state.subdir, state.subproject, state.environment, - self.tools['rcc'].get_command() + ['-name', name, '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS, + cmd, sources, [f'{name}.cpp'], depend_files=qrc_deps, @@ -466,12 +471,16 @@ class QtBaseModule(ExtensionModule): else: basename = os.path.basename(rcc_file.fname) name = f'qt{self.qt_version}-{basename.replace(".", "_")}' + cmd = [self.tools['rcc'], '-name', '@BASENAME@', '-o', '@OUTPUT@'] + cmd.extend(extra_args) + cmd.append('@INPUT@') + cmd.extend(DEPFILE_ARGS) res_target = build.CustomTarget( name, state.subdir, state.subproject, state.environment, - self.tools['rcc'].get_command() + ['-name', '@BASENAME@', '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS, + cmd, [rcc_file], [f'{name}.cpp'], depend_files=qrc_deps, @@ -724,7 +733,7 @@ class QtBaseModule(ExtensionModule): ts = os.path.basename(ts) else: outdir = state.subdir - cmd: T.List[T.Union[ExternalProgram, build.Executable, str]] = [self.tools['lrelease'], '@INPUT@', '-qm', '@OUTPUT@'] + cmd: T.List[T.Union[ExternalProgram, build.Executable, build.LocalProgram, str]] = [self.tools['lrelease'], '@INPUT@', '-qm', '@OUTPUT@'] lrelease_target = build.CustomTarget( f'qt{self.qt_version}-compile-{ts}', outdir, @@ -864,12 +873,15 @@ class QtBaseModule(ExtensionModule): input_args.append(f'@INPUT{input_counter}@') input_counter += 1 + cmd: T.List[T.Union[ExternalProgram, build.Executable, build.LocalProgram, str]] + cmd = [self.tools['moc'], '--collect-json', '-o', '@OUTPUT@'] + cmd.extend(input_args) return build.CustomTarget( f'moc_collect_json_{target_name}', state.subdir, state.subproject, state.environment, - self.tools['moc'].get_command() + ['--collect-json', '-o', '@OUTPUT@'] + input_args, + cmd, moc_json, [f'{target_name}_json_collect.json'], description=f'Collecting json type information for {target_name}', @@ -908,12 +920,17 @@ class QtBaseModule(ExtensionModule): ressource_path = os.path.join('/', kwargs['module_prefix'], source_basename) cachegen_inputs.append(ressource_path) + cmd: T.List[T.Union[ExternalProgram, build.Executable, build.LocalProgram, str]] + cmd = [self.tools['qmlcachegen'], '-o', '@OUTPUT@', '--resource-name', f'qmlcache_{target_name}'] + cmd.extend(kwargs['extra_args']) + cmd.append('--resource=@INPUT@') + cmd.extend(cachegen_inputs) cacheloader_target = build.CustomTarget( f'cacheloader_{target_name}', state.subdir, state.subproject, state.environment, - self.tools['qmlcachegen'].get_command() + ['-o', '@OUTPUT@'] + ['--resource-name', f'qmlcache_{target_name}'] + kwargs['extra_args'] + ['--resource=@INPUT@'] + cachegen_inputs, + cmd, [kwargs['qml_qrc']], #output name format matters here [f'{target_name}_qmlcache_loader.cpp'], @@ -941,11 +958,12 @@ class QtBaseModule(ExtensionModule): install_dir: T.List[T.Union[str, Literal[False]]] = [False] install_tag: T.List[T.Union[str, None]] = [None] - cmd = self.tools['qmltyperegistrar'].get_command() + [ + cmd = [ + self.tools['qmltyperegistrar'], '--import-name', import_name, '--major-version', major_version, '--minor-version', minor_version, - '-o', '@OUTPUT0@', + '-o', '@OUTPUT0@' ] cmd.extend(kwargs['extra_args']) diff --git a/mesonbuild/modules/dlang.py b/mesonbuild/modules/dlang.py index 35ce86be8..6d35e30ac 100644 --- a/mesonbuild/modules/dlang.py +++ b/mesonbuild/modules/dlang.py @@ -12,7 +12,7 @@ import typing as T from . import ExtensionModule, ModuleInfo from .. import mlog -from ..build import InvalidArguments +from ..build import InvalidArguments, LocalProgram from ..dependencies import Dependency from ..dependencies.dub import DubDependency from ..interpreterbase import typed_pos_args @@ -27,7 +27,7 @@ if T.TYPE_CHECKING: from ..interpreterbase.baseobjects import TYPE_kwargs from ..programs import ExternalProgram, OverrideProgram - _AnyProgram: TypeAlias = T.Union[OverrideExecutable, ExternalProgram, OverrideProgram] + _AnyProgram: TypeAlias = T.Union[OverrideExecutable, ExternalProgram, OverrideProgram, LocalProgram] _JSONTypes: TypeAlias = T.Union[str, int, bool, None, T.List['_JSONTypes'], T.Dict[str, '_JSONTypes']] diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 9e525601e..b4d4265b8 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -22,7 +22,7 @@ from .. import build from .. import interpreter from .. import mesonlib from .. import mlog -from ..build import CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments +from ..build import CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments, LocalProgram from ..dependencies import Dependency, InternalDependency from ..dependencies.pkgconfig import PkgConfigDependency, PkgConfigInterface from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, ENV_KW, INSTALL_DIR_KW, INSTALL_KW, NoneType, DEPENDENCY_SOURCES_KW, in_set_validator @@ -198,7 +198,7 @@ if T.TYPE_CHECKING: vtail: T.Optional[str] depends: T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]] - ToolType: TypeAlias = T.Union[Executable, ExternalProgram, OverrideProgram] + ToolType: TypeAlias = T.Union[Executable, ExternalProgram, LocalProgram] # Differs from the CustomTarget version in that it straight defaults to True @@ -789,8 +789,7 @@ class GnomeModule(ExtensionModule): if self.devenv is not None: b.devenv.append(self.devenv) - def _get_gir_dep(self, state: 'ModuleState') -> T.Tuple[Dependency, T.Union[Executable, 'ExternalProgram', 'OverrideProgram'], - T.Union[Executable, 'ExternalProgram', 'OverrideProgram']]: + def _get_gir_dep(self, state: 'ModuleState') -> T.Tuple[Dependency, ToolType, ToolType]: if not self.gir_dep: self.gir_dep = state.dependency('gobject-introspection-1.0') self.giscanner = self._find_tool(state, 'g-ir-scanner') @@ -971,7 +970,7 @@ class GnomeModule(ExtensionModule): self, state: 'ModuleState', girfile: str, - scan_command: T.Sequence[T.Union['FileOrString', Executable, ExternalProgram, OverrideProgram]], + scan_command: T.Sequence[T.Union['FileOrString', Executable, ToolType]], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.GeneratedTypes]], depends: T.Sequence[T.Union['FileOrString', build.BuildTarget, 'build.GeneratedTypes', build.StructuredSources]], env_flags: T.Sequence[str], @@ -1020,7 +1019,7 @@ class GnomeModule(ExtensionModule): @staticmethod def _make_typelib_target(state: 'ModuleState', typelib_output: str, - typelib_cmd: T.Sequence[T.Union[str, Executable, ExternalProgram, CustomTarget]], + typelib_cmd: T.Sequence[T.Union[str, CustomTarget, ToolType]], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.GeneratedTypes]], kwargs: T.Dict[str, T.Any]) -> TypelibTarget: install = kwargs['install_typelib'] @@ -1194,7 +1193,7 @@ class GnomeModule(ExtensionModule): gir_inc_dirs: T.List[str] = [] - scan_command: T.List[T.Union[str, Executable, 'ExternalProgram', 'OverrideProgram']] = [giscanner] + scan_command: T.List[T.Union[str, ToolType]] = [giscanner] scan_command += ['--quiet'] scan_command += ['--no-libtool'] scan_command += ['--namespace=' + ns, '--nsversion=' + nsversion] @@ -1347,7 +1346,7 @@ class GnomeModule(ExtensionModule): pot_file = os.path.join('@SOURCE_ROOT@', state.subdir, 'C', project_id + '.pot') pot_sources = [os.path.join('@SOURCE_ROOT@', state.subdir, 'C', s) for s in sources] - pot_args: T.List[T.Union[ExternalProgram, Executable, OverrideProgram, str]] = [itstool, '-o', pot_file] + pot_args: T.List[T.Union[ToolType, str]] = [itstool, '-o', pot_file] pot_args.extend(pot_sources) pottarget = build.RunTarget(f'help-{project_id}-pot', pot_args, [], os.path.join(state.subdir, 'C'), state.subproject, @@ -1379,7 +1378,7 @@ class GnomeModule(ExtensionModule): targets.append(l_data) po_file = l + '.po' - po_args: T.List[T.Union[ExternalProgram, Executable, OverrideProgram, str]] = [ + po_args: T.List[T.Union[ToolType, str]] = [ msgmerge, '-q', '-o', os.path.join('@SOURCE_ROOT@', l_subdir, po_file), os.path.join('@SOURCE_ROOT@', l_subdir, po_file), pot_file] @@ -2242,7 +2241,7 @@ class GnomeModule(ExtensionModule): build_dir = os.path.join(state.environment.get_build_dir(), state.subdir) source_dir = os.path.join(state.environment.get_source_dir(), state.subdir) pkg_cmd, vapi_depends, vapi_packages, vapi_includes, packages = self._extract_vapi_packages(state, kwargs['packages']) - cmd: T.List[T.Union[ExternalProgram, Executable, OverrideProgram, str]] + cmd: T.List[T.Union[ToolType, str]] cmd = [state.find_program('vapigen'), '--quiet', f'--library={library}', f'--directory={build_dir}'] cmd.extend([f'--vapidir={d}' for d in kwargs['vapi_dirs']]) cmd.extend([f'--metadatadir={d}' for d in kwargs['metadata_dirs']]) diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 2d8d04d3e..b3779f968 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -259,7 +259,7 @@ class I18nModule(ExtensionModule): 'itstool_join': self.itstool_join, 'xgettext': self.xgettext, }) - self.tools: T.Dict[str, T.Optional[T.Union[ExternalProgram, build.Executable]]] = { + self.tools: T.Dict[str, T.Optional[T.Union[ExternalProgram, build.Executable, build.LocalProgram]]] = { 'itstool': None, 'msgfmt': None, 'msginit': None, diff --git a/mesonbuild/modules/icestorm.py b/mesonbuild/modules/icestorm.py index 18bf0e202..a2a947d7f 100644 --- a/mesonbuild/modules/icestorm.py +++ b/mesonbuild/modules/icestorm.py @@ -29,7 +29,7 @@ class IceStormModule(ExtensionModule): def __init__(self, interpreter: Interpreter) -> None: super().__init__(interpreter) - self.tools: T.Dict[str, T.Union[ExternalProgram, build.Executable]] = {} + self.tools: T.Dict[str, T.Union[ExternalProgram, build.Executable, build.LocalProgram]] = {} self.methods.update({ 'project': self.project, }) diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index afcad98df..cd61b776d 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -13,7 +13,7 @@ from mesonbuild.interpreterbase.decorators import FeatureNew from . import ExtensionModule, ModuleReturnValue, ModuleInfo from .. import mesonlib, mlog from ..build import (BothLibraries, BuildTarget, CustomTargetIndex, Executable, ExtractedObjects, GeneratedList, - CustomTarget, InvalidArguments, Jar, StructuredSources, SharedLibrary, StaticLibrary) + CustomTarget, InvalidArguments, Jar, LocalProgram, StructuredSources, SharedLibrary, StaticLibrary) from ..compilers.compilers import are_asserts_disabled_for_subproject, lang_suffixes from ..interpreter.type_checking import ( DEPENDENCIES_KW, LINK_WITH_KW, LINK_WHOLE_KW, SHARED_LIB_KWS, TEST_KWS, TEST_KWS_NO_ARGS, @@ -91,7 +91,7 @@ class RustModule(ExtensionModule): def __init__(self, interpreter: Interpreter) -> None: super().__init__(interpreter) - self._bindgen_bin: T.Optional[T.Union[ExternalProgram, Executable, OverrideProgram]] = None + self._bindgen_bin: T.Optional[T.Union[ExternalProgram, Executable, OverrideProgram, LocalProgram]] = None if 'rust' in interpreter.compilers.host: rustc = T.cast('RustCompiler', interpreter.compilers.host['rust']) self._bindgen_rust_target = 'nightly' if rustc.is_nightly else rustc.version @@ -388,9 +388,7 @@ class RustModule(ExtensionModule): if 'Got an invalid' in err or 'is not a valid Rust target' in err: self._bindgen_rust_target = None - # TODO: Executable needs to learn about get_version - if isinstance(self._bindgen_bin, ExternalProgram): - self._bindgen_set_std = mesonlib.version_compare(self._bindgen_bin.get_version(), '>= 0.71') + self._bindgen_set_std = mesonlib.version_compare(self._bindgen_bin.get_version(), '>= 0.71') name: str if isinstance(header, File): diff --git a/mesonbuild/modules/wayland.py b/mesonbuild/modules/wayland.py index 94c6f819d..458a0a78d 100644 --- a/mesonbuild/modules/wayland.py +++ b/mesonbuild/modules/wayland.py @@ -6,7 +6,7 @@ import os import typing as T from . import ExtensionModule, ModuleReturnValue, ModuleInfo -from ..build import CustomTarget +from ..build import CustomTarget, LocalProgram from ..interpreter.type_checking import NoneType, in_set_validator from ..interpreterbase import typed_pos_args, typed_kwargs, KwargInfo, FeatureNew from ..mesonlib import File, MesonException @@ -42,7 +42,7 @@ class WaylandModule(ExtensionModule): self.protocols_dep: T.Optional[Dependency] = None self.pkgdatadir: T.Optional[str] = None - self.scanner_bin: T.Optional[T.Union[ExternalProgram, Executable]] = None + self.scanner_bin: T.Optional[T.Union[ExternalProgram, Executable, LocalProgram]] = None self.methods.update({ 'scan_xml': self.scan_xml, |
