Skip to content

Commit

Permalink
qt module: allow has_tools to specify which tools to check
Browse files Browse the repository at this point in the history
This allows checking for tools that may not be available in older version of qt
or avoiding to request tools that may not be necessary for a given project
  • Loading branch information
chubinou committed Aug 9, 2024
1 parent c20ef07 commit 046a6f6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mesonbuild/modules/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class PreprocessKwArgs(TypedDict):
class HasToolKwArgs(kwargs.ExtractRequired):

method: str
tools: T.List[T.Literal['moc', 'uic', 'rcc', 'lrelease']]

class CompileTranslationsKwArgs(TypedDict):

Expand All @@ -91,6 +92,16 @@ class CompileTranslationsKwArgs(TypedDict):
rcc_extra_arguments: T.List[str]
ts_files: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]

def _list_in_set_validator(choices: T.Set[str]) -> T.Callable[[T.List[str]], T.Optional[str]]:
"""Check that the choice given was one of the given set."""
def inner(checklist: T.List[str]) -> T.Optional[str]:
invalid = set(checklist).difference(choices)
if invalid:
return f"invalid selections {', '.join(sorted(invalid))}, valid elements are {', '.join(sorted(choices))}."
return None

return inner

class QtBaseModule(ExtensionModule):
_tools_detected = False
_rcc_supports_depfiles = False
Expand Down Expand Up @@ -258,6 +269,10 @@ def _parse_qrc_deps(self, state: 'ModuleState',
'qt.has_tools',
KwargInfo('required', (bool, options.UserFeatureOption), default=False),
KwargInfo('method', str, default='auto'),
KwargInfo('tools', ContainerTypeInfo(list, str), listify=True,
default=['moc', 'uic', 'rcc', 'lrelease'],
validator=_list_in_set_validator({'moc', 'uic', 'rcc', 'lrelease'}),
since='1.5.0'),
)
def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs: 'HasToolKwArgs') -> bool:
method = kwargs.get('method', 'auto')
Expand All @@ -269,8 +284,9 @@ def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs: 'HasToolKwArgs'
mlog.log('qt.has_tools skipped: feature', mlog.bold(feature), 'disabled')
return False
self._detect_tools(state, method, required=False)
for tool in self.tools.values():
if not tool.found():
for tool in kwargs['tools']:
assert tool in self.tools, 'tools must be in {moc, uic, rcc, lrelease}'
if not self.tools[tool].found():
if required:
raise MesonException('Qt tools not found')
return False
Expand Down

0 comments on commit 046a6f6

Please sign in to comment.