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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2025-08-18 01:00:01 +03:00
parent ac09782a17
commit 0cadad4345

View File

@@ -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({