kde-apps/ksirk: x86 stable (bug #661810)
[gentoo.git] / eclass / vcs-snapshot.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: vcs-snapshot.eclass
5 # @MAINTAINER:
6 # mgorny@gentoo.org
7 # @BLURB: support eclass for unpacking VCS snapshot tarballs
8 # @DESCRIPTION:
9 # This eclass provides a convenience src_unpack() which does unpack all
10 # the tarballs in SRC_URI to locations matching their (local) names,
11 # discarding the original parent directory.
12 #
13 # The typical use case are VCS snapshots, coming from bitbucket
14 # and similar services. They have hash appended to the directory name
15 # which makes extracting them a painful experience. But if you just use
16 # a SRC_URI arrow to rename it (which you're likely have to do anyway),
17 # vcs-snapshot will just extract it into a matching directory.
18 #
19 # Please note that this eclass handles only tarballs (.tar, .tar.gz,
20 # .tar.bz2 & .tar.xz). For any other file format (or suffix) it will
21 # fall back to regular unpack. Support for additional formats may be
22 # added at some point so please keep your SRC_URIs clean.
23 #
24 # Note: this eclass is no longer needed with the new-style 'archive'
25 # GitHub URLs. They have sane directory names and stable contents,
26 # so you should really prefer them.
27 #
28 # @EXAMPLE:
29 #
30 # @CODE
31 # EAPI=6
32 # inherit vcs-snapshot
33 #
34 # SRC_URI="https://github.com/example/${PN}/tarball/v${PV} -> ${P}.tar.gz
35 #       https://github.com/example/${PN}-otherstuff/tarball/v${PV} -> ${P}-otherstuff.tar.gz"
36 # @CODE
37 #
38 # and however the tarballs were originally packed, all files will appear
39 # in ${WORKDIR}/${P} and ${WORKDIR}/${P}-otherstuff respectively.
40
41 case ${EAPI:-0} in
42         0|1|2|3|4|5|6) ;;
43         *) die "vcs-snapshot.eclass API in EAPI ${EAPI} not yet established."
44 esac
45
46 EXPORT_FUNCTIONS src_unpack
47
48 # @FUNCTION: vcs-snapshot_src_unpack
49 # @DESCRIPTION:
50 # Extract all the archives from ${A}. The .tar, .tar.gz, .tar.bz2
51 # and .tar.xz archives will be unpacked to directories matching their
52 # local names. Other archive types will be passed down to regular
53 # unpack.
54 vcs-snapshot_src_unpack() {
55         debug-print-function ${FUNCNAME} "${@}"
56
57         local f
58
59         for f in ${A}
60         do
61                 case "${f}" in
62                         *.tar|*.tar.gz|*.tar.bz2|*.tar.xz)
63                                 local destdir=${WORKDIR}/${f%.tar*}
64
65                                 debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
66
67                                 # XXX: check whether the directory structure inside is
68                                 # fine? i.e. if the tarball has actually a parent dir.
69                                 mkdir "${destdir}" || die
70                                 # -o (--no-same-owner) to avoid restoring original owner
71                                 tar -C "${destdir}" -x -o --strip-components 1 \
72                                         -f "${DISTDIR}/${f}" || die
73                                 ;;
74                         *)
75                                 debug-print "${FUNCNAME}: falling back to unpack for ${f}"
76
77                                 # fall back to the default method
78                                 unpack "${f}"
79                                 ;;
80                 esac
81         done
82 }