qt5-build.eclass: Drop pre-Qt 5.14 quirks
[gentoo.git] / eclass / golang-vcs.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: golang-vcs.eclass
5 # @MAINTAINER:
6 # William Hubbs <williamh@gentoo.org>
7 # @SUPPORTED_EAPIS: 5 6 7
8 # @BLURB: Eclass for fetching and unpacking go repositories.
9 # @DESCRIPTION:
10 # This eclass is written to ease the maintenance of live ebuilds
11 # of software written in the Go programming language.
12
13 inherit estack eutils golang-base
14
15 case "${EAPI:-0}" in
16         5|6|7)
17                 ;;
18         *)
19                 die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
20                 ;;
21 esac
22
23 EXPORT_FUNCTIONS src_unpack
24
25 if [[ -z ${_GOLANG_VCS} ]]; then
26
27 _GOLANG_VCS=1
28
29 PROPERTIES+=" live"
30
31 # @ECLASS-VARIABLE: EGO_PN
32 # @REQUIRED
33 # @DESCRIPTION:
34 # This is the import path for the go package(s). Please emerge dev-lang/go
35 # and read "go help importpath" for syntax.
36 #
37 # Example:
38 # @CODE
39 # EGO_PN="github.com/user/package"
40 # EGO_PN="github.com/user1/package1 github.com/user2/package2"
41 # @CODE
42
43 # @ECLASS-VARIABLE: EGO_STORE_DIR
44 # @DESCRIPTION:
45 # Storage directory for Go sources.
46 #
47 # This is intended to be set by the user in make.conf. Ebuilds must not set
48 # it.
49 #
50 # EGO_STORE_DIR=${DISTDIR}/go-src
51
52 # @ECLASS-VARIABLE: EVCS_OFFLINE
53 # @DEFAULT_UNSET
54 # @DESCRIPTION:
55 # If non-empty, this variable prevents any online operations.
56
57 # @ECLASS-VARIABLE: EVCS_UMASK
58 # @DEFAULT_UNSET
59 # @DESCRIPTION:
60 # Set this variable to a custom umask. This is intended to be set by
61 # users. By setting this to something like 002, it can make life easier
62 # for people who do development as non-root (but are in the portage
63 # group) and use FEATURES=userpriv.
64
65 # @FUNCTION: _golang-vcs_env_setup
66 # @INTERNAL
67 # @DESCRIPTION:
68 # Create EGO_STORE_DIR if necessary.
69 _golang-vcs_env_setup() {
70         debug-print-function ${FUNCNAME} "$@"
71
72         local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
73         : ${EGO_STORE_DIR:=${distdir}/go-src}
74
75         [[ -n ${EVCS_UMASK} ]] && eumask_push $EVCS_UMASK
76
77         if [[ ! -d ${EGO_STORE_DIR} ]]; then
78                 (
79                         addwrite /
80                         mkdir -p "${EGO_STORE_DIR}"
81                 ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
82         fi
83
84         addwrite "${EGO_STORE_DIR}"
85
86         [[ -n ${EVCS_UMASK} ]] && eumask_pop
87         mkdir -p "${WORKDIR}/${P}/src" ||
88                 die "${ECLASS}: unable to create ${WORKDIR}/${P}"
89         return 0
90 }
91
92 # @FUNCTION: _golang-vcs_fetch
93 # @INTERNAL
94 # @DESCRIPTION:
95 # Retrieve the EGO_PN go package along with its dependencies.
96 _golang-vcs_fetch() {
97         debug-print-function ${FUNCNAME} "$@"
98
99         ego_pn_check
100
101         if [[ -z ${EVCS_OFFLINE} ]]; then
102                 [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK}
103
104                 set -- env GOPATH="${EGO_STORE_DIR}" go get -d -t -u -v -x "${EGO_PN}"
105                 echo "$@"
106                 "$@" || die
107                 # The above dies if you pass repositories in EGO_PN instead of
108                 # packages, e.g. golang.org/x/tools instead of golang.org/x/tools/cmd/vet.
109                 # This is being discussed in the following upstream issue:
110                 # https://github.com/golang/go/issues/11090
111
112                 [[ -n ${EVCS_UMASK} ]] && eumask_pop
113         fi
114         local go_srcpath="${WORKDIR}/${P}/src/${EGO_PN%/...}"
115         set -- mkdir -p "${go_srcpath}"
116         echo "$@"
117         "$@" || die "Unable to create ${go_srcpath}"
118         set -- cp -r    "${EGO_STORE_DIR}/src/${EGO_PN%/...}" \
119                 "${go_srcpath}/.."
120         echo "$@"
121         "$@" || die "Unable to copy sources to ${go_srcpath}"
122         return 0
123 }
124
125 golang-vcs_src_fetch() {
126         debug-print-function ${FUNCNAME} "$@"
127
128         _golang-vcs_env_setup
129         _golang-vcs_fetch
130 }
131
132 golang-vcs_src_unpack() {
133         debug-print-function ${FUNCNAME} "$@"
134
135         golang-vcs_src_fetch
136 }
137
138 fi