From 0cadad434540c5a1b41def7290c8ef16e0d3708a Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 18 Aug 2025 01:00:01 +0300 Subject: [PATCH] meson: Check for Python modules manually The meson python module's find_installation() method conveniently allows testing if the interpreter provides a set of modules. We use it to check for the presence of the modules required at build time. Unfortunately, the meson python module is not meant to access the system Python interpreter of the build machine, but the Python environment of the host machine. Usage of find_installation() for this purpose is incorrect, it may find modules in a different interpreter than the one used to run the build scripts that use those modules. For instance, when cross-compiling libcamera against a Buildroot environment, and pointing meson in the cross-file to the build machine Python interpreter from Buildroot, the find_installation() method will refer to the latter, while our code generation scripts that use the modules will use the former. Replace find_installation() with a manual check using python3 directly. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- meson.build | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index ccf709d8..fd508fd7 100644 --- a/meson.build +++ b/meson.build @@ -283,9 +283,14 @@ run_command('ln', '-fsT', meson.project_source_root(), meson.project_build_root( configure_file(output : 'config.h', configuration : config_h) -# Check for python installation and modules. -py_mod = import('python') -py_mod.find_installation('python3', modules : py_modules) +# Check for python modules. +foreach module : py_modules + result = run_command('python3', '-c' , 'import @0@'.format(module), + capture : false, check : false) + if result.returncode() != 0 + error('Python module \'@0@\' not found'.format(module)) + endif +endforeach ## Summarise Configurations summary({