1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: vcs-snapshot.eclass
7 # @BLURB: support eclass for unpacking VCS snapshot tarballs
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.
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.
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.
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.
32 # inherit vcs-snapshot
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"
38 # and however the tarballs were originally packed, all files will appear
39 # in ${WORKDIR}/${P} and ${WORKDIR}/${P}-otherstuff respectively.
43 *) die "vcs-snapshot.eclass API in EAPI ${EAPI} not yet established."
46 EXPORT_FUNCTIONS src_unpack
48 # @FUNCTION: vcs-snapshot_src_unpack
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
54 vcs-snapshot_src_unpack() {
55 debug-print-function ${FUNCNAME} "${@}"
62 *.tar|*.tar.gz|*.tar.bz2|*.tar.xz)
63 local destdir=${WORKDIR}/${f%.tar*}
65 debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
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
75 debug-print "${FUNCNAME}: falling back to unpack for ${f}"
77 # fall back to the default method