CI: comparing two pc files semantically

tlaronde at kergis.com tlaronde at kergis.com
Tue Mar 12 07:37:14 UTC 2024


When comparing autotools vs. meson generated files, the CI currently
compares the pc files lexically, byte by byte.

This is the reason why in the current version of xorg-sgml-doctools
there is a discrepancy between the definition of what is put in the pc
file and what is indeed used as definition of variables for
installation: the variables were defined the way they are defined in
autotools to pass the CI test. But if the user defines the variables
differently from the default, the pc file will not match the
installation.

I have modified xorg-sgml-doctools meson.build (and added a
meson_options.txt) to circumvent the problem (in my fork).

But it would be better to compare, in the CI, the files semantically:
just ensure that they "say" the same thing, whatever way the
definitions are written.

The attached script is an example on how to achieve this.
-- 
        Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C
-------------- next part --------------
#!/bin/sh
# Compare semantically two pc files, say one generated by autotools, the
# other 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.

# Pc file paths have to be given fully qualified to be independent
# from PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH definition.
#
test $# -eq 2 || {
	echo "Usage: $(basename $0) fq_pc1 fq_pc2" >&2
	exit 1
}

TMPDIR=${TMPDIR:-/tmp}

ifile=0
for pc in "$1" "$2"; do
	ifile=$(($ifile + 1))
	pkgconf --print-variables "$pc"\
		| sort\
		| while read var; do
			pkgconf --variable=$var "$pc"\
				| sed "s!^!$var=!"
		done >"$TMPDIR/$$.$ifile"
done

if ! cmp "$TMPDIR/$$.1" "$TMPDIR/$$2"; then
	echo "!!! Pc generated files differ:" >&2
	diff -U0 "$TMPDIR/$$.1" "$TMPDIR/$$.2" >&2
	status=1
else
	echo "Pc generated semantically equals" >&2
	status=0
fi

rm "$TMPDIR/$$".*
exit $status


More information about the xorg-devel mailing list