summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry LARONDE <tlaronde@kergis.com>2024-04-21 18:14:49 +0000
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-04-21 18:14:49 +0000
commit04c11ebb9d505ef082fe3a40593b8b5dace97d04 (patch)
tree5f1b4e1e4e8f05e98aa27720a613e018280ec55e
parentf7b16fe8e440a4cfe57f59aa00cc82ab9bfeb775 (diff)
CI: utility to compare semantically pc files between 2 dirs.
-rwxr-xr-xauto-meson-pc-cmp.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/auto-meson-pc-cmp.sh b/auto-meson-pc-cmp.sh
new file mode 100755
index 0000000..88d1cd8
--- /dev/null
+++ b/auto-meson-pc-cmp.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+# Compare semantically pc files between two dirs, with same relative
+# pathnames, say one generated by autotools, the other one generated
+# by meson, by not requesting lexical identity but by
+# checking that the same vars are available, and that they eventually
+# have the same definition, whatever way (with whatever pkconf
+# variable) they have been expressed.
+#
+# Copyright 2024 Thierry LARONDE <tlaronde@kergis.com>
+# SPDX-License-Identifier: MIT
+
+# Pc file paths have to be given fully qualified to be independent
+# from PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH definition.
+#
+test $# -eq 2 && test -d "$1" && test -d "$2"\
+ && test "${1#/}" != "$1" && test "${2#/}" != "$2" || {
+ echo "Usage: $(basename $0) fqdir1 fqdir2" >&2
+ exit 1
+}
+
+: ${TMPDIR:=/tmp}
+
+log() {
+ printf "$@" >&2
+}
+
+cleantmp() {
+ rm "$TMPDIR"/$$.*
+}
+
+dir1="$1"
+dir2="$2"
+
+# Start by simply comparing the list of pc files between the two dirs.
+#
+(cd "$dir1"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.1"
+(cd "$dir2"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.2"
+cmp "$TMPDIR/$$.1" "$TMPDIR/$$.2" 2>/dev/null || {
+ log "Pc files not matching between %s and %s:\n" "$dir1" "$dir2"
+ diff -u "$TMPDIR/$$.1" "$TMPDIR/$$.2" >&2
+ cleantmp
+ exit 1
+}
+
+status=0
+while read pcfile; do
+ pcfile=${pcfile#./}
+ ifile=0
+ for pc in "$dir1/$pcfile" "$dir2/$pcfile"; do
+ ifile=$(($ifile + 1))
+ pkgconf --print-variables "$pc"\
+ | sort\
+ | while read var; do
+ test "$var" != "pcfiledir" || continue
+ pkgconf --variable=$var "$pc"\
+ | sed "s!^!$var=!"
+ done >"$TMPDIR/$$.pc$ifile"
+ done
+ if ! cmp "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" 2>/dev/null; then
+ log "!!! %s generated files differ:\n" "$pcfile"
+ diff -U0 "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" >&2
+ status=$(($status + 1))
+ fi
+done <"$TMPDIR/$$.1"
+
+cleantmp
+if test "$status" -ne 0; then
+ log "%d pc files in %s and %s differ semantically.\n" "$status" "$dir1" "$dir2"
+ exit 1
+else
+ exit 0
+fi