From f818e9df582e27d73a36c0b7a94dc897a6e6dc62 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 19 Oct 2017 15:20:41 -0700 Subject: [PATCH] Add a configtool_variable method to dependency This mirrors the get_pkgconfig_variable but for config tool based dependencies. --- mesonbuild/dependencies/base.py | 14 +++++++++ mesonbuild/interpreter.py | 10 ++++++ .../165 config tool variable/meson.build | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test cases/common/165 config tool variable/meson.build diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 84b20e7d9..682182c69 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -132,6 +132,9 @@ class Dependency: def get_pkgconfig_variable(self, variable_name): raise NotImplementedError('{!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)) + class InternalDependency(Dependency): def __init__(self, version, incdirs, compile_args, link_args, libraries, sources, ext_deps): @@ -288,6 +291,17 @@ class ConfigToolDependency(ExternalDependency): def get_methods(self): return [DependencyMethods.AUTO, DependencyMethods.CONFIG_TOOL] + def get_configtool_variable(self, variable_name): + p, out, _ = Popen_safe([self.config, '--{}'.format(variable_name)]) + if p.returncode != 0: + if self.required: + raise DependencyException( + 'Could not get variable "{}" for dependency {}'.format( + variable_name, self.name)) + variable = out.strip() + mlog.debug('Got config-tool variable {} : {}'.format(variable_name, variable)) + return variable + class PkgConfigDependency(ExternalDependency): # The class's copy of the pkg-config path. Avoids having to search for it diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index fbf9a21de..dd0e0e60d 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -274,6 +274,7 @@ class DependencyHolder(InterpreterObject, ObjectHolder): 'type_name': self.type_name_method, 'version': self.version_method, 'get_pkgconfig_variable': self.pkgconfig_method, + 'get_configtool_variable': self.configtool_method, }) def type_name_method(self, args, kwargs): @@ -296,6 +297,15 @@ class DependencyHolder(InterpreterObject, ObjectHolder): raise InterpreterException('Variable name must be a string.') return self.held_object.get_pkgconfig_variable(varname) + def configtool_method(self, args, kwargs): + args = listify(args) + if len(args) != 1: + raise InterpreterException('get_configtool_variable takes exactly one argument.') + varname = args[0] + if not isinstance(varname, str): + raise InterpreterException('Variable name must be a string.') + return self.held_object.get_configtool_variable(varname) + class InternalDependencyHolder(InterpreterObject, ObjectHolder): def __init__(self, dep): InterpreterObject.__init__(self) diff --git a/test cases/common/165 config tool variable/meson.build b/test cases/common/165 config tool variable/meson.build new file mode 100644 index 000000000..0643042d8 --- /dev/null +++ b/test cases/common/165 config tool variable/meson.build @@ -0,0 +1,31 @@ +# Copyright © 2017 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project('config tool variable', 'cpp') + + +dep_llvm = dependency('llvm', required : false) +if not dep_llvm.found() + error('MESON_SKIP_TEST LLVM not installed.') +endif + +includedir = dep_llvm.get_configtool_variable('includedir') +includedir = join_paths(includedir, 'llvm') +if host_machine.system() == 'windows' + cmd = run_command(['dir', includedir]) +else + cmd = run_command(['ls', includedir]) +endif + +assert(cmd.returncode() == 0, 'did not run successfully')