aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
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
parente0c4cffd70761c9b8176724145fb42d11e5313c4 (diff)
downloadmeson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.zip
meson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.tar.gz
meson-30d7f506c7ffe4af52feab1a68263a4bd8d78c8a.tar.bz2
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')
-rw-r--r--mesonbuild/backend/backends.py2
-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
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py23
-rw-r--r--mesonbuild/interpreter/kwargs.py6
-rw-r--r--mesonbuild/interpreter/type_checking.py9
-rw-r--r--mesonbuild/mdevenv.py2
12 files changed, 54 insertions, 61 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 1d2283f..aef45b3 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -1143,7 +1143,7 @@ class Backend:
if dep.type_name == 'pkgconfig':
# If by chance pkg-config knows the bin dir...
- bindir = dep.get_pkgconfig_variable('bindir', [], default='')
+ bindir = dep.get_variable(pkgconfig='bindir', default_value='')
if bindir:
results.add(bindir)
continue
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index fa94f87..6da9a66 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 788ccbb..19c629d 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 2bb1f6b..5263e56 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 8dda298..bd6a9ff 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 e8f349e..1d9863a 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 d8a9407..25cf610 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 fc2f720..158056f 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)
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index f1f8ea8..a76a0cb 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -21,7 +21,7 @@ from ..interpreterbase import (
typed_pos_args, typed_kwargs, typed_operator,
noArgsFlattening, noPosargs, noKwargs, unholder_return,
flatten, resolve_second_level_holders, InterpreterException, InvalidArguments, InvalidCode)
-from ..interpreter.type_checking import NoneType, ENV_SEPARATOR_KW
+from ..interpreter.type_checking import NoneType, ENV_SEPARATOR_KW, PKGCONFIG_DEFINE_KW
from ..dependencies import Dependency, ExternalLibrary, InternalDependency
from ..programs import ExternalProgram
from ..mesonlib import HoldableObject, OptionKey, listify, Popen_safe
@@ -487,17 +487,18 @@ class DependencyHolder(ObjectHolder[Dependency]):
@typed_pos_args('dependency.get_pkgconfig_variable', str)
@typed_kwargs(
'dependency.get_pkgconfig_variable',
- KwargInfo('default', (str, NoneType)),
- KwargInfo(
- 'define_variable',
- ContainerTypeInfo(list, str, pairs=True),
- default=[],
- listify=True,
- validator=lambda x: 'must be of length 2 or empty' if len(x) not in {0, 2} else None,
- ),
+ KwargInfo('default', str, default=''),
+ PKGCONFIG_DEFINE_KW.evolve(name='define_variable')
)
def pkgconfig_method(self, args: T.Tuple[str], kwargs: 'kwargs.DependencyPkgConfigVar') -> str:
- return self.held_object.get_pkgconfig_variable(args[0], **kwargs)
+ from ..dependencies.pkgconfig import PkgConfigDependency
+ if not isinstance(self.held_object, PkgConfigDependency):
+ raise InvalidArguments(f'{self.held_object.get_name()!r} is not a pkgconfig dependency')
+ return self.held_object.get_variable(
+ pkgconfig=args[0],
+ default_value=kwargs['default'],
+ pkgconfig_define=kwargs['define_variable'],
+ )
@FeatureNew('dependency.get_configtool_variable', '0.44.0')
@FeatureDeprecated('dependency.get_configtool_variable', '0.56.0',
@@ -523,7 +524,7 @@ class DependencyHolder(ObjectHolder[Dependency]):
KwargInfo('configtool', (str, NoneType)),
KwargInfo('internal', (str, NoneType), since='0.54.0'),
KwargInfo('default_value', (str, NoneType)),
- KwargInfo('pkgconfig_define', ContainerTypeInfo(list, str, pairs=True), default=[], listify=True),
+ PKGCONFIG_DEFINE_KW,
)
def variable_method(self, args: T.Tuple[T.Optional[str]], kwargs: 'kwargs.DependencyGetVariable') -> str:
default_varname = args[0]
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index e67ebf0..35b8fb6 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -16,7 +16,7 @@ from ..dependencies.base import Dependency
from ..mesonlib import EnvironmentVariables, MachineChoice, File, FileMode, FileOrString, OptionKey
from ..modules.cmake import CMakeSubprojectOptions
from ..programs import ExternalProgram
-
+from .type_checking import PkgConfigDefineType
class FuncAddProjectArgs(TypedDict):
@@ -256,7 +256,7 @@ class FeatureOptionRequire(TypedDict):
class DependencyPkgConfigVar(TypedDict):
default: T.Optional[str]
- define_variable: T.List[str]
+ define_variable: PkgConfigDefineType
class DependencyGetVariable(TypedDict):
@@ -266,7 +266,7 @@ class DependencyGetVariable(TypedDict):
configtool: T.Optional[str]
internal: T.Optional[str]
default_value: T.Optional[str]
- pkgconfig_define: T.List[str]
+ pkgconfig_define: PkgConfigDefineType
class ConfigurationDataSet(TypedDict):
diff --git a/mesonbuild/interpreter/type_checking.py b/mesonbuild/interpreter/type_checking.py
index 047aff8..645b273 100644
--- a/mesonbuild/interpreter/type_checking.py
+++ b/mesonbuild/interpreter/type_checking.py
@@ -29,6 +29,7 @@ if T.TYPE_CHECKING:
from ..mesonlib import EnvInitValueType
_FullEnvInitValueType = T.Union[EnvironmentVariables, T.List[str], T.List[T.List[str]], EnvInitValueType, str, None]
+ PkgConfigDefineType = T.Optional[T.Tuple[str, str]]
def in_set_validator(choices: T.Set[str]) -> T.Callable[[str], T.Optional[str]]:
@@ -648,3 +649,11 @@ BUILD_TARGET_KWS = [
}
)
]
+
+PKGCONFIG_DEFINE_KW: KwargInfo = KwargInfo(
+ 'pkgconfig_define',
+ ContainerTypeInfo(list, str, pairs=True),
+ default=[],
+ validator=lambda x: 'must be of length 2 or empty' if len(x) not in {0, 2} else None,
+ convertor=lambda x: tuple(x) if x else None
+)
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py
index 46b1b60..aea5da2 100644
--- a/mesonbuild/mdevenv.py
+++ b/mesonbuild/mdevenv.py
@@ -85,7 +85,7 @@ def bash_completion_files(b: build.Build, install_data: 'InstallData') -> T.List
datadir = b.environment.coredata.get_option(OptionKey('datadir'))
assert isinstance(datadir, str), 'for mypy'
datadir_abs = os.path.join(prefix, datadir)
- completionsdir = dep.get_variable(pkgconfig='completionsdir', pkgconfig_define=['datadir', datadir_abs])
+ completionsdir = dep.get_variable(pkgconfig='completionsdir', pkgconfig_define=('datadir', datadir_abs))
assert isinstance(completionsdir, str), 'for mypy'
completionsdir_path = Path(completionsdir)
for f in install_data.data: