dependencies: Don't use NotImplementedError for invalid methods

Using NotImplementedError throws an ugly traceback to the user which
does not print the line number and other information making it
impossible to figure out what's causing it.

Also override it for internal dependencies because self.name is "null"
for them.
pull/2754/head
Nirbheek Chauhan 7 years ago committed by Jussi Pakkanen
parent 7ae5716f67
commit 2c4e7ebb9b
  1. 12
      mesonbuild/dependencies/base.py
  2. 16
      run_unittests.py

@ -131,10 +131,10 @@ class Dependency:
return False
def get_pkgconfig_variable(self, variable_name, kwargs):
raise NotImplementedError('{!r} is not a pkgconfig dependency'.format(self.name))
raise DependencyException('{!r} is not a pkgconfig dependency'.format(self.name))
def get_configtool_variable(self, variable_name):
raise NotImplementedError('{!r} is not a config-tool dependency'.format(self.name))
raise DependencyException('{!r} is not a config-tool dependency'.format(self.name))
class InternalDependency(Dependency):
@ -149,6 +149,14 @@ class InternalDependency(Dependency):
self.sources = sources
self.ext_deps = ext_deps
def get_pkgconfig_variable(self, variable_name, kwargs):
raise DependencyException('Method "get_pkgconfig_variable()" is '
'invalid for an internal dependency')
def get_configtool_variable(self, variable_name):
raise DependencyException('Method "get_configtool_variable()" is '
'invalid for an internal dependency')
class ExternalDependency(Dependency):
def __init__(self, type_name, environment, language, kwargs):

@ -1766,6 +1766,22 @@ class FailureTests(BasePlatformTests):
self.assertMesonRaises("dependency('boost')",
"(BOOST_ROOT.*absolute|{})".format(self.dnf))
def test_dependency_invalid_method(self):
code = '''zlib_dep = dependency('zlib', required : false)
zlib_dep.get_configtool_variable('foo')
'''
self.assertMesonRaises(code, "'zlib' is not a config-tool dependency")
code = '''zlib_dep = dependency('zlib', required : false)
dep = declare_dependency(dependencies : zlib_dep)
dep.get_pkgconfig_variable('foo')
'''
self.assertMesonRaises(code, "Method.*pkgconfig.*is invalid.*internal")
code = '''zlib_dep = dependency('zlib', required : false)
dep = declare_dependency(dependencies : zlib_dep)
dep.get_configtool_variable('foo')
'''
self.assertMesonRaises(code, "Method.*configtool.*is invalid.*internal")
class WindowsTests(BasePlatformTests):
'''

Loading…
Cancel
Save