summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2019-12-13 20:33:23 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2019-12-18 01:19:16 +0200
commitc4649704c8dc59f82826ddd41db2d1cc4f43af0b (patch)
treeb51b26e9271d4b00b219629d12c637bfc96a7d88
parent3122bac28a1e047da28b0190b8a0610cc26028dc (diff)
downloadmeson-c4649704c8dc59f82826ddd41db2d1cc4f43af0b.tar.gz
python: add embed to the python dependency function
-rw-r--r--docs/markdown/Python-module.md6
-rw-r--r--docs/markdown/snippets/python_embed.md4
-rw-r--r--mesonbuild/interpreter.py1
-rw-r--r--mesonbuild/modules/python.py24
-rw-r--r--test cases/frameworks/1 boost/meson.build4
5 files changed, 27 insertions, 12 deletions
diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md
index 6f9a76499..152aa5c70 100644
--- a/docs/markdown/Python-module.md
+++ b/docs/markdown/Python-module.md
@@ -103,7 +103,11 @@ need to add `dependencies : py_installation.dependency()`, see [][`dependency()`
python_dependency py_installation.dependency(...)
```
-This method accepts the same arguments as the standard [dependency] function.
+This method accepts the same arguments as the standard [dependency] function and
+the following additional keyword arguments:
+
+- `embed`: *(since 0.53.0)* If true, meson will try to find a python dependency
+ that can be used for embedding python into an application.
**Returns**: a [python dependency][`python_dependency` object]
diff --git a/docs/markdown/snippets/python_embed.md b/docs/markdown/snippets/python_embed.md
new file mode 100644
index 000000000..f50002cbb
--- /dev/null
+++ b/docs/markdown/snippets/python_embed.md
@@ -0,0 +1,4 @@
+## python.dependency() embed kwarg
+
+Added the `embed` kwarg to the python module dependency function to select
+the python library that can be used to embed python into an application.
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index c955ef10f..758c46146 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2055,6 +2055,7 @@ permitted_kwargs = {'add_global_arguments': {'language', 'native'},
'build_always_stale',
'console'},
'dependency': {'default_options',
+ 'embed',
'fallback',
'language',
'main',
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 7832eb8cc..07be3186a 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -27,7 +27,7 @@ from ..interpreterbase import (
InvalidArguments,
FeatureNew, FeatureNewKwargs, disablerIfNotFound
)
-from ..interpreter import ExternalProgramHolder, extract_required_kwarg
+from ..interpreter import ExternalProgramHolder, extract_required_kwarg, permitted_kwargs
from ..build import known_shmod_kwargs
from .. import mlog
from ..environment import detect_cpu_family
@@ -47,6 +47,7 @@ class PythonDependency(ExternalDependency):
super().__init__('python', environment, None, kwargs)
self.name = 'python'
self.static = kwargs.get('static', False)
+ self.embed = kwargs.get('embed', False)
self.version = python_holder.version
self.platform = python_holder.platform
self.pkgdep = None
@@ -62,9 +63,11 @@ class PythonDependency(ExternalDependency):
if DependencyMethods.PKGCONFIG in self.methods and not python_holder.is_pypy:
pkg_version = self.variables.get('LDVERSION') or self.version
pkg_libdir = self.variables.get('LIBPC')
+ pkg_embed = '-embed' if self.embed and mesonlib.version_compare(self.version, '>=3.8') else ''
+ pkg_name = 'python-{}{}'.format(pkg_version, pkg_embed)
# If python-X.Y.pc exists in LIBPC, we will try to use it
- if pkg_libdir is not None and Path(os.path.join(pkg_libdir, 'python-{}.pc'.format(pkg_version))).is_file():
+ if pkg_libdir is not None and Path(os.path.join(pkg_libdir, '{}.pc'.format(pkg_name))).is_file():
old_pkg_libdir = os.environ.get('PKG_CONFIG_LIBDIR')
old_pkg_path = os.environ.get('PKG_CONFIG_PATH')
@@ -74,11 +77,11 @@ class PythonDependency(ExternalDependency):
os.environ['PKG_CONFIG_LIBDIR'] = pkg_libdir
try:
- self.pkgdep = PkgConfigDependency('python-{}'.format(pkg_version), environment, kwargs)
- mlog.debug('Found "python-{}" via pkgconfig lookup in LIBPC ({})'.format(pkg_version, pkg_libdir))
+ self.pkgdep = PkgConfigDependency(pkg_name, environment, kwargs)
+ mlog.debug('Found "{}" via pkgconfig lookup in LIBPC ({})'.format(pkg_name, pkg_libdir))
py_lookup_method = 'pkgconfig'
except MesonException as e:
- mlog.debug('"python-{}" could not be found in LIBPC ({})'.format(pkg_version, pkg_libdir))
+ mlog.debug('"{}" could not be found in LIBPC ({})'.format(pkg_name, pkg_libdir))
mlog.debug(e)
if old_pkg_path is not None:
@@ -89,16 +92,16 @@ class PythonDependency(ExternalDependency):
else:
os.environ.pop('PKG_CONFIG_LIBDIR', None)
else:
- mlog.debug('"python-{}" could not be found in LIBPC ({}), this is likely due to a relocated python installation'.format(pkg_version, pkg_libdir))
+ mlog.debug('"{}" could not be found in LIBPC ({}), this is likely due to a relocated python installation'.format(pkg_name, pkg_libdir))
# If lookup via LIBPC failed, try to use fallback PKG_CONFIG_LIBDIR/PKG_CONFIG_PATH mechanisms
if self.pkgdep is None or not self.pkgdep.found():
try:
- self.pkgdep = PkgConfigDependency('python-{}'.format(pkg_version), environment, kwargs)
- mlog.debug('Found "python-{}" via fallback pkgconfig lookup in PKG_CONFIG_LIBDIR/PKG_CONFIG_PATH'.format(pkg_version))
+ self.pkgdep = PkgConfigDependency(pkg_name, environment, kwargs)
+ mlog.debug('Found "{}" via fallback pkgconfig lookup in PKG_CONFIG_LIBDIR/PKG_CONFIG_PATH'.format(pkg_name))
py_lookup_method = 'pkgconfig-fallback'
except MesonException as e:
- mlog.debug('"python-{}" could not be found via fallback pkgconfig lookup in PKG_CONFIG_LIBDIR/PKG_CONFIG_PATH'.format(pkg_version))
+ mlog.debug('"{}" could not be found via fallback pkgconfig lookup in PKG_CONFIG_LIBDIR/PKG_CONFIG_PATH'.format(pkg_name))
mlog.debug(e)
if self.pkgdep and self.pkgdep.found():
@@ -345,6 +348,9 @@ class PythonInstallation(ExternalProgramHolder):
return self.interpreter.func_shared_module(None, args, kwargs)
+ @noPosargs
+ @permittedKwargs(permitted_kwargs['dependency'])
+ @FeatureNewKwargs('python_installation.dependency', '0.53.0', ['embed'])
def dependency_method(self, args, kwargs):
dep = PythonDependency(self, self.interpreter.environment, kwargs)
return self.interpreter.holderify(dep)
diff --git a/test cases/frameworks/1 boost/meson.build b/test cases/frameworks/1 boost/meson.build
index 4526c300c..b528dca7c 100644
--- a/test cases/frameworks/1 boost/meson.build
+++ b/test cases/frameworks/1 boost/meson.build
@@ -30,8 +30,8 @@ extralibdep = dependency('boost', modules : ['thread', 'system', 'log_setup', 'l
pymod = import('python')
python2 = pymod.find_installation('python2', required: host_machine.system() == 'linux', disabler: true)
python3 = pymod.find_installation('python3', required: host_machine.system() == 'linux', disabler: true)
-python2dep = python2.dependency(required: host_machine.system() == 'linux', disabler: true)
-python3dep = python3.dependency(required: host_machine.system() == 'linux', disabler: true)
+python2dep = python2.dependency(required: host_machine.system() == 'linux', embed: true, disabler: true)
+python3dep = python3.dependency(required: host_machine.system() == 'linux', embed: true, disabler: true)
# compile python 2/3 modules only if we found a corresponding python version
if(python2dep.found() and host_machine.system() == 'linux')