summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-12-07 22:14:29 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2017-12-07 22:14:29 +0530
commit5ecc036de5bceaafe1aa6d2b95be838365a7e61f (patch)
treebe003082c2b2697779827f89db2b31333f4ffbde
parent4ae0cadb7f951691e2913a660a61d024d04b5485 (diff)
downloadmeson-nirbheek/dependency-notimplementederror.tar.gz
dependencies: Don't use NotImplementedError for invalid methodsnirbheek/dependency-notimplementederror
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.
-rw-r--r--mesonbuild/dependencies/base.py12
-rwxr-xr-xrun_unittests.py16
2 files changed, 26 insertions, 2 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index f8469c527..c2922f06f 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.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):
diff --git a/run_unittests.py b/run_unittests.py
index fed8fae1b..fe3e5be6c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -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):
'''