Merge github#758: media-sound/mpd: fix the systemd user service
[gentoo.git] / eclass / golang-vcs-snapshot.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-snapshot.eclass
6 # @MAINTAINER:
7 # William Hubbs <williamh@gentoo.org>
8 # @BLURB: support eclass for unpacking VCS snapshot tarballs for
9 # software written in the Go programming language
10 # @DESCRIPTION:
11 # This eclass provides a convenience src_unpack() which unpacks the
12 # first tarball mentioned in SRC_URI to its appropriate location in
13 # ${WORKDIR}/${P}, treating ${WORKDIR}/${P} as a go workspace.
14 #
15 # The location where the tarball is extracted is defined as
16 # ${WORKDIR}/${P}/src/${EGO_PN}.
17 #
18 # The typical use case is VCS snapshots coming from github, bitbucket
19 # and similar services.
20 #
21 # Please note that this eclass currently handles only tarballs
22 # (.tar.gz), but support for more formats may be added in the future.
23 #
24 # @EXAMPLE:
25 #
26 # @CODE
27 # EGO_PN=github.com/user/package
28 # inherit golang-vcs-snapshot
29 #
30 # SRC_URI="http://github.com/example/${PN}/tarball/v${PV} -> ${P}.tar.gz"
31 # @CODE
32 #
33 # The above example will extract the tarball to
34 # ${WORKDIR}/${P}/src/github.com/user/package
35
36 inherit golang-base
37
38 case ${EAPI:-0} in
39         5|6) ;;
40         *) die "${ECLASS} API in EAPI ${EAPI} not yet established."
41 esac
42
43 EXPORT_FUNCTIONS src_unpack
44
45 # @FUNCTION: golang-vcs-snapshot_src_unpack
46 # @DESCRIPTION:
47 # Extract the first archive from ${A} to the appropriate location for GOPATH.
48 golang-vcs-snapshot_src_unpack() {
49         local x
50         ego_pn_check
51         set -- ${A}
52         x="$1"
53         mkdir -p "${WORKDIR}/${P}/src/${EGO_PN%/...}" || die
54         tar -C "${WORKDIR}/${P}/src/${EGO_PN%/...}" -x --strip-components 1 \
55                 -f "${DISTDIR}/${x}" || die
56 }