1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: golang-vcs.eclass
6 # William Hubbs <williamh@gentoo.org>
7 # @BLURB: Eclass for fetching and unpacking go repositories.
9 # This eclass is written to ease the maintenance of live ebuilds
10 # of software written in the Go programming language.
12 inherit eutils golang-base
18 die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
22 EXPORT_FUNCTIONS src_unpack
24 if [[ -z ${_GOLANG_VCS} ]]; then
28 # @ECLASS-VARIABLE: EGO_PN
31 # This is the import path for the go package(s). Please emerge dev-lang/go
32 # and read "go help importpath" for syntax.
36 # EGO_PN="github.com/user/package"
37 # EGO_PN="github.com/user1/package1 github.com/user2/package2"
40 # @ECLASS-VARIABLE: EGO_STORE_DIR
42 # Storage directory for Go sources.
44 # This is intended to be set by the user in make.conf. Ebuilds must not set
47 # EGO_STORE_DIR=${DISTDIR}/go-src
49 # @ECLASS-VARIABLE: EVCS_OFFLINE
52 # If non-empty, this variable prevents any online operations.
54 # @ECLASS-VARIABLE: EVCS_UMASK
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.
62 # @FUNCTION: _golang-vcs_env_setup
65 # Create EGO_STORE_DIR if necessary.
66 _golang-vcs_env_setup() {
67 debug-print-function ${FUNCNAME} "$@"
69 local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
70 : ${EGO_STORE_DIR:=${distdir}/go-src}
72 [[ -n ${EVCS_UMASK} ]] && eumask_push $EVCS_UMASK
74 if [[ ! -d ${EGO_STORE_DIR} ]]; then
77 mkdir -p "${EGO_STORE_DIR}"
78 ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
81 addwrite "${EGO_STORE_DIR}"
83 [[ -n ${EVCS_UMASK} ]] && eumask_pop
84 mkdir -p "${WORKDIR}/${P}/src" ||
85 die "${ECLASS}: unable to create ${WORKDIR}/${P}"
89 # @FUNCTION: _golang-vcs_fetch
92 # Retrieve the EGO_PN go package along with its dependencies.
94 debug-print-function ${FUNCNAME} "$@"
98 if [[ -z ${EVCS_OFFLINE} ]]; then
99 [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK}
101 set -- env GOPATH="${EGO_STORE_DIR}" go get -d -t -u -v -x "${EGO_PN}"
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
109 [[ -n ${EVCS_UMASK} ]] && eumask_pop
111 local go_srcpath="${WORKDIR}/${P}/src/${EGO_PN%/...}"
112 set -- mkdir -p "${go_srcpath}"
114 "$@" || die "Unable to create ${go_srcpath}"
115 set -- cp -r "${EGO_STORE_DIR}/src/${EGO_PN%/...}" \
118 "$@" || die "Unable to copy sources to ${go_srcpath}"
122 golang-vcs_src_fetch() {
123 debug-print-function ${FUNCNAME} "$@"
125 _golang-vcs_env_setup
129 golang-vcs_src_unpack() {
130 debug-print-function ${FUNCNAME} "$@"