/usr/bin/dh_golang is in dh-golang 1.12ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | #!/usr/bin/perl -w
=head1 NAME
dh_golang - Generates Built-Using substvar
=cut
use strict;
use Debian::Debhelper::Dh_Lib; # not in core
use Dpkg; # not in core
use Dpkg::Control; # not in core
use Dpkg::Control::Info; # not in core
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
=head1 SYNOPSIS
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),
=head1 NOTES
The best way to invoke B<dh_golang> is by using B<dh --with=golang>.
=cut
init();
# This code was copied from dpkg-checkbuilddeps, see
# http://sources.debian.net/src/dpkg/1.18.1/scripts/dpkg-checkbuilddeps.pl/?hl=140#L140
sub parse_status {
my $status = shift;
my $facts = Dpkg::Deps::KnownFacts->new();
local $/ = '';
open(my $status_fh, '<', $status)
or syserr(g_('cannot open %s'), $status);
while (<$status_fh>) {
next unless /^Status: .*ok installed$/m;
my ($package) = /^Package: (.*)$/m;
my ($version) = /^Version: (.*)$/m;
my ($arch) = /^Architecture: (.*)$/m;
my ($multiarch) = /^Multi-Arch: (.*)$/m;
$facts->add_installed_package($package, $version, $arch,
$multiarch);
if (/^Provides: (.*)$/m) {
my $provides = deps_parse($1, reduce_arch => 1, union => 1);
next if not defined $provides;
foreach (grep { $_->isa('Dpkg::Deps::Simple') }
$provides->get_deps())
{
$facts->add_provided_package($_->{package},
$_->{relation}, $_->{version},
$package);
}
}
}
close $status_fh;
return $facts;
}
############################################################################
# Generate misc:Built-Using substvar with the versions of all golang-*
# build-dependency packages.
############################################################################
my $built_using;
my $control = Dpkg::Control::Info->new();
my $source = $control->get_source();
my $build_depends = $source->{"Build-Depends"};
if (defined($build_depends) && $build_depends ne '') {
my $facts;
if ($Dpkg::VERSION >= 1.01) {
$facts = parse_status($Dpkg::ADMINDIR . "/status");
} else {
$facts = parse_status($Dpkg::admindir . "/status");
}
sub flatten {
my ($dep) = @_;
if (blessed($dep) eq 'Dpkg::Deps::Simple') {
return $dep->get_evaluation($facts) ? $dep->{package} : undef;
}
if (blessed($dep) eq 'Dpkg::Deps::OR') {
# Return the first installed package.
return first { defined($_) } map { flatten($_) } $dep->get_deps();
}
die 'Unexpected object (of type ' . blessed($dep) . '), has the Dpkg::Deps API changed?';
}
my $deps = deps_parse($build_depends, reduce_restrictions => 1);
my $golang_deps = join(' ', grep { /^golang-/ }
map { flatten($_) }
$deps->get_deps());
# If the build depends contains a package that comes from golang-defaults
# (usually 'golang-go' but possibly just 'golang'), report the owner of
# where /usr/bin/go in Built-Using as well.
my $source_deps = `dpkg-query -f='\${source:Package} ' -W $golang_deps`;
if ($source_deps =~ /\bgolang-defaults\b/) {
my $golang_go_dep = `dpkg-query --search \$(readlink -f /usr/bin/go) 2>/dev/null | cut -d: -f1`;
if ($? == 0) {
chomp($golang_deps .= " $golang_go_dep");
}
}
if ($golang_deps ne '') {
$built_using = `dpkg-query -f='\${source:Package} (= \${source:Version}), ' -W $golang_deps`;
}
}
# If there is an easier way to have a universal misc:Built-Using on all binary
# packages, I am happy to merge your patch :).
foreach my $package (@{$dh{DOPACKAGES}}) {
addsubstvar($package, "misc:Built-Using", $built_using);
}
=head1 SEE ALSO
dh(1)
=head1 AUTHORS
Michael Stapelberg <stapelberg@debian.org>
=cut
# vim:ts=4:sw=4:et
|