Source: libgcrypt20
Severity: wishlist
Tags: patch
Packaging a shared library involves various annoying subtleties which
are easy to get wrong, and surprisingly often they can be detected and
avoided by a superficial autopkgtest that links an almost-trivial program
to the library under test.
I attach a simple implementation of this, which I found useful while
adjusting the packaging of libgcrypt20 in the Steam Runtime, a
Debian-derived container used to run games on Linux.
(For testing/unstable you might prefer to replace references to
pkg-config with pkgconf; the attached version is more backportable.)
Thanks,
smcv
>From ab7fff5480b0f9efca2e6e870184d4951588b6f0 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[email protected]>
Date: Mon, 25 Nov 2024 15:02:02 +0000
Subject: [PATCH] Add an autopkgtest smoke-test for linking to libgcrypt
Superficial tests like this one are a surprisingly effective way to
detect packaging regressions.
Signed-off-by: Simon McVittie <[email protected]>
---
debian/tests/control | 3 +++
debian/tests/libgcrypt20-dev | 33 +++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 debian/tests/control
create mode 100755 debian/tests/libgcrypt20-dev
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 00000000..d1550422
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: libgcrypt20-dev
+Depends: build-essential, libgcrypt20-dev, pkg-config
+Restrictions: allow-stderr, superficial
diff --git a/debian/tests/libgcrypt20-dev b/debian/tests/libgcrypt20-dev
new file mode 100755
index 00000000..945068b1
--- /dev/null
+++ b/debian/tests/libgcrypt20-dev
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Copyright 2019-2024 Collabora Ltd.
+# SPDX-License-Identifier: Expat
+
+set -eux
+
+WORKDIR="$(mktemp -d)"
+trap 'cd /; rm -fr "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM
+
+if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
+ CROSS_COMPILE="$DEB_HOST_GNU_TYPE-"
+else
+ CROSS_COMPILE=
+fi
+
+cat >"$WORKDIR/use.c"<<EOF
+#include <gcrypt.h>
+
+#include <stdio.h>
+
+int main(void)
+{
+ puts(gcry_check_version(NULL));
+ return 0;
+}
+EOF
+
+cd "$WORKDIR"
+
+# Deliberately word-splitting pkg-config's output:
+# shellcheck disable=SC2046
+"${CROSS_COMPILE}gcc" -ouse use.c $("${CROSS_COMPILE}pkg-config" --cflags --libs libgcrypt)
+./use
--
2.39.5