Much simpler patch.

On 3 May 2016 at 09:02, Michael Hudson-Doyle
<michael.hud...@canonical.com> wrote:
> On 3 May 2016 at 05:21, Tianon Gravi <admwig...@gmail.com> wrote:
>> On 1 May 2016 at 03:41, Michael Hudson-Doyle <michael.hud...@ubuntu.com> 
>> wrote:
>>> dh_golang can fail when compiling with gccgo because in this case it's 
>>> possible
>>> for go list to report no dependencies at all. Patch coming as soon as I get 
>>> a
>>> bug number :-)
>>
>> Couldn't this also be fixed by just adding "-r" to the "xargs" invocation?
>
> Ah TIL, yes. That would be easier :-)
>
> Cheers,
> mwh
From 7cbd70481b99429e1da20b84c94df214ddacede5 Mon Sep 17 00:00:00 2001
From: Michael Hudson-Doyle <michael.hud...@canonical.com>
Date: Sun, 1 May 2016 22:50:00 +1200
Subject: [PATCH] Yet another corner case in dh_golang, this one only shows up
 with gccgo. (Closes: 823136)

---
 debian/changelog |  7 +++++++
 script/dh_golang | 19 ++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index c943d98..b1d9f76 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+dh-golang (1.17) UNRELEASED; urgency=medium
+
+  * Yet another corner case in dh_golang, this one only shows up with gccgo.
+    (Closes: 823136)
+
+ -- Michael Hudson-Doyle <michael.hud...@ubuntu.com>  Sun, 01 May 2016 22:28:04 +1200
+
 dh-golang (1.16) unstable; urgency=medium
 
   [ Michael Hudson-Doyle ]
diff --git a/script/dh_golang b/script/dh_golang
index d39523b..bcf5432 100755
--- a/script/dh_golang
+++ b/script/dh_golang
@@ -51,6 +51,10 @@ system("go list -f \"$tmpl\" @targets > $tmpdir/godeps") == 0
 system("sort -u $tmpdir/godeps | xargs go list -f '{{ .Dir }}' > $tmpdir/godirs") == 0
     or die "go list of dependencies failed with code $?, $!";
 
+# It's possible for a Go package to report no dependencies at all when compiling
+# with gccgo. Avoid calling dpkg-query --search with no arguments in this case.
+my $at_least_one;
+
 open(my $inp, "<", "$tmpdir/godirs");
 open(my $outp, ">", "$tmpdir/realgodirs");
 while (<$inp>) {
@@ -58,18 +62,23 @@ while (<$inp>) {
     my $realpath = realpath($_);
     # godirs will include the directories of the package being built, so exclude them.
     if ($realpath !~ /^\Q$bs->{cwd}\E/) {
+        $at_least_one = 1;
         printf $outp "%s\n", $realpath;
     }
 }
 close($inp);
 close($outp);
 
-system("cat $tmpdir/realgodirs | xargs dpkg-query --search > $tmpdir/pkgs") == 0
-    or die "dpkg-query --search failed with code $?, $!";
+my $built_using;
+
+if ($at_least_one) {
+    system("cat $tmpdir/realgodirs | xargs dpkg-query --search > $tmpdir/pkgs") == 0
+        or die "dpkg-query --search failed with code $?, $!";
 
-my $built_using = `cut -d: -f1 $tmpdir/pkgs | sort -u | xargs dpkg-query -f='\${source:Package} (= \${source:Version}), ' -W`;
-if ($? != 0) {
-    die "dpkg-query -W failed with code $?, $!";
+    $built_using = `cut -d: -f1 $tmpdir/pkgs | sort -u | xargs dpkg-query -f='\${source:Package} (= \${source:Version}), ' -W`;
+    if ($? != 0) {
+        die "dpkg-query -W failed with code $?, $!";
+    }
 }
 
 # If there is an easier way to have a universal misc:Built-Using on all binary
-- 
2.7.4

Reply via email to