Your message dated Tue, 23 May 2023 09:41:43 +0200
with message-id <20230523074143.4dot6d67vbcazp4s@crossbow>
and subject line Re: pkg-config: please support DPKG_ROOT in dpkghook script
has caused the Debian Bug report #824774,
regarding pkg-config: please support DPKG_ROOT in dpkghook script
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
824774: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=824774
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
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 <[email protected]>  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


--- End Message ---
--- Begin Message ---
Version: 1.8.0-7

Hi bugreport,

I missed your seventh birthday by a couple days – sorry about that! –
but as the script this patch was about is gone for a few months,
I suppose now is as good a time as any to close you.


pkgconf (1.8.0-7) experimental; urgency=medium
[…]
    - Remove the pkg-config dpkg hook on upgrade.
[…]
 -- Andrej Shadura <[email protected]>  Sun, 02 Oct 2022 13:15:07 +0200


It was nice talking to you/myself over the years,
have a good time in the bugs archive!


Best regards

David Kalnischkies

Attachment: signature.asc
Description: PGP signature


--- End Message ---

Reply via email to