Your message dated Tue, 31 Jan 2017 06:03:37 +0000
with message-id <e1cyrxv-0002mq...@fasolo.debian.org>
and subject line Bug#841145: fixed in dh-golang 1.20
has caused the Debian Bug report #841145,
regarding dh-golang: Rewrite of dh_golang for a more robust and idiomatic perl
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 ow...@bugs.debian.org
immediately.)


-- 
841145: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841145
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: dh-golang
Version: 1.19
Severity: wishlist
Tags: patch

Hi!

I was taking a look at dh_golang the other day, and thought the code
could do with some rewrite to make it more idiomatic, more robust,
generate command output on DH_VERBOSE, and avoid the need for so many
temporary files (which TBH was what first caught my eye). So I rewrote
it. :)

I've tested building acmetool, before and after the changes and it
produces bit-for-bit idential .deb packages.

Thanks,
Guillem
From ee2c88f79ee2946d69eb9205fdd925605bc6839b Mon Sep 17 00:00:00 2001
From: Guillem Jover <guil...@debian.org>
Date: Tue, 18 Oct 2016 03:06:08 +0200
Subject: [PATCH] Rewrite dh_golang to be more idiomatic perl

The new code does not make use of temporary files anymore, is more
resilient against dpkg output, and should be a bit more idiomatic.
---
 script/dh_golang | 73 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/script/dh_golang b/script/dh_golang
index 4c4e09d..097550b 100755
--- a/script/dh_golang
+++ b/script/dh_golang
@@ -10,8 +10,6 @@ use strict;
 use Cwd qw(realpath);
 use Debian::Debhelper::Dh_Lib; # not in core
 use Debian::Debhelper::Dh_Buildsystems; # not in core
-use File::Temp qw(tempdir);
-use File::Path qw(rmtree);
 
 =head1 SYNOPSIS
 
@@ -30,6 +28,39 @@ The best way to invoke B<dh_golang> is by using B<dh --with=golang>.
 
 =cut
 
+sub uniq {
+    my %list = map { $_ => 1 } @_;
+
+    return sort keys %list;
+}
+
+sub exec_single {
+    my ($cmd, @args) = @_;
+
+    verbose_print(escape_shell(@_));
+
+    my @output = qx($cmd @args);
+    error_exitcode($cmd) if $? != 0;
+    chomp(@output);
+
+    return @output;
+}
+
+# Amount of chunking we are going to use for dpkg commands, which should speed
+# up the execution by avoiding too many database loads.
+use constant CHUNKSIZE => 200;
+
+sub exec_chunked {
+    my ($cmd, @list) = @_;
+
+    my @result;
+    for (my $i = 0; $i < @list; $i += CHUNKSIZE) {
+        push @result, exec_single($cmd, @list[$i .. $i + CHUNKSIZE - 1]);
+    }
+
+    return @result;
+}
+
 ############################################################################
 # Generate misc:Built-Using substvar.
 ############################################################################
@@ -43,44 +74,26 @@ my @targets = $bs->get_targets();
 
 my $tmpl = '{{ range .Deps }}{{.}}
 {{ end }}';
-
-my $tmpdir = tempdir("dh_golang_XXXXXXX", TMPDIR => 1);
-
-system("go list -f \"$tmpl\" @targets > $tmpdir/godeps") == 0
-    or die "go list of targets failed with code $?, $!";
+my @godeps = exec_single(qq{go list -f '$tmpl'}, @targets);
 
 my $gofiletmpl = '\
 {{ .Dir }}/{{ index (or .GoFiles .CgoFiles .TestGoFiles .XTestGoFiles .IgnoredGoFiles) 0 }}';
+my @gofiles = exec_chunked(qq{go list -f '$gofiletmpl'}, uniq(@godeps));
 
