Skip to content

Commit da3b3b3

Browse files
committed
interpreter: Expose install_vala_* and deprecate install_dir > 1 for BuildTarget
For an end user it's opaque what these extra dirs do (even if in the backend it's a fine data layout). Additionally, it isn't exactly obvious that passing `install_dir : [true, true, true, true]` isn't valid if `vala_gir` isn't set. This makes things much more obvious, and means that an end user only needs to set values they want to overwrite. Consider this: ```meson library( 'foo', 'foo.vala', vala_gir : 'foo.gir', install : true, install_dir : [true, true, true, get_option('datadir') / 'mygir'], ) ``` The end use needs to know what all of these fields mean, and they need to specify *every* field. Consider now: ```meson library( 'foo', 'foo.vala', vala_gir : 'foo.gir', install : true, install_vala_gir_dir : get_option('datadir') / 'mygir', ) ``` This does not change the backend representation, since that works and is mostly fine. There's probably some improvements that could be made to group outputs and their install status together in such a way that we cant have mismatched lists, but I haven't undertaken that here.
1 parent feb3e9f commit da3b3b3

File tree

8 files changed

+108
-6
lines changed

8 files changed

+108
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## BuildTarget(install_dir) length > 1 replaced with keywords
2+
3+
Build Targets currently support (with limited documentation), passing an array
4+
of more than one element to `install_dir:` (except for in some wrappers), and
5+
will map these additional install_dir's to extra outputs. This is only used by vala, and has been replaced by explicit keyword arguments.
6+
7+
Code like this:
8+
```meson
9+
library(
10+
'foo',
11+
'foo.vala',
12+
install : true,
13+
install_dir : [true, get_option('includedir') / 'foo', true],
14+
)
15+
```
16+
17+
should now be written as the much clearer:
18+
19+
```meson
20+
library(
21+
'foo',
22+
'foo.vala',
23+
install : true,
24+
install_vala_header_dir : get_option('includedir') / 'foo
25+
)
26+
```
27+
28+
Note that now you only need to specify values you want to deviate from the default.

docs/yaml/functions/_build_target_base.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ kwargs:
180180
of build targets with multiple outputs. Currently, that means Vala. Setting
181181
them to `true` means "use the default", and `false` means, don't install.
182182
183+
*Since 1.10.0* Passing an array is deprecated, and install_vala_header,
184+
install_vala_vapi, and install_vala_gir keyword arguments should be used
185+
instead.
186+
183187
install_mode:
184188
type: array[str | int]
185189
since: 0.47.0
@@ -376,3 +380,37 @@ kwargs:
376380
is not allowed to match a file or directory in the source
377381
directory, nor contain '..' to refer to the parent of the build
378382
directory.
383+
384+
install_vala_header:
385+
type: str | bool
386+
since: 1.10.0
387+
description: |
388+
If set to a string value, the vala generated header will be installed to
389+
that path, if set to `true`, the default include path will be used, if
390+
`false` the header will not be installed.
391+
392+
If it is unset then the value of `install_dir` will be used.
393+
394+
install_vala_vapi:
395+
type: str | bool
396+
since: 1.10.0
397+
description: |
398+
If set to a string value, the vala generated vapi library will be
399+
installed to that path, if set to `true`, the default vapi path will be
400+
used, if `false` the vapi library will not be installed.
401+
402+
If it is unset then the value of `install_dir` will be used.
403+
404+
install_vala_gir:
405+
type: str | bool
406+
since: 1.10.0
407+
description: |
408+
If set to a string value, the vala generated gir library will be
409+
installed to that path, if set to `true`, the default gir path will be
410+
used, if `false` the gir library will not be installed.
411+
412+
If it is unset then the value of `install_dir` will be used if `vala_gir`
413+
is set to a value.
414+
415+
It is an error for this to be either `true` or a string and `vala_gir` to
416+
be unset.

mesonbuild/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class StaticLibraryKeywordArguments(BuildTargetKeywordArguments, total=False):
160160
'd_debug',
161161
}
162162

163-
vala_kwargs = {'vala_header', 'vala_gir', 'vala_vapi'}
163+
vala_kwargs = {'vala_header', 'vala_gir', 'vala_vapi', 'install_vala_header', 'install_vala_gir', 'install_vala_vapi'}
164164
rust_kwargs = {'rust_crate_type', 'rust_dependency_map'}
165165
cs_kwargs = {'resources', 'cs_args'}
166166
swift_kwargs = {'swift_interoperability_mode', 'swift_module_name'}

mesonbuild/interpreter/interpreter.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,12 +3544,18 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs
35443544

35453545
if targetclass is not build.Jar:
35463546
kwargs = T.cast('kwtypes.Executable | kwtypes.StaticLibrary | kwtypes.SharedLibrary | kwtypes.SharedModule', kwargs)
3547+
# The order of these keys matters!
3548+
vala_keys = ('install_vala_header', 'install_vala_vapi', 'install_vala_gir')
3549+
35473550
# Rewrite `install_dir : [main, vala_header, vala_vapi, vala_gir]`
35483551
# Into split arguments
3549-
if kwargs['install_dir']:
3552+
if len(kwargs['install_dir']) > 1:
3553+
if any(kwargs[k] is not None for k in ('install_vala_gir', 'install_vala_header', 'install_vala_vapi')):
3554+
raise InvalidArguments('Passing install_vala_* and more than one argument to install_dir are mutually exclusive')
3555+
35503556
install_dir = kwargs['install_dir'].pop(0)
35513557

