rpmbuilding golang applications

Dennis Jacobfeuerborn dennisml at conversis.de
Wed Oct 28 00:26:03 UTC 2015


Hi,
I'm currently looking into creating an RPM for influxdb 0.9 but have run
into a problem when it comes to the %install step in the spec file.

I created RPMs for all dependencies which are installed at
/usr/share/gocode/src and these are found and influxdb builds fine
however once the "go install ./..." line is reached in the spec file I
get permission denied errors.

/home/dennis/rpmbuild/BUILD/influxdb-0.9.4.2
++ pwd
+ export
GOPATH=/home/dennis/rpmbuild/BUILD/influxdb-0.9.4.2/_build:/usr/share/gocode
+
GOPATH=/home/dennis/rpmbuild/BUILD/influxdb-0.9.4.2/_build:/usr/share/gocode
+ pushd ./_build/src/github.com/influxdb/influxdb
~/rpmbuild/BUILD/influxdb-0.9.4.2/_build/src/github.com/influxdb/influxdb ~/rpmbuild/BUILD/influxdb-0.9.4.2
+ go install ./...
go install golang.org/x/crypto/blowfish: mkdir /usr/share/gocode/pkg:
permission denied
go install gopkg.in/fatih/pool.v2: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/peterh/liner: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/armon/go-metrics: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/boltdb/bolt: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/rakyll/statik/fs: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/kimor79/gollectd: mkdir /usr/share/gocode/pkg:
permission denied
go install collectd.org/cdtime: mkdir /usr/share/gocode/pkg: permission
denied
go install github.com/golang/snappy: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/bmizerany/pat: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/BurntSushi/toml: mkdir /usr/share/gocode/pkg:
permission denied
go install github.com/hashicorp/go-msgpack/codec: mkdir
/usr/share/gocode/pkg: permission denied
go install github.com/gogo/protobuf/proto: mkdir /usr/share/gocode/pkg:
permission denied
error: Bad exit status from /var/tmp/rpm-tmp.YSKjXF (%install)

Notice how I set a special GOPATH with the intention that "go install"
then installs the binaries into that hierachy. As you can see though
that doesn't work and instead go tries to install the binaries for the
dependencies (!) to /usr/share/gocode/pkg instead of the first path in
GOPATH.

My theory is that since the sources for these dependencies are located
in /usr/share/gocode/src go ignores the GOPATH completely and simply
assumes that the corresponding binaries should be generated basically in
../pkg relative to the src directory.

My question is how am I to handle this?

At first I thought maybe I need to do a "go install" for each dependency
and ship the binaries in /usr/share/gocode/pkg for each RPM  but
https://fedoraproject.org/wiki/PackagingDrafts/Go has this to say:

"The standard golang compiler only produces static libraries. There is
little value in shipping these prebuilt, especially since these
libraries are very specifically tied to the exact minor release of the
golang compiler. Instead, each library package should consist of a
-devel subpackage which installs .go source code to
/usr/share/gocode/src, under the appropriate import path.

Binary packages which build against this source will set $GOPATH to
'%{_datadir}/gocode' ( or '%{gopath}' in golang > 1.2.1-1)"

So apparently I'm not supposed to ship these binaries but also
apparently go insists installing binaries into a system path which is
obviously a no-go for rpm builds.

What is the proper way to deal with this?

Regards,
  Dennis


More information about the devel mailing list