diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/changelog dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/changelog --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/changelog 2016-05-24 04:31:04.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/changelog 2016-08-16 04:31:09.000000000 +0000 @@ -1,15 +1,55 @@ -dh-golang (1.17ubuntu1~ubuntu16.04.1~ppa1) xenial; urgency=medium +dh-golang (1.19ubuntu1~ubuntu16.04.1~ppa1) xenial; urgency=medium * No-change backport to xenial - -- Stéphane Graber Tue, 24 May 2016 04:31:04 +0000 + -- Stéphane Graber Tue, 16 Aug 2016 04:31:09 +0000 -dh-golang (1.17ubuntu1) yakkety; urgency=medium +dh-golang (1.19ubuntu1) yakkety; urgency=medium + * Merge from Debian unstable. Remaining changes: + - Add support for compiling go packages into shared libraries. + - Add dh_makegolangshlibs to run after dh_makeshlibs in usual dh sequence. + + -- Michael Hudson-Doyle Tue, 16 Aug 2016 11:42:32 +1200 + +dh-golang (1.19) unstable; urgency=medium + + * Team upload. + + [ Paul Tagliamonte ] + * Use a secure transport for the Vcs-Git and Vcs-Browser URL + + [ Dmitry Smirnov ] + * Perlcritic corrections for "Glob written as <...>". + * Avoid linking pre-installed DH_GOPKG package to itself (Closes: #827226). + * Respect "--parallel" and "--max-parallel" options (Closes: #829302). + + -- Dmitry Smirnov Thu, 14 Jul 2016 15:07:49 +1000 + +dh-golang (1.18ubuntu2) yakkety; urgency=medium + + * Run dh_makegolangshlibs after dh_makeshlibs rather than instead of it, + fixing FTBFS when there are non-Go shared libraries in the package. + (LP: #1600399) + + -- Michael Hudson-Doyle Mon, 11 Jul 2016 12:28:51 +1200 + +dh-golang (1.18ubuntu1) yakkety; urgency=medium + + * Add support for compiling go packages into shared libraries. + * Add dh_makegolangshlibs to replace dh_makeshlibs in usual dh sequence. + + -- Michael Hudson-Doyle Sun, 01 May 2016 22:28:04 +1200 + +dh-golang (1.18) unstable; urgency=medium + + * Team upload. * Yet another corner case in dh_golang, this one only shows up with gccgo. (Closes: 823136) + * Pass a go file, not a directory, to dpkg-search in dh_golang so that only + one package is returned. (Closes: 827219) - -- Michael Hudson-Doyle Sun, 01 May 2016 22:28:04 +1200 + -- Michael Hudson-Doyle Wed, 15 Jun 2016 18:56:39 +1000 dh-golang (1.17) unstable; urgency=medium diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/compat dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/compat --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/compat 2014-10-28 22:24:53.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/compat 2016-08-15 23:39:55.000000000 +0000 @@ -1 +1 @@ -8 +9 diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/control dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/control --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/debian/control 2016-05-24 01:22:05.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/debian/control 2016-08-15 23:39:55.000000000 +0000 @@ -4,9 +4,9 @@ Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Debian Go Packaging Team Uploaders: Michael Stapelberg -Build-Depends: debhelper (>= 8.0.0), libmodule-install-perl +Build-Depends: debhelper (>= 9), libmodule-install-perl Standards-Version: 3.9.8 -Vcs-Git: git://anonscm.debian.org/pkg-go/packages/dh-golang.git +Vcs-Git: https://anonscm.debian.org/git/pkg-go/packages/dh-golang.git Vcs-Browser: https://anonscm.debian.org/cgit/pkg-go/packages/dh-golang.git/ Package: dh-golang diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/example/control-dev dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/example/control-dev --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/example/control-dev 1970-01-01 00:00:00.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/example/control-dev 2016-08-15 23:39:28.000000000 +0000 @@ -0,0 +1,14 @@ +Source: golang-go-library +Section: net +Priority: extra +Maintainer: Go Packager +Build-Depends: debhelper (>= 8.0.0), dh-golang, golang-go +Standards-Version: 3.9.2 +#Vcs-Git: git://git.debian.org/collab-maint/dcs.git +#Vcs-Browser: http://git.debian.org/?p=collab-maint/dcs.git;a=summary + +Package: golang-go-library-dev +Architecture: all +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Random Go library + A random Go library that does something very useful. diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/example/control-dev-shared dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/example/control-dev-shared --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/example/control-dev-shared 1970-01-01 00:00:00.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/example/control-dev-shared 2016-08-15 23:39:28.000000000 +0000 @@ -0,0 +1,21 @@ +Source: golang-go-library +Section: net +Priority: extra +Maintainer: Go Packager +Build-Depends: debhelper (>= 8.0.0), dh-golang, golang-any, golang-any-shared-dev +Standards-Version: 3.9.2 +#Vcs-Git: git://git.debian.org/collab-maint/dcs.git +#Vcs-Browser: http://git.debian.org/?p=collab-maint/dcs.git;a=summary + +Package: golang-go-library-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libgo-library1 (= ${binary:Version}) +Description: Random Go library -- development files + A random Go library that does something very useful. + +Package: libgo-library1 +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Provides: ${golang:Provides} +Description: Random Go library -- shared library + A random Go library that does something very useful. diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Buildsystem/golang.pm dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Buildsystem/golang.pm --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Buildsystem/golang.pm 2016-05-18 02:12:56.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Buildsystem/golang.pm 2016-08-15 23:41:48.000000000 +0000 @@ -7,6 +7,7 @@ use File::Copy; # in core since 5.002 use File::Path qw(make_path); # in core since 5.001 use File::Find; # in core since 5 +use File::Spec; sub DESCRIPTION { "Go" @@ -21,6 +22,7 @@ my $this = $class->SUPER::new(@_); $this->prefer_out_of_source_building(); _set_dh_gopkg(); + $this->read_shlibconfig(); return $this; } @@ -35,15 +37,42 @@ $ENV{DH_GOPKG} = $source->{"XS-Go-Import-Path"}; } +sub read_shlibconfig { + my $this = shift; + my $config = {linkshared => !!$ENV{DH_GOLANG_LINK_SHARED}}; + + foreach my $pkg (getpackages("both")) { + if ($pkg =~ /^lib(golang.*?)-?([0-9]+)$/) { + $config->{libpkg} = $pkg; + $config->{libname} = $1; + $config->{sover} = $2; + $config->{linkshared} = 1; + } elsif ($pkg =~ /-dev$/ && !$config->{devpkg}) { + $config->{devpkg} = $pkg; + } + } + + if (defined($config->{libpkg})) { + $config->{soname} = sprintf("lib%s.so.%s", $config->{libname}, $config->{sover}); + } + + $this->{shlibconfig} = $config; +} + sub _set_gopath { my $this = shift; - $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir(); + + if ($this->{shlibconfig}->{linkshared}) { + $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir() . ':' . $this->{cwd} . '/' . $this->get_builddir() . '/shlibdeps' . ':' . $this->{cwd} . '/' . $this->get_builddir() . '/srcdeps'; + } else { + $ENV{GOPATH} = $this->{cwd} . '/' . $this->get_builddir() + } } sub _link_contents { my ($src, $dst) = @_; - my @contents = <$src/*>; + my @contents = glob "$src/*"; # Safety-Check: We are already _in_ a Go library. Don’t copy its # subfolders, this has no use and potentially only screws things up. # This situation should never happen, unless some package ships files that @@ -54,7 +83,11 @@ for my $dir (@dirs) { my $base = basename($dir); if (-d "$dst/$base") { - _link_contents("$src/$base", "$dst/$base"); + if ( 0 <= index($dir, q{/usr/share/gocode/src/}.$ENV{DH_GOPKG}) ){ + warning( qq{"$ENV{DH_GOPKG}" is already installed. Please check for circular dependencies.\n} ); + }else{ + _link_contents("$src/$base", "$dst/$base"); + } } else { verbose_print("Symlink $src/$base -> $dst/$base"); symlink("$src/$base", "$dst/$base"); @@ -142,26 +175,65 @@ # buildroot. ############################################################################ - # NB: The naïve idea of just setting GOPATH=$builddir:/usr/share/godoc does - # not work. Let’s call the two paths in $GOPATH components. go(1), when - # installing a package, such as github.com/Debian/dcs/cmd/..., will also - # install the compiled dependencies, e.g. github.com/mstap/godebiancontrol. - # When such a dependency is found in a component’s src/ directory, the - # resulting files will be stored in the same component’s pkg/ directory. - # That is, in this example, go(1) wants to modify - # /usr/share/gocode/pkg/linux_amd64/github.com/mstap/godebiancontrol, which - # will obviously not succeed due to permission errors. - # - # Therefore, we just work with a single component that is under our control - # and symlink all the sources into that component ($builddir). - - _link_contents('/usr/share/gocode/src', "$builddir/src"); + if ($this->{shlibconfig}->{linkshared}) { + # When building or linking against shared libraries, we must make available any + # shared libraries that are already on the system. GOPATH is set up to have three + # components: $builddir (for the package we are building), $builddir/shlibdeps + # (for packages that are built into shared libraries that have already been + # installed) and $builddir/srcdeps (for dependencies that have only been installed + # as source). Setting up the shlibdeps component is more difficult than might be + # expected, because Go will consider a library that's older than the toolchain + # that builds it to require rebuilding and this gets us into a pickle if we + # rebuild golang-1.X to fix a packaging bug or whatever. So instead of linking, we + # have to *copy* all the installed files to the build directory, copy the targets + # of symlinks into place so that the symlinks still work and fix all the + # timestamps to be new enough (and all the same!). Finally, as a belt and brances + # check, it is set up so that the build can't write to it. + my $installed_shlib_data_dir = "/usr/lib/" . dpkg_architecture_value("DEB_HOST_MULTIARCH") . "/gocode"; + if (-d $installed_shlib_data_dir) { + make_path("$builddir/shlibdeps"); + $this->doit_in_builddir("ln", "-sT", "$installed_shlib_data_dir/src", "shlibdeps/src"); + doit("cp", "-dRT", "$installed_shlib_data_dir/pkg", "$builddir/shlibdeps/pkg"); + doit("find", "$builddir/shlibdeps/pkg", "-exec", "touch", "-r", "$builddir/shlibdeps/pkg", "{}", ";"); + find({ + wanted => sub { + if (-l $File::Find::name && /.so$/) { + my $relpath = $File::Find::name =~ s|^\Q$builddir/shlibdeps/pkg\E||r; + copy("$installed_shlib_data_dir/pkg$relpath", $File::Find::name) or error("copy failed $!"); + } + }, + no_chdir => 1, + }, "$builddir/shlibdeps/pkg"); + doit("chmod", "-R", "u-w", "$builddir/shlibdeps/pkg"); + } + make_path("$builddir/srcdeps/src"); + _link_contents('/usr/share/gocode/src', "$builddir/srcdeps/src"); + } else { + # NB: The naïve idea of just setting GOPATH=$builddir:/usr/share/gocode does + # not work. Let’s call the two paths in $GOPATH components. go(1), when + # installing a package, such as github.com/Debian/dcs/cmd/..., will also + # install the compiled dependencies, e.g. github.com/mstap/godebiancontrol. + # When such a dependency is found in a component’s src/ directory, the + # resulting files will be stored in the same component’s pkg/ directory. + # That is, in this example, go(1) wants to modify + # /usr/share/gocode/pkg/linux_amd64/github.com/mstap/godebiancontrol, which + # will obviously not succeed due to permission errors. + # + # Therefore, we just work with a single component that is under our control + # and symlink all the sources into that component ($builddir). + _link_contents('/usr/share/gocode/src', "$builddir/src"); + } } sub get_targets { my $buildpkg = $ENV{DH_GOLANG_BUILDPKG} || "$ENV{DH_GOPKG}/..."; - my $output = qx(go list $buildpkg); my @excludes = split(/ /, $ENV{DH_GOLANG_EXCLUDES}); + # If there are no excludes, just pass the form with /... to the go tool, which results + # in a better name for the shared library when one is being created. + if (!@excludes) { + return ($buildpkg) + } + my $output = qx(go list $buildpkg); my @targets = split(/\n/, $output); # Remove all targets that are matched by one of the regular expressions in DH_GOLANG_EXCLUDES. @@ -172,6 +244,60 @@ return @targets; } +# Return where the go tool thinks the shlib for our targets is. +sub go_shlib_path { + my @targets = get_targets(); + # In principle go list doesn't have to return the same Shlib for every package in + # @targets, but in that case the go install command would have failed. + my @shlib = qx(go list -linkshared -f '{{ .Shlib }}' @targets); + if (@shlib) { + my $line = $shlib[0]; + chomp($line); + return $line; + } +} + +sub build_shlib { + my $this = shift; + my $config = $this->{shlibconfig}; + + my $gccgo; + if (system("go tool -n compile > /dev/null 2>&1") == 0) { + $gccgo = 0; + } else { + $gccgo = 1; + } + my $ldflags; + + if ($gccgo) { + $ldflags = "-gccgoflags=-Wl,-soname=$config->{soname} -Wl,-znow"; + } else { + $ldflags = "-ldflags=-r '' -extldflags=-Wl,-soname=$config->{soname}" + } + + my @targets = get_targets(); + + $this->doit_in_builddir( + "go", "install", "-v", $ldflags, + "-buildmode=shared", "-linkshared", @_, @targets); + + my $shlib = go_shlib_path(); + my $dsodir = dirname($shlib); + + $this->doit_in_builddir("mv", "$shlib", "$dsodir/" . $config->{soname}); + $this->doit_in_builddir("ln", "-s", $config->{soname}, "$shlib"); + + if ($gccgo) { + $ldflags = "-gccgoflags=-Wl,-znow"; + } else { + $ldflags = "-ldflags=-r ''" + } + + $this->doit_in_builddir( + "go", "install", "-v", $ldflags, + "-buildmode=exe", "-linkshared", @_, @targets); +} + sub build { my $this = shift; @@ -179,13 +305,23 @@ if (exists($ENV{DH_GOLANG_GO_GENERATE}) && $ENV{DH_GOLANG_GO_GENERATE} == 1) { $this->doit_in_builddir("go", "generate", "-v", @_, get_targets()); } - $this->doit_in_builddir("go", "install", "-v", @_, get_targets()); + + unshift @_, ('-p', $this->get_parallel()); + if ($this->{shlibconfig}->{libpkg}) { + $this->build_shlib(@_); + } elsif ($this->{shlibconfig}->{linkshared}) { + $this->doit_in_builddir( + "go", "install", "-v", "-ldflags=-r ''", "-linkshared", @_, get_targets()); + } else { + $this->doit_in_builddir("go", "install", "-v", @_, get_targets()); + } } sub test { my $this = shift; $this->_set_gopath(); + unshift @_, ('-p', $this->get_parallel()); $this->doit_in_builddir("go", "test", "-v", @_, get_targets()); } @@ -207,18 +343,69 @@ error("Unknown option $_[0]"); } } + my $config = $this->{shlibconfig}; + + $this->_set_gopath(); - my @binaries = <$builddir/bin/*>; + my @binaries = glob "$builddir/bin/*"; if ($install_binaries and @binaries > 0) { $this->doit_in_builddir('mkdir', '-p', "$destdir/usr"); $this->doit_in_builddir('cp', '-r', 'bin', "$destdir/usr"); } - if ($install_source) { + if ($config->{libpkg}) { + if (!$install_source) { + die "Must have a source package when building shared library."; + } + # Here we are shuffling files about for two packages: + # 1) The lib package, which just contains usr/lib/$triplet/$soname + # 2) The dev package, which contains: + # a) the source at usr/share/gocode/src/$ENV{DH_GOPKG} + # b) the .a files at usr/lib/$triplet/gocode/pkg/*_dynlink/$ENV{DH_GOPKG} + # c) the .so symlink at usr/lib/$triplet/gocode/pkg/*_dynlink/lib${foo}.so to the lib as + # installed by 1) (${foo} is determined by the go tool and we do not make + # any assumptions about it here) + # d) a symlink from usr/lib/$triplet/gocode/src/$ENV{DH_GOPKG} to + # usr/share/gocode/src/$ENV{DH_GOPKG} + my $solink = go_shlib_path(); + + # lib package + # We install the shared library directly to + # debian/$libpkg/... so no install file is required. + my $shlib = dirname($solink) . "/" . $config->{soname}; + my $final_shlib_dir = "/usr/lib/" . dpkg_architecture_value("DEB_HOST_MULTIARCH"); + my $shlibdest = tmpdir($config->{libpkg}) . $final_shlib_dir; + doit('mkdir', '-p', $shlibdest); + doit('mv', $shlib, $shlibdest); + + # dev package + # a) source + my $dest_src = "$destdir/usr/share/gocode/src/$ENV{DH_GOPKG}"; + doit('mkdir', '-p', $dest_src); + doit('cp', '-r', '-T', "$builddir/src/$ENV{DH_GOPKG}", $dest_src); + + my $dest_lib_prefix = "$destdir$final_shlib_dir/gocode/"; + my $rel_sopath = File::Spec->abs2rel($solink, $builddir); + my $built_file_dir = "pkg/" . (File::Spec->splitdir($rel_sopath))[1]; + + # b) .a files (this copies the symlink too but that will get overwritten in the next step) + my $dest_pkg = "$dest_lib_prefix$built_file_dir"; + doit('mkdir', '-p', $dest_pkg); + doit('cp', '-r', '-T', "$builddir/$built_file_dir", $dest_pkg); + + # c) .so symlink + my $dest_solink = File::Spec->join($dest_lib_prefix, $rel_sopath); + doit('ln', '-s', '-f', '-T', $final_shlib_dir . "/" . $config->{soname}, $dest_solink); + + # d) src symlink + my $dest_srclink = $dest_lib_prefix . "src/$ENV{DH_GOPKG}"; + doit('mkdir', '-p', dirname($dest_srclink)); + doit('ln', '-s', '-T', "/usr/share/gocode/src/$ENV{DH_GOPKG}", $dest_srclink); + } elsif ($install_source) { # Path to the src/ directory within $destdir my $dest_src = "$destdir/usr/share/gocode/src/$ENV{DH_GOPKG}"; - $this->doit_in_builddir('mkdir', '-p', $dest_src); - $this->doit_in_builddir('cp', '-r', '-T', "src/$ENV{DH_GOPKG}", $dest_src); + doit('mkdir', '-p', $dest_src); + doit('cp', '-r', '-T', "$builddir/src/$ENV{DH_GOPKG}", $dest_src); } } diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Sequence/golang.pm dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Sequence/golang.pm --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Sequence/golang.pm 2016-05-18 02:10:54.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/lib/Debian/Debhelper/Sequence/golang.pm 2016-08-15 23:39:28.000000000 +0000 @@ -4,6 +4,7 @@ use Debian::Debhelper::Dh_Lib; insert_before('dh_gencontrol', 'dh_golang'); +insert_after('dh_makeshlibs', 'dh_makegolangshlibs'); # XXX: -u is deprecated, but we cannot use “-- -Zxz” because additional command # options will be appended (“-O--buildsystem=golang”), resulting in diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/Makefile.PL dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/Makefile.PL --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/Makefile.PL 2016-05-18 02:10:54.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/Makefile.PL 2016-08-15 23:39:28.000000000 +0000 @@ -4,6 +4,7 @@ version '1.0'; install_script 'dh_golang'; +install_script 'dh_makegolangshlibs'; #postamble <<'END_OF_MAKEFILE'; #install:: extra_install diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/script/dh_golang dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/script/dh_golang --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/script/dh_golang 2016-05-18 02:13:01.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/script/dh_golang 2016-08-15 23:39:28.000000000 +0000 @@ -11,6 +11,7 @@ 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 @@ -43,20 +44,30 @@ my $tmpl = '{{ range .Deps }}{{.}} {{ end }}'; -my $tmpdir = tempdir("dh_golang_XXXXXXX", TMPDIR => 1, CLEANUP => 1); +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 $?, $!"; -system("sort -u $tmpdir/godeps | xargs go list -f '{{ .Dir }}' > $tmpdir/godirs") == 0 +# If we're linking against shared libraries, we only want to consider +# the dependencies that are not in shared libraries. +my $linkshared; + +if ($bs->{shlibconfig}->{linkshared}) { + $linkshared = "-linkshared"; +} +my $gofiletmpl = '\ +{{if not .Shlib}}{{ .Dir }}/{{ index (or .GoFiles .CgoFiles .TestGoFiles .XTestGoFiles .IgnoredGoFiles) 0 }}{{end}}'; + +system("sort -u $tmpdir/godeps | grep -v '^unsafe\$' | xargs -r go list $linkshared -f '$gofiletmpl' > $tmpdir/gofiles") == 0 or die "go list of dependencies failed with code $?, $!"; -open(my $inp, "<", "$tmpdir/godirs"); -open(my $outp, ">", "$tmpdir/realgodirs"); +open(my $inp, "<", "$tmpdir/gofiles"); +open(my $outp, ">", "$tmpdir/realgofiles"); while (<$inp>) { chomp; my $realpath = realpath($_); - # godirs will include the directories of the package being built, so exclude them. + # gofiles will include packages being built, so exclude those. if ($realpath !~ /^\Q$bs->{cwd}\E/) { printf $outp "%s\n", $realpath; } @@ -64,14 +75,20 @@ close($inp); close($outp); -system("cat $tmpdir/realgodirs | xargs -r dpkg-query --search > $tmpdir/pkgs") == 0 +system("cat $tmpdir/realgofiles | xargs -r 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 -r dpkg-query -f='\${source:Package} (= \${source:Version}), ' -W`; +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; + +rmtree($tmpdir); + # 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}}) { diff -Nru dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/script/dh_makegolangshlibs dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/script/dh_makegolangshlibs --- dh-golang-1.17ubuntu1~ubuntu16.04.1~ppa1/script/dh_makegolangshlibs 1970-01-01 00:00:00.000000000 +0000 +++ dh-golang-1.19ubuntu1~ubuntu16.04.1~ppa1/script/dh_makegolangshlibs 2016-08-15 23:39:28.000000000 +0000 @@ -0,0 +1,107 @@ +#!/usr/bin/perl -w + +=head1 NAME + +dh_makegolangshlibs - Generates golang-specific shlibs files and substvars + +=cut + +use strict; +use Debian::Debhelper::Dh_Lib; +use File::Find; +use MIME::Base64; + +=head1 SYNOPSIS + +B [S>] + +=head1 DESCRIPTION + +B is a debhelper program which generates a +substvar and shlibs file to enable packages depending on go shared +libraries to conveniently depend on the ABI hash of the library rather +than just the soversion. It replaces dh_makeshlibs in the usual dh +sequences. + +=head1 NOTES + +The best way to invoke B is by using B. + +=cut + +init(); + +############################################################################ +# Generate ... +############################################################################ + +my ($libpkg, $devpkg, $libname, $sover); + +foreach my $pkg (@{$dh{DOPACKAGES}}) { + if ($pkg =~ /^lib(golang.*?)-?([0-9]+)$/) { + $libpkg = $pkg; + $libname = $1; + $sover = $2; + } + if ($pkg =~ /-dev$/) { + $devpkg = $pkg; + } +} + +if (!defined($libpkg)) { + exit(0); +} elsif (!defined($devpkg)) { + printf("found lib package but not dev"); + exit(1); +} + +my $sofile = sprintf( + "%s/usr/lib/%s/lib%s.so.%s", + tmpdir($libpkg), dpkg_architecture_value("DEB_HOST_MULTIARCH"), + $libname, $sover); + +my $gccgo; +if (system("go tool -n compile > /dev/null 2>&1") == 0) { + $gccgo = 0; +} else { + $gccgo = 1; +} +my $hexhash = ""; +if ($gccgo) { + open(my $fh, "-|", "bash -c 'objcopy --dump-section .go_export=>(cat) $sofile'"); + while (<$fh>) { + if (/^checksum ([A-Z0-9]+)/) { + $hexhash = $1; + } + } + close($fh); +} else { + $hexhash=`/usr/lib/go/pkg/readabihash $sofile`; +} +chomp($hexhash); +if ($hexhash eq "") { + die "could not compute hash of $sofile"; +} + +my $libpkgdir=tmpdir($libpkg); +if (! -d "$libpkgdir/DEBIAN") { + doit("install","-d","$libpkgdir/DEBIAN"); +} +my $provides = "$libpkg-$hexhash"; +addsubstvar($libpkg, "golang:Provides", $provides); +complex_doit("echo 'lib$libname $sover $provides' >$libpkgdir/DEBIAN/shlibs"); +doit("chmod",644,"$libpkgdir/DEBIAN/shlibs"); +doit("chown","0:0","$libpkgdir/DEBIAN/shlibs"); +autotrigger($libpkg, 'activate-noawait', 'ldconfig'); + +=head1 SEE ALSO + +dh(1) + +=head1 AUTHORS + +Michael Hudson-Doyle + +=cut + +# vim:ts=4:sw=4:et