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