diff options
Diffstat (limited to 'mesonbuild/modules')
-rw-r--r-- | mesonbuild/modules/__init__.py | 6 | ||||
-rw-r--r-- | mesonbuild/modules/unstable_wayland.py | 120 |
2 files changed, 124 insertions, 2 deletions
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 72bcd00..85bec0b 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -80,8 +80,10 @@ class ModuleState: 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, silent: bool = False) -> 'ExternalProgram': - return self._interpreter.find_program_impl(prog, required=required, version_func=version_func, wanted=wanted, silent=silent) + wanted: T.Optional[str] = None, silent: bool = False, + for_machine: MachineChoice = MachineChoice.HOST) -> 'ExternalProgram': + return self._interpreter.find_program_impl(prog, required=required, version_func=version_func, + wanted=wanted, silent=silent, for_machine=for_machine) def test(self, args: T.Tuple[str, T.Union[build.Executable, build.Jar, 'ExternalProgram', mesonlib.File]], workdir: T.Optional[str] = None, diff --git a/mesonbuild/modules/unstable_wayland.py b/mesonbuild/modules/unstable_wayland.py new file mode 100644 index 0000000..85da2b7 --- /dev/null +++ b/mesonbuild/modules/unstable_wayland.py @@ -0,0 +1,120 @@ +# Copyright 2022 Mark Bolhuis <mark@bolhuis.dev> + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from . import ExtensionModule, ModuleReturnValue +from ..build import CustomTarget +from ..interpreter.type_checking import NoneType, in_set_validator +from ..interpreterbase import FeatureNew, typed_pos_args, typed_kwargs, KwargInfo +from ..mesonlib import File, MesonException, MachineChoice + + +class WaylandModule(ExtensionModule): + + @FeatureNew('wayland module', '0.62.0') + def __init__(self, interpreter): + super().__init__(interpreter) + + self.protocols_dep = None + self.pkgdatadir = None + self.scanner_bin = None + + self.methods.update({ + 'scan_xml': self.scan_xml, + 'find_protocol': self.find_protocol, + }) + + @typed_pos_args('wayland.scan_xml', varargs=(str, File), min_varargs=1) + @typed_kwargs( + 'wayland.scan_xml', + KwargInfo('side', str, default='client', validator=in_set_validator({'client', 'server'})), + KwargInfo('scope', str, default='private', validator=in_set_validator({'private', 'public'})), + ) + def scan_xml(self, state, args, kwargs): + if self.scanner_bin is None: + self.scanner_bin = state.find_program('wayland-scanner', for_machine=MachineChoice.BUILD) + + scope = kwargs['scope'] + side = kwargs['side'] + + xml_files = self.interpreter.source_strings_to_files(args[0]) + targets = [] + for xml_file in xml_files: + name = os.path.splitext(os.path.basename(xml_file.fname))[0] + + code = CustomTarget( + f'{name}-protocol', + state.subdir, + state.subproject, + [self.scanner_bin, f'{scope}-code', '@INPUT@', '@OUTPUT@'], + [xml_file], + [f'{name}-protocol.c'], + backend=state.backend, + ) + targets.append(code) + + header = CustomTarget( + f'{name}-{side}-protocol', + state.subdir, + state.subproject, + [self.scanner_bin, f'{side}-header', '@INPUT@', '@OUTPUT@'], + [xml_file], + [f'{name}-{side}-protocol.h'], + backend=state.backend, + ) + targets.append(header) + + return ModuleReturnValue(targets, targets) + + @typed_pos_args('wayland.find_protocol', str) + @typed_kwargs( + 'wayland.find_protocol', + KwargInfo('state', str, default='stable', validator=in_set_validator({'stable', 'staging', 'unstable'})), + KwargInfo('version', (int, NoneType)), + ) + def find_protocol(self, state, args, kwargs): + base_name = args[0] + xml_state = kwargs['state'] + version = kwargs['version'] + + if xml_state != 'stable' and version is None: + raise MesonException(f'{xml_state} protocols require a version number.') + + if xml_state == 'stable' and version is not None: + raise MesonException('stable protocols do not require a version number.') + + if self.protocols_dep is None: + self.protocols_dep = self.interpreter.func_dependency(state.current_node, ['wayland-protocols'], {}) + + if self.pkgdatadir is None: + self.pkgdatadir = self.protocols_dep.get_variable(pkgconfig='pkgdatadir', internal='pkgdatadir') + + if xml_state == 'stable': + xml_name = f'{base_name}.xml' + elif xml_state == 'staging': + xml_name = f'{base_name}-v{version}.xml' + else: + xml_name = f'{base_name}-unstable-v{version}.xml' + + path = os.path.join(self.pkgdatadir, xml_state, base_name, xml_name) + + if not os.path.exists(path): + raise MesonException(f'The file {path} does not exist.') + + return File.from_absolute_file(path) + + +def initialize(interpreter): + return WaylandModule(interpreter) |