From d58bbe67278a1d8511679af45c0f0dfe27f83e39 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 28 Nov 2021 00:09:29 -0500 Subject: [PATCH] gnome module: document and fix install_dir x3, by allowing false *_gir and *_typelib generate_gir forces building both the typelib and gir, and some people only want one or the other (probably only the typelib?) which means flagging the other as install_dir: false in the same way custom_target supports. As this always worked, albeit undocumented, make sure it keeps working. It's pretty reasonable to allow, anyway. Fixes https://github.com/mesonbuild/meson/pull/9484#issuecomment-980131791 --- docs/markdown/Gnome-module.md | 4 +-- mesonbuild/modules/gnome.py | 30 +++++++++++++++---- .../12 multiple gir/gir/meson.build | 3 +- .../frameworks/12 multiple gir/test.json | 3 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/markdown/Gnome-module.md b/docs/markdown/Gnome-module.md index 41a8bbd19142..9d58768868b7 100644 --- a/docs/markdown/Gnome-module.md +++ b/docs/markdown/Gnome-module.md @@ -104,9 +104,9 @@ There are several keyword arguments. Many of these map directly to the * `include_directories`: extra include paths to look for gir files * `install`: if true, install the generated files * `install_dir_gir`: (*Added 0.35.0*) which directory to install the - gir file into + gir file into; can be false to disable installation * `install_dir_typelib`: (*Added 0.35.0*) which directory to install - the typelib file into + the typelib file into; can be false to disable installation * `link_with`: list of libraries to link with * `symbol_prefix`: the symbol prefix for the gir object, e.g. `gtk`, (*Since 0.43.0*) an ordered list of multiple prefixes is allowed diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index f7ce1a099d7b..9b64dedcbab5 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -801,13 +801,21 @@ def _make_gir_filelist(self, state: 'ModuleState', srcdir: str, ns: str, def _make_gir_target(self, state: 'ModuleState', girfile: str, scan_command: T.List[str], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], depends: T.List[build.Target], kwargs: T.Dict[str, T.Any]) -> GirTarget: + install = kwargs['install'] + + install_dir = kwargs['install_dir_gir'] + if install_dir is None: + install_dir = os.path.join(state.environment.get_datadir(), 'gir-1.0') + elif install_dir is False: + install = False + scankwargs = { 'input': generated_files, 'output': girfile, 'command': scan_command, 'depends': depends, - 'install': kwargs['install'], - 'install_dir': kwargs['install_dir_gir'] or os.path.join(state.environment.get_datadir(), 'gir-1.0'), + 'install': install, + 'install_dir': install_dir, 'install_tag': 'devel', 'build_by_default': kwargs['build_by_default'], } @@ -817,12 +825,20 @@ def _make_gir_target(self, state: 'ModuleState', girfile: str, scan_command: T.L def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, typelib_cmd: T.List[str], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], kwargs: T.Dict[str, T.Any]) -> TypelibTarget: + install = kwargs['install'] + + install_dir = kwargs['install_dir_typelib'] + if install_dir is None: + install_dir = os.path.join(state.environment.get_libdir(), 'girepository-1.0') + elif install_dir is False: + install = False + typelib_kwargs = { 'input': generated_files, 'output': [typelib_output], 'command': typelib_cmd, - 'install': kwargs['install'], - 'install_dir': kwargs['install_dir_typelib'] or os.path.join(state.environment.get_libdir(), 'girepository-1.0'), + 'install': install, + 'install_dir': install_dir, 'install_tag': 'typelib', 'build_by_default': kwargs['build_by_default'], } @@ -900,8 +916,10 @@ def _get_scanner_ldflags(ldflags: T.Iterable[str]) -> T.Iterable[str]: KwargInfo('identifier_prefix', ContainerTypeInfo(list, str), default=[], listify=True), KwargInfo('include_directories', ContainerTypeInfo(list, (str, build.IncludeDirs)), default=[], listify=True), KwargInfo('includes', ContainerTypeInfo(list, (str, GirTarget)), default=[], listify=True), - KwargInfo('install_dir_gir', (str, NoneType)), - KwargInfo('install_dir_typelib', (str, NoneType)), + KwargInfo('install_dir_gir', (str, bool, NoneType), + validator=lambda x: 'as boolean can only be false' if x is True else None), + KwargInfo('install_dir_typelib', (str, bool, NoneType), + validator=lambda x: 'as boolean can only be false' if x is True else None), KwargInfo('link_with', ContainerTypeInfo(list, (build.SharedLibrary, build.StaticLibrary)), default=[], listify=True), KwargInfo('namespace', str, required=True), KwargInfo('nsversion', str, required=True), diff --git a/test cases/frameworks/12 multiple gir/gir/meson.build b/test cases/frameworks/12 multiple gir/gir/meson.build index 6001a099fb4b..5a52c9c2b6db 100644 --- a/test cases/frameworks/12 multiple gir/gir/meson.build +++ b/test cases/frameworks/12 multiple gir/gir/meson.build @@ -22,7 +22,8 @@ gnome.generate_gir( symbol_prefix : 'meson_sub_', identifier_prefix : 'MesonSub', includes : ['GObject-2.0', meson_gir], - install : true + install : true, + install_dir_gir: false, ) message('TEST: ' + girsubproject.outdir()) diff --git a/test cases/frameworks/12 multiple gir/test.json b/test cases/frameworks/12 multiple gir/test.json index 4ccecc83f3e1..97744028683f 100644 --- a/test cases/frameworks/12 multiple gir/test.json +++ b/test cases/frameworks/12 multiple gir/test.json @@ -6,8 +6,7 @@ {"type": "file", "platform": "cygwin", "file": "usr/lib/libgirlib.dll.a"}, {"type": "expr", "file": "usr/lib/?libgirsubproject.so"}, {"type": "file", "platform": "cygwin", "file": "usr/lib/libgirsubproject.dll.a"}, - {"type": "file", "file": "usr/share/gir-1.0/Meson-1.0.gir"}, - {"type": "file", "file": "usr/share/gir-1.0/MesonSub-1.0.gir"} + {"type": "file", "file": "usr/share/gir-1.0/Meson-1.0.gir"} ], "skip_on_jobname": ["azure", "macos", "msys2"] }