Skip to content

Commit 56c9e95

Browse files
committed
Implicit dependency fallback when a subproject wrap or dir exists
1 parent 64f3661 commit 56c9e95

File tree

7 files changed

+35
-3
lines changed

7 files changed

+35
-3
lines changed

docs/markdown/Reference-manual.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ arguments:
456456
*(since 0.54.0)* `'subproj_dep'` argument can be omitted in the case the
457457
subproject used `meson.override_dependency('dependency_name', subproj_dep)`.
458458
In that case, the `fallback` keyword argument can be a single string instead
459-
of a list of 2 strings.
459+
of a list of 2 strings. *Since 0.55.0* the `fallback` keyword argument can be
460+
omitted when there is a wrap file or a directory with the same `dependency_name`,
461+
and subproject used `meson.override_dependency('dependency_name', subproj_dep)`.
460462
- `language` *(since 0.42.0)*: defines what language-specific
461463
dependency to find if it's available for multiple languages.
462464
- `method`: defines the way the dependency is detected, the default is
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Implicit dependency fallback
2+
3+
`dependency('foo')` now automatically fallback if the dependency is not found on
4+
the system but a subproject wrap file or directory exists with the same name.
5+
6+
That means that simply adding `subprojects/foo.wrap` is enough to add fallback
7+
to any `dependency('foo')` call. It is however requires that the subproject call
8+
`meson.override_dependency('foo', foo_dep)` to specify which dependency object
9+
should be used for `foo`.

mesonbuild/interpreter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,14 @@ def dependency_impl(self, name, display_name, kwargs):
35493549
return self.notfound_dependency()
35503550

35513551
has_fallback = 'fallback' in kwargs
3552+
if not has_fallback and name:
3553+
# Add an implicit fallback if we have a wrap file or a directory with the same name.
3554+
subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir)
3555+
wrap_, directory = wrap.get_directory(subproject_dir_abs, name)
3556+
if wrap_ or os.path.exists(os.path.join(subproject_dir_abs, directory)):
3557+
kwargs['fallback'] = name
3558+
has_fallback = True
3559+
35523560
if 'default_options' in kwargs and not has_fallback:
35533561
mlog.warning('The "default_options" keyworg argument does nothing without a "fallback" keyword argument.',
35543562
location=self.current_node)

run_unittests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,6 +4080,11 @@ def test_introspect_projectinfo_subprojects(self):
40804080
'name': 'sub',
40814081
'version': '1.0'
40824082
},
4083+
{
4084+
'descriptive_name': 'sub_implicit',
4085+
'name': 'sub_implicit',
4086+
'version': '1.0',
4087+
},
40834088
{
40844089
'descriptive_name': 'sub-novar',
40854090
'name': 'sub_novar',

test cases/common/102 subproject subdir/meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ dependency('sub-novar', fallback : 'sub_novar')
2525
# Verify a subproject can force a dependency to be not-found
2626
d = dependency('sub-notfound', fallback : 'sub_novar', required : false)
2727
assert(not d.found(), 'Dependency should be not-found')
28+
29+
# Verify that implicit fallback works because subprojects/sub_implicit directory exists
30+
d = dependency('sub_implicit')
31+
assert(d.found(), 'Should implicitly fallback')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project('sub_implicit', 'c', version : '1.0')
2+
3+
dep = declare_dependency()
4+
meson.override_dependency('sub_implicit', dep)

test cases/linuxlike/5 dependency versions/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ dependency('somebrokenlib', version : '>=1.0', required : false)
3131

3232
# Search for an external dependency that won't be found, but must later be
3333
# found via fallbacks
34-
somelibnotfound = dependency('somelib', required : false)
34+
somelibnotfound = dependency('somelib1', required : false)
3535
assert(somelibnotfound.found() == false, 'somelibnotfound was found?')
3636
# Find internal dependency without version
37-
somelibver = dependency('somelib',
37+
somelibver = dependency('somelib1',
3838
fallback : ['somelibnover', 'some_dep'])
3939
assert(somelibver.type_name() == 'internal', 'somelibver should be of type "internal", not ' + somelibver.type_name())
4040
# Find an internal dependency again with the same name and a specific version

0 commit comments

Comments
 (0)