summaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2023-08-15 16:56:23 -0400
committerXavier Claessens <xclaesse@gmail.com>2023-09-18 13:51:27 -0400
commit30d7f506c7ffe4af52feab1a68263a4bd8d78c8a (patch)
tree132587c0d6c69e4cb066ac8c862bf8e75703f25e /mesonbuild/dependencies
parente0c4cffd70761c9b8176724145fb42d11e5313c4 (diff)
downloadmeson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.tar.gz
Remove get_pkgconfig_variable()
Make sure that pkgconfig_define is a pair of strings and not a list with more than 2 strings.
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r--mesonbuild/dependencies/base.py17
-rw-r--r--mesonbuild/dependencies/boost.py2
-rw-r--r--mesonbuild/dependencies/cmake.py3
-rw-r--r--mesonbuild/dependencies/configtool.py3
-rw-r--r--mesonbuild/dependencies/pkgconfig.py32
-rw-r--r--mesonbuild/dependencies/qt.py14
-rw-r--r--mesonbuild/dependencies/scalapack.py2
7 files changed, 28 insertions, 45 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index fa94f8702..6da9a6665 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -30,7 +30,6 @@ from ..mesonlib import version_compare_many
#from ..interpreterbase import FeatureDeprecated, FeatureNew
if T.TYPE_CHECKING:
- from .._typing import ImmutableListProtocol
from ..compilers.compilers import Compiler
from ..environment import Environment
from ..interpreterbase import FeatureCheckBase
@@ -38,6 +37,7 @@ if T.TYPE_CHECKING:
CustomTarget, IncludeDirs, CustomTargetIndex, LibTypes,
StaticLibrary, StructuredSources, ExtractedObjects, GeneratedTypes
)
+ from ..interpreter.type_checking import PkgConfigDefineType
class DependencyException(MesonException):
@@ -193,11 +193,6 @@ class Dependency(HoldableObject):
def get_exe_args(self, compiler: 'Compiler') -> T.List[str]:
return []
- def get_pkgconfig_variable(self, variable_name: str,
- define_variable: 'ImmutableListProtocol[str]',
- default: T.Optional[str]) -> str:
- raise DependencyException(f'{self.name!r} is not a pkgconfig dependency')
-
def get_configtool_variable(self, variable_name: str) -> str:
raise DependencyException(f'{self.name!r} is not a config-tool dependency')
@@ -238,7 +233,7 @@ class Dependency(HoldableObject):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
+ pkgconfig_define: PkgConfigDefineType = None) -> str:
if default_value is not None:
return default_value
raise DependencyException(f'No default provided for dependency {self!r}, which is not pkg-config, cmake, or config-tool based.')
@@ -297,12 +292,6 @@ class InternalDependency(Dependency):
return True
return any(d.is_built() for d in self.ext_deps)
- def get_pkgconfig_variable(self, variable_name: str,
- define_variable: 'ImmutableListProtocol[str]',
- default: T.Optional[str]) -> str:
- raise DependencyException('Method "get_pkgconfig_variable()" is '
- 'invalid for an internal dependency')
-
def get_configtool_variable(self, variable_name: str) -> str:
raise DependencyException('Method "get_configtool_variable()" is '
'invalid for an internal dependency')
@@ -332,7 +321,7 @@ class InternalDependency(Dependency):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
+ pkgconfig_define: PkgConfigDefineType = None) -> str:
val = self.variables.get(internal, default_value)
if val is not None:
return val
diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py
index 788ccbb19..19c629d5b 100644
--- a/mesonbuild/dependencies/boost.py
+++ b/mesonbuild/dependencies/boost.py
@@ -662,7 +662,7 @@ class BoostDependency(SystemDependency):
try:
boost_pc = PkgConfigDependency('boost', self.env, {'required': False})
if boost_pc.found():
- boost_root = boost_pc.get_pkgconfig_variable('prefix', [], None)
+ boost_root = boost_pc.get_variable(pkgconfig='prefix')
if boost_root:
roots += [Path(boost_root)]
except DependencyException:
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
index 2bb1f6b74..5263e5643 100644
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -30,6 +30,7 @@ if T.TYPE_CHECKING:
from ..cmake import CMakeTarget
from ..environment import Environment
from ..envconfig import MachineInfo
+ from ..interpreter.type_checking import PkgConfigDefineType
class CMakeInfo(T.NamedTuple):
module_paths: T.List[str]
@@ -632,7 +633,7 @@ class CMakeDependency(ExternalDependency):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
+ pkgconfig_define: PkgConfigDefineType = None) -> str:
if cmake and self.traceparser is not None:
try:
v = self.traceparser.vars[cmake]
diff --git a/mesonbuild/dependencies/configtool.py b/mesonbuild/dependencies/configtool.py
index 8dda298d7..bd6a9ff73 100644
--- a/mesonbuild/dependencies/configtool.py
+++ b/mesonbuild/dependencies/configtool.py
@@ -24,6 +24,7 @@ from mesonbuild import mesonlib
if T.TYPE_CHECKING:
from ..environment import Environment
+ from ..interpreter.type_checking import PkgConfigDefineType
class ConfigToolDependency(ExternalDependency):
@@ -171,7 +172,7 @@ class ConfigToolDependency(ExternalDependency):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
+ pkgconfig_define: PkgConfigDefineType = None) -> str:
if configtool:
# In the not required case '' (empty string) will be returned if the
# variable is not found. Since '' is a valid value to return we
diff --git a/mesonbuild/dependencies/pkgconfig.py b/mesonbuild/dependencies/pkgconfig.py
index e8f349ec4..1d9863a1c 100644
--- a/mesonbuild/dependencies/pkgconfig.py
+++ b/mesonbuild/dependencies/pkgconfig.py
@@ -31,7 +31,7 @@ if T.TYPE_CHECKING:
from ..environment import Environment
from ..mesonlib import MachineChoice
from ..utils.core import EnvironOrDict
- from .._typing import ImmutableListProtocol
+ from ..interpreter.type_checking import PkgConfigDefineType
class PkgConfigInterface:
'''Base class wrapping a pkg-config implementation'''
@@ -52,14 +52,14 @@ class PkgConfigInterface:
raise NotImplementedError
def cflags(self, name: str, allow_system: bool = False,
- define_variable: T.Optional[ImmutableListProtocol[str]] = None) -> T.List[str]:
+ define_variable: PkgConfigDefineType = None) -> T.List[str]:
'''Return module cflags
@allow_system: If False, remove default system include paths
'''
raise NotImplementedError
def libs(self, name: str, static: bool = False, allow_system: bool = False,
- define_variable: T.Optional[ImmutableListProtocol[str]] = None) -> T.List[str]:
+ define_variable: PkgConfigDefineType = None) -> T.List[str]:
'''Return module libs
@static: If True, also include private libraries
@allow_system: If False, remove default system libraries search paths
@@ -67,7 +67,7 @@ class PkgConfigInterface:
raise NotImplementedError
def variable(self, name: str, variable_name: str,
- define_variable: ImmutableListProtocol[str]) -> T.Optional[str]:
+ define_variable: PkgConfigDefineType) -> T.Optional[str]:
'''Return module variable or None if variable is not defined'''
raise NotImplementedError
@@ -103,13 +103,13 @@ class PkgConfigCLI(PkgConfigInterface):
return version if ret == 0 else None
@staticmethod
- def _define_variable_args(define_variable: T.Optional[ImmutableListProtocol[str]]) -> T.List[str]:
+ def _define_variable_args(define_variable: PkgConfigDefineType) -> T.List[str]:
if define_variable:
return ['--define-variable=' + '='.join(define_variable)]
return []
def cflags(self, name: str, allow_system: bool = False,
- define_variable: T.Optional[ImmutableListProtocol[str]] = None) -> T.List[str]:
+ define_variable: PkgConfigDefineType = None) -> T.List[str]:
env = None
if allow_system:
env = os.environ.copy()
@@ -123,7 +123,7 @@ class PkgConfigCLI(PkgConfigInterface):
return self._split_args(out)
def libs(self, name: str, static: bool = False, allow_system: bool = False,
- define_variable: T.Optional[ImmutableListProtocol[str]] = None) -> T.List[str]:
+ define_variable: PkgConfigDefineType = None) -> T.List[str]:
env = None
if allow_system:
env = os.environ.copy()
@@ -139,7 +139,7 @@ class PkgConfigCLI(PkgConfigInterface):
return self._split_args(out)
def variable(self, name: str, variable_name: str,
- define_variable: ImmutableListProtocol[str]) -> T.Optional[str]:
+ define_variable: PkgConfigDefineType) -> T.Optional[str]:
args: T.List[str] = []
args += self._define_variable_args(define_variable)
args += ['--variable=' + variable_name, name]
@@ -516,16 +516,6 @@ class PkgConfigDependency(ExternalDependency):
raw_libs = self.pkgconfig.libs(self.name, self.static, allow_system=False)
self.link_args, self.raw_link_args = self._search_libs(libs, raw_libs)
- def get_pkgconfig_variable(self, variable_name: str,
- define_variable: ImmutableListProtocol[str],
- default: T.Optional[str]) -> str:
- variable = self.pkgconfig.variable(self.name, variable_name, define_variable)
- if variable is None:
- if default is None:
- mlog.warning(f'Pkg-config variable {variable_name!r} not defined for dependency {self.name}.')
- variable = default or ''
- return variable
-
def extract_field(self, la_file: str, fieldname: str) -> T.Optional[str]:
with open(la_file, encoding='utf-8') as f:
for line in f:
@@ -568,10 +558,12 @@ class PkgConfigDependency(ExternalDependency):
def get_variable(self, *, cmake: T.Optional[str] = None, pkgconfig: T.Optional[str] = None,
configtool: T.Optional[str] = None, internal: T.Optional[str] = None,
default_value: T.Optional[str] = None,
- pkgconfig_define: T.Optional[T.List[str]] = None) -> str:
+ pkgconfig_define: PkgConfigDefineType = None) -> str:
if pkgconfig:
try:
- return self.get_pkgconfig_variable(pkgconfig, pkgconfig_define or [], default_value)
+ variable = self.pkgconfig.variable(self.name, pkgconfig, pkgconfig_define)
+ if variable is not None:
+ return variable
except DependencyException:
pass
if default_value is not None:
diff --git a/mesonbuild/dependencies/qt.py b/mesonbuild/dependencies/qt.py
index d8a94074b..25cf610f0 100644
--- a/mesonbuild/dependencies/qt.py
+++ b/mesonbuild/dependencies/qt.py
@@ -198,7 +198,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
self.is_found = False
return
if self.private_headers:
- qt_inc_dir = mod.get_pkgconfig_variable('includedir', [], None)
+ qt_inc_dir = mod.get_variable(pkgconfig='includedir')
mod_private_dir = os.path.join(qt_inc_dir, 'Qt' + m)
if not os.path.isdir(mod_private_dir):
# At least some versions of homebrew don't seem to set this
@@ -220,7 +220,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
if arg == f'-l{debug_lib_name}' or arg.endswith(f'{debug_lib_name}.lib') or arg.endswith(f'{debug_lib_name}.a'):
is_debug = True
break
- libdir = self.get_pkgconfig_variable('libdir', [], None)
+ libdir = self.get_variable(pkgconfig='libdir')
if not self._link_with_qt_winmain(is_debug, libdir):
self.is_found = False
return
@@ -228,7 +228,7 @@ class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta)
self.bindir = self.get_pkgconfig_host_bins(self)
if not self.bindir:
# If exec_prefix is not defined, the pkg-config file is broken
- prefix = self.get_pkgconfig_variable('exec_prefix', [], None)
+ prefix = self.get_variable(pkgconfig='exec_prefix')
if prefix:
self.bindir = os.path.join(prefix, 'bin')
@@ -422,7 +422,7 @@ class Qt4PkgConfigDependency(QtPkgConfigDependency):
applications = ['moc', 'uic', 'rcc', 'lupdate', 'lrelease']
for application in applications:
try:
- return os.path.dirname(core.get_pkgconfig_variable(f'{application}_location', [], None))
+ return os.path.dirname(core.get_variable(pkgconfig=f'{application}_location'))
except mesonlib.MesonException:
pass
return None
@@ -439,7 +439,7 @@ class Qt5PkgConfigDependency(QtPkgConfigDependency):
@staticmethod
def get_pkgconfig_host_bins(core: PkgConfigDependency) -> str:
- return core.get_pkgconfig_variable('host_bins', [], None)
+ return core.get_variable(pkgconfig='host_bins')
@staticmethod
def get_pkgconfig_host_libexecs(core: PkgConfigDependency) -> str:
@@ -460,12 +460,12 @@ class Qt6PkgConfigDependency(Qt6WinMainMixin, QtPkgConfigDependency):
@staticmethod
def get_pkgconfig_host_bins(core: PkgConfigDependency) -> str:
- return core.get_pkgconfig_variable('bindir', [], None)
+ return core.get_variable(pkgconfig='bindir')
@staticmethod
def get_pkgconfig_host_libexecs(core: PkgConfigDependency) -> str:
# Qt6 pkg-config for Qt defines libexecdir from 6.3+
- return core.get_pkgconfig_variable('libexecdir', [], None)
+ return core.get_variable(pkgconfig='libexecdir')
def get_private_includes(self, mod_inc_dir: str, module: str) -> T.List[str]:
return _qt_get_private_includes(mod_inc_dir, module, self.version)
diff --git a/mesonbuild/dependencies/scalapack.py b/mesonbuild/dependencies/scalapack.py
index fc2f72064..158056fa0 100644
--- a/mesonbuild/dependencies/scalapack.py
+++ b/mesonbuild/dependencies/scalapack.py
@@ -148,5 +148,5 @@ class MKLPkgConfigDependency(PkgConfigDependency):
# gfortran doesn't appear to look in system paths for INCLUDE files,
# so don't allow pkg-config to suppress -I flags for system paths
allow_system = True
- cflags = self.pkgconfig.cflags(self.name, allow_system, define_variable=['prefix', self.__mklroot.as_posix()])
+ cflags = self.pkgconfig.cflags(self.name, allow_system, define_variable=('prefix', self.__mklroot.as_posix()))
self.compile_args = self._convert_mingw_paths(cflags)