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