Merge lp:~mwhudson/ubuntu/xenial/juju/use-dh-golang-proper into lp:~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta6

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Martin Packman
Approved revision: 129
Merged at revision: 121
Proposed branch: lp:~mwhudson/ubuntu/xenial/juju/use-dh-golang-proper
Merge into: lp:~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta6
Diff against target: 141 lines (+67/-23)
3 files modified
debian/control (+1/-0)
debian/helpers/setup-build-directory.py (+42/-0)
debian/rules (+24/-23)
To merge this branch: bzr merge lp:~mwhudson/ubuntu/xenial/juju/use-dh-golang-proper
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+293966@code.launchpad.net

Commit message

Convert to using dh-golang more conventionally.

Description of the change

As observed in https://bugs.launchpad.net/ubuntu/+source/juju-core/+bug/1578550 juju-core ftbfs in yakkety due to assumptions in dh_golang. This branch, therefore, arranges that the build tree looks much more like what dh_golang expects, via a terrifying perl script.

To post a comment you must log in.
121. By Michael Hudson-Doyle

Use dh_golang to build the package.

This fixes the ftbfs on yakkety.

dh_golang's "configure" step is replaced by a completely out of control perl script.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

One last comment for now: I could rewrite the perl script in python. I'm not sure how to do the Dpkg::Deps stuff in Python, I could always shell out to a perl one-liner from Python :-)

Revision history for this message
Martin Packman (gz) wrote :

Thanks Michael!

Some specific questions as inline comments, but the big thing to answer is do we want a juju-specific answer here or something generic that this distro can use for other go projects?

The current script is more terrifying than I imagined when we talked about the solution, but does seem to cover the edge cases well enough to be nearly reusable elsewhere. I think we could simplify it a fair by using dependencies.tsv from the github.com/juju/juju tree if we decide this is going to remain a juju-only packaging solution.

I think deb822 in python-debian does the dependency parsing bits we'd need, but I can live with perl.

Anyway, I'm down with trying this approach for juju out in yakkety, but think we need to point in out and ask for feedback from a wider audience of people who may care about how we do golang packaging.

review: Needs Information
122. By Michael Hudson-Doyle

use dependencies.tsv instead

123. By Michael Hudson-Doyle

review comments

124. By Michael Hudson-Doyle

kill the perl

125. By Michael Hudson-Doyle

fix so it actually works

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

> Thanks Michael!
>
> Some specific questions as inline comments, but the big thing to answer is do
> we want a juju-specific answer here or something generic that this distro can
> use for other go projects?
>
> The current script is more terrifying than I imagined when we talked about the
> solution,

:-)

> but does seem to cover the edge cases well enough to be nearly
> reusable elsewhere. I think we could simplify it a fair by using
> dependencies.tsv from the github.com/juju/juju tree if we decide this is going
> to remain a juju-only packaging solution.

Oh man, I forgot about that. That makes things so much easier that I've replaced that perl script with a simple Python script instead. (I can always get the perl out of branch history if I want it again).

My new Python has the issue that having extra packages installed might affect the build, but that's not new.

> I think deb822 in python-debian does the dependency parsing bits we'd need,
> but I can live with perl.
>
> Anyway, I'm down with trying this approach for juju out in yakkety, but think
> we need to point in out and ask for feedback from a wider audience of people
> who may care about how we do golang packaging.

I'll ask in Debian what they think about the general problem (although they'll probably just say "don't bundle dependencies"...)

Revision history for this message
Michael Hudson-Doyle (mwhudson) :
126. By Michael Hudson-Doyle

add comment

127. By Michael Hudson-Doyle

edit comment

128. By Michael Hudson-Doyle

finally tidying of comment

129. By Michael Hudson-Doyle

revert changelog, set DH_GOPKG as well for easier backporting to trusty

Revision history for this message
Martin Packman (gz) wrote :

