| 1 |
#!/bin/sh |
| 2 |
# autopkgtest check: Build and run a program against pygobject, to verify that |
| 3 |
# the headers and pkg-config file are installed correctly |
| 4 |
# (C) 2012 Canonical Ltd. |
| 5 |
# Author: Martin Pitt <[email protected]> |
| 6 |
|
| 7 |
set -e |
| 8 |
|
| 9 |
WORKDIR=$(mktemp -d) |
| 10 |
trap 'rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM |
| 11 |
cd "$WORKDIR" |
| 12 |
|
| 13 |
if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then |
| 14 |
CROSS_COMPILE="$DEB_HOST_GNU_TYPE-" |
| 15 |
else |
| 16 |
CROSS_COMPILE= |
| 17 |
fi |
| 18 |
|
| 19 |
cat <<EOF > pytest.c |
| 20 |
#include <Python.h> |
| 21 |
#include <pygobject.h> |
| 22 |
#include <assert.h> |
| 23 |
|
| 24 |
#define AT_LEAST_PYTHON(maj, min, mic, level, ser) \ |
| 25 |
(PY_VERSION_HEX >= ((maj << 24) | (min << 16) | (mic << 8) | (level << 4) | (ser))) |
| 26 |
|
| 27 |
int main(void) |
| 28 |
{ |
| 29 |
PyObject *gobject; |
| 30 |
#if AT_LEAST_PYTHON(3, 12, 0, 0, 0) |
| 31 |
PyConfig config; |
| 32 |
PyStatus status; |
| 33 |
|
| 34 |
PyConfig_InitPythonConfig (&config); |
| 35 |
config.buffered_stdio = 0; |
| 36 |
config.install_signal_handlers = 0; |
| 37 |
status = Py_InitializeFromConfig (&config); |
| 38 |
if (PyStatus_Exception (status)) { |
| 39 |
Py_ExitStatusException (status); |
| 40 |
} |
| 41 |
PyConfig_Clear (&config); |
| 42 |
#else |
| 43 |
Py_UnbufferedStdioFlag = 1; |
| 44 |
Py_InitializeEx (FALSE); |
| 45 |
if (PyErr_Occurred ()) { |
| 46 |
PySys_WriteStderr ("Error in Py_InitializeEx\n"); |
| 47 |
PyErr_Print (); |
| 48 |
return 1; |
| 49 |
} |
| 50 |
#endif |
| 51 |
|
| 52 |
gobject = pygobject_init (-1, -1, -1); |
| 53 |
if (PyErr_Occurred ()) { |
| 54 |
PySys_WriteStderr ("Error in pygobject_init\n"); |
| 55 |
PyErr_Print (); |
| 56 |
return 2; |
| 57 |
} |
| 58 |
assert (gobject != NULL); |
| 59 |
return 0; |
| 60 |
} |
| 61 |
EOF |
| 62 |
|
| 63 |
failed= |
| 64 |
|
| 65 |
for v in $(py3versions -sv); do |
| 66 |
pkg="python-${v}-embed" |
| 67 |
|
| 68 |
# Deliberately word-splitting, that's how pkg-config works: |
| 69 |
# shellcheck disable=SC2046 |
| 70 |
if "${CROSS_COMPILE}gcc" -o "pytest$v" pytest.c $("${CROSS_COMPILE}pkg-config" --cflags --libs "$pkg" pygobject-3.0); then |
| 71 |
echo "build ($v): OK" |
| 72 |
[ -x "pytest$v" ] |
| 73 |
if ./"pytest$v"; then |
| 74 |
echo "run ($v): OK" |
| 75 |
else |
| 76 |
echo "run ($v): FAILED" |
| 77 |
failed=yes |
| 78 |
fi |
| 79 |
else |
| 80 |
echo "build ($v): FAILED" |
| 81 |
failed=yes |
| 82 |
fi |
| 83 |
done |
| 84 |
if [ -n "$failed" ]; then |
| 85 |
exit 1 |
| 86 |
fi |