Bug#1026781: pkgconf: breaks adequate missing-pkgconfig-dependency check due to behaviour change in: pkg-config --exists --print-errors

2023-01-22 Thread Andrej Shadura

On Wed, 21 Dec 2022 14:24:53 +0800 Paul Wise  wrote:

Package: pkgconf
Severity: serious

When a pkg doesn't have its dependencies satisfied, pkgconf --cflags
etc all print an error message and return a failure exit code.


Here’s a reproducer:

$ docker run -it debian:unstable /bin/bash
root@4f9e1cf385db:/# apt update > /dev/null

WARNING: apt does not have a stable CLI interface. Use with caution in 
scripts.


root@4f9e1cf385db:/# apt install -y --no-install-recommends libmpv-dev > 
/dev/null


WARNING: apt does not have a stable CLI interface. Use with caution in 
scripts.


debconf: delaying package configuration, since apt-utils is not installed
root@4f9e1cf385db:/# apt install -y --no-install-recommends pkgconf > 
/dev/null


WARNING: apt does not have a stable CLI interface. Use with caution in 
scripts.


root@4f9e1cf385db:/# pkg-config --exists --print-errors mpv ; echo $?
0
root@4f9e1cf385db:/# pkg-config --cflags mpv ; echo $?
-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz 
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
-I/usr/include/fribidi -I/usr/include/x86_64-linux-gnu 
-I/usr/include/libxml2 -I/usr/include/lua5.2 -I/usr/include/SDL2 
-I/usr/include/uchardet -I/usr/include/pipewire-0.3 
-I/usr/include/spa-0.2 -D_REENTRANT -I/usr/include/libdrm 
-I/usr/include/sixel -I/usr/include/spirv_cross

0
root@4f9e1cf385db:/# rm /usr/share/pkgconfig/wayland-protocols.pc
root@4f9e1cf385db:/# pkg-config --exists --print-errors mpv ; echo $?
0
root@4f9e1cf385db:/# pkg-config --cflags mpv ; echo $?
Package wayland-protocols was not found in the pkg-config search path.
Perhaps you should add the directory containing `wayland-protocols.pc'
to the PKG_CONFIG_PATH environment variable
Package 'wayland-protocols', required by 'mpv', not found

1
root@4f9e1cf385db:/#

--
--
Cheers,
  Andrej



Bug#1026781: pkgconf: breaks adequate missing-pkgconfig-dependency check due to behaviour change in: pkg-config --exists --print-errors

2022-12-20 Thread Paul Wise
Package: pkgconf
Severity: serious

When a pkg doesn't have its dependencies satisfied, pkgconf --cflags
etc all print an error message and return a failure exit code.

With pkg-config, --exists does this check too, exits with an error and
with --print-errors present, prints the same error as --cflags etc do.

With pkgconf, --exists exits with an error only when the .pc file
doesn't actually exist, so I think it doesn't check if dependencies
are satisfied either, since with --print-errors no errors are printed.

This breaks the adequate test missing-pkgconfig-dependency, which runs
pkg-config and parses the output for errors about missing dependencies,
see below for the code that does this parsing.

   pkg-config --exists --print-errors foo

An example of the behaviour under pkg-config:

   $ pkg-config --exists --print-errors mpv ; echo $?
   Package wayland-protocols was not found in the pkg-config search path.
   Perhaps you should add the directory containing `wayland-protocols.pc'
   to the PKG_CONFIG_PATH environment variable
   Package 'wayland-protocols', required by 'mpv', not found
   1
   
