Package: pkg-config
Version: 0.29-4
Severity: wishlist
Tags: patch

Hi,

the apt test framework[0] breaks if pkg-config is installed as the later
configures dpkg to run a --post-invoke (limited to actions on
architectures) while the former sets up a pseudo-chroot environment by
calling dpkg with the --root option and includes configuring
architectures for such pseudo-chroots.

Now, ideally dpkg wouldn't even parse your dpkg.cfg.d file (#808203),
but it does, so I would like to propose fixing the hook script to
support (the rather new) DPKG_ROOT environment variable [1] which not
only fixes my problem now, but will also properly work then dpkg doesn't
parse the /etc file of the 'host' anymore, but uses the /etc of the
'chroot' and that 'chroot' happens to have pkg-config installed or is
installed into (postinst). (host/chroot for the lack of a better term).


The attached debdiff should implement this (together with asking for the
architectures configured in the chroot rather than the outer system
& not creating broken links if the crosswrapper doesn't exist), but my
perl skills are pretty much non-existent… note: most of the new lines
can be attributed to me attempting to support 'crazy' DPKG_ROOT values
like directories containing spaces and magic shell characters.


Best regards

David Kalnischkies

[0] run e.g. as autopkgtest, but pkg-config isn't in the (build-)
dependencies of apt so far, so that effects 'just' developer machines.
[1] some info on the why and how of the variable:
https://wiki.debian.org/Teams/Dpkg/Spec/InstallBootstrap

P.S.: While testing I noticed that this hook hadn't run since dpkg
changed the triplet of i386 from i586 to i686. No idea if, how or why
that should be solved, just a sidenote.
diff -u pkg-config-0.29/debian/changelog pkg-config-0.29/debian/changelog
--- pkg-config-0.29/debian/changelog
+++ pkg-config-0.29/debian/changelog
@@ -1,3 +1,10 @@
+pkg-config (0.29-4.1) UNRELEASED; urgency=medium
+
+  * Non-maintainer upload.
+  * support DPKG_ROOT in pkg-config-dpkghook
+
+ -- David Kalnischkies <da...@kalnischkies.de>  Thu, 19 May 2016 13:59:57 +0200
+
 pkg-config (0.29-4) unstable; urgency=medium
 
   * Update glib/m4macros/glib-gettext.m4 from newer upstream version to
diff -u pkg-config-0.29/debian/pkg-config-dpkghook pkg-config-0.29/debian/pkg-config-dpkghook
--- pkg-config-0.29/debian/pkg-config-dpkghook
+++ pkg-config-0.29/debian/pkg-config-dpkghook
@@ -14,25 +14,41 @@
 use Dpkg::Arch qw(debarch_to_gnutriplet);
 use Dpkg::ErrorHandling qw(error);
 
-my $crosswrapper = "/usr/share/pkg-config-crosswrapper";
+my $dpkgroot = $ENV{'DPKG_ROOT'} // '';
+my $crosswrapper = "$dpkgroot/usr/share/pkg-config-crosswrapper";
 
 my $action = $ARGV[0];
 error("parameter must be 'remove' or 'update'")
   unless defined $action && ($action eq "remove" || $action eq "update");
 
-my $arch = `dpkg --print-architecture`;
-error('dpkg --print-architecture failed') if $? >> 8;
-my @architectures = `dpkg --print-foreign-architectures`;
-error('dpkg --print-foreign-architectures failed') if $? >> 8;
-push @architectures, $arch;
+if ($dpkgroot) {
+  open(NATIVE_FH, "-|", "dpkg", "--root", $dpkgroot, "--print-architecture")
+    or error("dpkg --root $dpkgroot --print-architecture failed");
+  open(FOREIGN_FH, "-|", "dpkg", "--root", $dpkgroot, "--print-foreign-architectures")
+    or error("dpkg --root $dpkgroot --print-foreign-architecture failed");
+} else {
+  open(NATIVE_FH, "-|", "dpkg", "--print-architecture")
+    or error('dpkg --print-architecture failed');
+  open(FOREIGN_FH, "-|", "dpkg", "--print-foreign-architectures")
+    or error("dpkg --print-foreign-architecture failed");
+}
+my @architectures = <NATIVE_FH>;
+push @architectures, <FOREIGN_FH>;
 chomp @architectures;
 
 my %gnutriplets = map { debarch_to_gnutriplet($_) => 1 } @architectures;
 
-my %symlinks = map { $_ => 1 } </usr/bin/*-pkg-config>;
+my %symlinks;
+if (opendir(USRBIN, "$dpkgroot/usr/bin")) {
+  while (my $file = readdir(USRBIN)) {
+    next unless $file =~ /[^-]+-[^-]+-[^-]+-pkg-config$/;
+    my $name = "$dpkgroot/usr/bin/$file";
+    $symlinks{$name} = 1;
+  }
+}
 
 foreach my $symlink (keys %symlinks) {
-  $symlink =~ m,^/usr/bin/([^-]+-[^-]+-[^-]+)-pkg-config, or next;
+  $symlink =~ m,^$dpkgroot/usr/bin/([^-]+-[^-]+-[^-]+)-pkg-config, or next;
   next if exists $gnutriplets{$1} && $action eq "update";
   next unless -l $symlink;
   next unless readlink $symlink eq $crosswrapper;
@@ -40,9 +56,9 @@
     error("failed to remove symlink $symlink: $!");
 }
 
-if ($action eq 'update') {
+if ($action eq 'update' && -e $crosswrapper) {
   foreach (keys %gnutriplets) {
-    my $linktarget = "/usr/bin/${_}-pkg-config";
+    my $linktarget = "$dpkgroot/usr/bin/${_}-pkg-config";
     next if exists $symlinks{$linktarget};
     next if -e $linktarget;
     symlink $crosswrapper, $linktarget or

Attachment: signature.asc
Description: PGP signature

Reply via email to