From 04c11ebb9d505ef082fe3a40593b8b5dace97d04 Mon Sep 17 00:00:00 2001 From: Thierry LARONDE Date: Sun, 21 Apr 2024 18:14:49 +0000 Subject: [PATCH] CI: utility to compare semantically pc files between 2 dirs. --- auto-meson-pc-cmp.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 auto-meson-pc-cmp.sh 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 +# 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 -- 2.11.4.GIT