diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2018-09-12 13:38:36 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-09-16 15:07:43 +0300 |
commit | 3cf03ec6d603d2c4699cefb9fabdbd8de321a3f2 (patch) | |
tree | a7124115d8363911e16dc71e576d164bbda14d22 | |
parent | 43268bfb79eca55d5d2bd6ff73abcadf9a77c60b (diff) | |
download | meson-3cf03ec6d603d2c4699cefb9fabdbd8de321a3f2.zip meson-3cf03ec6d603d2c4699cefb9fabdbd8de321a3f2.tar.gz meson-3cf03ec6d603d2c4699cefb9fabdbd8de321a3f2.tar.bz2 |
find_installation: Add support for feature option in required kwarg
Closes: #4165.
-rw-r--r-- | docs/markdown/Python-module.md | 4 | ||||
-rw-r--r-- | mesonbuild/modules/python.py | 9 | ||||
-rw-r--r-- | test cases/unit/39 python extmodule/meson.build | 3 | ||||
-rw-r--r-- | test cases/unit/39 python extmodule/meson_options.txt | 1 |
4 files changed, 12 insertions, 5 deletions
diff --git a/docs/markdown/Python-module.md b/docs/markdown/Python-module.md index 51721f0..2bcad78 100644 --- a/docs/markdown/Python-module.md +++ b/docs/markdown/Python-module.md @@ -45,7 +45,9 @@ Keyword arguments are the following: abort if no python installation can be found. If `required` is set to `false`, Meson will continue even if no python installation was found. You can then use the `.found()` method on the returned object to check - whether it was found or not. + whether it was found or not. Since *0.48.0* the value of a + [`feature`](Build-options.md#features) option can also be passed to the + `required` keyword argument. **Returns**: a [python installation][`python_installation` object] diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index d9ec562..0ba086b 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -25,7 +25,7 @@ from ..interpreterbase import ( InterpreterObject, InvalidArguments, FeatureNew ) -from ..interpreter import ExternalProgramHolder +from ..interpreter import ExternalProgramHolder, extract_required_kwarg from ..interpreterbase import flatten from ..build import known_shmod_kwargs from .. import mlog @@ -477,9 +477,10 @@ class PythonModule(ExtensionModule): @permittedKwargs(['required']) def find_installation(self, interpreter, state, args, kwargs): - required = kwargs.get('required', True) - if not isinstance(required, bool): - raise InvalidArguments('"required" argument must be a boolean.') + disabled, required, feature = extract_required_kwarg(kwargs, state.subproject) + if disabled: + mlog.log('find_installation skipped: feature', mlog.bold(feature), 'disabled') + return ExternalProgramHolder(NonExistingExternalProgram()) if len(args) > 1: raise InvalidArguments('find_installation takes zero or one positional argument.') diff --git a/test cases/unit/39 python extmodule/meson.build b/test cases/unit/39 python extmodule/meson.build index 4798654..eb00a6a 100644 --- a/test cases/unit/39 python extmodule/meson.build +++ b/test cases/unit/39 python extmodule/meson.build @@ -21,3 +21,6 @@ if py.found() else error('MESON_SKIP_TEST: Python not found, skipping test.') endif + +py = py_mod.find_installation(get_option('python'), required : get_option('disabled_opt')) +assert(not py.found(), 'find_installation not working with disabled feature') diff --git a/test cases/unit/39 python extmodule/meson_options.txt b/test cases/unit/39 python extmodule/meson_options.txt index b8f645d..c85110d 100644 --- a/test cases/unit/39 python extmodule/meson_options.txt +++ b/test cases/unit/39 python extmodule/meson_options.txt @@ -1,3 +1,4 @@ option('python', type: 'string', description: 'Name of or path to the python executable' ) +option('disabled_opt', type: 'feature', value: 'disabled') |