Gentoo Archives: gentoo-dev

From: William Hubbs <williamh@g.o>
To: gentoo-dev@l.g.o
Cc: William Hubbs <williamh@g.o>
Subject: [gentoo-dev] [PATCH 1/3] go-module.eclass: introduce new eclass to handle go modules
Date: Wed, 11 Sep 2019 17:28:06
Message-Id: 20190911172128.18885-2-williamh@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/3] add eclass to handle go modules by William Hubbs
1 Copyright: Sony Interactive Entertainment Inc.
2 Signed-off-by: William Hubbs <williamh@g.o>
3 ---
4 eclass/go-module.eclass | 76 +++++++++++++++++++++++++++++++++++++++++
5 1 file changed, 76 insertions(+)
6 create mode 100644 eclass/go-module.eclass
7
8 diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
9 new file mode 100644
10 index 00000000000..7009fcd3beb
11 --- /dev/null
12 +++ b/eclass/go-module.eclass
13 @@ -0,0 +1,76 @@
14 +# Copyright 1999-2015 Gentoo Foundation
15 +# Distributed under the terms of the GNU General Public License v2
16 +
17 +# @ECLASS: go-module.eclass
18 +# @MAINTAINER:
19 +# William Hubbs <williamh@g.o>
20 +# @SUPPORTED_EAPIS: 7
21 +# @BLURB: basic eclass for building software written in the go
22 +# programming language that uses go modules.
23 +# @DESCRIPTION:
24 +# This eclass provides a convenience src_prepare() phase and some basic
25 +# settings needed for all software written in the go programming
26 +# language that uses go modules.
27 +#
28 +# You will know the software you are packaging uses modules because
29 +# it will have files named go.sum and go.mod in its top-level source
30 +# directory. If it does not have these files, use the golang-* eclasses.
31 +#
32 +# If the software you are packaging uses modules, the next question is
33 +# whether it has a directory named "vendor" at the top-level of the source tree.
34 +#
35 +# If it doesn't, you need to create a tarball of what would be in the
36 +# vendor directory and mirror it locally. This is done with the
37 +# following commands if upstream is using a git repository:
38 +#
39 +# @CODE:
40 +#
41 +# $ cd /my/clone/of/upstream
42 +# $ git checkout <release>
43 +# $ go mod vendor
44 +# $ tar cvf project-version-vendor.tar.gz vendor
45 +#
46 +# @CODE:
47 +#
48 +# Other than this, all you need to do is inherit this eclass then
49 +# make sure the exported src_prepare function is run.
50 +
51 +case ${EAPI:-0} in
52 + 7) ;;
53 + *) die "${ECLASS} API in EAPI ${EAPI} not yet established."
54 +esac
55 +
56 +if [[ -z ${_GO_MODULE} ]]; then
57 +
58 +_GO_MODULE=1
59 +
60 +BDEPEND=">=dev-lang/go-1.12"
61 +
62 +# Do not download dependencies from the internet
63 +# make build output verbose by default
64 +export GOFLAGS="-mod=vendor -v -x"
65 +
66 +# Do not complain about CFLAGS etc since go projects do not use them.
67 +QA_FLAGS_IGNORED='.*'
68 +
69 +# Upstream does not support stripping go packages
70 +RESTRICT="strip"
71 +
72 +EXPORT_FUNCTIONS src_prepare
73 +
74 +# @FUNCTION: go-module_src_prepare
75 +# @DESCRIPTION:
76 +# Run a default src_prepare then move our provided vendor directory to
77 +# the appropriate spot if upstream doesn't provide a vendor directory.
78 +go-module_src_prepare() {
79 + default
80 + # Use the upstream provided vendor directory if it exists.
81 + [[ -d vendor ]] && return
82 + # If we are not providing a mirror of a vendor directory we created
83 + # manually, return since there may be nothing to vendor.
84 + [[ ! -d ../vendor ]] && return
85 + # At this point, we know we are providing a vendor mirror.
86 + mv ../vendor . || die "Unable to move ../vendor directory"
87 +}
88 +
89 +fi
90 --
91 2.21.0

Replies