Source: freetype
Version: 2.10.2+dfsg-2
Severity: wishlist
Tags: patch

Please consider adding an autopkgtest that will check that a trivial
program can be compiled and linked against libfreetype-dev, and running
it when preparing uploads. This is a low-effort way to detect a surprisingly
large class of packaging mistakes, in particular missing -dev dependencies
(so it would have detected #964185).

Here's a simple implementation, also attached:
https://salsa.debian.org/debian/freetype/-/merge_requests/1

I've assumed in this implementation that the Debian maintainers of
freetype intend for statically linking it to be fully supported; if that's
not the case, please remove the last three lines of the test script.
See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=963933 (in which
GLib's equivalent test detected that static linking had regressed due
to a change in one of its dependencies) for some discussion of this.

Thanks,
    smcv
>From ea6bdd5ef2283b2168fa18f38623278142a8a24d Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@debian.org>
Date: Sat, 4 Jul 2020 00:11:58 +0100
Subject: [PATCH] d/tests: Add a superficial compile/link/run autopkgtest

This checks that there are no missing -dev dependencies for basic use
of the -dev package, and in particular would have detected #964185.
It also provides a superficial check that the library does not crash
on startup.

The static linking part (the last few lines) can be removed if freetype
or its dependencies stop supporting static linking, or if the package
maintainer does not intend to guarantee that it works.
---
 debian/tests/control         |  3 +++
 debian/tests/libfreetype-dev | 47 ++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 debian/tests/control
 create mode 100755 debian/tests/libfreetype-dev

diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..422439c
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,3 @@
+Tests: libfreetype-dev
+Depends: build-essential, pkg-config, libfreetype-dev
+Restrictions: allow-stderr, superficial
diff --git a/debian/tests/libfreetype-dev b/debian/tests/libfreetype-dev
new file mode 100755
index 0000000..343479f
--- /dev/null
+++ b/debian/tests/libfreetype-dev
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Copyright 2020 Collabora Ltd.
+# Copyright 2020 Simon McVittie
+# SPDX-License-Identifier: MIT
+
+set -eux
+
+if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
+    CROSS_COMPILE="$DEB_HOST_GNU_TYPE-"
+else
+    CROSS_COMPILE=
+fi
+
+cd "$AUTOPKGTEST_TMP"
+
+cat > trivial.c <<EOF
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include <assert.h>
+#include <stdio.h>
+
+int main(void)
+{
+    FT_Library library = NULL;
+    FT_Error error;
+    FT_Int x = 0, y = 0, z = 0;
+
+    error = FT_Init_FreeType(&library);
+    assert(error == FT_Err_Ok);
+    FT_Library_Version(library, &x, &y, &z);
+    printf("freetype %ld.%ld.%ld\n", (long) x, (long) y, (long) z);
+    assert(x >= 2);
+    error = FT_Done_FreeType(library);
+    assert(error == FT_Err_Ok);
+    return 0;
+}
+EOF
+
+# Deliberately word-splitting pkg-config's output:
+# shellcheck disable=SC2046
+"${CROSS_COMPILE}gcc" -Wall -otrivial trivial.c $("${CROSS_COMPILE}pkg-config" --cflags --libs freetype2)
+./trivial
+
+# shellcheck disable=SC2046
+"${CROSS_COMPILE}gcc" -Wall -static -ostatic trivial.c $("${CROSS_COMPILE}pkg-config" --static --cflags --libs freetype2)
+./static
-- 
2.27.0

Reply via email to