Thanks for addressing all the comments! Lets go with this and do a new upload for yakkety.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-04-20 17:22:29 +0000
3+++ debian/control 2016-05-09 04:09:18 +0000
4@@ -23,6 +23,7 @@
5 python
6 Standards-Version: 3.9.7
7 Homepage: http://launchpad.net/juju-core
8+Xs-Go-Import-Path: github.com/juju/juju
9 Testsuite: autopkgtest
10
11 Package: juju-2.0
12
13=== added directory 'debian/helpers'
14=== added file 'debian/helpers/setup-build-directory.py'
15--- debian/helpers/setup-build-directory.py 1970-01-01 00:00:00 +0000
16+++ debian/helpers/setup-build-directory.py 2016-05-09 04:09:18 +0000
17@@ -0,0 +1,42 @@
18+#!/usr/bin/python
19+
20+# This script sets up the _build directory to be suitable to have
21+# GOPATH pointed at it. The output looks much like what:
22+#
23+# dh_auto_configure --buildsystem=golang --builddirectory=golang
24+#
25+# would produce for a normal package build despite the fact that this
26+# package is not at all out laid in a fashion dh_golang thinks of as
27+# normal.
28+#
29+# Dependencies installed from .deb packages are used in favour of
30+# packages from ./src.
31+
32+import csv
33+import errno
34+import os
35+import shutil
36+
37+def ensure_directory(path):
38+ try:
39+ os.makedirs(path)
40+ except OSError as exception:
41+ if exception.errno != errno.EEXIST:
42+ raise
43+
44+reader = csv.reader(open("src/github.com/juju/juju/dependencies.tsv"), delimiter="\t")
45+
46+def link_pkg(pkgpath):
47+ target = os.path.join("_build/src", pkgpath)
48+ ensure_directory(os.path.dirname(target))
49+ for prefix in ['/usr/share/gocode/src', 'src']:
50+ srcpath = os.path.abspath(os.path.join(prefix, pkgpath))
51+ if os.path.exists(srcpath):
52+ os.symlink(srcpath, target)
53+ return
54+ raise Exception("%s not found", pkgpath)
55+
56+for record in reader:
57+ link_pkg(record[0])
58+
59+shutil.copytree("src/github.com/juju/juju", "_build/src/github.com/juju/juju", symlinks=True)
60
61=== modified file 'debian/rules'
62--- debian/rules 2016-04-19 09:21:40 +0000
63+++ debian/rules 2016-05-09 04:09:18 +0000
64@@ -1,14 +1,11 @@
65 #!/usr/bin/make -f
66 # -*- makefile -*-
67
68-# Uncomment this to turn on verbose mode.
69 #export DH_VERBOSE=1
70-# NOTE: debian/gocode/src will contain symlinks to system provided
71-# dev packages, which will be used over those in the upstream
72-# juju-core codebase.
73
74-export GOPATH:=$(CURDIR)/debian/gocode:$(CURDIR)
75-export PATH:=$(CURDIR)/bin:$(PATH)
76+export DH_GOPKG:=github.com/juju/juju
77+export GOPATH:=$(CURDIR)/_build
78+export PATH:=$(CURDIR)/_build/bin:$(PATH)
79
80 PKGDIR:=debian/juju
81 VERSION:=$(shell sed -n 's/^const version = "\(2\.[0-9]\+\)[\.-].*"/\1/p' $(CURDIR)/src/github.com/juju/juju/version/version.go)
82@@ -23,9 +20,9 @@
83 endif
84
85 %:
86- dh $@ --with=golang
87+ dh $@ --with=golang --buildsystem=golang --builddirectory=_build
88
89-COMMON_FLAGS:= -x -v -work
90+COMMON_FLAGS:= -x -v
91 golang_archs:= amd64 i386 armhf s390x ppc64el arm64
92 ifeq (,$(filter $(DEB_HOST_ARCH), $(golang_archs)))
93 # NOTE(james-page) statically link libgo for the jujud binary for gccgo
94@@ -37,28 +34,32 @@
95 # NOTE: ensure /usr/share/gocode is use in preference to any
96 # embedded source for dependencies.
97 override_dh_auto_configure:
98- dh_auto_configure
99- mkdir -p debian/gocode/src
100- ln -s /usr/share/gocode/src/* debian/gocode/src
101+ ./debian/helpers/setup-build-directory.py
102+
103+override_dh_auto_build:
104+ dh_auto_build -- $(COMMON_FLAGS)
105+ rm _build/bin/jujud
106+ # re-link jujud with specific options
107+ go install $(COMMON_FLAGS) $(JUJUD_FLAGS) github.com/juju/juju/cmd/jujud
108+
109+# Don't run the tests -- the juju unit tests are too heavyweight to run during
110+# package build.
111+override_dh_auto_test:
112+ :
113
114 override_dh_auto_install:
115- go install $(COMMON_FLAGS) github.com/juju/juju/cmd/juju
116- go install $(COMMON_FLAGS) github.com/juju/juju/cmd/plugins/juju-metadata
117- go install $(COMMON_FLAGS) github.com/juju/juju/cmd/plugins/juju-upgrade-mongo
118- go install $(COMMON_FLAGS) $(JUJUD_FLAGS) github.com/juju/juju/cmd/jujud
119- echo '#!/bin/sh\nexport PATH=/usr/lib/juju-$(VERSION)/bin:"$$PATH"\nexec juju "$$@"' > bin/juju-$(VERSION)
120- chmod 755 bin/juju-$(VERSION)
121+ echo '#!/bin/sh\nexport PATH=/usr/lib/juju-$(VERSION)/bin:"$$PATH"\nexec juju "$$@"' > _build/bin/juju-$(VERSION)
122+ chmod 755 _build/bin/juju-$(VERSION)
123 mkdir -p debian/home
124 HOME=debian/home $(CURDIR)/src/github.com/juju/juju/scripts/generate-docs.py man -o juju.1
125- dh_install bin/juju usr/lib/juju-$(VERSION)/bin
126- dh_install bin/juju-metadata usr/lib/juju-$(VERSION)/bin
127- dh_install bin/juju-upgrade-mongo usr/lib/juju-$(VERSION)/bin
128- dh_install bin/jujud usr/lib/juju-$(VERSION)/bin
129- dh_install bin/juju-$(VERSION) usr/bin
130+ dh_install _build/bin/juju usr/lib/juju-$(VERSION)/bin
131+ dh_install _build/bin/juju-metadata usr/lib/juju-$(VERSION)/bin
132+ dh_install _build/bin/juju-upgrade-mongo usr/lib/juju-$(VERSION)/bin
133+ dh_install _build/bin/jujud usr/lib/juju-$(VERSION)/bin
134+ dh_install _build/bin/juju-$(VERSION) usr/bin
135 dh_install juju.1 usr/lib/juju-$(VERSION)/man/man1
136 dh_install src/github.com/juju/juju/etc/bash_completion.d/juju2 \
137 usr/share/bash-completion/completions
138- dh_auto_install
139
140 override_dh_link:
141 dh_link -pjuju-2.0 usr/bin/juju-$(VERSION) usr/bin/juju

Subscribers

People subscribed via source and target branches