An example of the behaviour under pkgconf:

   $ pkgconf --exists --print-errors mpv ; echo $?
   0

   $ pkgconf --cflags mpv ; echo $?
   Package wayland-protocols was not found in the pkg-config search path.
   Perhaps you should add the directory containing `wayland-protocols.pc'
   to the PKG_CONFIG_PATH environment variable
   Package 'wayland-protocols', required by 'mpv', not found
   
   1

This is the bug that lead me to this pkgconf bug:

   https://bugs.debian.org/1026624

Here is the code from adequate that performs this check,
please ensure that the error message matches the regex below.

   $ dgrep -EC4 pkg-?conf adequate
   /usr/bin/adequate-    check_elfs(%file_map);
   /usr/bin/adequate-    check_paths(%file_map);
   /usr/bin/adequate-    check_alternatives(\%package_map, \%file_map);
   /usr/bin/adequate-    check_binfmts(@packages);
   /usr/bin/adequate:    check_pkgconfig(%file_map);
   /usr/bin/adequate-    flush_debconf();
   /usr/bin/adequate-    return;
   /usr/bin/adequate-}
   /usr/bin/adequate-
   --
   /usr/bin/adequate-    }
   /usr/bin/adequate-    return;
   /usr/bin/adequate-}
   /usr/bin/adequate-
   /usr/bin/adequate:sub check_pkgconfig
   /usr/bin/adequate:: Tags(qw(missing-pkgconfig-dependency))
   /usr/bin/adequate-{
   /usr/bin/adequate-    my %file_map = @_;
   /usr/bin/adequate-    my %pkg_map = ();
   /usr/bin/adequate:    -x '/usr/bin/pkg-config' or return;
   /usr/bin/adequate-    while (my ($debpkg, $files) = each %file_map) {
   /usr/bin/adequate-    for my $file (@{$files}) {
   /usr/bin/adequate:    $file =~ 
m{^/usr/(?:share|lib(?:/[^/]+)?)/pkgconfig/([^/]+)[.]pc$} or next;
   /usr/bin/adequate-    my $pkg = $1;
   /usr/bin/adequate-    $pkg_map{$pkg} = $debpkg;
   /usr/bin/adequate-    }
   /usr/bin/adequate-    }
   /usr/bin/adequate-    while (my ($pkg, $debpkg) = each %pkg_map) {
   /usr/bin/adequate-    local $ENV{LC_ALL} = 'C';
   /usr/bin/adequate-    flush_std_fh();
   /usr/bin/adequate:    my $pkgconfig_pid = open(my $pkgconfig, '-|') // 
die "can't fork: $ERRNO";
   /usr/bin/adequate:    if ($pkgconfig_pid) { # parent
   /usr/bin/adequate:    while (<$pkgconfig>) {
   /usr/bin/adequate-    if (m/^Package '(.+)', required by 
'\Q$pkg\E', not found$/) {
   /usr/bin/adequate-    my $deppkg = $1;
   /usr/bin/adequate:    tag $debpkg, 
'missing-pkgconfig-dependency', $pkg, '=>', $deppkg;
   /usr/bin/adequate-    }
   /usr/bin/adequate-    }
   /usr/bin/adequate:    wait or die "pkg-config --exists: $ERRNO";
   /usr/bin/adequate:    close $pkgconfig;  ## no critic 
(CheckedSyscalls)
   /usr/bin/adequate-    } else { # child
   /usr/bin/adequate-    open(STDERR, '>') or die "can't 
redirect stderr: $ERRNO";
   /usr/bin/adequate:    exec('pkg-config', '--exists', 
'--print-errors', $pkg);
   /usr/bin/adequate:    die "can't exec pkg-config: $ERRNO";
   /usr/bin/adequate-    }
   /usr/bin/adequate-    }
   /usr/bin/adequate-    return;
   /usr/bin/adequate-}

-- System Information:
Debian Release: bookworm/sid
  APT prefers testing-debug
  APT policy: (900, 'testing-debug'), (900, 'testing'), (800, 
'unstable-debug'), (800, 'unstable'), (790, 'buildd-unstable'), (700, 
'experimental-debug'), (700, 'experimental'), (690, 'buildd-experimental')
merged-usr: no
Architecture: amd64 (x86_64)

Kernel: Linux 6.0.0-6-amd64 (SMP w/4 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_AU.utf8, LC_CTYPE=en_AU.utf8 (charmap=UTF-8), LANGUAGE=en_AU:en
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages pkgconf depends on:
ii  pkgconf-bin  1.8.0-11

pkgconf recommends no packages.

pkgconf suggests