1 # Copyright 1999-2020 Gentoo Authors
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 estack eutils golang-base
19 die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
23 EXPORT_FUNCTIONS src_unpack
25 if [[ -z ${_GOLANG_VCS} ]]; then
31 # @ECLASS-VARIABLE: EGO_PN
34 # This is the import path for the go package(s). Please emerge dev-lang/go
35 # and read "go help importpath" for syntax.
39 # EGO_PN="github.com/user/package"
40 # EGO_PN="github.com/user1/package1 github.com/user2/package2"
43 # @ECLASS-VARIABLE: EGO_STORE_DIR
45 # Storage directory for Go sources.
47 # This is intended to be set by the user in make.conf. Ebuilds must not set
50 # EGO_STORE_DIR=${DISTDIR}/go-src
52 # @ECLASS-VARIABLE: EVCS_OFFLINE
55 # If non-empty, this variable prevents any online operations.
57 # @ECLASS-VARIABLE: EVCS_UMASK
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.
65 # @FUNCTION: _golang-vcs_env_setup
68 # Create EGO_STORE_DIR if necessary.
69 _golang-vcs_env_setup() {
70 debug-print-function ${FUNCNAME} "$@"
72 local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
73 : ${EGO_STORE_DIR:=${distdir}/go-src}
75 [[ -n ${EVCS_UMASK} ]] && eumask_push $EVCS_UMASK
77 if [[ ! -d ${EGO_STORE_DIR} ]]; then
80 mkdir -p "${EGO_STORE_DIR}"
81 ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
84 addwrite "${EGO_STORE_DIR}"
86 [[ -n ${EVCS_UMASK} ]] && eumask_pop
87 mkdir -p "${WORKDIR}/${P}/src" ||
88 die "${ECLASS}: unable to create ${WORKDIR}/${P}"
92 # @FUNCTION: _golang-vcs_fetch
95 # Retrieve the EGO_PN go package along with its dependencies.
97 debug-print-function ${FUNCNAME} "$@"
101 if [[ -z ${EVCS_OFFLINE} ]]; then
102 [[ -n ${EVCS_UMASK} ]] && eumask_push ${EVCS_UMASK}
104 set -- env GOPATH="${EGO_STORE_DIR}" go get -d -t -u -v -x "${EGO_PN}"
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
112 [[ -n ${EVCS_UMASK} ]] && eumask_pop
114 local go_srcpath="${WORKDIR}/${P}/src/${EGO_PN%/...}"
115 set -- mkdir -p "${go_srcpath}"
117 "$@" || die "Unable to create ${go_srcpath}"
118 set -- cp -r "${EGO_STORE_DIR}/src/${EGO_PN%/...}" \
121 "$@" || die "Unable to copy sources to ${go_srcpath}"
125 golang-vcs_src_fetch() {
126 debug-print-function ${FUNCNAME} "$@"
128 _golang-vcs_env_setup
132 golang-vcs_src_unpack() {
133 debug-print-function ${FUNCNAME} "$@"