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 # @SUPPORTED_EAPIS: 5 6 7
8 # @BLURB: Eclass for fetching and unpacking go repositories.
10 # This eclass is written to ease the maintenance of live ebuilds
11 # of software written in the Go programming language.
13 inherit eutils golang-base
19 die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
23 EXPORT_FUNCTIONS src_unpack
25 if [[ -z ${_GOLANG_VCS} ]]; then
29 # @ECLASS-VARIABLE: EGO_PN
32 # This is the import path for the go package(s). Please emerge dev-lang/go
33 # and read "go help importpath" for syntax.
37 # EGO_PN="github.com/user/package"
38 # EGO_PN="github.com/user1/package1 github.com/user2/package2"
41 # @ECLASS-VARIABLE: EGO_STORE_DIR
43 # Storage directory for Go sources.
45 # This is intended to be set by the user in make.conf. Ebuilds must not set
48 # EGO_STORE_DIR=${DISTDIR}/go-src
50 # @ECLASS-VARIABLE: EVCS_OFFLINE
53 # If non-empty, this variable prevents any online operations.
55 # @ECLASS-VARIABLE: EVCS_UMASK
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.
63 # @FUNCTION: _golang-vcs_env_setup
66 # Create EGO_STORE_DIR if necessary.
67 _golang-vcs_env_setup() {
68 debug-print-function ${FUNCNAME} "$@"
70 local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
71 : ${EGO_STORE_DIR:=${distdir}/go-src}
73 [[ -n ${EVCS_UMASK} ]] && eumask_push $EVCS_UMASK
75 if [[ ! -d ${EGO_STORE_DIR} ]]; then
78 mkdir -p "${EGO_STORE_DIR}"
79 ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
82 addwrite "${EGO_STORE_DIR}"
84 [[ -n ${EVCS_UMASK} ]] && eumask_pop
85 mkdir -p "${WORKDIR}/${P}/src" ||
86 die "${ECLASS}: unable to create ${WORKDIR}/${P}"
90 # @FUNCTION: _golang-vcs_fetch
93 # Retrieve the EGO_PN go package along with its dependencies.
95 debug-print-function ${FUNCNAME} "$@"
99 if [[ -z ${EVCS_OFFLINE} ]]; then
100 [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK}
102 set -- env GOPATH="${EGO_STORE_DIR}" go get -d -t -u -v -x "${EGO_PN}"
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
110 [[ -n ${EVCS_UMASK} ]] && eumask_pop
112 local go_srcpath="${WORKDIR}/${P}/src/${EGO_PN%/...}"
113 set -- mkdir -p "${go_srcpath}"
115 "$@" || die "Unable to create ${go_srcpath}"
116 set -- cp -r "${EGO_STORE_DIR}/src/${EGO_PN%/...}" \
119 "$@" || die "Unable to copy sources to ${go_srcpath}"
123 golang-vcs_src_fetch() {
124 debug-print-function ${FUNCNAME} "$@"
126 _golang-vcs_env_setup
130 golang-vcs_src_unpack() {
131 debug-print-function ${FUNCNAME} "$@"