-system("sort -u $tmpdir/godeps | xargs go list -f '$gofiletmpl' > $tmpdir/gofiles") == 0
-    or die "go list of dependencies failed with code $?, $!";
-
-open(my $inp, "<", "$tmpdir/gofiles");
-open(my $outp, ">", "$tmpdir/realgofiles");
-while (<$inp>) {
-    chomp;
-    my $realpath = realpath($_);
+my @realpath;
+foreach my $pathname (@gofiles) {
+    my $realpath = realpath($pathname);
     # gofiles will include packages being built, so exclude those.
     if ($realpath !~ /^\Q$bs->{cwd}\E/) {
-        printf $outp "%s\n", $realpath;
+        push @realpath, $realpath;
     }
 }
-close($inp);
-close($outp);
-
-system("cat $tmpdir/realgofiles | xargs -r dpkg-query --search > $tmpdir/pkgs") == 0
-    or die "dpkg-query --search failed with code $?, $!";
-
-system("cut -d: -f1 $tmpdir/pkgs | sort -u | xargs -r dpkg-query -f='\${source:Package} (= \${source:Version})\n' -W > $tmpdir/srcpkgs");
-if ($? != 0) {
-    die "dpkg-query -W failed with code $?, $!";
-}
-
-my $built_using = `cat $tmpdir/srcpkgs | sort -u`;
 
-$built_using =~ s/\n/, /g;
+my @searchoutput = exec_chunked('dpkg-query --search', @realpath);
+my @gopkgs = split /, */, join ', ', map { s/: .+$//r } @searchoutput;
 
-rmtree($tmpdir);
+my @srcdeps = exec_chunked(q{dpkg-query -f='${source:Package} (= ${source:Version})\n' -W}, uniq(@gopkgs));
+my $built_using = join ', ', uniq(@srcdeps);
 
 # If there is an easier way to have a universal misc:Built-Using on all binary
 # packages, I am happy to merge your patch :).
-- 
2.9.3


--- End Message ---
--- Begin Message ---
Source: dh-golang
Source-Version: 1.20

We believe that the bug you reported is fixed in the latest version of
dh-golang, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 841...@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Tim Potter <t...@hpe.com> (supplier of updated dh-golang package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmas...@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Tue, 31 Jan 2017 16:44:26 +1100
Source: dh-golang
Binary: dh-golang
Architecture: source
Version: 1.20
Distribution: unstable
Urgency: medium
Maintainer: Debian Go Packaging Team 
<pkg-go-maintainers@lists.alioth.debian.org>
Changed-By: Tim Potter <t...@hpe.com>
Description:
 dh-golang  - debhelper add-on for packaging software written in Go (golang)
Closes: 840821 841145 844284
Changes:
 dh-golang (1.20) unstable; urgency=medium
 .
   * Team upload.
 .
   [ Martín Ferrari
   * Stop forcing the compression to xz, and that has been the default for some
     time now, even Debian stable has that. Thanks to Guillem Jover for the
     patch. Closes: #840821.
   * Rewrite of dh_golang for a more robust and idiomatic perl. Patch by
     Guillem Jover. Closes: #841145.
 .
   [ Tim Potter ]
   * Add .cc and .hh to whitelisted extensions when copying source to build
     dir. Closes: #844284
Checksums-Sha1:
 cd05a219d22ef9d1449ffe20625234428fa864f5 1617 dh-golang_1.20.dsc
 115a58c64399f19fd8ab9011ca14a2dec524b94d 7768 dh-golang_1.20.tar.xz
Checksums-Sha256:
 75953db9a266deb59c14f6e48543481218f759df0818128121b12ea01fd0ae4f 1617 
dh-golang_1.20.dsc
 dcef7b5f04daafb5b35226f6039dd5992f134868f3cfc5847cca7bc370b0f819 7768 
dh-golang_1.20.tar.xz
Files:
 ecf479a5e96689cddfaf00896d059dad 1617 devel extra dh-golang_1.20.dsc
 ddc47100d744f05f0c7b3ad091faac81 7768 devel extra dh-golang_1.20.tar.xz

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCAAGBQJYkCTqAAoJELJMpj9uu+hNRWUP/0e0ucfIp2CytFSeCCES3qT6
pIkWZmI7hg59mdtSRTmTQ5oUEqMkWPT0PLyRs2pn/JqCb1eA3ftbYMW0AW4zBCqI
H7NN0umCQmcheuQq2Fm2mVKXGViTshVpenV58RPnHloN2jvAwJpp62515lcj4lzd
509y4Hk2jlC0NUgfjvpV2a8g8iHP2K8P5Du4EoXzC/HZt+g8lXVQk7KkkrqhBUgR
SxvAVY87BPlX6q6VTR3zLqNcveuQFlTpY95TWNMOj+vVFGHev4ivEXzMlMRThNjV
IorRrJ7+UZRc2v0npSy8+PUdx5O4/Rc3jvOY3ak+SKk+4Pn22qoXlZyYYfDL6Mnl
wi4ifQaglr/ClaOhCZc1JGUZOOLPnQt5wirSbLDxuFTTZz+5cT0+xs6DHa9juP3k
F4bRRnng/XyWMcffNfisxX2OsDBgqA9ftUTEa977dp9snaod7SAjcMfrs9UVbMQG
M/a36lv9XT7JLwxn9EyvM+IER7eLEMhD5T45fywnnVs7WoLF/3Q2bZO1BFfeml2/
NebyHBglVz5owDiNsv0OQkkk5Md4MqJYiFHwgFRdhD94x2LUTBbXGJDQIvaup5jG
DcUEP4tbf49jE0UIHuC1i78/bVBlEyHM6A+liqL9/m+trP6g52WvsmXUplM6ChyK
bQfSt9YFAYO3fHrSDPnN
=wioF
-----END PGP SIGNATURE-----

--- End Message ---
_______________________________________________
Pkg-go-maintainers mailing list
Pkg-go-maintainers@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-go-maintainers

Reply via email to