Gentoo Archives: gentoo-dev

From: William Hubbs <williamh@g.o>
To: gentoo-dev@l.g.o
Cc: mgorny@g.o
Subject: Re: [gentoo-dev] [PATCH 1/1] go-module.eclass: introduce new eclass to handle go modules
Date: Mon, 16 Sep 2019 18:46:55
Message-Id: 20190916184646.GC27855@whubbs1.dev.av1.gaikai.org
In Reply to: Re: [gentoo-dev] [PATCH 1/1] go-module.eclass: introduce new eclass to handle go modules by "Michał Górny"
1 On Mon, Sep 16, 2019 at 08:05:50PM +0200, Michał Górny wrote:
2 > On Mon, 2019-09-16 at 09:17 -0500, William Hubbs wrote:
3 > > Signed-off-by: William Hubbs <williamh@g.o>
4 > > ---
5 > > eclass/go-module.eclass | 117 ++++++++++++++++++++++++++++++++++++++++
6 > > 1 file changed, 117 insertions(+)
7 > > create mode 100644 eclass/go-module.eclass
8 > >
9 > > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
10 > > new file mode 100644
11 > > index 00000000000..7e16ec4e95c
12 > > --- /dev/null
13 > > +++ b/eclass/go-module.eclass
14 > > @@ -0,0 +1,117 @@
15 > > +# Copyright 2019 gentoo authors
16 > > +# Distributed under the terms of the GNU General Public License v2
17 > > +
18 > > +# @ECLASS: go-module.eclass
19 > > +# @MAINTAINER:
20 > > +# William Hubbs <williamh@g.o>
21 > > +# @SUPPORTED_EAPIS: 7
22 > > +# @BLURB: basic eclass for building software written in the go
23 > > +# programming language that uses go modules.
24 > > +# @DESCRIPTION:
25 > > +# This eclass provides some basic things needed by all software
26 > > +# written in the go programming 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 > Please add a big fat warning around here somewhere that people need to
33 > look through LICENSE files in all vendored modules, and list them
34 > in LICENSE. They also need to watch out for license conflicts.
35 >
36 > > +#
37 > > +# If the software you are packaging uses modules, the next question is
38 > > +# whether it has a directory named "vendor" at the top-level of the source tree.
39 > > +#
40 > > +# If it doesn't, you need to create a tarball of what would be in the
41 > > +# vendor directory and mirror it locally.
42 > > +# If foo-1.0 is the name of your project and you have the tarball for it
43 > > +# in your current directory, this is done with the following commands:
44 > > +#
45 > > +# @CODE:
46 > > +#
47 > > +# tar -xf foo-1.0.tar.gz
48 > > +# cd foo-1.0
49 > > +# go mod vendor
50 > > +# cd ..
51 > > +# tar -acf foo-1.0-vendor.tar.gz foo-1.0/vendor
52 > > +#
53 > > +# @CODE:
54 > > +
55 > > +# If we uncomment src_prepare below, the last two lines in the above
56 > > +# code block are reduced to one:
57 > > +#
58 > > +# @CODE:
59 > > +#
60 > > +# tar -acf foo-1.0-vendor.tar.gz vendor
61 > > +#
62 > > +# @CODE:
63 > > +
64 > > +case ${EAPI:-0} in
65 > > + 7) ;;
66 > > + *) die "${ECLASS} API in EAPI ${EAPI} not yet established."
67 > > +esac
68 > > +
69 > > +if [[ -z ${_GO_MODULE} ]]; then
70 > > +
71 > > +_GO_MODULE=1
72 > > +
73 > > +BDEPEND=">=dev-lang/go-1.12"
74 > > +
75 > > +# The following go flags should be used for all go builds.
76 > > +# -mod=vendor stopps downloading of dependencies from the internet.
77 > > +# -v prints the names of packages as they are compiled
78 > > +# -x prints commands as they are executed
79 > > +export GOFLAGS="-mod=vendor -v -x"
80 > > +
81 > > +# Do not complain about CFLAGS etc since go projects do not use them.
82 > > +QA_FLAGS_IGNORED='.*'
83 > > +
84 > > +# Go packages should not be stripped with strip(1).
85 > > +RESTRICT="strip"
86 > > +
87 > > +# EXPORT_FUNCTIONS src_prepare pkg_postinst
88 > > + EXPORT_FUNCTIONS pkg_postinst
89 > > +
90 > > +# @FUNCTION: go-module_src_prepare
91 > > +# @DESCRIPTION:
92 > > +# Run a default src_prepare then move our provided vendor directory to
93 > > +# the appropriate spot if upstream doesn't provide a vendor directory.
94 > > +#
95 > > +# This is commented out because I want to see where the discussion on
96 > > +# the ml leads.
97 > > +# Commenting it out and following the above instructions means that you
98 > > +# are forced to manually re-tar the vendored dependencies for every
99 > > +# version bump.
100 > > +# Using the previous method, it would be possible to decide if you need
101 > > +# to do this by comparing the contents of go.mod in the previous and new
102 > > +# version.
103 > > +# Also, note that we can generate a qa warning if a maintainer forgets
104 > > +# to drop the vendor tarball and upstream starts vendoring.
105 > > +# go-module_src_prepare() {
106 > > +# default
107 > > +# # If upstream vendors the dependencies and we provide a vendor
108 > > +# # tarball, generate a qa warning.
109 > > +# if [[ -d vendor ]] && [[ -d ../vendor ]] ; then
110 > > +# eqawarn "This package's upstream source includes a vendor
111 > > +# eqawarn "directory and the maintainer provides a vendor tarball."
112 > > +# eqawarn "Please report this on https://bugs.gentoo.org"
113 >
114 > Why aren't you making it fatal?
115
116 I didn't make it fatal because it doesn't break the build. The build
117 will ignore the ../vendor directory from the tarball since it is not
118 under ${S}. Do you want it to be fatal?
119
120 Thanks,
121
122 William

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies