fixup! interpreter: Add get_variable method to dependency holders

pull/5372/head
Dylan Baker 6 years ago
parent c890c947fa
commit 4f347ef14a
  1. 31
      mesonbuild/dependencies/base.py
  2. 2
      mesonbuild/interpreter.py

@ -194,10 +194,10 @@ class Dependency:
self.ext_deps.append(dep_type(env, kwargs)) self.ext_deps.append(dep_type(env, kwargs))
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None, def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default: typing.Optional[str] = None, configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]: pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
if default is not None: if default_value is not None:
return default return default_value
raise DependencyException('No default provided for dependency {!r}, which is not pkg-config, cmake, or config-tool based.'.format(self)) raise DependencyException('No default provided for dependency {!r}, which is not pkg-config, cmake, or config-tool based.'.format(self))
@ -526,7 +526,7 @@ class ConfigToolDependency(ExternalDependency):
return self.type_name return self.type_name
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None, def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default: typing.Optional[str] = None, configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]: pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
if configtool: if configtool:
# In the not required case '' (empty string) will be returned if the # In the not required case '' (empty string) will be returned if the
@ -541,8 +541,8 @@ class ConfigToolDependency(ExternalDependency):
pass pass
finally: finally:
self.required = restore self.required = restore
if default is not None: if default_value is not None:
return default return default_value
raise DependencyException('Could not get config-tool variable and no default provided for {!r}'.format(self)) raise DependencyException('Could not get config-tool variable and no default provided for {!r}'.format(self))
@ -956,20 +956,20 @@ class PkgConfigDependency(ExternalDependency):
return self.type_name return self.type_name
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None, def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default: typing.Optional[str] = None, configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]: pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
if pkgconfig: if pkgconfig:
kwargs = {} kwargs = {}
if default is not None: if default_value is not None:
kwargs['default'] = default kwargs['default'] = default_value
if pkgconfig_define is not None: if pkgconfig_define is not None:
kwargs['define_variable'] = pkgconfig_define kwargs['define_variable'] = pkgconfig_define
try: try:
return self.get_pkgconfig_variable(pkgconfig, kwargs) return self.get_pkgconfig_variable(pkgconfig, kwargs)
except DependencyException: except DependencyException:
pass pass
if default is not None: if default_value is not None:
return default return default_value
raise DependencyException('Could not get pkg-config variable and no default provided for {!r}'.format(self)) raise DependencyException('Could not get pkg-config variable and no default provided for {!r}'.format(self))
class CMakeTraceLine: class CMakeTraceLine:
@ -1829,21 +1829,20 @@ set(CMAKE_SIZEOF_VOID_P "{}")
return '' return ''
def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None, def get_variable(self, *, cmake: typing.Optional[str] = None, pkgconfig: typing.Optional[str] = None,
configtool: typing.Optional[str] = None, default: typing.Optional[str] = None, configtool: typing.Optional[str] = None, default_value: typing.Optional[str] = None,
pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]: pkgconfig_define: typing.Optional[typing.List[str]] = None) -> typing.Union[str, typing.List[str]]:
if cmake: if cmake:
try: try:
v = self.vars[cmake] v = self.vars[cmake]
except KeyError: except KeyError:
if default is not None: pass
return default
else: else:
if len(v) == 1: if len(v) == 1:
return v[0] return v[0]
elif v: elif v:
return v return v
elif default is not None: if default_value is not None:
return default return default_value
raise DependencyException('Could not get cmake variable and no default provided for {!r}'.format(self)) raise DependencyException('Could not get cmake variable and no default provided for {!r}'.format(self))
class DubDependency(ExternalDependency): class DubDependency(ExternalDependency):

@ -476,7 +476,7 @@ class InternalDependencyHolder(InterpreterObject, ObjectHolder):
@FeatureNew('dep.get_variable', '0.51.0') @FeatureNew('dep.get_variable', '0.51.0')
@noPosargs @noPosargs
@permittedKwargs({'cmake', 'pkgconfig', 'configtool', 'default', 'pkgconfig_define'}) @permittedKwargs({'cmake', 'pkgconfig', 'configtool', 'default_variable', 'pkgconfig_define'})
def variable_method(self, args, kwargs): def variable_method(self, args, kwargs):
return self.held_object.get_variable(**kwargs) return self.held_object.get_variable(**kwargs)

Loading…
Cancel
Save