commit:     0ac65ddf7cff60a64730ca7c123f492fb68217a4
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 28 00:38:43 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Apr 12 01:59:53 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0ac65ddf

install-qa-check.d/60pkgconfig: check for not respecting libdir in pc files

It's not valid to reference lib64 when installing to /usr/lib where we
want 32-bit libraries.

We want to make sure that if we're installing a pkgconfig file for a 32-bit
variant (multilib), we make sure that the file references the right library:
it should have e.g. /usr/lib, not /usr/lib64, or consumers trying to use
the 32-bit library will try to link against a 64-bit library.

(We also cover the opposite case: /usr/lib64 pkgconfig files referencing
/usr/lib).

Bug: https://bugs.gentoo.org/729642
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/install-qa-check.d/60pkgconfig | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/bin/install-qa-check.d/60pkgconfig 
b/bin/install-qa-check.d/60pkgconfig
index 9e09a1053..cb6660bcb 100644
--- a/bin/install-qa-check.d/60pkgconfig
+++ b/bin/install-qa-check.d/60pkgconfig
@@ -14,7 +14,7 @@ pkgconfig_check() {
        f=$(egrep -zsH '^Libs.*-Wl,(-O[012]|--hash-style)' "${files[@]}")
        if [[ -n ${f} ]] ; then
                eqawarn "QA Notice: pkg-config files with wrong LDFLAGS 
detected:"
-               eqawarn "${f//${D}}"
+               eqatag -v pkgconfig.bad-ldlags "${f//${D}}"
        fi
 
        # Validate using pkgconfig
@@ -39,10 +39,45 @@ pkgconfig_check() {
                                        eqawarn "QA Notice: pkg-config files 
not respecting EPREFIX found"
                                        eqawarn "${f}'s key=${key} does not 
respect EPREFIX:"
                                        eqawarn "${key}=${value}"
+                                       eqatag -v pkgconfig.bad-paths "${f}"
                                fi
                        done
                done
        fi
+
+       # TODO: Generalise for non-lib64 libdir? Not that this is very common 
now
+       # that riscv chose a more standard layout.
+       #
+       # If we're installing to ${ED}/usr/lib/pkgconfig, let's make sure
+       # we're not referencing lib64.
+       #
+       # e.g. https://bugs.gentoo.org/729642
+       local bad_libdir=()
+       for f in "${files[@]}" ; do
+               # In ${ED}/usr/lib, we shouldn't reference lib64
+               if [[ ${f} == *lib/pkgconfig* ]] ; then
+                       if [[ -d "${ED}"/usr/lib && -L "${ED}"/usr/lib ]] ; then
+                               # (Don't bother if /usr/lib is a symlink to 
/usr/lib64)
+                               continue
+                       fi
+
+                       if egrep -q "/lib64" ${f} ; then
+                               bad_libdir+=( ${f} )
+                       fi
+               elif [[ ${f} == *lib64/pkgconfig* ]] ; then
+                       # We want to match /lib/, /lib/foo/, but not e.g. 
/lib64 or /lib64/, or libfoo
+                       if grep -qP '/lib\b' ${f} ; then
+                               bad_libdir+=( ${f} )
+                       fi
+               fi
+       done
+
+       if [[ -n "${bad_libdir[@]}" ]] ; then
+               eqawarn "QA Notice: pkg-config files not respecting libdir 
found"
+               eqawarn "(contains reference to either lib or lib64 in wrong 
directory)"
+               eqatag -v pkgconfig.bad-libdir "${bad_libdir[@]}"
+       fi
+
 }
 
 pkgconfig_check

Reply via email to