Add a configtool_variable method to dependency

This mirrors the get_pkgconfig_variable but for config tool based
dependencies.
pull/2512/head
Dylan Baker 7 years ago
parent df3c006456
commit f818e9df58
  1. 14
      mesonbuild/dependencies/base.py
  2. 10
      mesonbuild/interpreter.py
  3. 31
      test cases/common/165 config tool variable/meson.build

@ -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

@ -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)

@ -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')
Loading…
Cancel
Save