wrap: Add special 'dependency_names' key in [provide] section

The value for that key must be a coma separated list of dependecy names
provided by that subproject, when no variable name is needed because the
subproject uses override_dependency().
pull/6902/head
Xavier Claessens 5 years ago
parent 2a7f72885f
commit 71804e56eb
  1. 22
      docs/markdown/Wrap-dependency-system-manual.md
  2. 14
      mesonbuild/wrap/wrap.py
  3. 2
      test cases/common/102 subproject subdir/meson.build
  4. 4
      test cases/common/102 subproject subdir/subprojects/sub_implicit.wrap

@ -145,12 +145,15 @@ wrap-git, the repository must contain all Meson build definitions.
Wrap files can define the dependencies it provides in the `[provide]` section.
When a wrap file provides the dependency `foo` any call do `dependency('foo')`
will automatically fallback to that subproject even if no `fallback` keyword
argument is given. Each entry in the format `dependency_name = variable_name`,
argument is given. It is recommended for subprojects to call
`meson.override_dependency('foo', foo_dep)`, dependency name can then be added into
the special `dependency_names` entry which takes coma separated list of dependency
names. For backward compatibility with subprojects that does not call
`meson.override_dependency()`, the variable name can be provided in the wrap file
with entries in the format `dependency_name = variable_name`,
where `dependency_name` usually match the corresponding pkg-config name and
`variable_name` is the name of a variable defined in the subproject that should
be returned for that dependency. In the case the subproject uses
`meson.override_dependency('foo', foo_dep)` the `variable_name` can be left empty
in the wrap file.
be returned for that dependency.
For example `glib.wrap` provides `glib-2.0`, `gobject-2.0` and `gio-2.0`. A wrap
file for glib would look like:
@ -165,6 +168,17 @@ gobject-2.0=gobject_dep
gio-2.0=gio_dep
```
Alternatively, when using a recent enough version of glib that uses
`meson.override_dependency()`:
```ini
[wrap-git]
url=https://gitlab.gnome.org/GNOME/glib.git
revision=glib-2-62
[provide]
dependency_names = glib-2.0, gobject-2.0, gio-2.0
```
With such wrap file, `dependency('glib-2.0')` will automatically fallback to use
`glib.wrap` and return `glib_dep` variable from the subproject.

@ -127,7 +127,19 @@ class PackageDefinition:
def parse_provide_section(self):
self.provide = {self.name: None}
if self.config.has_section('provide'):
self.provide.update(self.config['provide'])
for k, v in self.config['provide'].items():
if k == 'dependency_names':
# A coma separated list of dependency names that does not
# need a variable name
names = {n.strip(): None for n in v.split(',')}
self.provide.update(names)
continue
if not v:
m = ('Empty dependency variable name for {!r} in {}. '
'If the subproject uses meson.override_dependency() '
'it can be added in the "dependency_names" special key.')
raise WrapException(m.format(k, self.basename))
self.provide[k] = v
def get(self, key: str) -> str:
try:

@ -31,7 +31,7 @@ d = dependency('sub_implicit')
assert(d.found(), 'Should implicitly fallback')
# Verify that implicit fallback works because sub_implicit.wrap has
# `sub_implicit_provide1=` and the subproject overrides sub_implicit_provide1.
# `dependency_names=sub_implicit_provide1` and the subproject overrides sub_implicit_provide1.
d = dependency('sub_implicit_provide1')
assert(d.found(), 'Should implicitly fallback')

@ -1,5 +1,5 @@
[wrap-file]
[provide]
sub_implicit_provide1=
sub_implicit_provide2=sub_implicit_provide2_dep
dependency_names = sub_implicit_provide1
sub_implicit_provide2 = sub_implicit_provide2_dep

Loading…
Cancel
Save