| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2015-2016 The Meson development team |
| 3 |
# Copyright © 2023-2026 Intel Corporation |
| 4 |
|
| 5 |
'''This module provides helper functions for Gnome/GLib related |
| 6 |
functionality such as gobject-introspection, gresources and gtk-doc''' |
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
import copy |
| 10 |
import itertools |
| 11 |
import pathlib |
| 12 |
import functools |
| 13 |
import os |
| 14 |
import subprocess |
| 15 |
import textwrap |
| 16 |
import typing as T |
| 17 |
|
| 18 |
from . import ( |
| 19 |
ExtensionModule, GirTarget, GResourceHeaderTarget, GResourceTarget, ModuleInfo, |
| 20 |
ModuleReturnValue, TypelibTarget, VapiTarget, |
| 21 |
) |
| 22 |
from .. import build |
| 23 |
from .. import interpreter |
| 24 |
from .. import mesonlib |
| 25 |
from .. import mlog |
| 26 |
from ..build import CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments, LocalProgram |
| 27 |
from ..dependencies import Dependency, InternalDependency |
| 28 |
from ..dependencies.pkgconfig import PkgConfigDependency, PkgConfigInterface |
| 29 |
from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, ENV_KW, INSTALL_DIR_KW, INSTALL_KW, NoneType, DEPENDENCY_SOURCES_KW, in_set_validator |
| 30 |
from ..interpreterbase import noPosargs, noKwargs, FeatureNew, FeatureDeprecated |
| 31 |
from ..interpreterbase import typed_kwargs, KwargInfo, ContainerTypeInfo |
| 32 |
from ..interpreterbase.decorators import typed_pos_args |
| 33 |
from ..mesonlib import ( |
| 34 |
InstallScriptFailure, MachineChoice, MesonException, OrderedSet, Popen_safe, join_args, quote_arg |
| 35 |
) |
| 36 |
from ..options import OptionKey |
| 37 |
from ..scripts.gettext import read_linguas |
| 38 |
|
| 39 |
if T.TYPE_CHECKING: |
| 40 |
from typing_extensions import Literal, TypedDict |
| 41 |
|
| 42 |
from . import ModuleState |
| 43 |
from ..build import BuildTarget |
| 44 |
from ..compilers import Compiler |
| 45 |
from ..compilers.compilers import Language |
| 46 |
from ..interpreter import Interpreter |
| 47 |
from ..interpreter.interpreter import CustomTargetSources |
| 48 |
from ..interpreter.kwargs import CustomTargetInputs, TargetDepends |
| 49 |
from ..interpreterbase import TYPE_var, TYPE_kwargs |
| 50 |
from ..mesonlib import EnvironmentVariables, FileOrString, InstallScript |
| 51 |
from ..programs import Program, CommandList, CommandListEntry |
| 52 |
|
| 53 |
class PostInstall(TypedDict): |
| 54 |
glib_compile_schemas: bool |
| 55 |
gio_querymodules: T.List[str] |
| 56 |
gtk_update_icon_cache: bool |
| 57 |
update_desktop_database: bool |
| 58 |
update_mime_database: bool |
| 59 |
|
| 60 |
class CompileSchemas(TypedDict): |
| 61 |
|
| 62 |
build_by_default: bool |
| 63 |
depend_files: T.List[FileOrString] |
| 64 |
|
| 65 |
class Yelp(TypedDict): |
| 66 |
|
| 67 |
languages: T.List[str] |
| 68 |
media: T.List[str] |
| 69 |
sources: T.List[str] |
| 70 |
symlink_media: bool |
| 71 |
|
| 72 |
class CompileResources(TypedDict): |
| 73 |
|
| 74 |
build_by_default: bool |
| 75 |
c_name: T.Optional[str] |
| 76 |
dependencies: T.List[T.Union[mesonlib.File, CustomTarget, CustomTargetIndex]] |
| 77 |
export: bool |
| 78 |
extra_args: T.List[str] |
| 79 |
gresource_bundle: bool |
| 80 |
install: bool |
| 81 |
install_dir: T.Optional[str] |
| 82 |
install_header: bool |
| 83 |
source_dir: T.List[str] |
| 84 |
|
| 85 |
class GenerateGir(TypedDict): |
| 86 |
|
| 87 |
build_by_default: bool |
| 88 |
dependencies: T.List[Dependency] |
| 89 |
doc_format: T.Optional[str] |
| 90 |
env: EnvironmentVariables |
| 91 |
export_packages: T.List[str] |
| 92 |
extra_args: T.List[str] |
| 93 |
fatal_warnings: bool |
| 94 |
header: T.List[str] |
| 95 |
identifier_prefix: T.List[str] |
| 96 |
include_directories: T.List[T.Union[build.IncludeDirs, str]] |
| 97 |
includes: T.List[T.Union[str, GirTarget]] |
| 98 |
install: bool |
| 99 |
install_gir: T.Optional[bool] |
| 100 |
install_dir_gir: T.Union[str, None, Literal[False]] |
| 101 |
install_typelib: T.Optional[bool] |
| 102 |
install_dir_typelib: T.Union[str, None, Literal[False]] |
| 103 |
link_with: T.List[T.Union[build.SharedLibrary, build.StaticLibrary]] |
| 104 |
namespace: str |
| 105 |
nsversion: str |
| 106 |
sources: T.List[str | build.TargetSources] |
| 107 |
symbol_prefix: T.List[str] |
| 108 |
|
| 109 |
class GtkDoc(TypedDict): |
| 110 |
|
| 111 |
src_dir: T.List[T.Union[str, build.IncludeDirs]] |
| 112 |
main_sgml: str |
| 113 |
main_xml: str |
| 114 |
module_version: str |
| 115 |
namespace: str |
| 116 |
mode: Literal['xml', 'smgl', 'auto', 'none'] |
| 117 |
html_args: T.List[str] |
| 118 |
scan_args: T.List[str] |
| 119 |
scanobjs_args: T.List[str] |
| 120 |
fixxref_args: T.List[str] |
| 121 |
mkdb_args: T.List[str] |
| 122 |
content_files: T.List[T.Union[build.GeneratedTypes, FileOrString]] |
| 123 |
ignore_headers: T.List[str] |
| 124 |
install_dir: T.List[str] |
| 125 |
check: bool |
| 126 |
install: bool |
| 127 |
gobject_typesfile: T.List[FileOrString] |
| 128 |
html_assets: T.List[FileOrString] |
| 129 |
expand_content_files: T.List[FileOrString] |
| 130 |
c_args: T.List[str] |
| 131 |
include_directories: T.List[T.Union[str, build.IncludeDirs]] |
| 132 |
dependencies: T.List[T.Union[Dependency, build.SharedLibrary, build.StaticLibrary]] |
| 133 |
|
| 134 |
class GdbusCodegen(TypedDict): |
| 135 |
|
| 136 |
sources: T.List[FileOrString] |
| 137 |
extra_args: T.List[str] |
| 138 |
interface_prefix: T.Optional[str] |
| 139 |
namespace: T.Optional[str] |
| 140 |
object_manager: bool |
| 141 |
build_by_default: bool |
| 142 |
annotations: T.List[T.List[str]] |
| 143 |
install_header: bool |
| 144 |
install_dir: T.Optional[str] |
| 145 |
docbook: T.Optional[str] |
| 146 |
rst: T.Optional[str] |
| 147 |
markdown: T.Optional[str] |
| 148 |
autocleanup: Literal['all', 'none', 'objects', 'default'] |
| 149 |
|
| 150 |
class GenMarshal(TypedDict): |
| 151 |
|
| 152 |
build_always: T.Optional[str] |
| 153 |
build_always_stale: T.Optional[bool] |
| 154 |
build_by_default: T.Optional[bool] |
| 155 |
depend_files: T.List[mesonlib.File] |
| 156 |
extra_args: T.List[str] |
| 157 |
install_dir: T.Optional[str] |
| 158 |
install_header: bool |
| 159 |
internal: bool |
| 160 |
nostdinc: bool |
| 161 |
prefix: T.Optional[str] |
| 162 |
skip_source: bool |
| 163 |
sources: T.List[CustomTargetInputs] |
| 164 |
stdinc: bool |
| 165 |
valist_marshallers: bool |
| 166 |
|
| 167 |
class GenerateVapi(TypedDict): |
| 168 |
|
| 169 |
sources: T.List[T.Union[str, GirTarget]] |
| 170 |
install_dir: T.Optional[str] |
| 171 |
install: bool |
| 172 |
vapi_dirs: T.List[str] |
| 173 |
metadata_dirs: T.List[str] |
| 174 |
gir_dirs: T.List[str] |
| 175 |
packages: T.List[T.Union[str, InternalDependency]] |
| 176 |
|
| 177 |
class _MkEnumsCommon(TypedDict): |
| 178 |
|
| 179 |
install_header: bool |
| 180 |
install_dir: T.Optional[str] |
| 181 |
identifier_prefix: T.Optional[str] |
| 182 |
symbol_prefix: T.Optional[str] |
| 183 |
|
| 184 |
class MkEnumsSimple(_MkEnumsCommon): |
| 185 |
|
| 186 |
sources: T.List[FileOrString] |
| 187 |
header_prefix: str |
| 188 |
decorator: str |
| 189 |
function_prefix: str |
| 190 |
body_prefix: str |
| 191 |
|
| 192 |
class MkEnums(_MkEnumsCommon): |
| 193 |
|
| 194 |
sources: T.List[str | build.TargetSources] |
| 195 |
c_template: T.Optional[FileOrString] |
| 196 |
h_template: T.Optional[FileOrString] |
| 197 |
comments: T.Optional[str] |
| 198 |
eprod: T.Optional[str] |
| 199 |
fhead: T.Optional[str] |
| 200 |
fprod: T.Optional[str] |
| 201 |
ftail: T.Optional[str] |
| 202 |
vhead: T.Optional[str] |
| 203 |
vprod: T.Optional[str] |
| 204 |
vtail: T.Optional[str] |
| 205 |
depends: T.List[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]] |
| 206 |
|
| 207 |
|
| 208 |
# Differs from the CustomTarget version in that it straight defaults to True |
| 209 |
_BUILD_BY_DEFAULT: KwargInfo[bool] = KwargInfo( |
| 210 |
'build_by_default', bool, default=True, |
| 211 |
) |
| 212 |
|
| 213 |
_EXTRA_ARGS_KW: KwargInfo[T.List[str]] = KwargInfo( |
| 214 |
'extra_args', |
| 215 |
ContainerTypeInfo(list, str), |
| 216 |
default=[], |
| 217 |
listify=True, |
| 218 |
) |
| 219 |
|
| 220 |
_MK_ENUMS_COMMON_KWS: T.List[KwargInfo] = [ |
| 221 |
INSTALL_KW.evolve(name='install_header'), |
| 222 |
INSTALL_DIR_KW, |
| 223 |
KwargInfo('identifier_prefix', (str, NoneType)), |
| 224 |
KwargInfo('symbol_prefix', (str, NoneType)), |
| 225 |
] |
| 226 |
|
| 227 |
def annotations_validator(annotations: T.List[T.Union[str, T.List[str]]]) -> T.Optional[str]: |
| 228 |
"""Validate gdbus-codegen annotations argument""" |
| 229 |
|
| 230 |
badlist = 'must be made up of 3 strings for ELEMENT, KEY, and VALUE' |
| 231 |
|
| 232 |
if not annotations: |
| 233 |
return None |
| 234 |
elif all(isinstance(annot, str) for annot in annotations): |
| 235 |
if len(annotations) == 3: |
| 236 |
return None |
| 237 |
else: |
| 238 |
return badlist |
| 239 |
elif not all(isinstance(annot, list) for annot in annotations): |
| 240 |
for c, annot in enumerate(annotations): |
| 241 |
if not isinstance(annot, list): |
| 242 |
return f'element {c+1} must be a list' |
| 243 |
else: |
| 244 |
for c, annot in enumerate(annotations): |
| 245 |
if len(annot) != 3 or not all(isinstance(i, str) for i in annot): |
| 246 |
return f'element {c+1} {badlist}' |
| 247 |
return None |
| 248 |
|
| 249 |
# gresource compilation is broken due to the way |
| 250 |
# the resource compiler and Ninja clash about it |
| 251 |
# |
| 252 |
# https://github.com/ninja-build/ninja/issues/1184 |
| 253 |
# https://bugzilla.gnome.org/show_bug.cgi?id=774368 |
| 254 |
gresource_dep_needed_version = '>= 2.51.1' |
| 255 |
|
| 256 |
class GnomeModule(ExtensionModule): |
| 257 |
|
| 258 |
INFO = ModuleInfo('gnome') |
| 259 |
|
| 260 |
def __init__(self, interpreter: 'Interpreter') -> None: |
| 261 |
super().__init__(interpreter) |
| 262 |
self.gir_dep: T.Optional[Dependency] = None |
| 263 |
self.giscanner: T.Optional[Program] = None |
| 264 |
self.gicompiler: T.Optional[Program] = None |
| 265 |
self.install_glib_compile_schemas = False |
| 266 |
self.install_gio_querymodules: T.List[str] = [] |
| 267 |
self.install_gtk_update_icon_cache = False |
| 268 |
self.install_update_desktop_database = False |
| 269 |
self.install_update_mime_database = False |
| 270 |
self.devenv: T.Optional[mesonlib.EnvironmentVariables] = None |
| 271 |
self.native_glib_version: T.Optional[str] = None |
| 272 |
self.methods.update({ |
| 273 |
'post_install': self.post_install, |
| 274 |
'compile_resources': self.compile_resources, |
| 275 |
'generate_gir': self.generate_gir, |
| 276 |
'compile_schemas': self.compile_schemas, |
| 277 |
'yelp': self.yelp, |
| 278 |
'gtkdoc': self.gtkdoc, |
| 279 |
'gtkdoc_html_dir': self.gtkdoc_html_dir, |
| 280 |
'gdbus_codegen': self.gdbus_codegen, |
| 281 |
'mkenums': self.mkenums, |
| 282 |
'mkenums_simple': self.mkenums_simple, |
| 283 |
'genmarshal': self.genmarshal, |
| 284 |
'generate_vapi': self.generate_vapi, |
| 285 |
}) |
| 286 |
|
| 287 |
def _get_native_glib_version(self, state: 'ModuleState') -> str: |
| 288 |
if self.native_glib_version is None: |
| 289 |
glib_dep = PkgConfigDependency('glib-2.0', state.environment, |
| 290 |
{'native': MachineChoice.BUILD, 'required': False}) |
| 291 |
if glib_dep.found(): |
| 292 |
self.native_glib_version = glib_dep.get_version() |
| 293 |
else: |
| 294 |
mlog.warning('Could not detect glib version, assuming 2.54. ' |
| 295 |
'You may get build errors if your glib is older.') |
| 296 |
self.native_glib_version = '2.54' |
| 297 |
return self.native_glib_version |
| 298 |
|
| 299 |
@mesonlib.run_once |
| 300 |
def __print_gresources_warning(self, state: 'ModuleState') -> None: |
| 301 |
if not mesonlib.version_compare(self._get_native_glib_version(state), |
| 302 |
gresource_dep_needed_version): |
| 303 |
mlog.warning('GLib compiled dependencies do not work reliably with \n' |
| 304 |
'the current version of GLib. See the following upstream issue:', |
| 305 |
mlog.bold('https://bugzilla.gnome.org/show_bug.cgi?id=774368'), |
| 306 |
once=True, fatal=False) |
| 307 |
|
| 308 |
@staticmethod |
| 309 |
def _print_gdbus_warning() -> None: |
| 310 |
mlog.warning('Code generated with gdbus_codegen() requires the root directory be added to\n' |
| 311 |
' include_directories of targets with GLib < 2.51.3:', |
| 312 |
mlog.bold('https://github.com/mesonbuild/meson/issues/1387'), |
| 313 |
once=True, fatal=False) |
| 314 |
|
| 315 |
@staticmethod |
| 316 |
def _find_tool(state: 'ModuleState', tool: str, required: bool = True) -> Program: |
| 317 |
tool_map = { |
| 318 |
'gio-querymodules': 'gio-2.0', |
| 319 |
'glib-compile-schemas': 'gio-2.0', |
| 320 |
'glib-compile-resources': 'gio-2.0', |
| 321 |
'gdbus-codegen': 'gio-2.0', |
| 322 |
'glib-genmarshal': 'glib-2.0', |
| 323 |
'glib-mkenums': 'glib-2.0', |
| 324 |
'g-ir-scanner': 'gobject-introspection-1.0', |
| 325 |
'g-ir-compiler': 'gobject-introspection-1.0', |
| 326 |
} |
| 327 |
depname = tool_map[tool] |
| 328 |
varname = tool.replace('-', '_') |
| 329 |
return state.find_tool(tool, depname, varname, required=required, native=depname != "gobject-introspection-1.0") |
| 330 |
|
| 331 |
@staticmethod |
| 332 |
def _get_install_script(state: ModuleState, name: str, exe: Program, args: T.List[str], skip_if_destdir: bool = True) -> InstallScript: |
| 333 |
if not exe.found(): |
| 334 |
mlog.warning(f'Program {name} was not found, installation without DESTDIR will fail', fatal=False) |
| 335 |
return InstallScriptFailure(name, 'Executable was not found') |
| 336 |
try: |
| 337 |
install_script = state.backend.get_executable_serialisation([exe, *args]) |
| 338 |
install_script.skip_if_destdir = skip_if_destdir |
| 339 |
return install_script |
| 340 |
except MesonException as e: |
| 341 |
mlog.warning(f'Meson will be unable to run {name}, installation without DESTDIR will fail', fatal=False) |
| 342 |
return InstallScriptFailure(name, str(e)) |
| 343 |
|
| 344 |
@typed_kwargs( |
| 345 |
'gnome.post_install', |
| 346 |
KwargInfo('glib_compile_schemas', bool, default=False), |
| 347 |
KwargInfo('gio_querymodules', ContainerTypeInfo(list, str), default=[], listify=True), |
| 348 |
KwargInfo('gtk_update_icon_cache', bool, default=False), |
| 349 |
KwargInfo('update_desktop_database', bool, default=False, since='0.59.0'), |
| 350 |
KwargInfo('update_mime_database', bool, default=False, since='0.64.0'), |
| 351 |
) |
| 352 |
@noPosargs |
| 353 |
@FeatureNew('gnome.post_install', '0.57.0') |
| 354 |
def post_install(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'PostInstall') -> ModuleReturnValue: |
| 355 |
rv: T.List[InstallScript] = [] |
| 356 |
datadir_abs = os.path.join(state.environment.get_prefix(), state.environment.get_datadir()) |
| 357 |
if kwargs['glib_compile_schemas'] and not self.install_glib_compile_schemas: |
| 358 |
self.install_glib_compile_schemas = True |
| 359 |
prog = self._find_tool(state, 'glib-compile-schemas', required=False) |
| 360 |
schemasdir = os.path.join(datadir_abs, 'glib-2.0', 'schemas') |
| 361 |
script = self._get_install_script(state, 'glib-compile-schemas', prog, [schemasdir]) |
| 362 |
rv.append(script) |
| 363 |
for d in kwargs['gio_querymodules']: |
| 364 |
if d not in self.install_gio_querymodules: |
| 365 |
self.install_gio_querymodules.append(d) |
| 366 |
prog = self._find_tool(state, 'gio-querymodules', required=False) |
| 367 |
moduledir = os.path.join(state.environment.get_prefix(), d) |
| 368 |
script = self._get_install_script(state, 'gio-querymodules', prog, [moduledir]) |
| 369 |
rv.append(script) |
| 370 |
if kwargs['gtk_update_icon_cache'] and not self.install_gtk_update_icon_cache: |
| 371 |
self.install_gtk_update_icon_cache = True |
| 372 |
prog = state.find_program('gtk4-update-icon-cache', required=False) |
| 373 |
found = isinstance(prog, Executable) or prog.found() |
| 374 |
if not found: |
| 375 |
prog = state.find_program('gtk-update-icon-cache', required=False) |
| 376 |
icondir = os.path.join(datadir_abs, 'icons', 'hicolor') |
| 377 |
script = self._get_install_script(state, 'gtk4-update-icon-cache', prog, ['-q', '-t', '-f', icondir]) |
| 378 |
rv.append(script) |
| 379 |
if kwargs['update_desktop_database'] and not self.install_update_desktop_database: |
| 380 |
self.install_update_desktop_database = True |
| 381 |
prog = state.find_program('update-desktop-database', required=False) |
| 382 |
appdir = os.path.join(datadir_abs, 'applications') |
| 383 |
script = self._get_install_script(state, 'update-desktop-database', prog, ['-q', appdir]) |
| 384 |
rv.append(script) |
| 385 |
if kwargs['update_mime_database'] and not self.install_update_mime_database: |
| 386 |
self.install_update_mime_database = True |
| 387 |
prog = state.find_program('update-mime-database', required=False) |
| 388 |
appdir = os.path.join(datadir_abs, 'mime') |
| 389 |
script = self._get_install_script(state, 'update-mime-database', prog, [appdir]) |
| 390 |
rv.append(script) |
| 391 |
return ModuleReturnValue(None, rv) |
| 392 |
|
| 393 |
@typed_pos_args('gnome.compile_resources', str, (str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList)) |
| 394 |
@typed_kwargs( |
| 395 |
'gnome.compile_resources', |
| 396 |
_BUILD_BY_DEFAULT, |
| 397 |
_EXTRA_ARGS_KW, |
| 398 |
INSTALL_KW, |
| 399 |
INSTALL_KW.evolve(name='install_header', since='0.37.0'), |
| 400 |
INSTALL_DIR_KW, |
| 401 |
KwargInfo('c_name', (str, NoneType)), |
| 402 |
KwargInfo('dependencies', ContainerTypeInfo(list, (mesonlib.File, CustomTarget, CustomTargetIndex)), default=[], listify=True), |
| 403 |
KwargInfo('export', bool, default=False, since='0.37.0'), |
| 404 |
KwargInfo('gresource_bundle', bool, default=False, since='0.37.0'), |
| 405 |
KwargInfo('source_dir', ContainerTypeInfo(list, str), default=[], listify=True), |
| 406 |
) |
| 407 |
def compile_resources(self, state: 'ModuleState', args: T.Tuple[str, CustomTargetInputs], |
| 408 |
kwargs: 'CompileResources') -> 'ModuleReturnValue': |
| 409 |
self.__print_gresources_warning(state) |
| 410 |
glib_version = self._get_native_glib_version(state) |
| 411 |
|
| 412 |
glib_compile_resources = self._find_tool(state, 'glib-compile-resources') |
| 413 |
cmd: CommandList = [glib_compile_resources, '@INPUT@'] |
| 414 |
|
| 415 |
source_dirs = kwargs['source_dir'] |
| 416 |
dependencies = kwargs['dependencies'] |
| 417 |
target_name, input_file_arg = args |
| 418 |
|
| 419 |
input_file: CustomTargetSources |
| 420 |
if isinstance(input_file_arg, str): |
| 421 |
input_file = mesonlib.File.from_source_file(state.environment.get_source_dir(), |
| 422 |
state.subdir, input_file_arg) |
| 423 |
else: |
| 424 |
input_file = input_file_arg |
| 425 |
|
| 426 |
# Validate dependencies |
| 427 |
subdirs: T.List[str] = [] |
| 428 |
depends: T.List[T.Union[CustomTarget, CustomTargetIndex]] = [] |
| 429 |
for dep in dependencies: |
| 430 |
if isinstance(dep, mesonlib.File): |
| 431 |
subdirs.append(dep.subdir) |
| 432 |
else: |
| 433 |
depends.append(dep) |
| 434 |
subdirs.append(dep.get_subdir()) |
| 435 |
if not mesonlib.version_compare(glib_version, gresource_dep_needed_version): |
| 436 |
m = 'The "dependencies" argument of gnome.compile_resources() cannot\n' \ |
| 437 |
'be used with the current version of glib-compile-resources due to\n' \ |
| 438 |
'<https://bugzilla.gnome.org/show_bug.cgi?id=774368>' |
| 439 |
raise MesonException(m) |
| 440 |
|
| 441 |
if not mesonlib.version_compare(glib_version, gresource_dep_needed_version): |
| 442 |
# Resource xml files generated at build-time cannot be used with |
| 443 |
# gnome.compile_resources() because we need to scan the xml for |
| 444 |
# dependencies. Use configure_file() instead to generate it at |
| 445 |
# configure-time |
| 446 |
if isinstance(input_file, mesonlib.File): |
| 447 |
# glib-compile-resources will be run inside the source dir, |
| 448 |
# so we need either 'src_to_build' or the absolute path. |
| 449 |
# Absolute path is the easiest choice. |
| 450 |
if input_file.is_built: |
| 451 |
ifile = os.path.join(state.environment.get_build_dir(), input_file.subdir, input_file.fname) |
| 452 |
else: |
| 453 |
ifile = os.path.join(input_file.subdir, input_file.fname) |
| 454 |
|
| 455 |
elif isinstance(input_file, (CustomTarget, CustomTargetIndex, GeneratedList)): |
| 456 |
# TODO: this could be fixed with dyndeps |
| 457 |
raise MesonException('Resource xml files generated at build-time cannot be used with ' |
| 458 |
'gnome.compile_resources() in the current version of glib-compile-resources ' |
| 459 |
'because we need to scan the xml for dependencies due to ' |
| 460 |
'<https://bugzilla.gnome.org/show_bug.cgi?id=774368>\nUse ' |
| 461 |
'configure_file() instead to generate it at configure-time.') |
| 462 |
|
| 463 |
depend_files, depends, subdirs = self._get_gresource_dependencies( |
| 464 |
state, ifile, source_dirs, dependencies) |
| 465 |
else: |
| 466 |
depend_files = [] |
| 467 |
|
| 468 |
# Make source dirs relative to build dir now |
| 469 |
source_dirs = [os.path.join(state.build_to_src, state.subdir, d) for d in source_dirs] |
| 470 |
# Ensure build directories of generated deps are included |
| 471 |
source_dirs += subdirs |
| 472 |
# Always include current directory, but after paths set by user |
| 473 |
source_dirs.append(os.path.join(state.build_to_src, state.subdir)) |
| 474 |
|
| 475 |
# Clean up duplicate directories |
| 476 |
source_dirs = list(OrderedSet(os.path.normpath(dir) for dir in source_dirs)) |
| 477 |
|
| 478 |
for source_dir in source_dirs: |
| 479 |
cmd += ['--sourcedir', source_dir] |
| 480 |
|
| 481 |
if kwargs['c_name']: |
| 482 |
cmd += ['--c-name', kwargs['c_name']] |
| 483 |
if not kwargs['export']: |
| 484 |
cmd += ['--internal'] |
| 485 |
|
| 486 |
cmd += ['--generate', '--target', '@OUTPUT@'] |
| 487 |
cmd += kwargs['extra_args'] |
| 488 |
|
| 489 |
gresource = kwargs['gresource_bundle'] |
| 490 |
if gresource: |
| 491 |
output = f'{target_name}.gresource' |
| 492 |
name = f'{target_name}_gresource' |
| 493 |
else: |
| 494 |
if 'c' in state.environment.coredata.compilers.host: |
| 495 |
output = f'{target_name}.c' |
| 496 |
name = f'{target_name}_c' |
| 497 |
elif 'cpp' in state.environment.coredata.compilers.host: |
| 498 |
output = f'{target_name}.cpp' |
| 499 |
name = f'{target_name}_cpp' |
| 500 |
else: |
| 501 |
raise MesonException('Compiling GResources into code is only supported in C and C++ projects') |
| 502 |
|
| 503 |
if kwargs['install']: |
| 504 |
if not gresource: |
| 505 |
raise MesonException('The install kwarg only applies to gresource bundles, see install_header') |
| 506 |
elif not kwargs['install_dir']: |
| 507 |
raise MesonException('gnome.compile_resources: "install_dir" keyword argument must be set when "install" is true.') |
| 508 |
|
| 509 |
install_header = kwargs['install_header'] |
| 510 |
if install_header and gresource: |
| 511 |
raise MesonException('The install_header kwarg does not apply to gresource bundles') |
| 512 |
if install_header and not kwargs['export']: |
| 513 |
raise MesonException('GResource header is installed yet export is not enabled') |
| 514 |
|
| 515 |
depfile: T.Optional[str] = None |
| 516 |
target_cmd: CommandList |
| 517 |
if not mesonlib.version_compare(glib_version, gresource_dep_needed_version): |
| 518 |
# This will eventually go out of sync if dependencies are added |
| 519 |
target_cmd = cmd |
| 520 |
else: |
| 521 |
depfile = f'{output}.d' |
| 522 |
target_cmd = copy.copy(cmd) + ['--dependency-file', '@DEPFILE@'] |
| 523 |
target_c = GResourceTarget( |
| 524 |
name, |
| 525 |
state.subdir, |
| 526 |
state.environment, |
| 527 |
target_cmd, |
| 528 |
[input_file], |
| 529 |
[output], |
| 530 |
state.current_build_project, |
| 531 |
build_by_default=kwargs['build_by_default'], |
| 532 |
depfile=depfile, |
| 533 |
depend_files=depend_files, |
| 534 |
extra_depends=depends, |
| 535 |
install=kwargs['install'], |
| 536 |
install_dir=[kwargs['install_dir']] if kwargs['install_dir'] else [], |
| 537 |
install_tag=['runtime'], |
| 538 |
) |
| 539 |
target_c.source_dirs = source_dirs |
| 540 |
|
| 541 |
if gresource: # Only one target for .gresource files |
| 542 |
return ModuleReturnValue(target_c, [target_c]) |
| 543 |
|
| 544 |
install_dir = kwargs['install_dir'] or state.environment.coredata.optstore.get_value_for(OptionKey('includedir')) |
| 545 |
assert isinstance(install_dir, str), 'for mypy' |
| 546 |
target_h = GResourceHeaderTarget( |
| 547 |
f'{target_name}_h', |
| 548 |
state.subdir, |
| 549 |
state.environment, |
| 550 |
cmd, |
| 551 |
[input_file], |
| 552 |
[f'{target_name}.h'], |
| 553 |
state.current_build_project, |
| 554 |
build_by_default=kwargs['build_by_default'], |
| 555 |
extra_depends=depends, |
| 556 |
install=install_header, |
| 557 |
install_dir=[install_dir], |
| 558 |
install_tag=['devel'], |
| 559 |
) |
| 560 |
rv = [target_c, target_h] |
| 561 |
return ModuleReturnValue(rv, rv) |
| 562 |
|
| 563 |
@staticmethod |
| 564 |
def _get_gresource_dependencies( |
| 565 |
state: 'ModuleState', input_file: str, source_dirs: T.List[str], |
| 566 |
dependencies: T.Sequence[T.Union[mesonlib.File, CustomTarget, CustomTargetIndex]] |
| 567 |
) -> T.Tuple[T.List[mesonlib.File], T.List[T.Union[CustomTarget, CustomTargetIndex]], T.List[str]]: |
| 568 |
|
| 569 |
cmd = ['glib-compile-resources', |
| 570 |
input_file, |
| 571 |
'--generate-dependencies'] |
| 572 |
|
| 573 |
# Prefer generated files over source files |
| 574 |
cmd += ['--sourcedir', state.subdir] # Current build dir |
| 575 |
for source_dir in source_dirs: |
| 576 |
cmd += ['--sourcedir', os.path.join(state.subdir, source_dir)] |
| 577 |
|
| 578 |
try: |
| 579 |
pc, stdout, stderr = Popen_safe(cmd, cwd=state.environment.get_source_dir()) |
| 580 |
except (FileNotFoundError, PermissionError): |
| 581 |
raise MesonException('Could not execute glib-compile-resources.') |
| 582 |
if pc.returncode != 0: |
| 583 |
m = f'glib-compile-resources failed to get dependencies for {cmd[1]}:\n{stderr}' |
| 584 |
mlog.warning(m) |
| 585 |
raise subprocess.CalledProcessError(pc.returncode, cmd) |
| 586 |
|
| 587 |
raw_dep_files: T.List[str] = stdout.split('\n')[:-1] |
| 588 |
|
| 589 |
depends: T.List[T.Union[CustomTarget, CustomTargetIndex]] = [] |
| 590 |
subdirs: T.List[str] = [] |
| 591 |
dep_files: T.List[mesonlib.File] = [] |
| 592 |
for resfile in raw_dep_files.copy(): |
| 593 |
resbasename = os.path.basename(resfile) |
| 594 |
for dep in dependencies: |
| 595 |
if isinstance(dep, mesonlib.File): |
| 596 |
if dep.fname != resbasename: |
| 597 |
continue |
| 598 |
raw_dep_files.remove(resfile) |
| 599 |
dep_files.append(dep) |
| 600 |
subdirs.append(dep.subdir) |
| 601 |
break |
| 602 |
elif isinstance(dep, (CustomTarget, CustomTargetIndex)): |
| 603 |
fname = None |
| 604 |
outputs = {(o, os.path.basename(o)) for o in dep.get_outputs()} |
| 605 |
for o, baseo in outputs: |
| 606 |
if baseo == resbasename: |
| 607 |
fname = o |
| 608 |
break |
| 609 |
if fname is not None: |
| 610 |
raw_dep_files.remove(resfile) |
| 611 |
depends.append(dep) |
| 612 |
subdirs.append(dep.get_subdir()) |
| 613 |
break |
| 614 |
else: |
| 615 |
# In generate-dependencies mode, glib-compile-resources doesn't raise |
| 616 |
# an error for missing resources but instead prints whatever filename |
| 617 |
# was listed in the input file. That's good because it means we can |
| 618 |
# handle resource files that get generated as part of the build, as |
| 619 |
# follows. |
| 620 |
# |
| 621 |
# If there are multiple generated resource files with the same basename |
| 622 |
# then this code will get confused. |
| 623 |
try: |
| 624 |
f = mesonlib.File.from_source_file(state.environment.get_source_dir(), |
| 625 |
".", resfile) |
| 626 |
except MesonException: |
| 627 |
raise MesonException( |
| 628 |
f'Resource "{resfile}" listed in "{input_file}" was not found. ' |
| 629 |
'If this is a generated file, pass the target that generates ' |
| 630 |
'it to gnome.compile_resources() using the "dependencies" ' |
| 631 |
'keyword argument.') |
| 632 |
raw_dep_files.remove(resfile) |
| 633 |
dep_files.append(f) |
| 634 |
dep_files.extend(mesonlib.File.from_absolute_file(r) for r in raw_dep_files) |
| 635 |
return dep_files, depends, subdirs |
| 636 |
|
| 637 |
def _get_link_args(self, state: 'ModuleState', |
| 638 |
lib: T.Union[build.SharedLibrary, build.StaticLibrary], |
| 639 |
depends: T.Sequence[TargetDepends], |
| 640 |
include_rpath: bool = False, |
| 641 |
use_gir_args: bool = False |
| 642 |
) -> T.Tuple[T.List[str], T.List[TargetDepends]]: |
| 643 |
link_command: T.List[str] = [] |
| 644 |
new_depends = list(depends) |
| 645 |
# Construct link args |
| 646 |
if isinstance(lib, build.SharedLibrary): |
| 647 |
libdir = os.path.join(state.environment.get_build_dir(), state.backend.get_target_dir(lib)) |
| 648 |
link_command.append('-L' + libdir) |
| 649 |
if include_rpath: |
| 650 |
link_command.append('-Wl,-rpath,' + libdir) |
| 651 |
new_depends.append(lib) |
| 652 |
# Needed for the following binutils bug: |
| 653 |
# https://github.com/mesonbuild/meson/issues/1911 |
| 654 |
# However, g-ir-scanner does not understand -Wl,-rpath |
| 655 |
# so we need to use -L instead |
| 656 |
for d in lib.determine_rpath_dirs(): |
| 657 |
d = os.path.join(state.environment.get_build_dir(), d) |
| 658 |
link_command.append('-L' + d) |
| 659 |
if include_rpath: |
| 660 |
link_command.append('-Wl,-rpath,' + d) |
| 661 |
if use_gir_args and self._gir_has_option('--extra-library'): |
| 662 |
link_command.append('--extra-library=' + lib.name) |
| 663 |
else: |
| 664 |
link_command.append('-l' + lib.name) |
| 665 |
return link_command, new_depends |
| 666 |
|
| 667 |
def _get_dependencies_flags_raw( |
| 668 |
self, deps: T.Sequence[T.Union['Dependency', build.BuildTargetTypes]], |
| 669 |
state: 'ModuleState', |
| 670 |
depends: T.Sequence[TargetDepends], |
| 671 |
include_rpath: bool, |
| 672 |
use_gir_args: bool, |
| 673 |
) -> T.Tuple[OrderedSet[str], OrderedSet[T.Union[str, T.Tuple[str, str]]], OrderedSet[T.Union[str, T.Tuple[str, str]]], OrderedSet[str], |
| 674 |
T.List[TargetDepends]]: |
| 675 |
cflags: OrderedSet[str] = OrderedSet() |
| 676 |
# External linker flags that can't be de-duped reliably because they |
| 677 |
# require two args in order, such as -framework AVFoundation will be stored as a tuple. |
| 678 |
internal_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet() |
| 679 |
external_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet() |
| 680 |
gi_includes: OrderedSet[str] = OrderedSet() |
| 681 |
deps = mesonlib.listify(deps) |
| 682 |
depends = list(depends) |
| 683 |
|
| 684 |
for dep in deps: |
| 685 |
if isinstance(dep, Dependency): |
| 686 |
girdir = dep.get_variable(pkgconfig='girdir', internal='girdir', default_value='') |
| 687 |
if girdir: |
| 688 |
assert isinstance(girdir, str), 'for mypy' |
| 689 |
gi_includes.update([girdir]) |
| 690 |
if isinstance(dep, InternalDependency): |
| 691 |
cflags.update(dep.get_compile_args()) |
| 692 |
cflags.update(state.get_include_args(dep.include_directories)) |
| 693 |
for lib in dep.libraries: |
| 694 |
if isinstance(lib, build.SharedLibrary): |
| 695 |
_ld, depends = self._get_link_args(state, lib, depends, include_rpath) |
| 696 |
internal_ldflags.update(_ld) |
| 697 |
libdepflags = self._get_dependencies_flags_raw(lib.get_external_deps(), state, depends, include_rpath, |
| 698 |
use_gir_args) |
| 699 |
cflags.update(libdepflags[0]) |
| 700 |
internal_ldflags.update(libdepflags[1]) |
| 701 |
external_ldflags.update(libdepflags[2]) |
| 702 |
gi_includes.update(libdepflags[3]) |
| 703 |
depends = libdepflags[4] |
| 704 |
extdepflags = self._get_dependencies_flags_raw(dep.ext_deps, state, depends, include_rpath, |
| 705 |
use_gir_args) |
| 706 |
cflags.update(extdepflags[0]) |
| 707 |
internal_ldflags.update(extdepflags[1]) |
| 708 |
external_ldflags.update(extdepflags[2]) |
| 709 |
gi_includes.update(extdepflags[3]) |
| 710 |
depends = extdepflags[4] |
| 711 |
for source in dep.sources: |
| 712 |
if isinstance(source, GirTarget): |
| 713 |
gi_includes.update([os.path.join(state.environment.get_build_dir(), |
| 714 |
source.get_subdir())]) |
| 715 |
# This should be any dependency other than an internal one. |
| 716 |
elif isinstance(dep, Dependency): |
| 717 |
cflags.update(dep.get_compile_args()) |
| 718 |
ldflags = iter(dep.get_link_args(raw=True)) |
| 719 |
for flag in ldflags: |
| 720 |
if (os.path.isabs(flag) and |
| 721 |
# For PkgConfigDependency only: |
| 722 |
getattr(dep, 'is_libtool', False)): |
| 723 |
lib_dir = os.path.dirname(flag) |
| 724 |
external_ldflags.update([f'-L{lib_dir}']) |
| 725 |
if include_rpath: |
| 726 |
external_ldflags.update([f'-Wl,-rpath,{lib_dir}']) |
| 727 |
libname = os.path.basename(flag) |
| 728 |
if libname.startswith("lib"): |
| 729 |
libname = libname[3:] |
| 730 |
libname = libname.split(".so")[0] |
| 731 |
flag = f"-l{libname}" |
| 732 |
# FIXME: Hack to avoid passing some compiler options in |
| 733 |
if flag.startswith("-W") and not flag.startswith('-Wl,-rpath,'): |
| 734 |
continue |
| 735 |
# If it's a framework arg, slurp the framework name too |
| 736 |
# to preserve the order of arguments |
| 737 |
if flag == '-framework': |
| 738 |
external_ldflags.update([(flag, next(ldflags))]) |
| 739 |
else: |
| 740 |
external_ldflags.update([flag]) |
| 741 |
elif isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): |
| 742 |
cflags.update(state.get_include_args(dep.get_include_dirs())) |
| 743 |
depends.append(dep) |
| 744 |
else: |
| 745 |
mlog.log(f'dependency {dep!r} not handled to build gir files') |
| 746 |
continue |
| 747 |
|
| 748 |
if use_gir_args and self._gir_has_option('--extra-library'): |
| 749 |
def fix_ldflags(ldflags: T.Iterable[T.Union[str, T.Tuple[str, str]]]) -> OrderedSet[T.Union[str, T.Tuple[str, str]]]: |
| 750 |
fixed_ldflags: OrderedSet[T.Union[str, T.Tuple[str, str]]] = OrderedSet() |
| 751 |
for ldflag in ldflags: |
| 752 |
if isinstance(ldflag, str) and ldflag.startswith("-l"): |
| 753 |
ldflag = ldflag.replace('-l', '--extra-library=', 1) |
| 754 |
fixed_ldflags.add(ldflag) |
| 755 |
return fixed_ldflags |
| 756 |
internal_ldflags = fix_ldflags(internal_ldflags) |
| 757 |
external_ldflags = fix_ldflags(external_ldflags) |
| 758 |
return cflags, internal_ldflags, external_ldflags, gi_includes, depends |
| 759 |
|
| 760 |
def _get_dependencies_flags( |
| 761 |
self, deps: T.Sequence[T.Union['Dependency', build.BuildTargetTypes]], |
| 762 |
state: 'ModuleState', |
| 763 |
depends: T.Sequence[TargetDepends], |
| 764 |
include_rpath: bool = False, |
| 765 |
use_gir_args: bool = False, |
| 766 |
) -> T.Tuple[OrderedSet[str], T.List[str], T.List[str], OrderedSet[str], |
| 767 |
T.List[TargetDepends]]: |
| 768 |
|
| 769 |
cflags, internal_ldflags_raw, external_ldflags_raw, gi_includes, new_depends = self._get_dependencies_flags_raw(deps, state, depends, include_rpath, use_gir_args) |
| 770 |
internal_ldflags: T.List[str] = [] |
| 771 |
external_ldflags: T.List[str] = [] |
| 772 |
|
| 773 |
# Extract non-deduplicable argument groups out of the tuples. |
| 774 |
for ldflag in internal_ldflags_raw: |
| 775 |
if isinstance(ldflag, str): |
| 776 |
internal_ldflags.append(ldflag) |
| 777 |
else: |
| 778 |
internal_ldflags.extend(ldflag) |
| 779 |
for ldflag in external_ldflags_raw: |
| 780 |
if isinstance(ldflag, str): |
| 781 |
external_ldflags.append(ldflag) |
| 782 |
else: |
| 783 |
external_ldflags.extend(ldflag) |
| 784 |
|
| 785 |
return cflags, internal_ldflags, external_ldflags, gi_includes, new_depends |
| 786 |
|
| 787 |
def _unwrap_gir_target(self, girtarget: T.Union[Executable, build.StaticLibrary, build.SharedLibrary], state: 'ModuleState' |
| 788 |
) -> T.Union[Executable, build.StaticLibrary, build.SharedLibrary]: |
| 789 |
if not isinstance(girtarget, (Executable, build.SharedLibrary, |
| 790 |
build.StaticLibrary)): |
| 791 |
raise MesonException(f'Gir target must be an executable or library but is "{girtarget}" of type {type(girtarget).__name__}') |
| 792 |
|
| 793 |
STATIC_BUILD_REQUIRED_VERSION = ">=1.58.1" |
| 794 |
if isinstance(girtarget, (build.StaticLibrary)) and \ |
| 795 |
not self._giscanner_version_compare(state, STATIC_BUILD_REQUIRED_VERSION): |
| 796 |
raise MesonException('Static libraries can only be introspected with GObject-Introspection ' + STATIC_BUILD_REQUIRED_VERSION) |
| 797 |
|
| 798 |
return girtarget |
| 799 |
|
| 800 |
def _devenv_prepend(self, varname: str, value: str) -> None: |
| 801 |
if self.devenv is None: |
| 802 |
self.devenv = mesonlib.EnvironmentVariables() |
| 803 |
self.devenv.prepend(varname, [value]) |
| 804 |
|
| 805 |
def postconf_hook(self, b: build.Build) -> None: |
| 806 |
if self.devenv is not None: |
| 807 |
b.devenv.append(self.devenv) |
| 808 |
|
| 809 |
def _get_gir_dep(self, state: 'ModuleState') -> T.Tuple[Dependency, Program, Program]: |
| 810 |
if not self.gir_dep: |
| 811 |
self.gir_dep = state.dependency('gobject-introspection-1.0') |
| 812 |
self.giscanner = self._find_tool(state, 'g-ir-scanner') |
| 813 |
self.gicompiler = self._find_tool(state, 'g-ir-compiler') |
| 814 |
return self.gir_dep, self.giscanner, self.gicompiler |
| 815 |
|
| 816 |
def _giscanner_version_compare(self, state: 'ModuleState', cmp: str) -> bool: |
| 817 |
# Support for --version was introduced in g-i 1.58, but Ubuntu |
| 818 |
# Bionic shipped 1.56.1. As all our version checks are greater |
| 819 |
# than 1.58, we can just return False if get_version fails. |
| 820 |
try: |
| 821 |
giscanner, _, _ = self._get_gir_dep(state) |
| 822 |
return mesonlib.version_compare(giscanner.get_version(), cmp) |
| 823 |
except MesonException: |
| 824 |
return False |
| 825 |
|
| 826 |
@functools.lru_cache(maxsize=None) |
| 827 |
def _gir_has_option(self, option: str) -> bool: |
| 828 |
exe = self.giscanner |
| 829 |
if isinstance(exe, LocalProgram): |
| 830 |
# Handle overridden g-ir-scanner |
| 831 |
assert option in {'--extra-library', '--sources-top-dirs'} |
| 832 |
return True |
| 833 |
p, o, _ = Popen_safe(exe.get_command() + ['--help'], stderr=subprocess.STDOUT) |
| 834 |
return p.returncode == 0 and option in o |
| 835 |
|
| 836 |
# May mutate depends and gir_inc_dirs |
| 837 |
@staticmethod |
| 838 |
def _scan_include(state: 'ModuleState', includes: T.List[T.Union[str, GirTarget]] |
| 839 |
) -> T.Tuple[T.List[str], T.List[str], T.List[GirTarget]]: |
| 840 |
ret: T.List[str] = [] |
| 841 |
gir_inc_dirs: T.List[str] = [] |
| 842 |
depends: T.List[GirTarget] = [] |
| 843 |
|
| 844 |
for inc in includes: |
| 845 |
if isinstance(inc, str): |
| 846 |
ret += [f'--include={inc}'] |
| 847 |
elif isinstance(inc, GirTarget): |
| 848 |
gir_inc_dirs .append(os.path.join(state.environment.get_build_dir(), inc.get_builddir())) |
| 849 |
ret.append(f"--include-uninstalled={os.path.join(inc.get_builddir(), inc.get_basename())}") |
| 850 |
depends.append(inc) |
| 851 |
|
| 852 |
return ret, gir_inc_dirs, depends |
| 853 |
|
| 854 |
@staticmethod |
| 855 |
def _scan_langs(state: 'ModuleState', langs: T.Iterable[str]) -> T.List[str]: |
| 856 |
ret: T.List[str] = [] |
| 857 |
|
| 858 |
for lang in langs: |
| 859 |
link_args = state.environment.coredata.get_external_link_args(MachineChoice.HOST, lang) |
| 860 |
for link_arg in link_args: |
| 861 |
if link_arg.startswith('-L'): |
| 862 |
ret.append(link_arg) |
| 863 |
|
| 864 |
return ret |
| 865 |
|
| 866 |
@staticmethod |
| 867 |
def _scan_gir_targets(state: 'ModuleState', girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Union[str, Executable]]: |
| 868 |
ret: T.List[T.Union[str, Executable]] = [] |
| 869 |
|
| 870 |
for girtarget in girtargets: |
| 871 |
if isinstance(girtarget, Executable): |
| 872 |
ret += ['--program', girtarget] |
| 873 |
else: |
| 874 |
# Because of https://gitlab.gnome.org/GNOME/gobject-introspection/merge_requests/72 |
| 875 |
# we can't use the full path until this is merged. |
| 876 |
libpath = os.path.join(girtarget.get_subdir(), girtarget.get_filename()) |
| 877 |
# Must use absolute paths here because g-ir-scanner will not |
| 878 |
# add them to the runtime path list if they're relative. This |
| 879 |
# means we cannot use @BUILD_ROOT@ |
| 880 |
build_root = state.environment.get_build_dir() |
| 881 |
if isinstance(girtarget, build.SharedLibrary): |
| 882 |
# need to put our output directory first as we need to use the |
| 883 |
# generated libraries instead of any possibly installed system/prefix |
| 884 |
# ones. |
| 885 |
ret += ["-L{}/{}".format(build_root, os.path.dirname(libpath))] |
| 886 |
libname = girtarget.get_basename() |
| 887 |
else: |
| 888 |
libname = os.path.join(f"{build_root}/{libpath}") |
| 889 |
ret += ['--library', libname] |
| 890 |
# Needed for the following binutils bug: |
| 891 |
# https://github.com/mesonbuild/meson/issues/1911 |
| 892 |
# However, g-ir-scanner does not understand -Wl,-rpath |
| 893 |
# so we need to use -L instead |
| 894 |
for d in girtarget.determine_rpath_dirs(): |
| 895 |
d = os.path.join(state.environment.get_build_dir(), d) |
| 896 |
ret.append('-L' + d) |
| 897 |
|
| 898 |
return ret |
| 899 |
|
| 900 |
@staticmethod |
| 901 |
def _get_girtargets_langs_compilers(girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Tuple[Language, 'Compiler']]: |
| 902 |
ret: T.List[T.Tuple[Language, 'Compiler']] = [] |
| 903 |
for girtarget in girtargets: |
| 904 |
for lang, compiler in girtarget.compilers.items(): |
| 905 |
# XXX: Can you use g-i with any other language? |
| 906 |
if lang in {'c', 'cpp', 'objc', 'objcpp', 'd'}: |
| 907 |
ret.append((lang, compiler)) |
| 908 |
break |
| 909 |
|
| 910 |
return ret |
| 911 |
|
| 912 |
@staticmethod |
| 913 |
def _get_gir_targets_deps(girtargets: T.Sequence[build.BuildTarget] |
| 914 |
) -> T.List[T.Union[build.BuildTargetTypes, Dependency]]: |
| 915 |
ret: T.List[T.Union[build.BuildTargetTypes, Dependency]] = [] |
| 916 |
for girtarget in girtargets: |
| 917 |
ret += girtarget.get_all_link_deps() |
| 918 |
ret += girtarget.get_external_deps() |
| 919 |
return ret |
| 920 |
|
| 921 |
@staticmethod |
| 922 |
def _get_gir_targets_inc_dirs(girtargets: T.Sequence[build.BuildTarget]) -> OrderedSet[build.IncludeDirs]: |
| 923 |
ret: OrderedSet = OrderedSet() |
| 924 |
for girtarget in girtargets: |
| 925 |
ret.update(girtarget.get_include_dirs()) |
| 926 |
return ret |
| 927 |
|
| 928 |
@staticmethod |
| 929 |
def _get_langs_compilers_flags(state: 'ModuleState', langs_compilers: T.List[T.Tuple[Language, 'Compiler']] |
| 930 |
) -> T.Tuple[T.List[str], T.List[str], T.List[str]]: |
| 931 |
cflags: T.List[str] = [] |
| 932 |
internal_ldflags: T.List[str] = [] |
| 933 |
external_ldflags: T.List[str] = [] |
| 934 |
|
| 935 |
for lang, compiler in langs_compilers: |
| 936 |
if state.global_args.get(lang): |
| 937 |
cflags += state.global_args[lang] |
| 938 |
if state.project_args.get(lang): |
| 939 |
cflags += state.project_args[lang] |
| 940 |
if OptionKey('b_sanitize') in compiler.base_options: |
| 941 |
sanitize = state.environment.coredata.optstore.get_value_for('b_sanitize') |
| 942 |
assert isinstance(sanitize, list) |
| 943 |
cflags += compiler.sanitizer_compile_args(None, sanitize) |
| 944 |
# These must be first in ldflags |
| 945 |
if 'address' in sanitize: |
| 946 |
internal_ldflags += ['-lasan'] |
| 947 |
if 'thread' in sanitize: |
| 948 |
internal_ldflags += ['-ltsan'] |
| 949 |
if 'undefined' in sanitize: |
| 950 |
internal_ldflags += ['-lubsan'] |
| 951 |
# FIXME: Linking directly to lib*san is not recommended but g-ir-scanner |
| 952 |
# does not understand -f LDFLAGS. https://bugzilla.gnome.org/show_bug.cgi?id=783892 |
| 953 |
# ldflags += compiler.sanitizer_link_args(None, state.environment, sanitize) |
| 954 |
|
| 955 |
return cflags, internal_ldflags, external_ldflags |
| 956 |
|
| 957 |
@staticmethod |
| 958 |
def _make_gir_filelist(state: 'ModuleState', srcdir: str, ns: str, |
| 959 |
nsversion: str, girtargets: T.Sequence[build.BuildTarget], |
| 960 |
libsources: T.Sequence[T.Union[ |
| 961 |
str, mesonlib.File, GeneratedList, |
| 962 |
CustomTarget, CustomTargetIndex]] |
| 963 |
) -> str: |
| 964 |
gir_filelist_dir = state.backend.get_target_private_dir_abs(girtargets[0]) |
| 965 |
if not os.path.isdir(gir_filelist_dir): |
| 966 |
os.mkdir(gir_filelist_dir) |
| 967 |
gir_filelist_filename = os.path.join(gir_filelist_dir, f'{ns}_{nsversion}_gir_filelist') |
| 968 |
|
| 969 |
with open(gir_filelist_filename, 'w', encoding='utf-8') as gir_filelist: |
| 970 |
for s in libsources: |
| 971 |
if isinstance(s, (CustomTarget, CustomTargetIndex)): |
| 972 |
for custom_output in s.get_outputs(): |
| 973 |
gir_filelist.write(os.path.join(state.environment.get_build_dir(), |
| 974 |
state.backend.get_target_dir(s), |
| 975 |
custom_output) + '\n') |
| 976 |
elif isinstance(s, mesonlib.File): |
| 977 |
gir_filelist.write(s.rel_to_builddir(state.build_to_src) + '\n') |
| 978 |
elif isinstance(s, GeneratedList): |
| 979 |
for gen_src in s.get_outputs(): |
| 980 |
gir_filelist.write(os.path.join(srcdir, gen_src) + '\n') |
| 981 |
else: |
| 982 |
gir_filelist.write(os.path.join(srcdir, s) + '\n') |
| 983 |
|
| 984 |
return gir_filelist_filename |
| 985 |
|
| 986 |
def _make_gir_target( |
| 987 |
self, |
| 988 |
state: 'ModuleState', |
| 989 |
girfile: str, |
| 990 |
scan_command: T.Sequence[T.Union['FileOrString', Executable, Program]], |
| 991 |
generated_files: T.Sequence[build.GeneratedTypes], |
| 992 |
depends: T.Sequence[TargetDepends], |
| 993 |
env_flags: T.Sequence[str], |
| 994 |
kwargs: GenerateGir) -> GirTarget: |
| 995 |
install = kwargs['install_gir'] |
| 996 |
if install is None: |
| 997 |
install = kwargs['install'] |
| 998 |
|
| 999 |
install_dir = kwargs['install_dir_gir'] |
| 1000 |
if install_dir is None: |
| 1001 |
install_dir = os.path.join(state.environment.get_datadir(), 'gir-1.0') |
| 1002 |
elif install_dir is False: |
| 1003 |
install = False |
| 1004 |
|
| 1005 |
# g-ir-scanner uses pkg-config to find libraries such as glib. They could |
| 1006 |
# be built as subproject in which case we need to trick it to use |
| 1007 |
# -uninstalled.pc files Meson generated. It also must respect pkgconfig |
| 1008 |
# settings user could have set in machine file, like PKG_CONFIG_LIBDIR, |
| 1009 |
# SYSROOT, etc. |
| 1010 |
run_env = PkgConfigInterface.get_env(state.environment, MachineChoice.HOST, uninstalled=True) |
| 1011 |
# g-ir-scanner uses Python's distutils to find the compiler, which uses 'CC' |
| 1012 |
cc_exelist = state.environment.coredata.compilers.host['c'].get_exelist() |
| 1013 |
# g-ir-scanner uses distutils/setuptools which splits CC with both Posix |
| 1014 |
# and Windows rules to get the first argument, which breaks if there are |
| 1015 |
# backslashes, so best avoid them entirely. |
| 1016 |
cc_exelist = [pathlib.Path(exe).as_posix() for exe in cc_exelist] |
| 1017 |
run_env.set('CC', [quote_arg(x) for x in cc_exelist], ' ') |
| 1018 |
run_env.set('CFLAGS', [quote_arg(x) for x in env_flags], ' ') |
| 1019 |
run_env.merge(kwargs['env']) |
| 1020 |
|
| 1021 |
# response file supported? |
| 1022 |
rspable = self._giscanner_version_compare(state, '>= 1.85.0') |
| 1023 |
|
| 1024 |
return GirTarget( |
| 1025 |
girfile, |
| 1026 |
state.subdir, |
| 1027 |
state.environment, |
| 1028 |
scan_command, |
| 1029 |
generated_files, |
| 1030 |
[girfile], |
| 1031 |
state.current_build_project, |
| 1032 |
build_by_default=kwargs['build_by_default'], |
| 1033 |
extra_depends=depends, |
| 1034 |
install=install, |
| 1035 |
install_dir=[install_dir], |
| 1036 |
install_tag=['devel'], |
| 1037 |
env=run_env, |
| 1038 |
rspable=rspable, |
| 1039 |
) |
| 1040 |
|
| 1041 |
@staticmethod |
| 1042 |
def _make_typelib_target(state: 'ModuleState', typelib_output: str, |
| 1043 |
typelib_cmd: T.Sequence[T.Union[str, CustomTarget, Program]], |
| 1044 |
generated_files: T.Sequence[build.GeneratedTypes], |
| 1045 |
kwargs: GenerateGir) -> TypelibTarget: |
| 1046 |
install = kwargs['install_typelib'] |
| 1047 |
if install is None: |
| 1048 |
install = kwargs['install'] |
| 1049 |
|
| 1050 |
install_dir = kwargs['install_dir_typelib'] |
| 1051 |
if install_dir is None: |
| 1052 |
install_dir = os.path.join(state.environment.get_libdir(), 'girepository-1.0') |
| 1053 |
elif install_dir is False: |
| 1054 |
install = False |
| 1055 |
|
| 1056 |
return TypelibTarget( |
| 1057 |
typelib_output, |
| 1058 |
state.subdir, |
| 1059 |
state.environment, |
| 1060 |
typelib_cmd, |
| 1061 |
generated_files, |
| 1062 |
[typelib_output], |
| 1063 |
state.current_build_project, |
| 1064 |
install=install, |
| 1065 |
install_dir=[install_dir], |
| 1066 |
install_tag=['typelib'], |
| 1067 |
build_by_default=kwargs['build_by_default'], |
| 1068 |
env=kwargs['env'], |
| 1069 |
) |
| 1070 |
|
| 1071 |
@staticmethod |
| 1072 |
def _gather_typelib_includes_and_update_depends( |
| 1073 |
state: 'ModuleState', |
| 1074 |
deps: T.Sequence[T.Union[Dependency, build.BuildTargetTypes]], |
| 1075 |
depends: T.Sequence[TargetDepends] |
| 1076 |
) -> T.Tuple[T.List[str], T.List[TargetDepends]]: |
| 1077 |
# Need to recursively add deps on GirTarget sources from our |
| 1078 |
# dependencies and also find the include directories needed for the |
| 1079 |
# typelib generation custom target below. |
| 1080 |
typelib_includes: T.List[str] = [] |
| 1081 |
new_depends = list(depends) |
| 1082 |
for dep in deps: |
| 1083 |
# Add a dependency on each GirTarget listed in dependencies and add |
| 1084 |
# the directory where it will be generated to the typelib includes |
| 1085 |
if isinstance(dep, InternalDependency): |
| 1086 |
for source in dep.sources: |
| 1087 |
if isinstance(source, GirTarget) and source not in depends: |
| 1088 |
new_depends.append(source) |
| 1089 |
subdir = os.path.join(state.environment.get_build_dir(), |
| 1090 |
source.get_subdir()) |
| 1091 |
if subdir not in typelib_includes: |
| 1092 |
typelib_includes.append(subdir) |
| 1093 |
# Do the same, but for dependencies of dependencies. These are |
| 1094 |
# stored in the list of generated sources for each link dep (from |
| 1095 |
# girtarget.get_all_link_deps() above). |
| 1096 |
# FIXME: Store this in the original form from declare_dependency() |
| 1097 |
# so it can be used here directly. |
| 1098 |
elif isinstance(dep, build.SharedLibrary): |
| 1099 |
for g_source in dep.generated: |
| 1100 |
if isinstance(g_source, GirTarget): |
| 1101 |
subdir = os.path.join(state.environment.get_build_dir(), |
| 1102 |
g_source.get_subdir()) |
| 1103 |
if subdir not in typelib_includes: |
| 1104 |
typelib_includes.append(subdir) |
| 1105 |
if isinstance(dep, Dependency): |
| 1106 |
girdir = dep.get_variable(pkgconfig='girdir', internal='girdir', default_value='') |
| 1107 |
assert isinstance(girdir, str), 'for mypy' |
| 1108 |
if girdir and girdir not in typelib_includes: |
| 1109 |
typelib_includes.append(girdir) |
| 1110 |
return typelib_includes, new_depends |
| 1111 |
|
| 1112 |
@staticmethod |
| 1113 |
def _get_external_args_for_langs(state: 'ModuleState', langs: T.List[str]) -> T.List[str]: |
| 1114 |
ret: T.List[str] = [] |
| 1115 |
for lang in langs: |
| 1116 |
ret += mesonlib.listify(state.environment.coredata.get_external_args(MachineChoice.HOST, lang)) |
| 1117 |
return ret |
| 1118 |
|
| 1119 |
@staticmethod |
| 1120 |
def _get_scanner_cflags(cflags: T.Iterable[str]) -> T.Iterable[str]: |
| 1121 |
'g-ir-scanner only accepts -I/-D/-U; must ignore all other flags' |
| 1122 |
for f in cflags: |
| 1123 |
# _FORTIFY_SOURCE depends on / works together with -O, on the other hand this |
| 1124 |
# just invokes the preprocessor anyway |
| 1125 |
if f.startswith(('-D', '-U', '-I')) and not f.startswith('-D_FORTIFY_SOURCE'): |
| 1126 |
yield f |
| 1127 |
|
| 1128 |
@staticmethod |
| 1129 |
def _get_scanner_ldflags(ldflags: T.Iterable[str]) -> tuple[list[str], list[str]]: |
| 1130 |
'g-ir-scanner only accepts -L/-l; must ignore -F and other linker flags' |
| 1131 |
return ( |
| 1132 |
[f for f in ldflags if f.startswith(('-L', '-l', '--extra-library'))], |
| 1133 |
[f for f in ldflags if f.startswith(('-Wl,-rpath,'))], |
| 1134 |
) |
| 1135 |
|
| 1136 |
@typed_pos_args('gnome.generate_gir', varargs=(Executable, build.SharedLibrary, build.StaticLibrary), min_varargs=1) |
| 1137 |
@typed_kwargs( |
| 1138 |
'gnome.generate_gir', |
| 1139 |
INSTALL_KW, |
| 1140 |
_BUILD_BY_DEFAULT.evolve(since='0.40.0'), |
| 1141 |
_EXTRA_ARGS_KW, |
| 1142 |
ENV_KW.evolve(since='1.2.0'), |
| 1143 |
KwargInfo('dependencies', ContainerTypeInfo(list, Dependency), default=[], listify=True), |
| 1144 |
KwargInfo('doc_format', (str, NoneType), since='1.8.0'), |
| 1145 |
KwargInfo('export_packages', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1146 |
KwargInfo('fatal_warnings', bool, default=False, since='0.55.0'), |
| 1147 |
KwargInfo('header', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1148 |
KwargInfo('identifier_prefix', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1149 |
KwargInfo('include_directories', ContainerTypeInfo(list, (str, build.IncludeDirs)), default=[], listify=True), |
| 1150 |
KwargInfo('includes', ContainerTypeInfo(list, (str, GirTarget)), default=[], listify=True), |
| 1151 |
KwargInfo('install_gir', (bool, NoneType), since='0.61.0'), |
| 1152 |
KwargInfo('install_dir_gir', (str, bool, NoneType), |
| 1153 |
deprecated_values={False: ('0.61.0', 'Use install_gir to disable installation')}, |
| 1154 |
validator=lambda x: 'as boolean can only be false' if x is True else None), |
| 1155 |
KwargInfo('install_typelib', (bool, NoneType), since='0.61.0'), |
| 1156 |
KwargInfo('install_dir_typelib', (str, bool, NoneType), |
| 1157 |
deprecated_values={False: ('0.61.0', 'Use install_typelib to disable installation')}, |
| 1158 |
validator=lambda x: 'as boolean can only be false' if x is True else None), |
| 1159 |
KwargInfo('link_with', ContainerTypeInfo(list, (build.SharedLibrary, build.StaticLibrary)), default=[], listify=True), |
| 1160 |
KwargInfo('namespace', str, required=True), |
| 1161 |
KwargInfo('nsversion', str, required=True), |
| 1162 |
KwargInfo('sources', ContainerTypeInfo(list, (str, mesonlib.File, GeneratedList, CustomTarget, CustomTargetIndex)), default=[], listify=True), |
| 1163 |
KwargInfo('symbol_prefix', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1164 |
) |
| 1165 |
def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Executable, build.SharedLibrary, build.StaticLibrary]]], |
| 1166 |
kwargs: 'GenerateGir') -> ModuleReturnValue: |
| 1167 |
# Ensure we have a C compiler even in C++ projects. |
| 1168 |
state.add_language('c', MachineChoice.HOST) |
| 1169 |
|
| 1170 |
girtargets = [self._unwrap_gir_target(arg, state) for arg in args[0]] |
| 1171 |
if len(girtargets) > 1 and any(isinstance(el, Executable) for el in girtargets): |
| 1172 |
raise MesonException('generate_gir only accepts a single argument when one of the arguments is an executable') |
| 1173 |
|
| 1174 |
gir_dep, giscanner, gicompiler = self._get_gir_dep(state) |
| 1175 |
|
| 1176 |
ns = kwargs['namespace'] |
| 1177 |
nsversion = kwargs['nsversion'] |
| 1178 |
libsources = kwargs['sources'] |
| 1179 |
|
| 1180 |
girfile = f'{ns}-{nsversion}.gir' |
| 1181 |
srcdir = os.path.join(state.environment.get_source_dir(), state.subdir) |
| 1182 |
builddir = os.path.join(state.environment.get_build_dir(), state.subdir) |
| 1183 |
|
| 1184 |
depends: T.List[TargetDepends] = [] |
| 1185 |
# hack - this cast represents how sources are defined for the |
| 1186 |
# dependency in gobject-introspection's gir/meson.build |
| 1187 |
depends.extend(T.cast('T.List[CustomTarget]', gir_dep.sources)) |
| 1188 |
depends.extend(girtargets) |
| 1189 |
|
| 1190 |
langs_compilers = self._get_girtargets_langs_compilers(girtargets) |
| 1191 |
cflags, internal_ldflags, external_ldflags = self._get_langs_compilers_flags(state, langs_compilers) |
| 1192 |
deps = self._get_gir_targets_deps(girtargets) |
| 1193 |
deps += kwargs['dependencies'] |
| 1194 |
deps += [gir_dep] |
| 1195 |
typelib_includes, depends = self._gather_typelib_includes_and_update_depends(state, deps, depends) |
| 1196 |
# ldflags will be misinterpreted by gir scanner (showing |
| 1197 |
# spurious dependencies) but building GStreamer fails if they |
| 1198 |
# are not used here. |
| 1199 |
dep_cflags, dep_internal_ldflags, dep_external_ldflags, gi_includes, depends = \ |
| 1200 |
self._get_dependencies_flags(deps, state, depends, use_gir_args=True) |
| 1201 |
scan_cflags = [] |
| 1202 |
scan_cflags += list(self._get_scanner_cflags(cflags)) |
| 1203 |
scan_cflags += list(self._get_scanner_cflags(dep_cflags)) |
| 1204 |
scan_cflags += list(self._get_scanner_cflags(self._get_external_args_for_langs(state, [lc[0] for lc in langs_compilers]))) |
| 1205 |
scan_internal_ldflags = [] |
| 1206 |
scan_external_ldflags = [] |
| 1207 |
scan_env_ldflags = state.environment.coredata.get_external_link_args(MachineChoice.HOST, 'c') |
| 1208 |
for cli_flags, env_flags in (self._get_scanner_ldflags(internal_ldflags), self._get_scanner_ldflags(dep_internal_ldflags)): |
| 1209 |
scan_internal_ldflags += cli_flags |
| 1210 |
scan_env_ldflags += env_flags |
| 1211 |
for cli_flags, env_flags in (self._get_scanner_ldflags(external_ldflags), self._get_scanner_ldflags(dep_external_ldflags)): |
| 1212 |
scan_external_ldflags += cli_flags |
| 1213 |
scan_env_ldflags += env_flags |
| 1214 |
girtargets_inc_dirs = self._get_gir_targets_inc_dirs(girtargets) |
| 1215 |
inc_dirs = kwargs['include_directories'] |
| 1216 |
|
| 1217 |
gir_inc_dirs: T.List[str] = [] |
| 1218 |
|
| 1219 |
# Executables are passed as indexes other than 0 in this List |
| 1220 |
scan_command: T.List[T.Union[CommandListEntry, Executable]] = [giscanner] |
| 1221 |
scan_command += ['--quiet'] |
| 1222 |
scan_command += ['--no-libtool'] |
| 1223 |
scan_command += ['--namespace=' + ns, '--nsversion=' + nsversion] |
| 1224 |
scan_command += ['--warn-all'] |
| 1225 |
scan_command += ['--output', '@OUTPUT@'] |
| 1226 |
scan_command += [f'--c-include={h}' for h in kwargs['header']] |
| 1227 |
scan_command += kwargs['extra_args'] |
| 1228 |
scan_command += ['-I' + srcdir, '-I' + builddir] |
| 1229 |
scan_command += state.get_include_args(girtargets_inc_dirs) |
| 1230 |
scan_command += ['--filelist=' + self._make_gir_filelist(state, srcdir, ns, nsversion, girtargets, libsources)] |
| 1231 |
for l in kwargs['link_with']: |
| 1232 |
_cflags, depends = self._get_link_args(state, l, depends, use_gir_args=True) |
| 1233 |
scan_command.extend(_cflags) |
| 1234 |
_cmd, _ginc, _deps = self._scan_include(state, kwargs['includes']) |
| 1235 |
scan_command.extend(_cmd) |
| 1236 |
gir_inc_dirs.extend(_ginc) |
| 1237 |
depends.extend(_deps) |
| 1238 |
|
| 1239 |
scan_command += [f'--symbol-prefix={p}' for p in kwargs['symbol_prefix']] |
| 1240 |
scan_command += [f'--identifier-prefix={p}' for p in kwargs['identifier_prefix']] |
| 1241 |
scan_command += [f'--pkg-export={p}' for p in kwargs['export_packages']] |
| 1242 |
scan_command += ['--cflags-begin'] |
| 1243 |
scan_command += scan_cflags |
| 1244 |
scan_command += ['--cflags-end'] |
| 1245 |
scan_command += state.get_include_args(inc_dirs) |
| 1246 |
scan_command += state.get_include_args(itertools.chain(gi_includes, gir_inc_dirs, inc_dirs), prefix='--add-include-path=') |
| 1247 |
scan_command += list(scan_internal_ldflags) |
| 1248 |
scan_command += self._scan_gir_targets(state, girtargets) |
| 1249 |
scan_command += self._scan_langs(state, [lc[0] for lc in langs_compilers]) |
| 1250 |
scan_command += list(scan_external_ldflags) |
| 1251 |
|
| 1252 |
if self._gir_has_option('--sources-top-dirs'): |
| 1253 |
scan_command += ['--sources-top-dirs', os.path.join(state.environment.get_source_dir(), state.root_subdir)] |
| 1254 |
scan_command += ['--sources-top-dirs', os.path.join(state.environment.get_build_dir(), state.root_subdir)] |
| 1255 |
|
| 1256 |
if kwargs['doc_format'] is not None and self._gir_has_option('--doc-format'): |
| 1257 |
scan_command += ['--doc-format', kwargs['doc_format']] |
| 1258 |
|
| 1259 |
if '--warn-error' in scan_command: |
| 1260 |
FeatureDeprecated.single_use('gnome.generate_gir argument --warn-error', '0.55.0', |
| 1261 |
state.subproject, 'Use "fatal_warnings" keyword argument', state.current_node) |
| 1262 |
if kwargs['fatal_warnings']: |
| 1263 |
scan_command.append('--warn-error') |
| 1264 |
|
| 1265 |
generated_files = [f for f in libsources if isinstance(f, (GeneratedList, CustomTarget, CustomTargetIndex))] |
| 1266 |
|
| 1267 |
scan_target = self._make_gir_target( |
| 1268 |
state, girfile, scan_command, generated_files, depends, |
| 1269 |
scan_env_ldflags, kwargs) |
| 1270 |
|
| 1271 |
typelib_output = f'{ns}-{nsversion}.typelib' |
| 1272 |
typelib_cmd: T.List[T.Union[str, Program, CustomTarget]] |
| 1273 |
typelib_cmd = [gicompiler, scan_target, '--output', '@OUTPUT@'] |
| 1274 |
typelib_cmd += state.get_include_args(gir_inc_dirs, prefix='--includedir=') |
| 1275 |
|
| 1276 |
for incdir in typelib_includes: |
| 1277 |
typelib_cmd += ["--includedir=" + incdir] |
| 1278 |
|
| 1279 |
typelib_target = self._make_typelib_target( |
| 1280 |
state, typelib_output, typelib_cmd, generated_files, kwargs) |
| 1281 |
|
| 1282 |
self._devenv_prepend('GI_TYPELIB_PATH', os.path.join(state.environment.get_build_dir(), state.subdir)) |
| 1283 |
|
| 1284 |
rv = [scan_target, typelib_target] |
| 1285 |
|
| 1286 |
return ModuleReturnValue(rv, rv) |
| 1287 |
|
| 1288 |
@noPosargs |
| 1289 |
@typed_kwargs('gnome.compile_schemas', _BUILD_BY_DEFAULT.evolve(since='0.40.0'), DEPEND_FILES_KW) |
| 1290 |
def compile_schemas(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'CompileSchemas') -> ModuleReturnValue: |
| 1291 |
srcdir = os.path.join(state.build_to_src, state.subdir) |
| 1292 |
outdir = state.subdir |
| 1293 |
|
| 1294 |
cmd: CommandList = [self._find_tool(state, 'glib-compile-schemas'), '--targetdir', outdir, srcdir] |
| 1295 |
if state.subdir == '': |
| 1296 |
targetname = 'gsettings-compile' |
| 1297 |
else: |
| 1298 |
targetname = 'gsettings-compile-' + state.subdir.replace('/', '_') |
| 1299 |
target_g = CustomTarget( |
| 1300 |
targetname, |
| 1301 |
state.subdir, |
| 1302 |
state.environment, |
| 1303 |
cmd, |
| 1304 |
[], |
| 1305 |
['gschemas.compiled'], |
| 1306 |
state.current_build_project, |
| 1307 |
build_by_default=kwargs['build_by_default'], |
| 1308 |
depend_files=state._interpreter.source_strings_to_files(kwargs['depend_files']), |
| 1309 |
description='Compiling gschemas {}', |
| 1310 |
) |
| 1311 |
self._devenv_prepend('GSETTINGS_SCHEMA_DIR', os.path.join(state.environment.get_build_dir(), state.subdir)) |
| 1312 |
return ModuleReturnValue(target_g, [target_g]) |
| 1313 |
|
| 1314 |
@typed_pos_args('gnome.yelp', str, varargs=str) |
| 1315 |
@typed_kwargs( |
| 1316 |
'gnome.yelp', |
| 1317 |
KwargInfo( |
| 1318 |
'languages', ContainerTypeInfo(list, str), |
| 1319 |
listify=True, default=[], |
| 1320 |
deprecated='0.43.0', |
| 1321 |
deprecated_message='Use a LINGUAS file in the source directory instead', |
| 1322 |
), |
| 1323 |
KwargInfo('media', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 1324 |
KwargInfo('sources', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 1325 |
KwargInfo('symlink_media', bool, default=True), |
| 1326 |
) |
| 1327 |
def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Yelp') -> ModuleReturnValue: |
| 1328 |
project_id = args[0] |
| 1329 |
sources = kwargs['sources'] |
| 1330 |
if args[1]: |
| 1331 |
FeatureDeprecated.single_use('gnome.yelp more than one positional argument', '0.60.0', |
| 1332 |
state.subproject, 'use the "sources" keyword argument instead.', state.current_node) |
| 1333 |
if not sources: |
| 1334 |
sources = args[1] |
| 1335 |
if not sources: |
| 1336 |
raise MesonException('Yelp requires a list of sources') |
| 1337 |
elif args[1]: |
| 1338 |
mlog.warning('"gnome.yelp" ignores positional sources arguments when the "sources" keyword argument is set') |
| 1339 |
sources_files = [mesonlib.File.from_source_file(state.environment.source_dir, |
| 1340 |
os.path.join(state.subdir, 'C'), |
| 1341 |
s) for s in sources] |
| 1342 |
|
| 1343 |
langs = kwargs['languages'] |
| 1344 |
if not langs: |
| 1345 |
langs = read_linguas(os.path.join(state.environment.source_dir, state.subdir)) |
| 1346 |
|
| 1347 |
media = kwargs['media'] |
| 1348 |
symlinks = kwargs['symlink_media'] |
| 1349 |
targets: T.List[T.Union['build.Target', build.Data, build.SymlinkData]] = [] |
| 1350 |
potargets: T.List[build.RunTarget] = [] |
| 1351 |
|
| 1352 |
itstool = state.find_program('itstool') |
| 1353 |
msgmerge = state.find_program('msgmerge') |
| 1354 |
msgfmt = state.find_program('msgfmt') |
| 1355 |
|
| 1356 |
install_dir = os.path.join(state.environment.get_datadir(), 'help') |
| 1357 |
c_install_dir = os.path.join(install_dir, 'C', project_id) |
| 1358 |
c_data = build.Data(sources_files, c_install_dir, c_install_dir, |
| 1359 |
mesonlib.FileMode(), state.subproject, install_tag='doc') |
| 1360 |
targets.append(c_data) |
| 1361 |
|
| 1362 |
media_files: T.List[mesonlib.File] = [] |
| 1363 |
for m in media: |
| 1364 |
f = mesonlib.File.from_source_file(state.environment.source_dir, |
| 1365 |
os.path.join(state.subdir, 'C'), m) |
| 1366 |
media_files.append(f) |
| 1367 |
m_install_dir = os.path.join(c_install_dir, os.path.dirname(m)) |
| 1368 |
m_data = build.Data([f], m_install_dir, m_install_dir, |
| 1369 |
mesonlib.FileMode(), state.subproject, install_tag='doc') |
| 1370 |
targets.append(m_data) |
| 1371 |
|
| 1372 |
pot_file = os.path.join('@SOURCE_ROOT@', state.subdir, 'C', project_id + '.pot') |
| 1373 |
pot_sources = [os.path.join('@SOURCE_ROOT@', state.subdir, 'C', s) for s in sources] |
| 1374 |
pot_args: CommandList = [itstool, '-o', pot_file] |
| 1375 |
pot_args.extend(pot_sources) |
| 1376 |
pottarget = build.RunTarget(f'help-{project_id}-pot', pot_args, [], |
| 1377 |
os.path.join(state.subdir, 'C'), |
| 1378 |
state.environment, state.current_build_project) |
| 1379 |
targets.append(pottarget) |
| 1380 |
|
| 1381 |
for l in langs: |
| 1382 |
l_subdir = os.path.join(state.subdir, l) |
| 1383 |
l_install_dir = os.path.join(install_dir, l, project_id) |
| 1384 |
|
| 1385 |
for i, m in enumerate(media): |
| 1386 |
m_dir = os.path.dirname(m) |
| 1387 |
m_install_dir = os.path.join(l_install_dir, m_dir) |
| 1388 |
try: |
| 1389 |
m_file: T.Optional[mesonlib.File] = mesonlib.File.from_source_file(state.environment.source_dir, l_subdir, m) |
| 1390 |
except MesonException: |
| 1391 |
m_file = None |
| 1392 |
|
| 1393 |
l_data: T.Union[build.Data, build.SymlinkData] |
| 1394 |
if symlinks and not m_file: |
| 1395 |
link_target = os.path.join(os.path.relpath(c_install_dir, start=m_install_dir), m) |
| 1396 |
l_data = build.SymlinkData(link_target, os.path.basename(m), |
| 1397 |
m_install_dir, state.subproject, install_tag='doc') |
| 1398 |
else: |
| 1399 |
if not m_file: |
| 1400 |
m_file = media_files[i] |
| 1401 |
l_data = build.Data([m_file], m_install_dir, m_install_dir, |
| 1402 |
mesonlib.FileMode(), state.subproject, install_tag='doc') |
| 1403 |
targets.append(l_data) |
| 1404 |
|
| 1405 |
po_path = os.path.join('@SOURCE_ROOT@', l_subdir, l + '.po') |
| 1406 |
po_args: CommandList = [*state.environment.get_build_command(), |
| 1407 |
'--internal', 'exe', '--capture', po_path, '--', |
| 1408 |
msgmerge, '-q', po_path, pot_file] |
| 1409 |
potarget = build.RunTarget(f'help-{project_id}-{l}-update-po', |
| 1410 |
po_args, [pottarget], l_subdir, |
| 1411 |
state.environment, state.current_build_project) |
| 1412 |
targets.append(potarget) |
| 1413 |
potargets.append(potarget) |
| 1414 |
|
| 1415 |
gmo_file = project_id + '-' + l + '.gmo' |
| 1416 |
po_file = mesonlib.File.from_source_file(state.environment.source_dir, l_subdir, l + '.po') |
| 1417 |
gmotarget = CustomTarget( |
| 1418 |
f'help-{project_id}-{l}-gmo', |
| 1419 |
l_subdir, |
| 1420 |
state.environment, |
| 1421 |
[msgfmt, '@INPUT@', '-o', '@OUTPUT@'], |
| 1422 |
[po_file], |
| 1423 |
[gmo_file], |
| 1424 |
state.current_build_project, |
| 1425 |
install_tag=['doc'], |
| 1426 |
description='Generating yelp doc {}', |
| 1427 |
) |
| 1428 |
targets.append(gmotarget) |
| 1429 |
|
| 1430 |
mergetarget = CustomTarget( |
| 1431 |
f'help-{project_id}-{l}', |
| 1432 |
l_subdir, |
| 1433 |
state.environment, |
| 1434 |
[itstool, '-m', os.path.join(l_subdir, gmo_file), '--lang', l, '-o', '@OUTDIR@', '@INPUT@'], |
| 1435 |
sources_files, |
| 1436 |
sources, |
| 1437 |
state.current_build_project, |
| 1438 |
extra_depends=[gmotarget], |
| 1439 |
install=True, |
| 1440 |
install_dir=[l_install_dir], |
| 1441 |
install_tag=['doc'], |
| 1442 |
description='Generating yelp doc {}', |
| 1443 |
) |
| 1444 |
targets.append(mergetarget) |
| 1445 |
|
| 1446 |
allpotarget = build.AliasTarget(f'help-{project_id}-update-po', potargets, |
| 1447 |
state.subdir, state.environment, |
| 1448 |
state.current_build_project) |
| 1449 |
targets.append(allpotarget) |
| 1450 |
|
| 1451 |
return ModuleReturnValue(None, targets) |
| 1452 |
|
| 1453 |
@typed_pos_args('gnome.gtkdoc', str) |
| 1454 |
@typed_kwargs( |
| 1455 |
'gnome.gtkdoc', |
| 1456 |
KwargInfo('c_args', ContainerTypeInfo(list, str), since='0.48.0', default=[], listify=True), |
| 1457 |
KwargInfo('check', bool, default=False, since='0.52.0'), |
| 1458 |
KwargInfo('content_files', ContainerTypeInfo(list, (str, mesonlib.File, GeneratedList, CustomTarget, CustomTargetIndex)), default=[], listify=True), |
| 1459 |
KwargInfo( |
| 1460 |
'dependencies', |
| 1461 |
ContainerTypeInfo(list, (Dependency, build.SharedLibrary, build.StaticLibrary)), |
| 1462 |
listify=True, default=[]), |
| 1463 |
KwargInfo('expand_content_files', ContainerTypeInfo(list, (str, mesonlib.File)), default=[], listify=True), |
| 1464 |
KwargInfo('fixxref_args', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1465 |
KwargInfo('gobject_typesfile', ContainerTypeInfo(list, (str, mesonlib.File)), default=[], listify=True), |
| 1466 |
KwargInfo('html_args', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1467 |
KwargInfo('html_assets', ContainerTypeInfo(list, (str, mesonlib.File)), default=[], listify=True), |
| 1468 |
KwargInfo('ignore_headers', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1469 |
KwargInfo( |
| 1470 |
'include_directories', |
| 1471 |
ContainerTypeInfo(list, (str, build.IncludeDirs)), |
| 1472 |
listify=True, default=[]), |
| 1473 |
KwargInfo('install', bool, default=True), |
| 1474 |
KwargInfo('install_dir', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1475 |
KwargInfo('main_sgml', (str, NoneType)), |
| 1476 |
KwargInfo('main_xml', (str, NoneType)), |
| 1477 |
KwargInfo('mkdb_args', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1478 |
KwargInfo( |
| 1479 |
'mode', str, default='auto', since='0.37.0', |
| 1480 |
validator=in_set_validator({'xml', 'sgml', 'none', 'auto'})), |
| 1481 |
KwargInfo('module_version', str, default='', since='0.48.0'), |
| 1482 |
KwargInfo('namespace', str, default='', since='0.37.0'), |
| 1483 |
KwargInfo('scan_args', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1484 |
KwargInfo('scanobjs_args', ContainerTypeInfo(list, str), default=[], listify=True), |
| 1485 |
KwargInfo('src_dir', ContainerTypeInfo(list, (str, build.IncludeDirs)), listify=True, required=True), |
| 1486 |
) |
| 1487 |
def gtkdoc(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GtkDoc') -> ModuleReturnValue: |
| 1488 |
modulename = args[0] |
| 1489 |
main_file = kwargs['main_sgml'] |
| 1490 |
main_xml = kwargs['main_xml'] |
| 1491 |
if main_xml is not None: |
| 1492 |
if main_file is not None: |
| 1493 |
raise InvalidArguments('gnome.gtkdoc: main_xml and main_sgml are exclusive arguments') |
| 1494 |
main_file = main_xml |
| 1495 |
moduleversion = kwargs['module_version'] |
| 1496 |
targetname = modulename + ('-' + moduleversion if moduleversion else '') + '-doc' |
| 1497 |
command = state.environment.get_build_command() |
| 1498 |
|
| 1499 |
namespace = kwargs['namespace'] |
| 1500 |
|
| 1501 |
# Ensure we have a C compiler even in C++ projects. |
| 1502 |
state.add_language('c', MachineChoice.HOST) |
| 1503 |
|
| 1504 |
def abs_filenames(files: T.Iterable['FileOrString']) -> T.Iterator[str]: |
| 1505 |
for f in files: |
| 1506 |
if isinstance(f, mesonlib.File): |
| 1507 |
yield f.absolute_path(state.environment.get_source_dir(), state.environment.get_build_dir()) |
| 1508 |
else: |
| 1509 |
yield os.path.join(state.environment.get_source_dir(), state.subdir, f) |
| 1510 |
|
| 1511 |
src_dirs = kwargs['src_dir'] |
| 1512 |
header_dirs: T.List[str] = [] |
| 1513 |
for src_dir in src_dirs: |
| 1514 |
if isinstance(src_dir, build.IncludeDirs): |
| 1515 |
header_dirs.extend(src_dir.abs_string_list(state.environment.get_source_dir(), |
| 1516 |
state.environment.get_build_dir())) |
| 1517 |
else: |
| 1518 |
header_dirs.append(src_dir) |
| 1519 |
|
| 1520 |
t_args: T.List[str] = [ |
| 1521 |
'--internal', 'gtkdoc', |
| 1522 |
'--sourcedir=' + state.environment.get_source_dir(), |
| 1523 |
'--builddir=' + state.environment.get_build_dir(), |
| 1524 |
'--subdir=' + state.subdir, |
| 1525 |
'--headerdirs=' + '@@'.join(header_dirs), |
| 1526 |
'--mainfile=' + main_file, |
| 1527 |
'--modulename=' + modulename, |
| 1528 |
'--moduleversion=' + moduleversion, |
| 1529 |
'--mode=' + kwargs['mode']] |
| 1530 |
for tool in ['scan', 'scangobj', 'mkdb', 'mkhtml', 'fixxref']: |
| 1531 |
program_name = 'gtkdoc-' + tool |
| 1532 |
program = state.find_program(program_name) |
| 1533 |
path = mesonlib.unwrap(program.get_path()) |
| 1534 |
t_args.append(f'--{program_name}={path}') |
| 1535 |
if namespace: |
| 1536 |
t_args.append('--namespace=' + namespace) |
| 1537 |
exe_wrapper = state.environment.get_exe_wrapper() |
| 1538 |
if exe_wrapper: |
| 1539 |
t_args.append('--run=' + ' '.join(exe_wrapper.get_command())) |
| 1540 |
t_args.append(f'--htmlargs={"@@".join(kwargs["html_args"])}') |
| 1541 |
t_args.append(f'--scanargs={"@@".join(kwargs["scan_args"])}') |
| 1542 |
t_args.append(f'--scanobjsargs={"@@".join(kwargs["scanobjs_args"])}') |
| 1543 |
t_args.append(f'--gobjects-types-file={"@@".join(abs_filenames(kwargs["gobject_typesfile"]))}') |
| 1544 |
t_args.append(f'--fixxrefargs={"@@".join(kwargs["fixxref_args"])}') |
| 1545 |
t_args.append(f'--mkdbargs={"@@".join(kwargs["mkdb_args"])}') |
| 1546 |
t_args.append(f'--html-assets={"@@".join(abs_filenames(kwargs["html_assets"]))}') |
| 1547 |
|
| 1548 |
depends: T.List['build.GeneratedTypes'] = [] |
| 1549 |
content_files = [] |
| 1550 |
for s in kwargs['content_files']: |
| 1551 |
if isinstance(s, (CustomTarget, CustomTargetIndex)): |
| 1552 |
depends.append(s) |
| 1553 |
for o in s.get_outputs(): |
| 1554 |
content_files.append(os.path.join(state.environment.get_build_dir(), |
| 1555 |
state.backend.get_target_dir(s), |
| 1556 |
o)) |
| 1557 |
elif isinstance(s, mesonlib.File): |
| 1558 |
content_files.append(s.absolute_path(state.environment.get_source_dir(), |
| 1559 |
state.environment.get_build_dir())) |
| 1560 |
elif isinstance(s, GeneratedList): |
| 1561 |
depends.append(s) |
| 1562 |
for gen_src in s.get_outputs(): |
| 1563 |
content_files.append(os.path.join(state.environment.get_source_dir(), |
| 1564 |
state.subdir, |
| 1565 |
gen_src)) |
| 1566 |
else: |
| 1567 |
content_files.append(os.path.join(state.environment.get_source_dir(), |
| 1568 |
state.subdir, |
| 1569 |
s)) |
| 1570 |
t_args += ['--content-files=' + '@@'.join(content_files)] |
| 1571 |
|
| 1572 |
t_args.append(f'--expand-content-files={"@@".join(abs_filenames(kwargs["expand_content_files"]))}') |
| 1573 |
t_args.append(f'--ignore-headers={"@@".join(kwargs["ignore_headers"])}') |
| 1574 |
t_args.append(f'--installdir={"@@".join(kwargs["install_dir"])}') |
| 1575 |
build_args, new_depends = self._get_build_args(kwargs['c_args'], kwargs['include_directories'], |
| 1576 |
kwargs['dependencies'], state, depends) |
| 1577 |
t_args.extend(build_args) |
| 1578 |
new_depends.extend(depends) |
| 1579 |
custom_target = CustomTarget( |
| 1580 |
targetname, |
| 1581 |
state.subdir, |
| 1582 |
state.environment, |
| 1583 |
command + t_args, |
| 1584 |
[], |
| 1585 |
[f'{modulename}-decl.txt'], |
| 1586 |
state.current_build_project, |
| 1587 |
build_always_stale=True, |
| 1588 |
extra_depends=new_depends, |
| 1589 |
description='Generating gtkdoc {}', |
| 1590 |
) |
| 1591 |
alias_target = build.AliasTarget(targetname, [custom_target], state.subdir, |
| 1592 |
state.environment, state.current_build_project) |
| 1593 |
if kwargs['check']: |
| 1594 |
check_cmd = state.find_program('gtkdoc-check') |
| 1595 |
check_env = ['DOC_MODULE=' + modulename, |
| 1596 |
'DOC_MAIN_SGML_FILE=' + main_file] |
| 1597 |
check_args = (targetname + '-check', check_cmd) |
| 1598 |
check_workdir = os.path.join(state.environment.get_build_dir(), state.subdir) |
| 1599 |
state.test(check_args, env=check_env, workdir=check_workdir, depends=[custom_target]) |
| 1600 |
res: T.List[T.Union[build.Target, mesonlib.ExecutableSerialisation]] = [custom_target, alias_target] |
| 1601 |
if kwargs['install']: |
| 1602 |
res.append(state.backend.get_executable_serialisation(command + t_args, tag='doc')) |
| 1603 |
return ModuleReturnValue(custom_target, res) |
| 1604 |
|
| 1605 |
def _get_build_args(self, c_args: T.List[str], inc_dirs: T.List[T.Union[str, build.IncludeDirs]], |
| 1606 |
deps: T.List[T.Union[Dependency, build.SharedLibrary, build.StaticLibrary]], |
| 1607 |
state: 'ModuleState', |
| 1608 |
depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes']]) -> T.Tuple[ |
| 1609 |
T.List[str], T.List[TargetDepends]]: |
| 1610 |
args: T.List[str] = [] |
| 1611 |
cflags = c_args.copy() |
| 1612 |
deps_cflags, internal_ldflags, external_ldflags, _gi_includes, new_depends = \ |
| 1613 |
self._get_dependencies_flags(deps, state, depends, include_rpath=True) |
| 1614 |
|
| 1615 |
cflags.extend(deps_cflags) |
| 1616 |
cflags.extend(state.get_include_args(inc_dirs)) |
| 1617 |
ldflags: T.List[str] = [] |
| 1618 |
ldflags.extend(internal_ldflags) |
| 1619 |
ldflags.extend(external_ldflags) |
| 1620 |
|
| 1621 |
cflags.extend(state.environment.coredata.get_external_args(MachineChoice.HOST, 'c')) |
| 1622 |
ldflags.extend(state.environment.coredata.get_external_link_args(MachineChoice.HOST, 'c')) |
| 1623 |
compiler = state.environment.coredata.compilers[MachineChoice.HOST]['c'] |
| 1624 |
|
| 1625 |
compiler_flags = self._get_langs_compilers_flags(state, [('c', compiler)]) |
| 1626 |
cflags.extend(compiler_flags[0]) |
| 1627 |
ldflags.extend(compiler_flags[1]) |
| 1628 |
ldflags.extend(compiler_flags[2]) |
| 1629 |
if compiler: |
| 1630 |
args += ['--cc=%s' % join_args(compiler.get_exelist())] |
| 1631 |
args += ['--ld=%s' % join_args(compiler.get_linker_exelist())] |
| 1632 |
if cflags: |
| 1633 |
args += ['--cflags=%s' % join_args(cflags)] |
| 1634 |
if ldflags: |
| 1635 |
args += ['--ldflags=%s' % join_args(ldflags)] |
| 1636 |
|
| 1637 |
return args, new_depends |
| 1638 |
|
| 1639 |
@noKwargs |
| 1640 |
@typed_pos_args('gnome.gtkdoc_html_dir', str) |
| 1641 |
def gtkdoc_html_dir(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'TYPE_kwargs') -> str: |
| 1642 |
return os.path.join('share/gtk-doc/html', args[0]) |
| 1643 |
|
| 1644 |
@typed_pos_args('gnome.gdbus_codegen', str, optargs=[(str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList)]) |
| 1645 |
@typed_kwargs( |
| 1646 |
'gnome.gdbus_codegen', |
| 1647 |
_BUILD_BY_DEFAULT.evolve(since='0.40.0'), |
| 1648 |
DEPENDENCY_SOURCES_KW.evolve(since='0.46.0'), |
| 1649 |
KwargInfo('extra_args', ContainerTypeInfo(list, str), since='0.47.0', default=[], listify=True), |
| 1650 |
KwargInfo('interface_prefix', (str, NoneType)), |
| 1651 |
KwargInfo('namespace', (str, NoneType)), |
| 1652 |
KwargInfo('object_manager', bool, default=False), |
| 1653 |
KwargInfo( |
| 1654 |
'annotations', ContainerTypeInfo(list, (list, str)), |
| 1655 |
default=[], |
| 1656 |
validator=annotations_validator, |
| 1657 |
convertor=lambda x: [x] if x and isinstance(x[0], str) else x, |
| 1658 |
), |
| 1659 |
KwargInfo('install_header', bool, default=False, since='0.46.0'), |
| 1660 |
KwargInfo('docbook', (str, NoneType)), |
| 1661 |
KwargInfo('rst', (str, NoneType), since='1.9.0'), |
| 1662 |
KwargInfo('markdown', (str, NoneType), since='1.9.0'), |
| 1663 |
KwargInfo( |
| 1664 |
'autocleanup', str, default='default', since='0.47.0', |
| 1665 |
validator=in_set_validator({'all', 'none', 'objects'})), |
| 1666 |
INSTALL_DIR_KW.evolve(since='0.46.0') |
| 1667 |
) |
| 1668 |
def gdbus_codegen(self, state: 'ModuleState', args: T.Tuple[str, T.Optional[str | build.TargetSources]], |
| 1669 |
kwargs: 'GdbusCodegen') -> ModuleReturnValue: |
| 1670 |
namebase = args[0] |
| 1671 |
xml_files: T.List[build.TargetSources] = \ |
| 1672 |
self.interpreter.source_strings_to_files([args[1]]) if args[1] else [] |
| 1673 |
cmd: CommandList = [self._find_tool(state, 'gdbus-codegen')] |
| 1674 |
cmd.extend(kwargs['extra_args']) |
| 1675 |
|
| 1676 |
# Autocleanup supported? |
| 1677 |
glib_version = self._get_native_glib_version(state) |
| 1678 |
if not mesonlib.version_compare(glib_version, '>= 2.49.1'): |
| 1679 |
# Warn if requested, silently disable if not |
| 1680 |
if kwargs['autocleanup'] != 'default': |
| 1681 |
mlog.warning(f'Glib version ({glib_version}) is too old to support the \'autocleanup\' ' |
| 1682 |
'kwarg, need 2.49.1 or newer') |
| 1683 |
else: |
| 1684 |
# Handle legacy glib versions that don't have autocleanup |
| 1685 |
ac = kwargs['autocleanup'] |
| 1686 |
if ac == 'default': |
| 1687 |
ac = 'all' |
| 1688 |
cmd.extend(['--c-generate-autocleanup', ac]) |
| 1689 |
|
| 1690 |
if kwargs['interface_prefix'] is not None: |
| 1691 |
cmd.extend(['--interface-prefix', kwargs['interface_prefix']]) |
| 1692 |
if kwargs['namespace'] is not None: |
| 1693 |
cmd.extend(['--c-namespace', kwargs['namespace']]) |
| 1694 |
if kwargs['object_manager']: |
| 1695 |
cmd.extend(['--c-generate-object-manager']) |
| 1696 |
xml_files.extend(self.interpreter.source_strings_to_files(kwargs['sources'])) |
| 1697 |
build_by_default = kwargs['build_by_default'] |
| 1698 |
|
| 1699 |
# Annotations are a bit ugly in that they are a list of lists of strings... |
| 1700 |
for annot in kwargs['annotations']: |
| 1701 |
cmd.append('--annotate') |
| 1702 |
cmd.extend(annot) |
| 1703 |
|
| 1704 |
targets = [] |
| 1705 |
install_header = kwargs['install_header'] |
| 1706 |
install_dir = kwargs['install_dir'] or state.environment.coredata.optstore.get_value_for(OptionKey('includedir')) |
| 1707 |
assert isinstance(install_dir, str), 'for mypy' |
| 1708 |
|
| 1709 |
output = namebase + '.c' |
| 1710 |
# Added in https://gitlab.gnome.org/GNOME/glib/commit/e4d68c7b3e8b01ab1a4231bf6da21d045cb5a816 (2.55.2) |
| 1711 |
# Fixed in https://gitlab.gnome.org/GNOME/glib/commit/cd1f82d8fc741a2203582c12cc21b4dacf7e1872 (2.56.2) |
| 1712 |
if mesonlib.version_compare(glib_version, '>= 2.56.2'): |
| 1713 |
c_cmd = cmd + ['--body', '--output', '@OUTPUT@', '@INPUT@'] |
| 1714 |
else: |
| 1715 |
if kwargs['docbook'] is not None: |
| 1716 |
docbook = kwargs['docbook'] |
| 1717 |
|
| 1718 |
cmd += ['--generate-docbook', docbook] |
| 1719 |
|
| 1720 |
if kwargs['rst'] is not None: |
| 1721 |
if not mesonlib.version_compare(glib_version, '>= 2.71.1'): |
| 1722 |
mlog.error(f'Glib version ({glib_version}) is too old to ' |
| 1723 |
'support the \'rst\' kwarg, need 2.71.1 or ' |
| 1724 |
'newer') |
| 1725 |
|
| 1726 |
rst = kwargs['rst'] |
| 1727 |
|
| 1728 |
cmd += ['--generate-rst', rst] |
| 1729 |
|
| 1730 |
if kwargs['markdown'] is not None: |
| 1731 |
if not mesonlib.version_compare(glib_version, '>= 2.75.2'): |
| 1732 |
mlog.error(f'Glib version ({glib_version}) is too old to ' |
| 1733 |
'support the \'markdown\' kwarg, need 2.75.2 ' |
| 1734 |
'or newer') |
| 1735 |
|
| 1736 |
markdown = kwargs['markdown'] |
| 1737 |
|
| 1738 |
cmd += ['--generate-md', markdown] |
| 1739 |
|
| 1740 |
# https://git.gnome.org/browse/glib/commit/?id=ee09bb704fe9ccb24d92dd86696a0e6bb8f0dc1a |
| 1741 |
if mesonlib.version_compare(glib_version, '>= 2.51.3'): |
| 1742 |
cmd += ['--output-directory', '@OUTDIR@', '--generate-c-code', namebase, '@INPUT@'] |
| 1743 |
else: |
| 1744 |
self._print_gdbus_warning() |
| 1745 |
cmd += ['--generate-c-code', '@OUTDIR@/' + namebase, '@INPUT@'] |
| 1746 |
c_cmd = cmd |
| 1747 |
|
| 1748 |
cfile_custom_target = CustomTarget( |
| 1749 |
output, |
| 1750 |
state.subdir, |
| 1751 |
state.environment, |
| 1752 |
c_cmd, |
| 1753 |
xml_files, |
| 1754 |
[output], |
| 1755 |
state.current_build_project, |
| 1756 |
build_by_default=build_by_default, |
| 1757 |
description='Generating gdbus source {}', |
| 1758 |
) |
| 1759 |
targets.append(cfile_custom_target) |
| 1760 |
|
| 1761 |
output = namebase + '.h' |
| 1762 |
if mesonlib.version_compare(glib_version, '>= 2.56.2'): |
| 1763 |
hfile_cmd = cmd + ['--header', '--output', '@OUTPUT@', '@INPUT@'] |
| 1764 |
depends = [] |
| 1765 |
else: |
| 1766 |
hfile_cmd = cmd |
| 1767 |
depends = [cfile_custom_target] |
| 1768 |
|
| 1769 |
hfile_custom_target = CustomTarget( |
| 1770 |
output, |
| 1771 |
state.subdir, |
| 1772 |
state.environment, |
| 1773 |
hfile_cmd, |
| 1774 |
xml_files, |
| 1775 |
[output], |
| 1776 |
state.current_build_project, |
| 1777 |
build_by_default=build_by_default, |
| 1778 |
extra_depends=depends, |
| 1779 |
install=install_header, |
| 1780 |
install_dir=[install_dir], |
| 1781 |
install_tag=['devel'], |
| 1782 |
description='Generating gdbus header {}', |
| 1783 |
) |
| 1784 |
targets.append(hfile_custom_target) |
| 1785 |
|
| 1786 |
if kwargs['docbook'] is not None: |
| 1787 |
docbook = kwargs['docbook'] |
| 1788 |
# The docbook output is always ${docbook}-${name_of_xml_file} |
| 1789 |
output = namebase + '-docbook' |
| 1790 |
outputs = [] |
| 1791 |
for f in xml_files: |
| 1792 |
outputs.append('{}-{}'.format(docbook, os.path.basename(str(f)))) |
| 1793 |
|
| 1794 |
if mesonlib.version_compare(glib_version, '>= 2.56.2'): |
| 1795 |
docbook_cmd = cmd + ['--output-directory', '@OUTDIR@', '--generate-docbook', docbook, '@INPUT@'] |
| 1796 |
depends = [] |
| 1797 |
else: |
| 1798 |
docbook_cmd = cmd |
| 1799 |
depends = [cfile_custom_target] |
| 1800 |
|
| 1801 |
docbook_custom_target = CustomTarget( |
| 1802 |
output, |
| 1803 |
state.subdir, |
| 1804 |
state.environment, |
| 1805 |
docbook_cmd, |
| 1806 |
xml_files, |
| 1807 |
outputs, |
| 1808 |
state.current_build_project, |
| 1809 |
build_by_default=build_by_default, |
| 1810 |
extra_depends=depends, |
| 1811 |
description='Generating gdbus docbook {}', |
| 1812 |
) |
| 1813 |
targets.append(docbook_custom_target) |
| 1814 |
|
| 1815 |
if kwargs['rst'] is not None: |
| 1816 |
rst = kwargs['rst'] |
| 1817 |
# The rst output is always ${rst}-${name_of_xml_file} |
| 1818 |
output = namebase + '-rst' |
| 1819 |
outputs = [] |
| 1820 |
for f in xml_files: |
| 1821 |
outputs.append('{}-{}'.format(rst, os.path.basename(str(f)))) |
| 1822 |
|
| 1823 |
rst_custom_target = CustomTarget( |
| 1824 |
output, |
| 1825 |
state.subdir, |
| 1826 |
state.environment, |
| 1827 |
cmd + ['--output-directory', '@OUTDIR@', '--generate-rst', rst, '@INPUT@'], |
| 1828 |
xml_files, |
| 1829 |
outputs, |
| 1830 |
state.current_build_project, |
| 1831 |
build_by_default=build_by_default, |
| 1832 |
description='Generating gdbus reStructuredText {}', |
| 1833 |
) |
| 1834 |
targets.append(rst_custom_target) |
| 1835 |
|
| 1836 |
if kwargs['markdown'] is not None: |
| 1837 |
markdown = kwargs['markdown'] |
| 1838 |
# The markdown output is always ${markdown}-${name_of_xml_file} |
| 1839 |
output = namebase + '-markdown' |
| 1840 |
outputs = [] |
| 1841 |
for f in xml_files: |
| 1842 |
outputs.append('{}-{}'.format(markdown, os.path.basename(str(f)))) |
| 1843 |
|
| 1844 |
markdown_custom_target = CustomTarget( |
| 1845 |
output, |
| 1846 |
state.subdir, |
| 1847 |
state.environment, |
| 1848 |
cmd + ['--output-directory', '@OUTDIR@', '--generate-md', markdown, '@INPUT@'], |
| 1849 |
xml_files, |
| 1850 |
outputs, |
| 1851 |
state.current_build_project, |
| 1852 |
build_by_default=build_by_default, |
| 1853 |
description='Generating gdbus markdown {}', |
| 1854 |
) |
| 1855 |
targets.append(markdown_custom_target) |
| 1856 |
|
| 1857 |
return ModuleReturnValue(targets, targets) |
| 1858 |
|
| 1859 |
@typed_pos_args('gnome.mkenums', str) |
| 1860 |
@typed_kwargs( |
| 1861 |
'gnome.mkenums', |
| 1862 |
*_MK_ENUMS_COMMON_KWS, |
| 1863 |
DEPENDS_KW, |
| 1864 |
KwargInfo( |
| 1865 |
'sources', |
| 1866 |
ContainerTypeInfo(list, (str, mesonlib.File, CustomTarget, CustomTargetIndex, |
| 1867 |
GeneratedList)), |
| 1868 |
listify=True, |
| 1869 |
required=True, |
| 1870 |
), |
| 1871 |
KwargInfo('c_template', (str, mesonlib.File, NoneType)), |
| 1872 |
KwargInfo('h_template', (str, mesonlib.File, NoneType)), |
| 1873 |
KwargInfo('comments', (str, NoneType)), |
| 1874 |
KwargInfo('eprod', (str, NoneType)), |
| 1875 |
KwargInfo('fhead', (str, NoneType)), |
| 1876 |
KwargInfo('fprod', (str, NoneType)), |
| 1877 |
KwargInfo('ftail', (str, NoneType)), |
| 1878 |
KwargInfo('vhead', (str, NoneType)), |
| 1879 |
KwargInfo('vprod', (str, NoneType)), |
| 1880 |
KwargInfo('vtail', (str, NoneType)), |
| 1881 |
) |
| 1882 |
def mkenums(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'MkEnums') -> ModuleReturnValue: |
| 1883 |
basename = args[0] |
| 1884 |
|
| 1885 |
c_template = kwargs['c_template'] |
| 1886 |
if isinstance(c_template, str): |
| 1887 |
c_template = mesonlib.File.from_source_file(state.environment.source_dir, state.subdir, c_template) |
| 1888 |
h_template = kwargs['h_template'] |
| 1889 |
if isinstance(h_template, str): |
| 1890 |
h_template = mesonlib.File.from_source_file(state.environment.source_dir, state.subdir, h_template) |
| 1891 |
|
| 1892 |
cmd: T.List[str] = [] |
| 1893 |
known_kwargs = ['comments', 'eprod', 'fhead', 'fprod', 'ftail', |
| 1894 |
'identifier_prefix', 'symbol_prefix', |
| 1895 |
'vhead', 'vprod', 'vtail'] |
| 1896 |
for arg in known_kwargs: |
| 1897 |
# Mypy can't figure out that this TypedDict index is correct, without repeating T.Literal for the entire list |
| 1898 |
if kwargs[arg]: # type: ignore |
| 1899 |
cmd += ['--' + arg.replace('_', '-'), kwargs[arg]] # type: ignore |
| 1900 |
|
| 1901 |
sources = self.interpreter.source_strings_to_files(kwargs['sources']) |
| 1902 |
targets: T.List[CustomTarget] = [] |
| 1903 |
|
| 1904 |
h_target: T.Optional[CustomTarget] = None |
| 1905 |
if h_template is not None: |
| 1906 |
h_output = os.path.basename(os.path.splitext(h_template.fname)[0]) |
| 1907 |
# We always set template as the first element in the source array |
| 1908 |
# so --template consumes it. |
| 1909 |
h_cmd = cmd + ['--template', '@INPUT@'] |
| 1910 |
h_sources: T.List[CustomTargetSources] = [h_template, *sources] |
| 1911 |
h_target = self._make_mkenum_impl( |
| 1912 |
state, h_sources, h_output, h_cmd, install=kwargs['install_header'], |
| 1913 |
install_dir=kwargs['install_dir']) |
| 1914 |
targets.append(h_target) |
| 1915 |
|
| 1916 |
if c_template is not None: |
| 1917 |
c_output = os.path.basename(os.path.splitext(c_template.fname)[0]) |
| 1918 |
# We always set template as the first element in the source array |
| 1919 |
# so --template consumes it. |
| 1920 |
c_cmd = cmd + ['--template', '@INPUT@'] |
| 1921 |
c_sources: T.List[CustomTargetSources] = [c_template, *sources] |
| 1922 |
|
| 1923 |
depends = kwargs['depends'].copy() |
| 1924 |
if h_target is not None: |
| 1925 |
depends.append(h_target) |
| 1926 |
c_target = self._make_mkenum_impl( |
| 1927 |
state, c_sources, c_output, c_cmd, depends=depends) |
| 1928 |
targets.insert(0, c_target) |
| 1929 |
|
| 1930 |
if c_template is None and h_template is None: |
| 1931 |
generic_cmd = cmd + ['@INPUT@'] |
| 1932 |
target = self._make_mkenum_impl( |
| 1933 |
state, sources, basename, generic_cmd, |
| 1934 |
install=kwargs['install_header'], |
| 1935 |
install_dir=kwargs['install_dir']) |
| 1936 |
return ModuleReturnValue(target, [target]) |
| 1937 |
else: |
| 1938 |
return ModuleReturnValue(targets, targets) |
| 1939 |
|
| 1940 |
@FeatureNew('gnome.mkenums_simple', '0.42.0') |
| 1941 |
@typed_pos_args('gnome.mkenums_simple', str) |
| 1942 |
@typed_kwargs( |
| 1943 |
'gnome.mkenums_simple', |
| 1944 |
*_MK_ENUMS_COMMON_KWS, |
| 1945 |
KwargInfo( |
| 1946 |
'sources', |
| 1947 |
ContainerTypeInfo(list, (str, mesonlib.File)), |
| 1948 |
listify=True, |
| 1949 |
required=True, |
| 1950 |
), |
| 1951 |
KwargInfo('header_prefix', str, default=''), |
| 1952 |
KwargInfo('function_prefix', str, default=''), |
| 1953 |
KwargInfo('body_prefix', str, default=''), |
| 1954 |
KwargInfo('decorator', str, default=''), |
| 1955 |
) |
| 1956 |
def mkenums_simple(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'MkEnumsSimple') -> ModuleReturnValue: |
| 1957 |
hdr_filename = f'{args[0]}.h' |
| 1958 |
body_filename = f'{args[0]}.c' |
| 1959 |
|
| 1960 |
header_prefix = kwargs['header_prefix'] |
| 1961 |
decl_decorator = kwargs['decorator'] |
| 1962 |
func_prefix = kwargs['function_prefix'] |
| 1963 |
body_prefix = kwargs['body_prefix'] |
| 1964 |
|
| 1965 |
cmd: T.List[str] = [] |
| 1966 |
if kwargs['identifier_prefix']: |
| 1967 |
cmd.extend(['--identifier-prefix', kwargs['identifier_prefix']]) |
| 1968 |
if kwargs['symbol_prefix']: |
| 1969 |
cmd.extend(['--symbol-prefix', kwargs['symbol_prefix']]) |
| 1970 |
|
| 1971 |
c_cmd = cmd.copy() |
| 1972 |
# Maybe we should write our own template files into the build dir |
| 1973 |
# instead, but that seems like much more work, nice as it would be. |
| 1974 |
fhead = '' |
| 1975 |
if body_prefix != '': |
| 1976 |
fhead += '%s\n' % body_prefix |
| 1977 |
fhead += '#include "%s"\n' % hdr_filename |
| 1978 |
for hdr in self.interpreter.source_strings_to_files(kwargs['sources']): |
| 1979 |
hdr_path = os.path.relpath(hdr.relative_name(), state.subdir) |
| 1980 |
fhead += f'#include "{hdr_path}"\n' |
| 1981 |
fhead += textwrap.dedent( |
| 1982 |
''' |
| 1983 |
#define C_ENUM(v) ((gint) v) |
| 1984 |
#define C_FLAGS(v) ((guint) v) |
| 1985 |
''') |
| 1986 |
c_cmd.extend(['--fhead', fhead]) |
| 1987 |
|
| 1988 |
c_cmd.append('--fprod') |
| 1989 |
c_cmd.append(textwrap.dedent( |
| 1990 |
''' |
| 1991 |
/* enumerations from "@basename@" */ |
| 1992 |
''')) |
| 1993 |
|
| 1994 |
c_cmd.append('--vhead') |
| 1995 |
c_cmd.append(textwrap.dedent( |
| 1996 |
f''' |
| 1997 |
GType |
| 1998 |
{func_prefix}@enum_name@_get_type (void) |
| 1999 |
{{ |
| 2000 |
static gsize gtype_id = 0; |
| 2001 |
static const G@Type@Value values[] = {{''')) |
| 2002 |
|
| 2003 |
c_cmd.extend(['--vprod', ' { C_@TYPE@ (@VALUENAME@), "@VALUENAME@", "@valuenick@" },']) |
| 2004 |
|
| 2005 |
c_cmd.append('--vtail') |
| 2006 |
c_cmd.append(textwrap.dedent( |
| 2007 |
'''\ |
| 2008 |
{ 0, NULL, NULL } |
| 2009 |
}; |
| 2010 |
if (g_once_init_enter (>ype_id)) { |
| 2011 |
GType new_type = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); |
| 2012 |
g_once_init_leave (>ype_id, new_type); |
| 2013 |
} |
| 2014 |
return (GType) gtype_id; |
| 2015 |
}''')) |
| 2016 |
c_cmd.append('@INPUT@') |
| 2017 |
|
| 2018 |
sources = self.interpreter.source_strings_to_files(kwargs['sources']) |
| 2019 |
c_file = self._make_mkenum_impl(state, sources, body_filename, c_cmd) |
| 2020 |
|
| 2021 |
# .h file generation |
| 2022 |
h_cmd = cmd.copy() |
| 2023 |
|
| 2024 |
if header_prefix and not header_prefix.endswith('\n'): |
| 2025 |
header_prefix += '\n' # Extra trailing newline for style |
| 2026 |
|
| 2027 |
h_cmd.append('--fhead') |
| 2028 |
h_cmd.append(textwrap.dedent( |
| 2029 |
f'''\ |
| 2030 |
#pragma once |
| 2031 |
|
| 2032 |
#include <glib-object.h> |
| 2033 |
{header_prefix} |
| 2034 |
G_BEGIN_DECLS |
| 2035 |
''')) |
| 2036 |
|
| 2037 |
h_cmd.append('--fprod') |
| 2038 |
h_cmd.append(textwrap.dedent( |
| 2039 |
''' |
| 2040 |
/* enumerations from "@basename@" */ |
| 2041 |
''')) |
| 2042 |
|
| 2043 |
extra_newline = '' |
| 2044 |
if decl_decorator: |
| 2045 |
extra_newline = '\n' # Extra leading newline for style |
| 2046 |
|
| 2047 |
h_cmd.append('--vhead') |
| 2048 |
h_cmd.append(extra_newline + textwrap.dedent( |
| 2049 |
f'''\ |
| 2050 |
{decl_decorator} |
| 2051 |
GType {func_prefix}@enum_name@_get_type (void); |
| 2052 |
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ ({func_prefix}@enum_name@_get_type())''')) |
| 2053 |
|
| 2054 |
h_cmd.append('--ftail') |
| 2055 |
h_cmd.append(textwrap.dedent( |
| 2056 |
''' |
| 2057 |
G_END_DECLS''')) |
| 2058 |
h_cmd.append('@INPUT@') |
| 2059 |
|
| 2060 |
h_file = self._make_mkenum_impl( |
| 2061 |
state, sources, hdr_filename, h_cmd, |
| 2062 |
install=kwargs['install_header'], |
| 2063 |
install_dir=kwargs['install_dir']) |
| 2064 |
|
| 2065 |
return ModuleReturnValue([c_file, h_file], [c_file, h_file]) |
| 2066 |
|
| 2067 |
def _make_mkenum_impl( |
| 2068 |
self, |
| 2069 |
state: 'ModuleState', |
| 2070 |
sources: T.Sequence[CustomTargetSources], |
| 2071 |
output: str, |
| 2072 |
cmd: T.List[str], |
| 2073 |
*, |
| 2074 |
install: bool = False, |
| 2075 |
install_dir: T.Optional[T.Sequence[T.Union[str, bool]]] = None, |
| 2076 |
depends: T.Optional[T.Sequence[build.BuildTargetTypes]] = None |
| 2077 |
) -> build.CustomTarget: |
| 2078 |
real_cmd: CommandList = [self._find_tool(state, 'glib-mkenums')] |
| 2079 |
real_cmd.extend(cmd) |
| 2080 |
_install_dir = install_dir or state.environment.coredata.optstore.get_value_for(OptionKey('includedir')) |
| 2081 |
assert isinstance(_install_dir, str), 'for mypy' |
| 2082 |
|
| 2083 |
return CustomTarget( |
| 2084 |
output, |
| 2085 |
state.subdir, |
| 2086 |
state.environment, |
| 2087 |
real_cmd, |
| 2088 |
sources, |
| 2089 |
[output], |
| 2090 |
state.current_build_project, |
| 2091 |
capture=True, |
| 2092 |
install=install, |
| 2093 |
install_dir=[_install_dir], |
| 2094 |
install_tag=['devel'], |
| 2095 |
extra_depends=depends, |
| 2096 |
# https://github.com/mesonbuild/meson/issues/973 |
| 2097 |
absolute_paths=True, |
| 2098 |
rspable=mesonlib.is_windows() or mesonlib.is_cygwin(), |
| 2099 |
description='Generating GObject enum file {}', |
| 2100 |
) |
| 2101 |
|
| 2102 |
@typed_pos_args('gnome.genmarshal', str) |
| 2103 |
@typed_kwargs( |
| 2104 |
'gnome.genmarshal', |
| 2105 |
DEPEND_FILES_KW.evolve(since='0.61.0'), |
| 2106 |
DEPENDS_KW.evolve(since='0.61.0'), |
| 2107 |
INSTALL_KW.evolve(name='install_header'), |
| 2108 |
INSTALL_DIR_KW, |
| 2109 |
KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 2110 |
KwargInfo('internal', bool, default=False), |
| 2111 |
KwargInfo('nostdinc', bool, default=False), |
| 2112 |
KwargInfo('prefix', (str, NoneType)), |
| 2113 |
KwargInfo('skip_source', bool, default=False), |
| 2114 |
KwargInfo('sources', ContainerTypeInfo(list, (str, mesonlib.File, CustomTarget, CustomTargetIndex, GeneratedList), allow_empty=False), listify=True, required=True, |
| 2115 |
since_values={ContainerTypeInfo(list, (CustomTarget, CustomTargetIndex, GeneratedList), allow_empty=False): '1.12.0'}, |
| 2116 |
|
| 2117 |
), |
| 2118 |
KwargInfo('stdinc', bool, default=False), |
| 2119 |
KwargInfo('valist_marshallers', bool, default=False), |
| 2120 |
) |
| 2121 |
def genmarshal(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GenMarshal') -> ModuleReturnValue: |
| 2122 |
output = args[0] |
| 2123 |
sources = self.interpreter.source_strings_to_files(kwargs['sources']) |
| 2124 |
|
| 2125 |
new_genmarshal = mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.53.3') |
| 2126 |
|
| 2127 |
cmd: CommandList = [self._find_tool(state, 'glib-genmarshal'), '--quiet'] |
| 2128 |
if kwargs['prefix']: |
| 2129 |
cmd.extend(['--prefix', kwargs['prefix']]) |
| 2130 |
if kwargs['extra_args']: |
| 2131 |
if new_genmarshal: |
| 2132 |
cmd.extend(kwargs['extra_args']) |
| 2133 |
else: |
| 2134 |
mlog.warning('The current version of GLib does not support extra arguments \n' |
| 2135 |
'for glib-genmarshal. You need at least GLib 2.53.3. See ', |
| 2136 |
mlog.bold('https://github.com/mesonbuild/meson/pull/2049'), |
| 2137 |
once=True, fatal=False) |
| 2138 |
for k in ['internal', 'nostdinc', 'skip_source', 'stdinc', 'valist_marshallers']: |
| 2139 |
# Mypy can't figure out that this TypedDict index is correct, without repeating T.Literal for the entire list |
| 2140 |
if kwargs[k]: # type: ignore |
| 2141 |
cmd.append(f'--{k.replace("_", "-")}') |
| 2142 |
|
| 2143 |
install_header = kwargs['install_header'] |
| 2144 |
capture = False |
| 2145 |
|
| 2146 |
# https://github.com/GNOME/glib/commit/0fbc98097fac4d3e647684f344e508abae109fdf |
| 2147 |
if mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.51.0'): |
| 2148 |
cmd += ['--output', '@OUTPUT@'] |
| 2149 |
else: |
| 2150 |
capture = True |
| 2151 |
|
| 2152 |
header_file = output + '.h' |
| 2153 |
h_cmd = cmd + ['--header', '@INPUT@'] |
| 2154 |
if new_genmarshal: |
| 2155 |
h_cmd += ['--pragma-once'] |
| 2156 |
header = CustomTarget( |
| 2157 |
output + '_h', |
| 2158 |
state.subdir, |
| 2159 |
state.environment, |
| 2160 |
h_cmd, |
| 2161 |
sources, |
| 2162 |
[header_file], |
| 2163 |
state.current_build_project, |
| 2164 |
install=install_header, |
| 2165 |
install_dir=[kwargs['install_dir']] if kwargs['install_dir'] else [], |
| 2166 |
install_tag=['devel'], |
| 2167 |
capture=capture, |
| 2168 |
depend_files=kwargs['depend_files'], |
| 2169 |
description='Generating glib marshaller header {}', |
| 2170 |
) |
| 2171 |
|
| 2172 |
c_cmd = cmd + ['--body', '@INPUT@'] |
| 2173 |
extra_deps: T.List[CustomTarget] = [] |
| 2174 |
if mesonlib.version_compare(self._get_native_glib_version(state), '>= 2.53.4'): |
| 2175 |
# Silence any warnings about missing prototypes |
| 2176 |
c_cmd += ['--include-header', header_file] |
| 2177 |
extra_deps.append(header) |
| 2178 |
body = CustomTarget( |
| 2179 |
output + '_c', |
| 2180 |
state.subdir, |
| 2181 |
state.environment, |
| 2182 |
c_cmd, |
| 2183 |
sources, |
| 2184 |
[f'{output}.c'], |
| 2185 |
state.current_build_project, |
| 2186 |
capture=capture, |
| 2187 |
depend_files=kwargs['depend_files'], |
| 2188 |
extra_depends=extra_deps, |
| 2189 |
description='Generating glib marshaller source {}', |
| 2190 |
) |
| 2191 |
|
| 2192 |
rv = [body, header] |
| 2193 |
return ModuleReturnValue(rv, rv) |
| 2194 |
|
| 2195 |
def _extract_vapi_packages(self, state: 'ModuleState', packages: T.List[T.Union[InternalDependency, str]], |
| 2196 |
) -> T.Tuple[T.List[str], T.List[VapiTarget], T.List[str], T.List[str], T.List[str]]: |
| 2197 |
''' |
| 2198 |
Packages are special because we need to: |
| 2199 |
- Get a list of packages for the .deps file |
| 2200 |
- Get a list of depends for any VapiTargets |
| 2201 |
- Get package name from VapiTargets |
| 2202 |
- Add include dirs for any VapiTargets |
| 2203 |
''' |
| 2204 |
if not packages: |
| 2205 |
return [], [], [], [], [] |
| 2206 |
vapi_depends: T.List[VapiTarget] = [] |
| 2207 |
vapi_packages: T.List[str] = [] |
| 2208 |
vapi_includes: T.List[str] = [] |
| 2209 |
vapi_args: T.List[str] = [] |
| 2210 |
remaining_args = [] |
| 2211 |
for arg in packages: |
| 2212 |
if isinstance(arg, InternalDependency): |
| 2213 |
targets = [t for t in arg.sources if isinstance(t, VapiTarget)] |
| 2214 |
for target in targets: |
| 2215 |
srcdir = os.path.join(state.environment.get_source_dir(), |
| 2216 |
target.get_subdir()) |
| 2217 |
outdir = os.path.join(state.environment.get_build_dir(), |
| 2218 |
target.get_subdir()) |
| 2219 |
outfile = target.get_outputs()[0][:-5] # Strip .vapi |
| 2220 |
vapi_args.append('--vapidir=' + outdir) |
| 2221 |
vapi_args.append('--girdir=' + outdir) |
| 2222 |
vapi_args.append('--pkg=' + outfile) |
| 2223 |
vapi_depends.append(target) |
| 2224 |
vapi_packages.append(outfile) |
| 2225 |
vapi_includes.append(srcdir) |
| 2226 |
else: |
| 2227 |
assert isinstance(arg, str), 'for mypy' |
| 2228 |
vapi_args.append(f'--pkg={arg}') |
| 2229 |
vapi_packages.append(arg) |
| 2230 |
remaining_args.append(arg) |
| 2231 |
|
| 2232 |
# TODO: this is supposed to take IncludeDirs, but it never worked |
| 2233 |
return vapi_args, vapi_depends, vapi_packages, vapi_includes, remaining_args |
| 2234 |
|
| 2235 |
def _generate_deps(self, state: 'ModuleState', library: str, packages: T.List[str], install_dir: str) -> build.Data: |
| 2236 |
outdir = state.environment.scratch_dir |
| 2237 |
fname = os.path.join(outdir, library + '.deps') |
| 2238 |
with open(fname, 'w', encoding='utf-8') as ofile: |
| 2239 |
for package in packages: |
| 2240 |
ofile.write(package + '\n') |
| 2241 |
return build.Data([mesonlib.File(True, outdir, fname)], install_dir, install_dir, mesonlib.FileMode(), state.subproject, install_tag='devel') |
| 2242 |
|
| 2243 |
def _get_vapi_link_with(self, target: CustomTarget) -> T.List[build.LibTypes]: |
| 2244 |
link_with: T.List[build.LibTypes] = [] |
| 2245 |
for dep in target.get_target_dependencies(): |
| 2246 |
if isinstance(dep, build.SharedLibrary): |
| 2247 |
link_with.append(dep) |
| 2248 |
elif isinstance(dep, GirTarget): |
| 2249 |
link_with += self._get_vapi_link_with(dep) |
| 2250 |
return link_with |
| 2251 |
|
| 2252 |
@typed_pos_args('gnome.generate_vapi', str) |
| 2253 |
@typed_kwargs( |
| 2254 |
'gnome.generate_vapi', |
| 2255 |
INSTALL_KW, |
| 2256 |
INSTALL_DIR_KW, |
| 2257 |
KwargInfo( |
| 2258 |
'sources', |
| 2259 |
ContainerTypeInfo(list, (str, mesonlib.File, GirTarget), allow_empty=False), |
| 2260 |
listify=True, |
| 2261 |
required=True, |
| 2262 |
since_values={ContainerTypeInfo(list, (mesonlib.File), allow_empty=False): '1.12.0'}, |
| 2263 |
), |
| 2264 |
KwargInfo('vapi_dirs', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 2265 |
KwargInfo('metadata_dirs', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 2266 |
KwargInfo('gir_dirs', ContainerTypeInfo(list, str), listify=True, default=[]), |
| 2267 |
KwargInfo('packages', ContainerTypeInfo(list, (str, InternalDependency)), listify=True, default=[]), |
| 2268 |
) |
| 2269 |
def generate_vapi(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GenerateVapi') -> ModuleReturnValue: |
| 2270 |
created_values: T.List[T.Union[Dependency, build.Data]] = [] |
| 2271 |
library = args[0] |
| 2272 |
build_dir = os.path.join(state.environment.get_build_dir(), state.subdir) |
| 2273 |
source_dir = os.path.join(state.environment.get_source_dir(), state.subdir) |
| 2274 |
pkg_cmd, vapi_depends, vapi_packages, vapi_includes, packages = self._extract_vapi_packages(state, kwargs['packages']) |
| 2275 |
cmd: CommandList = [state.find_program('vapigen'), '--quiet', f'--library={library}', f'--directory={build_dir}'] |
| 2276 |
cmd.extend([f'--vapidir={d}' for d in kwargs['vapi_dirs']]) |
| 2277 |
cmd.extend([f'--metadatadir={d}' for d in kwargs['metadata_dirs']]) |
| 2278 |
cmd.extend([f'--girdir={d}' for d in kwargs['gir_dirs']]) |
| 2279 |
cmd += pkg_cmd |
| 2280 |
cmd += ['--metadatadir=' + source_dir] |
| 2281 |
|
| 2282 |
inputs: T.List[T.Union[mesonlib.File, GirTarget]] = [] |
| 2283 |
link_with: T.List[build.LinkableTargetTypes] = [] |
| 2284 |
i: CustomTargetInputs |
| 2285 |
for i in kwargs['sources']: |
| 2286 |
if isinstance(i, str): |
| 2287 |
cmd.append(os.path.join(source_dir, i)) |
| 2288 |
i = mesonlib.File.from_source_file(state.environment.source_dir, state.subdir, i) |
| 2289 |
elif isinstance(i, GirTarget): |
| 2290 |
link_with += self._get_vapi_link_with(i) |
| 2291 |
subdir = os.path.join(state.environment.get_build_dir(), |
| 2292 |
i.get_subdir()) |
| 2293 |
gir_file = os.path.join(subdir, i.get_outputs()[0]) |
| 2294 |
cmd.append(gir_file) |
| 2295 |
inputs.append(i) |
| 2296 |
|
| 2297 |
vapi_output = library + '.vapi' |
| 2298 |
datadir = state.environment.coredata.optstore.get_value_for(OptionKey('datadir')) |
| 2299 |
assert isinstance(datadir, str), 'for mypy' |
| 2300 |
install_dir = kwargs['install_dir'] or os.path.join(datadir, 'vala', 'vapi') |
| 2301 |
|
| 2302 |
if kwargs['install']: |
| 2303 |
# We shouldn't need this locally but we install it |
| 2304 |
deps_target = self._generate_deps(state, library, vapi_packages, install_dir) |
| 2305 |
created_values.append(deps_target) |
| 2306 |
vapi_target = VapiTarget( |
| 2307 |
vapi_output, |
| 2308 |
state.subdir, |
| 2309 |
state.environment, |
| 2310 |
cmd, |
| 2311 |
inputs, |
| 2312 |
[vapi_output], |
| 2313 |
state.current_build_project, |
| 2314 |
extra_depends=vapi_depends, |
| 2315 |
install=kwargs['install'], |
| 2316 |
install_dir=[install_dir], |
| 2317 |
install_tag=['devel'], |
| 2318 |
) |
| 2319 |
|
| 2320 |
# So to try our best to get this to just work we need: |
| 2321 |
# - link with the correct library |
| 2322 |
# - include the vapi and dependent vapi files in sources |
| 2323 |
# - add relevant directories to include dirs |
| 2324 |
incs = [build.IncludeDirs(state.subdir, ['.'] + vapi_includes, False, |
| 2325 |
state.current_build_project)] |
| 2326 |
sources = [vapi_target] + vapi_depends |
| 2327 |
rv = InternalDependency(None, incs, [], [], link_with, [], sources, [], [], {}, [], [], []) |
| 2328 |
created_values.append(rv) |
| 2329 |
return ModuleReturnValue(rv, created_values) |
| 2330 |
|
| 2331 |
def initialize(interp: 'Interpreter') -> GnomeModule: |
| 2332 |
mod = GnomeModule(interp) |
| 2333 |
mod.interpreter.append_holder_map(GResourceTarget, interpreter.CustomTargetHolder) |
| 2334 |
mod.interpreter.append_holder_map(GResourceHeaderTarget, interpreter.CustomTargetHolder) |
| 2335 |
mod.interpreter.append_holder_map(GirTarget, interpreter.CustomTargetHolder) |
| 2336 |
mod.interpreter.append_holder_map(TypelibTarget, interpreter.CustomTargetHolder) |
| 2337 |
mod.interpreter.append_holder_map(VapiTarget, interpreter.CustomTargetHolder) |
| 2338 |
return mod |