Android Meson test improvements (#2964)

This commit is contained in:
Malcolm Smith
2026-08-15 10:05:08 +02:00
committed by GitHub
parent 10c055d89c
commit 96ba88f3aa
+49 -11
View File
@@ -619,24 +619,54 @@ def test_repair_error(
assert error in capfd.readouterr().err assert error in capfd.readouterr().err
# This also tests integration with pkgconf, because Meson uses it to find Python. # This also tests integration with pkgconf, which Meson uses to find Python and
# OpenBLAS.
@needs_emulator @needs_emulator
def test_meson(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None: def test_meson(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None:
# Alter spam.filter to return the value of a Fortran function.
new_meson_project( new_meson_project(
spam_c_top_level_add="int fortran_func_();",
spam_c_function_add="sts = fortran_func_();",
project_args_add="'fortran',", project_args_add="'fortran',",
extension_args_add="'fortran.f90', link_language: 'fortran',", extension_args_add=dedent(
"""\
'fortran.f90',
link_language: 'fortran',
dependencies: [dependency('openblas', method: 'pkg-config')],
"""
),
# Alter spam.filter to call an OpenBLAS function, and return the value of a
# Fortran function.
spam_c_top_level_add=dedent(
"""\
#include <cblas.h>
int fortran_func_();
"""
),
spam_c_function_add=dedent(
"""\
openblas_get_config();
sts = fortran_func_();
"""
),
).generate(tmp_path) ).generate(tmp_path)
# TODO: remove once meson-python has a release with Android support. # Add a before-build script to download OpenBLAS.
pyproject_path = tmp_path / "pyproject.toml" before_build = tmp_path / "cibw_before_build.sh"
pyproject_path.write_text( before_build.write_text(
pyproject_path.read_text().replace( dedent(
"meson-python", "meson-python @ git+https://github.com/mesonbuild/meson-python@main" """\
#!/bin/sh
set -eu
openblas_dir=$(pwd)/openblas
rm -rf $openblas_dir
mkdir -p $openblas_dir
pip install \\
--target $openblas_dir \\
--index-url https://chaquo.com/pypi-upstream/ \\
chaquopy-openblas==0.3.33
"""
) )
) )
before_build.chmod(0o755)
# Add Fortran code. # Add Fortran code.
(tmp_path / "fortran.f90").write_text( (tmp_path / "fortran.f90").write_text(
@@ -652,7 +682,15 @@ def test_meson(tmp_path: Path, capfd: pytest.CaptureFixture[str]) -> None:
script = 'import spam; print(f"result: {spam.filter("")}")' script = 'import spam; print(f"result: {spam.filter("")}")'
cibuildwheel_run( cibuildwheel_run(
tmp_path, tmp_path,
add_env={**cp313_env, "CIBW_TEST_COMMAND": f"python -c '{script}'"}, add_env={
**cp313_env,
"CIBW_BEFORE_BUILD": str(before_build),
"CIBW_ENVIRONMENT": (
'PKG_CONFIG_PATH="$(pwd)/openblas/chaquopy/lib/pkgconfig" '
'AUDITWHEEL_LD_LIBRARY_PATH="$(pwd)/openblas/chaquopy/lib"'
),
"CIBW_TEST_COMMAND": f"python -c '{script}'",
},
) )
assert "result: 42" in capfd.readouterr().out assert "result: 42" in capfd.readouterr().out