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/1] go-module.eclass: introduce new eclass to handle go modules
Date: Fri, 13 Sep 2019 15:50:54
Message-Id: 20190913154951.3360-2-williamh@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/1] Introduce new eclass to handle go modules (round 2) by William Hubbs
1 Signed-off-by: William Hubbs <williamh@g.o>
2 ---
3 eclass/go-module.eclass | 100 ++++++++++++++++++++++++++++++++++++++++
4 1 file changed, 100 insertions(+)
5 create mode 100644 eclass/go-module.eclass
6
7 diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
8 new file mode 100644
9 index 00000000000..501e334b23f
10 --- /dev/null
11 +++ b/eclass/go-module.eclass
12 @@ -0,0 +1,100 @@
13 +# Copyright 2019 gentoo authors
14 +# Distributed under the terms of the GNU General Public License v2
15 +
16 +# @ECLASS: go-module.eclass
17 +# @MAINTAINER:
18 +# William Hubbs <williamh@g.o>
19 +# @SUPPORTED_EAPIS: 7
20 +# @BLURB: basic eclass for building software written in the go
21 +# programming language that uses go modules.
22 +# @DESCRIPTION:
23 +# This eclass provides some basic things needed by all software
24 +# written in the go programming language that uses go modules.
25 +#
26 +# You will know the software you are packaging uses modules because
27 +# it will have files named go.sum and go.mod in its top-level source
28 +# directory. If it does not have these files, use the golang-* eclasses.
29 +#
30 +# If the software you are packaging uses modules, the next question is
31 +# whether it has a directory named "vendor" at the top-level of the source tree.
32 +#
33 +# If it doesn't, you need to create a tarball of what would be in the
34 +# vendor directory and mirror it locally.
35 +# If foo-1.0 is the name of your project and you have the tarball for it
36 +# in your current directory, this is done with the following commands:
37 +#
38 +# @CODE:
39 +#
40 +# tar -xf foo-1.0.tar.gz
41 +# cd foo-1.0
42 +# go mod vendor
43 +# cd ..
44 +# tar -acf foo-1.0-vendor.tar.gz foo-1.0/vendor
45 +#
46 +# @CODE:
47 +
48 +# If we uncomment src_prepare below, the last two lines in the above
49 +# code block are reduced to one:
50 +#
51 +# @CODE:
52 +#
53 +# tar -acf foo-1.0-vendor.tar.gz vendor
54 +#
55 +# @CODE:
56 +
57 +case ${EAPI:-0} in
58 + 7) ;;
59 + *) die "${ECLASS} API in EAPI ${EAPI} not yet established."
60 +esac
61 +
62 +if [[ -z ${_GO_MODULE} ]]; then
63 +
64 +_GO_MODULE=1
65 +
66 +BDEPEND=">=dev-lang/go-1.12"
67 +
68 +# The following go flags should be used for all go builds.
69 +# -mod=vendor stopps downloading of dependencies from the internet.
70 +# -v prints the names of packages as they are compiled
71 +# -x prints commands as they are executed
72 +export GOFLAGS="-mod=vendor -v -x"
73 +
74 +# Do not complain about CFLAGS etc since go projects do not use them.
75 +QA_FLAGS_IGNORED='.*'
76 +
77 +# Go packages should not be stripped with strip(1).
78 +RESTRICT="strip"
79 +
80 +# EXPORT_FUNCTIONS src_prepare
81 +#
82 +# @FUNCTION: go-module_src_prepare
83 +# @DESCRIPTION:
84 +# Run a default src_prepare then move our provided vendor directory to
85 +# the appropriate spot if upstream doesn't provide a vendor directory.
86 +#
87 +# This is commented out because I want to see where the discussion on
88 +# the ml leads.
89 +# Commenting it out and following the above instructions means that you
90 +# are forced to manually re-tar the vendored dependencies for every
91 +# version bump.
92 +# Using the previous method, it would be possible to decide if you need
93 +# to do this by comparing the contents of go.mod in the previous and new
94 +# version.
95 +# go-module_src_prepare() {
96 +# default
97 +# # If upstream vendors the dependencies and we provide a vendor
98 +# # tarball, generate a qa warning.
99 +# [[ -d vendor ]] && [[ -d ../vendor ]] &&
100 +# eqawarn "This package's upstream source includes a vendor
101 +# eqawarn "directory and the maintainer provides a vendor tarball."
102 +# eqawarn "Please report this on https://bugs.gentoo.org"
103 +# # Use the upstream provided vendor directory if it exists.
104 +# [[ -d vendor ]] && return
105 +# # If we are not providing a mirror of a vendor directory we created
106 +# # manually, return since there may be nothing to vendor.
107 +# [[ ! -d ../vendor ]] && return
108 +# # At this point, we know we are providing a vendor mirror.
109 +# mv ../vendor . || die "Unable to move ../vendor directory"
110 +# }
111 +
112 +fi
113 --
114 2.21.0

Replies