Skip to content

Commit

Permalink
dependencies/detect: rewrite get_dep_indentifier around DEPENDENCY_KWS
Browse files Browse the repository at this point in the history
This gives us one source of truth, as well as ensure that an empty value
and a default value are treated the same.
  • Loading branch information
dcbaker committed Dec 13, 2024
1 parent 578e2bd commit 7c76ef2
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions mesonbuild/dependencies/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,34 @@ def __contains__(self, key: object) -> bool:
def get_dep_identifier(name: str, kwargs: T.Dict[str, T.Any]) -> 'TV_DepID':
identifier: 'TV_DepID' = (('name', name), )
from ..interpreter.type_checking import DEPENDENCY_KWS
nkwargs = {k.name: k.default for k in DEPENDENCY_KWS}
nkwargs.update(kwargs)

assert len(DEPENDENCY_KWS) == 20, \
'Extra kwargs have been added to dependency(), please review if it makes sense to handle it here'
for key, value in nkwargs.items():
# 'version' is irrelevant for caching; the caller must check version matches
# 'native' is handled above with `for_machine`
# 'required' is irrelevant for caching; the caller handles it separately
# 'fallback' and 'allow_fallback' is not part of the cache because,
# once a dependency has been found through a fallback, it should
# be used for the rest of the Meson run.
# 'default_options' is only used in fallback case
# 'not_found_message' has no impact on the dependency lookup
# 'include_type' is handled after the dependency lookup
if key in {'version', 'native', 'required', 'fallback', 'allow_fallback', 'default_options',
'not_found_message', 'include_type'}:
continue
# 'version' is irrelevant for caching; the caller must check version matches
# 'native' is handled above with `for_machine`
# 'required' is irrelevant for caching; the caller handles it separately
# 'fallback' and 'allow_fallback' is not part of the cache because,
# once a dependency has been found through a fallback, it should
# be used for the rest of the Meson run.
# 'default_options' is only used in fallback case
# 'not_found_message' has no impact on the dependency lookup
# 'include_type' is handled after the dependency lookup
# 'method' does not matter, we really only want one kind of a dependency
invalid_keys = {
'version', 'native', 'required', 'fallback', 'allow_fallback',
'default_options', 'not_found_message', 'include_type'}
valid_keys = [n for n in DEPENDENCY_KWS
if n.name not in invalid_keys]
for dep in valid_keys:
value = kwargs.get(dep.name, dep.default)
# All keyword arguments are strings, ints, or lists (or lists of lists)
if isinstance(value, list):
for i in value:
assert isinstance(i, str), i
value = tuple(frozenset(listify(value)))
else:
assert value is None or isinstance(value, (str, bool, int)), value
identifier = (*identifier, (key, value),)
identifier = (*identifier, (dep.name, value),)
return identifier

display_name_map = {
Expand Down

0 comments on commit 7c76ef2

Please sign in to comment.