1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | diff --git a/debian/changelog b/debian/changelog
index d92b257..e9dba09 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,16 @@
-dh-golang (1.12ubuntu1) xenial; urgency=medium
+dh-golang (1.14) unstable; urgency=medium
- * Follow /usr/bin/go symlink when computing Built-Using. (LP: #1564124)
+ [ Michael Hudson-Doyle ]
+ * Compute Built-Using with go list, not Build-Depends (Closes: #819473)
- -- Michael Hudson-Doyle <michael.hudson@canonical.com> Thu, 31 Mar 2016 11:42:07 +1300
+ -- Michael Stapelberg <stapelberg@debian.org> Thu, 14 Apr 2016 09:11:54 +0200
+
+dh-golang (1.13) unstable; urgency=medium
+
+ [ Stephen Gelman ]
+ * Set build_dep to 1 to support the “native” architecture (Closes: #819596)
+
+ -- Michael Stapelberg <stapelberg@debian.org> Thu, 14 Apr 2016 08:51:20 +0200
dh-golang (1.12) unstable; urgency=medium
diff --git a/lib/Debian/Debhelper/Buildsystem/golang.pm b/lib/Debian/Debhelper/Buildsystem/golang.pm
index bedafd0..fbdf510 100644
--- a/lib/Debian/Debhelper/Buildsystem/golang.pm
+++ b/lib/Debian/Debhelper/Buildsystem/golang.pm
@@ -35,6 +35,11 @@ sub _set_dh_gopkg {
$ENV{DH_GOPKG} = $source->{"XS-Go-Import-Path"};
}
+sub _set_gopath {
+ my $this = shift;
+ $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir();
+}
+
sub _link_contents {
my ($src, $dst) = @_;
@@ -156,7 +161,6 @@ sub get_targets {
sub build {
my $this = shift;
- $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir();
if (exists($ENV{DH_GOLANG_GO_GENERATE}) && $ENV{DH_GOLANG_GO_GENERATE} == 1) {
$this->doit_in_builddir("go", "generate", "-v", @_, get_targets());
}
@@ -166,7 +170,7 @@ sub build {
sub test {
my $this = shift;
- $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir();
+ $this->_set_gopath();
$this->doit_in_builddir("go", "test", "-v", @_, get_targets());
}
diff --git a/script/dh_golang b/script/dh_golang
index 9f13e61..5e1e71d 100755
--- a/script/dh_golang
+++ b/script/dh_golang
@@ -16,6 +16,7 @@ use Dpkg::Deps; # not in core
use Dpkg::Gettext; # not in core
use Scalar::Util qw(blessed); # in core since v5.7.3
use List::Util qw(first); # in core since v5.7.3
+use Debian::Debhelper::Buildsystem::golang;
=head1 SYNOPSIS
@@ -24,14 +25,9 @@ B<dh_golang> [S<I<debhelper options>>]
=head1 DESCRIPTION
B<dh_golang> is a debhelper program which adds the misc:Built-Using substvar
-based on the Build-Dependencies of your packages. Every package starting with
-golang is queried for the precise version number.
-
-As an example, if you Build-Depend on golang-pq-dev, the resulting
-misc:Built-Using value (aside from the precise version number) will look like
-this:
-
-golang (= 2:1.1.1-1), golang-pq-dev (= 0.0~git20130606-1),
+based on the dependencies of the package being built. It uses go list to
+determine the packages imported and dpkg-query to find the source package and
+version that provided that package.
=head1 NOTES
@@ -45,28 +41,24 @@ init();
# Generate misc:Built-Using substvar.
############################################################################
-sub _set_dh_gopkg {
- # If DH_GOPKG is missing, try to set it from the XS-Go-Import-Path field
- # from debian/control. If this approach works well, we will only use this
- # method in the future.
- return if defined($ENV{DH_GOPKG}) && $ENV{DH_GOPKG} ne '';
+my $bs = Debian::Debhelper::Buildsystem::golang->new();
- my $control = Dpkg::Control::Info->new();
- my $source = $control->get_source();
- $ENV{DH_GOPKG} = $source->{"XS-Go-Import-Path"};
-}
+$bs->_set_dh_gopkg();
+$bs->_set_gopath();
+
+my @targets = $bs->get_targets();
-chomp(my $pwd = `pwd`);
-chomp($ENV{GOPATH} = $pwd . "/obj-" . `dpkg-architecture -qDEB_BUILD_GNU_TYPE`);
-_set_dh_gopkg();
-print("$ENV{GOPATH}\n");
-my $godeps = `go list -f '{{ range .Deps }}{{.}}
-{{ end }}' $ENV{DH_GOPKG}/... | grep -v ^$ENV{DH_GOPKG}`;
+my $godeps = `go list -f '{{ range .Deps }}{{.}} {{ end }}' @targets`;
$godeps =~ s/\n/ /g;
my @godirs = split /\n/, `go list -f '{{ .Dir }}' $godeps`;
my $realgodirs;
+my $cwd = $bs->{cwd};
for my $godir (@godirs) {
- $realgodirs .= realpath($godir) . " ";
+ my $realpath = realpath($godir);
+ # @godirs will include the directories of the package being built, so exclude them.
+ if ($realpath !~ /^$bs->{cwd}/) {
+ $realgodirs .= realpath($godir) . " ";
+ }
}
my $pkgs = `dpkg-query --search $realgodirs | cut -d: -f1`;
$pkgs =~ s/\n/ /g;
|