1 |
Signed-off-by: William Hubbs <williamh@g.o> |
2 |
--- |
3 |
eclass/go-module.eclass | 105 ++++++++++++++++++++++++++++++++++++++++ |
4 |
1 file changed, 105 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..810e66e1c5b |
10 |
--- /dev/null |
11 |
+++ b/eclass/go-module.eclass |
12 |
@@ -0,0 +1,105 @@ |
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 |
+# tar -acf foo-1.0-vendor.tar.gz vendor |
44 |
+# |
45 |
+# @CODE: |
46 |
+# |
47 |
+# Regardless of whether you create a vendor tarball, Since Go programs |
48 |
+# are statically linked, it is important that the ebuild's LICENSE= |
49 |
+# setting includes the licenses of all statically linked |
50 |
+# dependencies. So please make sure it is accurate. |
51 |
+ |
52 |
+case ${EAPI:-0} in |
53 |
+ 7) ;; |
54 |
+ *) die "${ECLASS} API in EAPI ${EAPI} not yet established." |
55 |
+esac |
56 |
+ |
57 |
+if [[ -z ${_GO_MODULE} ]]; then |
58 |
+ |
59 |
+_GO_MODULE=1 |
60 |
+ |
61 |
+BDEPEND=">=dev-lang/go-1.12" |
62 |
+ |
63 |
+# Force go to build in module mode. |
64 |
+# In this mode the GOPATH environment variable is ignored. |
65 |
+# this will become the default in the future. |
66 |
+export GO111MODULE=on |
67 |
+ |
68 |
+# The following go flags should be used for all 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 |
+ |
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 |
+# If upstream vendors and we provide a vendor tarball, this is a fatal |
87 |
+# error. |
88 |
+go-module_src_prepare() { |
89 |
+ default |
90 |
+ if [[ -d "${S}"/vendor ]] && [[ -d ../vendor ]] ; then |
91 |
+ eerror "The upstream source for ${P} includes a vendor directory" |
92 |
+ eerror "and a local vendor tarball is provided." |
93 |
+ die "vendored dependencies are provided upstream" |
94 |
+ fi |
95 |
+ # Use the upstream provided vendor directory if it exists. |
96 |
+ [[ -d "${S}"/vendor ]] && return |
97 |
+ # If we are not providing a mirror of a vendor directory we created |
98 |
+ # manually, return since there may be nothing to vendor. |
99 |
+ [[ ! -d ../vendor ]] && return |
100 |
+ # At this point, we know we are providing a vendor mirror. |
101 |
+ mv ../vendor "${S}" || die "Unable to move ../vendor directory" |
102 |
+} |
103 |
+ |
104 |
+# @FUNCTION: go-module_pkg_postinst |
105 |
+# @DESCRIPTION: |
106 |
+# Display a warning about security updates for Go programs. |
107 |
+go-module_pkg_postinst() { |
108 |
+ ewarn "${PN} is written in the Go programming language." |
109 |
+ ewarn "Since this language is statically linked, security" |
110 |
+ ewarn "updates will be handled in individual packages and will be" |
111 |
+ ewarn "difficult for us to track as a distribution." |
112 |
+ ewarn "For this reason, please update any go packages asap when new" |
113 |
+ ewarn "versions enter the tree or go stable if you are running the" |
114 |
+ ewarn "stable tree." |
115 |
+} |
116 |
+ |
117 |
+fi |
118 |
-- |
119 |
2.21.0 |