diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2021-09-20 09:01:07 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2021-09-20 13:42:07 -0400 |
commit | e9386e80ae413e04e4fe36d46820c8346ef835e0 (patch) | |
tree | f0e5f99e47346242cb03e8ceaa1c400c56d296c7 | |
parent | 4e41a6203fe2d5bc37d44216bcfd865d9575a819 (diff) | |
download | meson-e9386e80ae413e04e4fe36d46820c8346ef835e0.zip meson-e9386e80ae413e04e4fe36d46820c8346ef835e0.tar.gz meson-e9386e80ae413e04e4fe36d46820c8346ef835e0.tar.bz2 |
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
5 files changed, 14 insertions, 15 deletions
diff --git a/mesonbuild/interpreter/dependencyfallbacks.py b/mesonbuild/interpreter/dependencyfallbacks.py index 2a4f212..64b3f47 100644 --- a/mesonbuild/interpreter/dependencyfallbacks.py +++ b/mesonbuild/interpreter/dependencyfallbacks.py @@ -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() diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 891c606..1268e3e 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -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.') diff --git a/test cases/common/98 subproject subdir/meson.build b/test cases/common/98 subproject subdir/meson.build index 95bf34e..3053b3b 100644 --- a/test cases/common/98 subproject subdir/meson.build +++ b/test cases/common/98 subproject subdir/meson.build @@ -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 diff --git a/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson.build b/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson.build index a1c46a1..9f43604 100644 --- a/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson.build +++ b/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson.build @@ -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')
\ No newline at end of file diff --git a/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson_options.txt b/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson_options.txt new file mode 100644 index 0000000..770178c --- /dev/null +++ b/test cases/common/98 subproject subdir/subprojects/sub_implicit/meson_options.txt @@ -0,0 +1 @@ +option('opt', type: 'string', value: 'default')
\ No newline at end of file |