dependencyfallbacks: Use default_options for implicit fallbacks

This removes the warning when using default_options without fallback
kwarg completely because a subproject does not know if the main project
has an implicit fallback or not, so it could set default_options even if
not fallback is available at all.

Fixes: #9278
pull/9282/head
Xavier Claessens 3 years ago committed by Xavier Claessens
parent 4e41a6203f
commit e9386e80ae
  1. 20
      mesonbuild/interpreter/dependencyfallbacks.py
  2. 4
      mesonbuild/interpreter/interpreter.py
  3. 2
      test cases/common/98 subproject subdir/meson.build
  4. 2
      test cases/common/98 subproject subdir/subprojects/sub_implicit/meson.build
  5. 1
      test cases/common/98 subproject subdir/subprojects/sub_implicit/meson_options.txt

@ -16,7 +16,8 @@ if T.TYPE_CHECKING:
class DependencyFallbacksHolder(MesonInterpreterObject):
def __init__(self, interpreter: 'Interpreter', names: T.List[str], allow_fallback: T.Optional[bool] = None) -> None:
def __init__(self, interpreter: 'Interpreter', names: T.List[str], allow_fallback: T.Optional[bool] = None,
default_options: T.Optional[T.List[str]] = None) -> None:
super().__init__(subproject=interpreter.subproject)
self.interpreter = interpreter
self.subproject = interpreter.subproject
@ -27,7 +28,7 @@ class DependencyFallbacksHolder(MesonInterpreterObject):
self.allow_fallback = allow_fallback
self.subproject_name = None
self.subproject_varname = None
self.subproject_kwargs = None
self.subproject_kwargs = {'default_options': default_options or []}
self.names: T.List[str] = []
for name in names:
if not name:
@ -39,12 +40,9 @@ class DependencyFallbacksHolder(MesonInterpreterObject):
raise InterpreterException('dependency_fallbacks name {name!r} is duplicated')
self.names.append(name)
def set_fallback(self, fbinfo: T.Optional[T.Union[T.List[str], str]], default_options: T.Optional[T.List[str]] = None) -> None:
# Legacy: This converts dependency()'s fallback and default_options kwargs.
def set_fallback(self, fbinfo: T.Optional[T.Union[T.List[str], str]]) -> None:
# Legacy: This converts dependency()'s fallback kwargs.
if fbinfo is None:
if default_options is not None:
mlog.warning('The "default_options" keyword argument does nothing without a fallback subproject.',
location=self.interpreter.current_node)
return
if self.allow_fallback is not None:
raise InvalidArguments('"fallback" and "allow_fallback" arguments are mutually exclusive')
@ -60,10 +58,9 @@ class DependencyFallbacksHolder(MesonInterpreterObject):
subp_name, varname = fbinfo
else:
raise InterpreterException('Fallback info must have one or two items.')
kwargs = {'default_options': default_options or []}
self._subproject_impl(subp_name, varname, kwargs)
self._subproject_impl(subp_name, varname)
def _subproject_impl(self, subp_name: str, varname: str, kwargs: TYPE_nkwargs) -> None:
def _subproject_impl(self, subp_name: str, varname: str) -> None:
if not varname:
# If no variable name is specified, check if the wrap file has one.
# If the wrap file has a variable name, better use it because the
@ -75,7 +72,6 @@ class DependencyFallbacksHolder(MesonInterpreterObject):
assert self.subproject_name is None
self.subproject_name = subp_name
self.subproject_varname = varname
self.subproject_kwargs = kwargs
def _do_dependency_cache(self, kwargs: TYPE_nkwargs, func_args: TYPE_nvar, func_kwargs: TYPE_nkwargs) -> T.Optional[Dependency]:
name = func_args[0]
@ -329,7 +325,7 @@ class DependencyFallbacksHolder(MesonInterpreterObject):
if subp_name:
self.forcefallback |= subp_name in force_fallback_for
if self.forcefallback or self.allow_fallback is True or required or self._get_subproject(subp_name):
self._subproject_impl(subp_name, varname, {})
self._subproject_impl(subp_name, varname)
break
candidates = self._get_candidates()

@ -1472,8 +1472,8 @@ external dependencies (including libraries) must go to "dependencies".''')
raise InvalidArguments('"allow_fallback" argument must be boolean')
fallback = kwargs.get('fallback')
default_options = kwargs.get('default_options')
df = DependencyFallbacksHolder(self, names, allow_fallback)
df.set_fallback(fallback, default_options)
df = DependencyFallbacksHolder(self, names, allow_fallback, default_options)
df.set_fallback(fallback)
not_found_message = kwargs.get('not_found_message', '')
if not isinstance(not_found_message, str):
raise InvalidArguments('The not_found_message must be a string.')

@ -27,7 +27,7 @@ d = dependency('sub-notfound', fallback : 'sub_novar', required : false)
assert(not d.found(), 'Dependency should be not-found')
# Verify that implicit fallback works because subprojects/sub_implicit directory exists
d = dependency('sub_implicit')
d = dependency('sub_implicit', default_options: 'opt=overriden')
assert(d.found(), 'Should implicitly fallback')
# Verify that implicit fallback works because sub_implicit.wrap has

@ -9,3 +9,5 @@ sub_implicit_provide2_dep = dep
# This one is not overridden but the wrap file tells the variable name to use.
glib_dep = dep
assert(get_option('opt') == 'overriden')
Loading…
Cancel
Save