1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: vcs-snapshot.eclass
7 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
8 # @BLURB: support eclass for unpacking VCS snapshot tarballs
10 # THIS ECLASS IS NOT NECESSARY FOR MODERN GITHUB AND GITLAB SNAPSHOTS.
11 # THEIR DIRECTORY STRUCTURE IS ENTIRELY PREDICTABLE, SO UPDATE YOUR
12 # EBUILD TO USE /ARCHIVE/ URI AND SET S IF NECESSARY.
14 # This eclass provides a convenience src_unpack() which does unpack all
15 # the tarballs in SRC_URI to locations matching their (local) names,
16 # discarding the original parent directory.
18 # The typical use case are VCS tag snapshots coming from BitBucket
19 # (but not GitHub or GitLab). They have hash appended to the directory
20 # name which makes extracting them a painful experience. But if you are
21 # using a SRC_URI arrow to rename them (which quite likely you have to
22 # do anyway), vcs-snapshot will just extract them into matching
25 # Please note that this eclass handles only tarballs (.tar, .tar.gz,
26 # .tar.bz2 & .tar.xz). For any other file format (or suffix) it will
27 # fall back to regular unpack. Support for additional formats may be
28 # added in the future if necessary.
34 # inherit vcs-snapshot
37 # https://bitbucket.org/foo/bar/get/${PV}.tar.bz2 -> ${P}.tar.bz2
38 # https://bitbucket.org/foo/bar-otherstuff/get/${PV}.tar.bz2
39 # -> ${P}-otherstuff.tar.bz2"
42 # and however the tarballs were originally packed, all files will appear
43 # in ${WORKDIR}/${P} and ${WORKDIR}/${P}-otherstuff respectively.
47 *) die "vcs-snapshot.eclass API in EAPI ${EAPI} not yet established."
50 EXPORT_FUNCTIONS src_unpack
52 # @FUNCTION: vcs-snapshot_src_unpack
54 # Extract all the archives from ${A}. The .tar, .tar.gz, .tar.bz2
55 # and .tar.xz archives will be unpacked to directories matching their
56 # local names. Other archive types will be passed down to regular
58 vcs-snapshot_src_unpack() {
59 debug-print-function ${FUNCNAME} "${@}"
67 *.tar|*.tar.gz|*.tar.bz2|*.tar.xz)
68 local destdir=${WORKDIR}/${f%.tar*}
70 debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
75 done < <(tar -t -f "${DISTDIR}/${f}" | cut -d/ -f1 | sort -u)
76 if [[ ${#topdirs[@]} -gt 1 ]]; then
77 eerror "The archive ${f} contains multiple or no top directory."
78 eerror "It is impossible for vcs-snapshot to unpack this correctly."
79 eerror "Top directories found:"
81 for d in "${topdirs[@]}"; do
84 die "${FUNCNAME}: Invalid directory structure in archive ${f}"
86 [[ ${topdirs[0]} != ${f%.tar*} ]] && renamed_any=1
88 mkdir "${destdir}" || die
89 # -o (--no-same-owner) to avoid restoring original owner
90 einfo "Unpacking ${f}"
91 tar -C "${destdir}" -x -o --strip-components 1 \
92 -f "${DISTDIR}/${f}" || die
95 debug-print "${FUNCNAME}: falling back to unpack for ${f}"
97 # fall back to the default method
103 if [[ ! ${renamed_any} ]]; then
105 [[ ${EAPI} == [0123456] ]] && w=eqawarn
106 "${w}" "${FUNCNAME} did not find any archives that needed renaming."
107 "${w}" "Please verify that its usage is really necessary, and remove"
108 "${w}" "the inherit if it is not."
110 [[ ${w} == eerror ]] && die "${FUNCNAME}: Unnecessary usage detected"