2017-10-10 15:27:43 +08:00
|
|
|
# Copyright 2015 The Meson development team
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2021-06-01 01:46:09 +08:00
|
|
|
from mesonbuild.dependencies import find_external_dependency
|
2017-10-10 15:27:43 +08:00
|
|
|
import os
|
2020-06-16 05:25:07 +08:00
|
|
|
import shutil
|
2021-03-23 03:07:04 +08:00
|
|
|
import typing as T
|
|
|
|
|
2017-10-10 15:27:43 +08:00
|
|
|
from .. import mlog
|
|
|
|
from .. import build
|
2021-03-23 03:07:04 +08:00
|
|
|
from .. import mesonlib
|
2020-06-25 23:32:12 +08:00
|
|
|
from ..mesonlib import MesonException, extract_as_list, File, unholder, version_compare
|
2021-03-23 06:25:29 +08:00
|
|
|
from ..dependencies import Dependency
|
2017-10-10 15:27:43 +08:00
|
|
|
import xml.etree.ElementTree as ET
|
2021-05-11 21:18:47 +08:00
|
|
|
from . import ModuleReturnValue, ExtensionModule
|
2021-06-02 04:45:42 +08:00
|
|
|
from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs
|
2020-03-03 23:50:15 +08:00
|
|
|
from ..interpreter import extract_required_kwarg
|
2020-10-02 04:02:08 +08:00
|
|
|
from ..programs import NonExistingExternalProgram
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2021-03-23 03:07:04 +08:00
|
|
|
if T.TYPE_CHECKING:
|
2021-06-02 04:45:42 +08:00
|
|
|
from . import ModuleState
|
2021-03-23 03:07:04 +08:00
|
|
|
from ..dependencies.qt import QtBaseDependency
|
2021-03-23 06:25:29 +08:00
|
|
|
from ..environment import Environment
|
2021-06-02 04:45:42 +08:00
|
|
|
from ..interpreter import Interpreter
|
2021-03-23 03:07:04 +08:00
|
|
|
from ..programs import ExternalProgram
|
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
from typing_extensions import TypedDict
|
|
|
|
|
|
|
|
class ResourceCompilerKwArgs(TypedDict):
|
|
|
|
|
|
|
|
"""Keyword arguments for the Resource Compiler method."""
|
|
|
|
|
|
|
|
name: T.Optional[str]
|
|
|
|
sources: T.List[mesonlib.FileOrString]
|
|
|
|
extra_args: T.List[str]
|
|
|
|
method: str
|
|
|
|
|
2021-06-02 05:11:13 +08:00
|
|
|
class UICompilerKwArgs(TypedDict):
|
|
|
|
|
|
|
|
"""Keyword arguments for the Ui Compiler method."""
|
|
|
|
|
|
|
|
sources: T.List[mesonlib.FileOrString]
|
|
|
|
extra_args: T.List[str]
|
|
|
|
method: str
|
|
|
|
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2018-10-25 05:17:44 +08:00
|
|
|
class QtBaseModule(ExtensionModule):
|
2017-10-10 15:27:43 +08:00
|
|
|
tools_detected = False
|
2020-06-25 23:32:12 +08:00
|
|
|
rcc_supports_depfiles = False
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2021-03-23 03:07:04 +08:00
|
|
|
def __init__(self, interpreter: 'Interpreter', qt_version=5):
|
2018-10-25 05:17:44 +08:00
|
|
|
ExtensionModule.__init__(self, interpreter)
|
2017-10-10 15:27:43 +08:00
|
|
|
self.qt_version = qt_version
|
2021-03-23 03:07:04 +08:00
|
|
|
self.moc: 'ExternalProgram' = NonExistingExternalProgram('moc')
|
|
|
|
self.uic: 'ExternalProgram' = NonExistingExternalProgram('uic')
|
|
|
|
self.rcc: 'ExternalProgram' = NonExistingExternalProgram('rcc')
|
|
|
|
self.lrelease: 'ExternalProgram' = NonExistingExternalProgram('lrelease')
|
2021-04-10 03:15:07 +08:00
|
|
|
self.methods.update({
|
|
|
|
'has_tools': self.has_tools,
|
|
|
|
'preprocess': self.preprocess,
|
|
|
|
'compile_translations': self.compile_translations,
|
2021-06-02 04:45:42 +08:00
|
|
|
'compile_resources': self.compile_resources,
|
2021-06-02 05:11:13 +08:00
|
|
|
'compile_ui': self.compile_ui,
|
2021-04-10 03:15:07 +08:00
|
|
|
})
|
2021-03-23 03:07:04 +08:00
|
|
|
|
2021-04-11 04:56:05 +08:00
|
|
|
def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None:
|
2021-03-23 03:07:04 +08:00
|
|
|
"""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
|
|
|
|
bins = ['moc', 'uic', 'rcc', 'lrelease']
|
2021-03-23 06:25:29 +08:00
|
|
|
found = {b: NonExistingExternalProgram(name=f'{b}-qt{qt_dep.qtver}')
|
2021-03-23 03:07:04 +08:00
|
|
|
for b in bins}
|
|
|
|
wanted = f'== {qt_dep.version}'
|
|
|
|
|
|
|
|
def gen_bins() -> T.Generator[T.Tuple[str, str], None, None]:
|
|
|
|
for b in bins:
|
|
|
|
if qt_dep.bindir:
|
|
|
|
yield os.path.join(qt_dep.bindir, b), b
|
|
|
|
# prefer the <tool>-qt<version> of the tool to the plain one, as we
|
|
|
|
# don't know what the unsuffixed one points to without calling it.
|
2021-03-23 06:25:29 +08:00
|
|
|
yield f'{b}-qt{qt_dep.qtver}', b
|
2021-03-23 03:07:04 +08:00
|
|
|
yield b, b
|
|
|
|
|
|
|
|
for b, name in gen_bins():
|
|
|
|
if found[name].found():
|
|
|
|
continue
|
|
|
|
|
|
|
|
if name == 'lrelease':
|
|
|
|
arg = ['-version']
|
|
|
|
elif mesonlib.version_compare(qt_dep.version, '>= 5'):
|
|
|
|
arg = ['--version']
|
|
|
|
else:
|
|
|
|
arg = ['-v']
|
|
|
|
|
|
|
|
# Ensure that the version of qt and each tool are the same
|
|
|
|
def get_version(p: 'ExternalProgram') -> str:
|
|
|
|
_, out, err = mesonlib.Popen_safe(p.get_command() + arg)
|
|
|
|
if b.startswith('lrelease') or not qt_dep.version.startswith('4'):
|
|
|
|
care = out
|
|
|
|
else:
|
|
|
|
care = err
|
|
|
|
return care.split(' ')[-1].replace(')', '').strip()
|
|
|
|
|
2021-04-11 04:56:05 +08:00
|
|
|
p = state.find_program(b, required=False,
|
|
|
|
version_func=get_version,
|
|
|
|
wanted=wanted).held_object
|
2021-03-23 03:07:04 +08:00
|
|
|
if p.found():
|
|
|
|
setattr(self, name, p)
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
def _detect_tools(self, state: 'ModuleState', method: str, required: bool = True) -> None:
|
2017-10-10 15:27:43 +08:00
|
|
|
if self.tools_detected:
|
|
|
|
return
|
2020-07-03 04:39:10 +08:00
|
|
|
self.tools_detected = True
|
2021-03-05 06:16:11 +08:00
|
|
|
mlog.log(f'Detecting Qt{self.qt_version} tools')
|
2020-07-03 04:39:10 +08:00
|
|
|
kwargs = {'required': required, 'modules': 'Core', 'method': method}
|
2021-04-11 04:56:05 +08:00
|
|
|
qt = find_external_dependency(f'qt{self.qt_version}', state.environment, kwargs)
|
2020-07-03 04:39:10 +08:00
|
|
|
if qt.found():
|
|
|
|
# Get all tools and then make sure that they are the right version
|
2021-04-11 04:56:05 +08:00
|
|
|
self.compilers_detect(state, qt)
|
2020-06-25 23:32:12 +08:00
|
|
|
if version_compare(qt.version, '>=5.14.0'):
|
|
|
|
self.rcc_supports_depfiles = True
|
|
|
|
else:
|
|
|
|
mlog.warning('rcc dependencies will not work properly until you move to Qt >= 5.14:',
|
|
|
|
mlog.bold('https://bugreports.qt.io/browse/QTBUG-45460'), fatal=False)
|
2020-07-03 04:39:10 +08:00
|
|
|
else:
|
2021-03-05 06:16:11 +08:00
|
|
|
suffix = f'-qt{self.qt_version}'
|
2020-07-03 04:39:10 +08:00
|
|
|
self.moc = NonExistingExternalProgram(name='moc' + suffix)
|
|
|
|
self.uic = NonExistingExternalProgram(name='uic' + suffix)
|
|
|
|
self.rcc = NonExistingExternalProgram(name='rcc' + suffix)
|
|
|
|
self.lrelease = NonExistingExternalProgram(name='lrelease' + suffix)
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
@staticmethod
|
|
|
|
def _qrc_nodes(state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.Tuple[str, T.List[str]]:
|
|
|
|
abspath: str
|
|
|
|
if isinstance(rcc_file, str):
|
2018-03-27 04:26:01 +08:00
|
|
|
abspath = os.path.join(state.environment.source_dir, state.subdir, rcc_file)
|
2018-04-04 07:06:43 +08:00
|
|
|
rcc_dirname = os.path.dirname(abspath)
|
2021-06-02 04:45:42 +08:00
|
|
|
else:
|
2018-03-30 07:49:35 +08:00
|
|
|
abspath = rcc_file.absolute_path(state.environment.source_dir, state.environment.build_dir)
|
2018-04-04 07:06:43 +08:00
|
|
|
rcc_dirname = os.path.dirname(abspath)
|
2018-03-27 04:26:01 +08:00
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
# FIXME: what error are we actually tring to check here?
|
2017-10-10 15:27:43 +08:00
|
|
|
try:
|
|
|
|
tree = ET.parse(abspath)
|
|
|
|
root = tree.getroot()
|
2021-06-02 04:45:42 +08:00
|
|
|
result: T.List[str] = []
|
2017-10-10 15:27:43 +08:00
|
|
|
for child in root[0]:
|
|
|
|
if child.tag != 'file':
|
2021-06-02 04:45:42 +08:00
|
|
|
mlog.warning("malformed rcc file: ", os.path.join(state.subdir, str(rcc_file)))
|
2017-10-10 15:27:43 +08:00
|
|
|
break
|
|
|
|
else:
|
2020-06-16 05:25:07 +08:00
|
|
|
result.append(child.text)
|
|
|
|
|
|
|
|
return rcc_dirname, result
|
|
|
|
except Exception:
|
2021-05-08 23:24:22 +08:00
|
|
|
raise MesonException(f'Unable to parse resource file {abspath}')
|
2020-06-16 05:25:07 +08:00
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
def _parse_qrc_deps(self, state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.List[File]:
|
|
|
|
rcc_dirname, nodes = self._qrc_nodes(state, rcc_file)
|
|
|
|
result: T.List[File] = []
|
2020-06-16 05:25:07 +08:00
|
|
|
for resource_path in nodes:
|
2020-09-23 00:43:48 +08:00
|
|
|
# We need to guess if the pointed resource is:
|
|
|
|
# a) in build directory -> implies a generated file
|
|
|
|
# b) in source directory
|
|
|
|
# c) somewhere else external dependency file to bundle
|
|
|
|
#
|
|
|
|
# Also from qrc documentation: relative path are always from qrc file
|
|
|
|
# So relative path must always be computed from qrc file !
|
|
|
|
if os.path.isabs(resource_path):
|
|
|
|
# a)
|
|
|
|
if resource_path.startswith(os.path.abspath(state.environment.build_dir)):
|
|
|
|
resource_relpath = os.path.relpath(resource_path, state.environment.build_dir)
|
|
|
|
result.append(File(is_built=True, subdir='', fname=resource_relpath))
|
|
|
|
# either b) or c)
|
|
|
|
else:
|
|
|
|
result.append(File(is_built=False, subdir=state.subdir, fname=resource_path))
|
|
|
|
else:
|
|
|
|
path_from_rcc = os.path.normpath(os.path.join(rcc_dirname, resource_path))
|
|
|
|
# a)
|
|
|
|
if path_from_rcc.startswith(state.environment.build_dir):
|
|
|
|
result.append(File(is_built=True, subdir=state.subdir, fname=resource_path))
|
|
|
|
# b)
|
|
|
|
else:
|
|
|
|
result.append(File(is_built=False, subdir=state.subdir, fname=path_from_rcc))
|
2020-06-16 05:25:07 +08:00
|
|
|
return result
|
2017-10-10 15:27:43 +08:00
|
|
|
|
2020-03-03 23:50:15 +08:00
|
|
|
@noPosargs
|
|
|
|
@permittedKwargs({'method', 'required'})
|
|
|
|
@FeatureNew('qt.has_tools', '0.54.0')
|
2021-03-03 22:02:49 +08:00
|
|
|
def has_tools(self, state, args, kwargs):
|
2020-03-03 23:50:15 +08:00
|
|
|
method = kwargs.get('method', 'auto')
|
|
|
|
disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, default=False)
|
|
|
|
if disabled:
|
|
|
|
mlog.log('qt.has_tools skipped: feature', mlog.bold(feature), 'disabled')
|
|
|
|
return False
|
2021-04-11 04:56:05 +08:00
|
|
|
self._detect_tools(state, method, required=False)
|
2020-03-03 23:50:15 +08:00
|
|
|
for tool in (self.moc, self.uic, self.rcc, self.lrelease):
|
|
|
|
if not tool.found():
|
|
|
|
if required:
|
|
|
|
raise MesonException('Qt tools not found')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
@FeatureNew('qt.compile_resources', '0.59.0')
|
|
|
|
@noPosargs
|
|
|
|
@typed_kwargs(
|
|
|
|
'qt.compile_resources',
|
|
|
|
KwargInfo('name', str),
|
|
|
|
KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True),
|
|
|
|
KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True),
|
|
|
|
KwargInfo('method', str, default='auto')
|
|
|
|
)
|
2021-06-02 04:57:39 +08:00
|
|
|
def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue:
|
2021-06-02 04:45:42 +08:00
|
|
|
"""Compile Qt resources files.
|
|
|
|
|
|
|
|
Uses CustomTargets to generate .cpp files from .qrc files.
|
|
|
|
"""
|
|
|
|
self._detect_tools(state, kwargs['method'])
|
|
|
|
if not self.rcc.found():
|
|
|
|
err_msg = ("{0} sources specified and couldn't find {1}, "
|
|
|
|
"please check your qt{2} installation")
|
|
|
|
raise MesonException(err_msg.format('RCC', f'rcc-qt{self.qt_version}', self.qt_version))
|
|
|
|
|
|
|
|
# List of generated CustomTargets
|
|
|
|
targets: T.List[build.CustomTarget] = []
|
|
|
|
|
|
|
|
# depfile arguments
|
|
|
|
DEPFILE_ARGS: T.List[str] = ['--depfile', '@DEPFILE@'] if self.rcc_supports_depfiles else []
|
|
|
|
|
|
|
|
name = kwargs['name']
|
|
|
|
sources = kwargs['sources']
|
|
|
|
extra_args = kwargs['extra_args'] or []
|
|
|
|
|
|
|
|
# If a name was set generate a single .cpp file from all of the qrc
|
|
|
|
# files, otherwise generate one .cpp file per qrc file.
|
|
|
|
if name:
|
|
|
|
qrc_deps: T.List[File] = []
|
|
|
|
for s in sources:
|
|
|
|
qrc_deps.extend(self._parse_qrc_deps(state, s))
|
|
|
|
|
|
|
|
rcc_kwargs: T.Dict[str, T.Any] = { # TODO: if CustomTarget had typing information we could use that here...
|
|
|
|
'input': sources,
|
|
|
|
'output': name + '.cpp',
|
|
|
|
'command': [self.rcc, '-name', name, '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS,
|
|
|
|
'depend_files': qrc_deps,
|
|
|
|
'depfile': f'{name}.d',
|
|
|
|
}
|
|
|
|
res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs)
|
|
|
|
targets.append(res_target)
|
|
|
|
else:
|
|
|
|
for rcc_file in sources:
|
|
|
|
qrc_deps = self._parse_qrc_deps(state, rcc_file)
|
|
|
|
if isinstance(rcc_file, str):
|
|
|
|
basename = os.path.basename(rcc_file)
|
|
|
|
else:
|
|
|
|
basename = os.path.basename(rcc_file.fname)
|
|
|
|
name = f'qt{self.qt_version}-{basename.replace(".", "_")}'
|
|
|
|
rcc_kwargs = {
|
|
|
|
'input': rcc_file,
|
|
|
|
'output': f'{name}.cpp',
|
|
|
|
'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS,
|
|
|
|
'depend_files': qrc_deps,
|
|
|
|
'depfile': f'{name}.d',
|
|
|
|
}
|
|
|
|
res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs)
|
|
|
|
targets.append(res_target)
|
|
|
|
|
|
|
|
return ModuleReturnValue(targets, [targets])
|
|
|
|
|
2021-06-02 05:11:13 +08:00
|
|
|
@FeatureNew('qt.compile_ui', '0.59.0')
|
|
|
|
@noPosargs
|
|
|
|
@typed_kwargs(
|
|
|
|
'qt.compile_ui',
|
|
|
|
KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True),
|
|
|
|
KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True),
|
|
|
|
KwargInfo('method', str, default='auto')
|
|
|
|
)
|
|
|
|
def compile_ui(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue:
|
|
|
|
"""Compile UI resources into cpp headers."""
|
|
|
|
self._detect_tools(state, kwargs['method'])
|
|
|
|
if not self.uic.found():
|
|
|
|
err_msg = ("{0} sources specified and couldn't find {1}, "
|
|
|
|
"please check your qt{2} installation")
|
|
|
|
raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version))
|
|
|
|
|
|
|
|
ui_kwargs: T.Dict[str, T.Any] = { # TODO: if Generator was properly annotated…
|
|
|
|
'output': 'ui_@BASENAME@.h',
|
|
|
|
'arguments': kwargs['extra_args'] or [] + ['-o', '@OUTPUT@', '@INPUT@']}
|
|
|
|
# TODO: This generator isn't added to the generator list in the Interpreter
|
|
|
|
gen = build.Generator([self.uic], ui_kwargs)
|
|
|
|
out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state)
|
|
|
|
return ModuleReturnValue(out, [out]) # type: ignore
|
2021-06-02 04:45:42 +08:00
|
|
|
|
2018-09-29 04:01:27 +08:00
|
|
|
@FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments'])
|
2018-04-27 23:04:48 +08:00
|
|
|
@FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments'])
|
2018-10-25 00:11:08 +08:00
|
|
|
@FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments'])
|
2021-06-02 02:25:39 +08:00
|
|
|
@FeatureDeprecatedKwargs('qt.preprocess', '0.59.0', ['sources'])
|
2018-10-25 00:11:08 +08:00
|
|
|
@permittedKwargs({'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'include_directories', 'dependencies', 'ui_files', 'qresources', 'method'})
|
2017-10-10 15:27:43 +08:00
|
|
|
def preprocess(self, state, args, kwargs):
|
2018-10-25 00:11:08 +08:00
|
|
|
rcc_files, ui_files, moc_headers, moc_sources, uic_extra_arguments, moc_extra_arguments, rcc_extra_arguments, sources, include_directories, dependencies \
|
2020-03-05 05:04:24 +08:00
|
|
|
= [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']]
|
2021-06-02 02:03:21 +08:00
|
|
|
_sources = args[1:]
|
|
|
|
if _sources:
|
2021-06-02 02:25:39 +08:00
|
|
|
FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject)
|
2021-06-02 02:03:21 +08:00
|
|
|
sources.extend(_sources)
|
2017-10-10 15:27:43 +08:00
|
|
|
method = kwargs.get('method', 'auto')
|
2021-04-11 04:56:05 +08:00
|
|
|
self._detect_tools(state, method)
|
2017-10-10 15:27:43 +08:00
|
|
|
err_msg = "{0} sources specified and couldn't find {1}, " \
|
|
|
|
"please check your qt{2} installation"
|
2019-04-23 06:54:16 +08:00
|
|
|
if (moc_headers or moc_sources) and not self.moc.found():
|
2021-03-05 06:16:11 +08:00
|
|
|
raise MesonException(err_msg.format('MOC', f'moc-qt{self.qt_version}', self.qt_version))
|
2021-06-02 04:57:39 +08:00
|
|
|
|
2019-04-23 06:54:16 +08:00
|
|
|
if rcc_files:
|
2017-11-09 06:08:53 +08:00
|
|
|
# custom output name set? -> one output file, multiple otherwise
|
2021-06-02 04:45:42 +08:00
|
|
|
rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': rcc_files, 'extra_args': rcc_extra_arguments, 'method': method}
|
2019-04-23 06:54:16 +08:00
|
|
|
if args:
|
2021-06-02 04:57:39 +08:00
|
|
|
rcc_kwargs['name'] = args[0]
|
|
|
|
sources.extend(self.compile_resources(state, tuple(), rcc_kwargs).return_value)
|
|
|
|
|
2019-04-23 06:54:16 +08:00
|
|
|
if ui_files:
|
2017-10-10 15:27:43 +08:00
|
|
|
if not self.uic.found():
|
2021-03-05 06:16:11 +08:00
|
|
|
raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version))
|
2018-09-29 04:01:27 +08:00
|
|
|
arguments = uic_extra_arguments + ['-o', '@OUTPUT@', '@INPUT@']
|
2017-10-10 15:27:43 +08:00
|
|
|
ui_kwargs = {'output': 'ui_@BASENAME@.h',
|
2018-09-29 04:01:27 +08:00
|
|
|
'arguments': arguments}
|
2017-10-10 15:27:43 +08:00
|
|
|
ui_gen = build.Generator([self.uic], ui_kwargs)
|
2021-03-05 06:16:11 +08:00
|
|
|
ui_output = ui_gen.process_files(f'Qt{self.qt_version} ui', ui_files, state)
|
2017-10-10 15:27:43 +08:00
|
|
|
sources.append(ui_output)
|
2021-06-02 05:11:13 +08:00
|
|
|
|
2021-05-11 21:18:47 +08:00
|
|
|
inc = state.get_include_args(include_dirs=include_directories)
|
2018-08-24 01:25:29 +08:00
|
|
|
compile_args = []
|
2020-03-06 01:50:30 +08:00
|
|
|
for dep in unholder(dependencies):
|
2018-08-24 01:25:29 +08:00
|
|
|
if isinstance(dep, Dependency):
|
2021-03-23 06:25:29 +08:00
|
|
|
for arg in dep.get_all_compile_args():
|
2018-08-24 01:25:29 +08:00
|
|
|
if arg.startswith('-I') or arg.startswith('-D'):
|
|
|
|
compile_args.append(arg)
|
|
|
|
else:
|
|
|
|
raise MesonException('Argument is of an unacceptable type {!r}.\nMust be '
|
|
|
|
'either an external dependency (returned by find_library() or '
|
|
|
|
'dependency()) or an internal dependency (returned by '
|
|
|
|
'declare_dependency()).'.format(type(dep).__name__))
|
2019-04-23 06:54:16 +08:00
|
|
|
if moc_headers:
|
2018-08-24 01:25:29 +08:00
|
|
|
arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@']
|
2017-10-10 15:27:43 +08:00
|
|
|
moc_kwargs = {'output': 'moc_@BASENAME@.cpp',
|
2017-10-24 16:05:26 +08:00
|
|
|
'arguments': arguments}
|
2017-10-10 15:27:43 +08:00
|
|
|
moc_gen = build.Generator([self.moc], moc_kwargs)
|
2021-03-05 06:16:11 +08:00
|
|
|
moc_output = moc_gen.process_files(f'Qt{self.qt_version} moc header', moc_headers, state)
|
2017-10-10 15:27:43 +08:00
|
|
|
sources.append(moc_output)
|
2019-04-23 06:54:16 +08:00
|
|
|
if moc_sources:
|
2018-08-24 01:25:29 +08:00
|
|
|
arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@']
|
2017-10-10 15:27:43 +08:00
|
|
|
moc_kwargs = {'output': '@BASENAME@.moc',
|
2017-10-24 16:05:26 +08:00
|
|
|
'arguments': arguments}
|
2017-10-10 15:27:43 +08:00
|
|
|
moc_gen = build.Generator([self.moc], moc_kwargs)
|
2021-03-05 06:16:11 +08:00
|
|
|
moc_output = moc_gen.process_files(f'Qt{self.qt_version} moc source', moc_sources, state)
|
2017-10-10 15:27:43 +08:00
|
|
|
sources.append(moc_output)
|
|
|
|
return ModuleReturnValue(sources, sources)
|
2017-11-23 08:42:49 +08:00
|
|
|
|
2019-03-16 19:43:44 +08:00
|
|
|
@FeatureNew('qt.compile_translations', '0.44.0')
|
2020-06-16 05:25:07 +08:00
|
|
|
@FeatureNewKwargs('qt.compile_translations', '0.56.0', ['qresource'])
|
|
|
|
@FeatureNewKwargs('qt.compile_translations', '0.56.0', ['rcc_extra_arguments'])
|
|
|
|
@permittedKwargs({'ts_files', 'qresource', 'rcc_extra_arguments', 'install', 'install_dir', 'build_by_default', 'method'})
|
2017-11-23 08:42:49 +08:00
|
|
|
def compile_translations(self, state, args, kwargs):
|
2020-06-16 05:25:07 +08:00
|
|
|
ts_files, install_dir = [extract_as_list(kwargs, c, pop=True) for c in ['ts_files', 'install_dir']]
|
|
|
|
qresource = kwargs.get('qresource')
|
|
|
|
if qresource:
|
|
|
|
if ts_files:
|
|
|
|
raise MesonException('qt.compile_translations: Cannot specify both ts_files and qresource')
|
|
|
|
if os.path.dirname(qresource) != '':
|
|
|
|
raise MesonException('qt.compile_translations: qresource file name must not contain a subdirectory.')
|
|
|
|
qresource = File.from_built_file(state.subdir, qresource)
|
|
|
|
infile_abs = os.path.join(state.environment.source_dir, qresource.relative_name())
|
|
|
|
outfile_abs = os.path.join(state.environment.build_dir, qresource.relative_name())
|
|
|
|
os.makedirs(os.path.dirname(outfile_abs), exist_ok=True)
|
|
|
|
shutil.copy2(infile_abs, outfile_abs)
|
|
|
|
self.interpreter.add_build_def_file(infile_abs)
|
|
|
|
|
2021-06-02 04:45:42 +08:00
|
|
|
rcc_file, nodes = self._qrc_nodes(state, qresource)
|
2020-06-16 05:25:07 +08:00
|
|
|
for c in nodes:
|
|
|
|
if c.endswith('.qm'):
|
|
|
|
ts_files.append(c.rstrip('.qm')+'.ts')
|
|
|
|
else:
|
2021-03-05 06:16:11 +08:00
|
|
|
raise MesonException(f'qt.compile_translations: qresource can only contain qm files, found {c}')
|
2020-06-16 05:25:07 +08:00
|
|
|
results = self.preprocess(state, [], {'qresources': qresource, 'rcc_extra_arguments': kwargs.get('rcc_extra_arguments', [])})
|
2021-04-11 04:56:05 +08:00
|
|
|
self._detect_tools(state, kwargs.get('method', 'auto'))
|
2017-11-23 08:42:49 +08:00
|
|
|
translations = []
|
|
|
|
for ts in ts_files:
|
2019-11-26 17:15:52 +08:00
|
|
|
if not self.lrelease.found():
|
|
|
|
raise MesonException('qt.compile_translations: ' +
|
|
|
|
self.lrelease.name + ' not found')
|
2020-06-16 05:25:07 +08:00
|
|
|
if qresource:
|
|
|
|
outdir = os.path.dirname(os.path.normpath(os.path.join(state.subdir, ts)))
|
|
|
|
ts = os.path.basename(ts)
|
|
|
|
else:
|
|
|
|
outdir = state.subdir
|
2017-11-23 08:42:49 +08:00
|
|
|
cmd = [self.lrelease, '@INPUT@', '-qm', '@OUTPUT@']
|
|
|
|
lrelease_kwargs = {'output': '@BASENAME@.qm',
|
|
|
|
'input': ts,
|
|
|
|
'install': kwargs.get('install', False),
|
|
|
|
'build_by_default': kwargs.get('build_by_default', False),
|
|
|
|
'command': cmd}
|
|
|
|
if install_dir is not None:
|
|
|
|
lrelease_kwargs['install_dir'] = install_dir
|
2021-03-05 06:16:11 +08:00
|
|
|
lrelease_target = build.CustomTarget(f'qt{self.qt_version}-compile-{ts}', outdir, state.subproject, lrelease_kwargs)
|
2017-11-23 08:42:49 +08:00
|
|
|
translations.append(lrelease_target)
|
2020-06-16 05:25:07 +08:00
|
|
|
if qresource:
|
|
|
|
return ModuleReturnValue(results.return_value[0], [results.new_objects, translations])
|
|
|
|
else:
|
|
|
|
return ModuleReturnValue(translations, translations)
|