diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-12-07 22:14:29 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2017-12-09 22:05:05 +0200 |
commit | 2c4e7ebb9b8567ebe198b2d436963dacf667a093 (patch) | |
tree | 19631c978e3742f43ab81aa85e423b59e5c0535e | |
parent | 7ae5716f6703700496e36241cdfdc46c8f2c828b (diff) | |
download | meson-2c4e7ebb9b8567ebe198b2d436963dacf667a093.tar.gz |
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.
-rw-r--r-- | mesonbuild/dependencies/base.py | 12 | ||||
-rwxr-xr-x | run_unittests.py | 16 |
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 343065dba..f717e6dd1 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): ''' |