1 |
Signed-off-by: William Hubbs <williamh@g.o> |
2 |
--- |
3 |
eclass/go-module.eclass | 117 ++++++++++++++++++++++++++++++++++++++++ |
4 |
1 file changed, 117 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..7e16ec4e95c |
10 |
--- /dev/null |
11 |
+++ b/eclass/go-module.eclass |
12 |
@@ -0,0 +1,117 @@ |
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 pkg_postinst |
81 |
+ EXPORT_FUNCTIONS pkg_postinst |
82 |
+ |
83 |
+# @FUNCTION: go-module_src_prepare |
84 |
+# @DESCRIPTION: |
85 |
+# Run a default src_prepare then move our provided vendor directory to |
86 |
+# the appropriate spot if upstream doesn't provide a vendor directory. |
87 |
+# |
88 |
+# This is commented out because I want to see where the discussion on |
89 |
+# the ml leads. |
90 |
+# Commenting it out and following the above instructions means that you |
91 |
+# are forced to manually re-tar the vendored dependencies for every |
92 |
+# version bump. |
93 |
+# Using the previous method, it would be possible to decide if you need |
94 |
+# to do this by comparing the contents of go.mod in the previous and new |
95 |
+# version. |
96 |
+# Also, note that we can generate a qa warning if a maintainer forgets |
97 |
+# to drop the vendor tarball and upstream starts vendoring. |
98 |
+# go-module_src_prepare() { |
99 |
+# default |
100 |
+# # If upstream vendors the dependencies and we provide a vendor |
101 |
+# # tarball, generate a qa warning. |
102 |
+# if [[ -d vendor ]] && [[ -d ../vendor ]] ; then |
103 |
+# eqawarn "This package's upstream source includes a vendor |
104 |
+# eqawarn "directory and the maintainer provides a vendor tarball." |
105 |
+# eqawarn "Please report this on https://bugs.gentoo.org" |
106 |
+# fi |
107 |
+# # Use the upstream provided vendor directory if it exists. |
108 |
+# [[ -d vendor ]] && return |
109 |
+# # If we are not providing a mirror of a vendor directory we created |
110 |
+# # manually, return since there may be nothing to vendor. |
111 |
+# [[ ! -d ../vendor ]] && return |
112 |
+# # At this point, we know we are providing a vendor mirror. |
113 |
+# mv ../vendor . || die "Unable to move ../vendor directory" |
114 |
+# } |
115 |
+ |
116 |
+# @FUNCTION: go-module_pkg_postinst |
117 |
+# @DESCRIPTION: |
118 |
+# Display a warning about security updates for Go programs. |
119 |
+go-module_pkg_postinst() { |
120 |
+ ewarn "${PN} is written in the Go programming language." |
121 |
+ ewarn "Since this language is statically linked, security" |
122 |
+ ewarn "updates will be handled in individual packages and will be" |
123 |
+ ewarn "difficult for us to track as a distribution." |
124 |
+ ewarn "For this reason, please update any go packages asap when new" |
125 |
+ ewarn "versions enter the tree or go stable if you are running the" |
126 |
+ ewarn "stable tree." |
127 |
+} |
128 |
+ |
129 |
+fi |
130 |
-- |
131 |
2.21.0 |