3552-
for key in ['install_vala_header', 'install_vala_vapi', 'install_vala_gir']:
3558+
for key in vala_keys:
35533559
action = kwargs['install_dir'].pop(0) if kwargs['install_dir'] else install_dir
35543560
if isinstance(action, bool):
35553561
kwargs[key] = action
@@ -3561,9 +3567,24 @@ def build_target(self, node: mparser.BaseNode, args: T.Tuple[str, SourcesVarargs
35613567
# This was previously allowed, and tested, so we need to allow it to keep working.
35623568
if kwargs['vala_gir'] is None and kwargs['install_vala_gir']:
35633569
kwargs['install_vala_gir'] = False
3570+
elif kwargs['install_dir']:
3571+
for key in vala_keys:
3572+
action = kwargs[key]
3573+
if action is None:
3574+
if key == 'install_vala_gir' and not kwargs['vala_gir']:
3575+
continue
3576+
action = kwargs['install_dir'][0]
3577+
if isinstance(action, bool):
3578+
kwargs[key] = action
3579+
else:
3580+
kwargs[key] = True
3581+
kwargs[f'{key}_dir'] = action
35643582
else:
35653583
kwargs['install_dir'] = [True]
35663584

3585+
if kwargs['vala_gir'] is None and kwargs['install_vala_gir']:
3586+
raise InvalidArguments('Cannot set `install_vala_gir` without `vala_gir`')
3587+
35673588
target = targetclass(name, self.subdir, self.subproject, for_machine, srcs, struct, objs,
35683589
self.environment, self.compilers[for_machine], kwargs)
35693590
if objs and target.uses_rust():

mesonbuild/interpreter/kwargs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ class _BuildTarget(_BaseBuildTarget):
366366
d_module_versions: T.List[T.Union[str, int]]
367367
d_unittest: bool
368368
install_dir: T.List[T.Union[str, bool]]
369+
install_vala_header: T.Union[str, bool, None]
370+
install_vala_vapi: T.Union[str, bool, None]
371+
install_vala_gir: T.Union[str, bool, None]
369372
rust_crate_type: T.Optional[Literal['bin', 'lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro']]
370373
rust_dependency_map: T.Dict[str, str]
371374
swift_interoperability_mode: Literal['c', 'cpp']

mesonbuild/interpreter/type_checking.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
BothLibraries, SharedLibrary, StaticLibrary, Jar, Executable, StructuredSources)
1414
from ..options import OptionKey, UserFeatureOption
1515
from ..dependencies import Dependency, DependencyMethods, InternalDependency
16-
from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo, FeatureBroken
16+
from ..interpreterbase.decorators import KwargInfo, ContainerTypeInfo, FeatureBroken, FeatureDeprecated
1717
from ..mesonlib import (File, FileMode, MachineChoice, has_path_sep, listify, stringlistify,
1818
EnvironmentVariables)
1919
from ..programs import ExternalProgram
@@ -595,6 +595,12 @@ def _extra_files_validator(args: T.List[T.Union[File, str]]) -> T.Optional[str]:
595595
return None
596596

597597

598+
def _bt_install_dir_deprecated(args: T.List[T.Union[str, bool]]) -> T.Iterator[FeatureCheckBase]:
599+
if len(args) > 1:
600+
yield FeatureDeprecated('passing more than one argument to install_dir', '1.10.0',
601+
'use the install_vala_* arguments instead')
602+
603+
598604
# Applies to all build_target like classes
599605
_ALL_TARGET_KWS: T.List[KwargInfo] = [
600606
OVERRIDE_OPTIONS_KW,
@@ -619,6 +625,7 @@ def _extra_files_validator(args: T.List[T.Union[File, str]]) -> T.Optional[str]:
619625
ContainerTypeInfo(list, (str, bool)),
620626
default=[],
621627
listify=True,
628+
feature_validator=_bt_install_dir_deprecated,
622629
),
623630
KwargInfo('implicit_include_directories', bool, default=True, since='0.42.0'),
624631
NATIVE_KW,
@@ -700,8 +707,11 @@ def _name_suffix_validator(arg: T.Optional[T.Union[str, T.List]]) -> T.Optional[
700707
since='0.51.0',
701708
),
702709
KwargInfo('vala_gir', (str, NoneType)),
710+
KwargInfo('install_vala_gir', (str, bool, NoneType), since='1.10.0'),
703711
KwargInfo('vala_header', (str, NoneType)),
712+
KwargInfo('install_vala_header', (str, bool, NoneType), since='1.10.0'),
704713
KwargInfo('vala_vapi', (str, NoneType)),
714+
KwargInfo('install_vala_vapi', (str, bool, NoneType), since='1.10.0'),
705715
]
706716

707717
def _validate_win_subsystem(value: T.Optional[str]) -> T.Optional[str]:

test cases/vala/7 shared library/lib/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ shared_library('installed_vala_all_nolib', 'mylib.vala',
2727
shared_library('installed_vala_onlyh', 'mylib.vala',
2828
dependencies : valadeps,
2929
install : true,
30-
install_dir : [false, get_option('includedir'), false])
30+
install_vala_header : get_option('includedir'),
31+
install_vala_vapi : false,
32+
install_dir : [false])
3133

3234
shared_library('installed_vala_onlyvapi', 'mylib.vala',
3335
dependencies : valadeps,

test cases/vala/7 shared library/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('shared library', 'vala', 'c')
1+
project('shared library', 'vala', 'c', meson_version : '>= 1.10.0')
22

33
valadeps = [dependency('glib-2.0'), dependency('gobject-2.0')]
44

0 commit comments

Comments
 (0)