dlang module: simplify dependency handling with DRY

It can be a list or a single dependency, but the same logic happens
either way. Instead of manually expanding the logic for both cases, just
convert it to a list as needed.
pull/12839/head
Eli Schwartz 11 months ago
parent f4f50db441
commit dbfc9d0908
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 33
      mesonbuild/modules/dlang.py

@ -13,7 +13,7 @@ from .. import mlog
from ..dependencies import Dependency
from ..dependencies.dub import DubDependency
from ..interpreterbase import typed_pos_args
from ..mesonlib import Popen_safe, MesonException
from ..mesonlib import Popen_safe, MesonException, listify
class DlangModule(ExtensionModule):
class_dubbin = None
@ -69,27 +69,18 @@ class DlangModule(ExtensionModule):
for key, value in kwargs.items():
if key == 'dependencies':
values = listify(value, flatten=False)
config[key] = {}
if isinstance(value, list):
for dep in value:
if isinstance(dep, Dependency):
name = dep.get_name()
ret, res = self._call_dubbin(['describe', name])
if ret == 0:
version = dep.get_version()
if version is None:
config[key][name] = ''
else:
config[key][name] = version
elif isinstance(value, Dependency):
name = value.get_name()
ret, res = self._call_dubbin(['describe', name])
if ret == 0:
version = value.get_version()
if version is None:
config[key][name] = ''
else:
config[key][name] = version
for dep in values:
if isinstance(dep, Dependency):
name = dep.get_name()
ret, res = self._call_dubbin(['describe', name])
if ret == 0:
version = dep.get_version()
if version is None:
config[key][name] = ''
else:
config[key][name] = version
else:
config[key] = value

Loading…
Cancel
Save