Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH v2 5/5] vcs-snapshot.eclass: Detect unnecessary usage and complain
Date: Thu, 25 Jul 2019 07:38:29
Message-Id: 20190725073722.14482-5-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH v2 1/5] vcs-snapshot.eclass: Allow EAPI 7 by "Michał Górny"
1 Signed-off-by: Michał Górny <mgorny@g.o>
2 ---
3 eclass/vcs-snapshot.eclass | 12 ++++++++++++
4 1 file changed, 12 insertions(+)
5
6 diff --git a/eclass/vcs-snapshot.eclass b/eclass/vcs-snapshot.eclass
7 index 33abd9a7c190..dad586c9e40b 100644
8 --- a/eclass/vcs-snapshot.eclass
9 +++ b/eclass/vcs-snapshot.eclass
10 @@ -1,100 +1,112 @@
11 # Copyright 1999-2019 Gentoo Authors
12 # Distributed under the terms of the GNU General Public License v2
13
14 # @ECLASS: vcs-snapshot.eclass
15 # @MAINTAINER:
16 # mgorny@g.o
17 # @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
18 # @BLURB: support eclass for unpacking VCS snapshot tarballs
19 # @DESCRIPTION:
20 # THIS ECLASS IS NOT NECESSARY FOR MODERN GITHUB AND GITLAB SNAPSHOTS.
21 # THEIR DIRECTORY STRUCTURE IS ENTIRELY PREDICTABLE, SO UPDATE YOUR
22 # EBUILD TO USE /ARCHIVE/ URI AND SET S IF NECESSARY.
23 #
24 # This eclass provides a convenience src_unpack() which does unpack all
25 # the tarballs in SRC_URI to locations matching their (local) names,
26 # discarding the original parent directory.
27 #
28 # The typical use case are VCS tag snapshots coming from BitBucket
29 # (but not GitHub or GitLab). They have hash appended to the directory
30 # name which makes extracting them a painful experience. But if you are
31 # using a SRC_URI arrow to rename them (which quite likely you have to
32 # do anyway), vcs-snapshot will just extract them into matching
33 # directories.
34 #
35 # Please note that this eclass handles only tarballs (.tar, .tar.gz,
36 # .tar.bz2 & .tar.xz). For any other file format (or suffix) it will
37 # fall back to regular unpack. Support for additional formats may be
38 # added in the future if necessary.
39 #
40 # @EXAMPLE:
41 #
42 # @CODE
43 # EAPI=7
44 # inherit vcs-snapshot
45 #
46 # SRC_URI="
47 # https://bitbucket.org/foo/bar/get/${PV}.tar.bz2 -> ${P}.tar.bz2
48 # https://bitbucket.org/foo/bar-otherstuff/get/${PV}.tar.bz2
49 # -> ${P}-otherstuff.tar.bz2"
50 # @CODE
51 #
52 # and however the tarballs were originally packed, all files will appear
53 # in ${WORKDIR}/${P} and ${WORKDIR}/${P}-otherstuff respectively.
54
55 case ${EAPI:-0} in
56 0|1|2|3|4|5|6|7) ;;
57 *) die "vcs-snapshot.eclass API in EAPI ${EAPI} not yet established."
58 esac
59
60 EXPORT_FUNCTIONS src_unpack
61
62 # @FUNCTION: vcs-snapshot_src_unpack
63 # @DESCRIPTION:
64 # Extract all the archives from ${A}. The .tar, .tar.gz, .tar.bz2
65 # and .tar.xz archives will be unpacked to directories matching their
66 # local names. Other archive types will be passed down to regular
67 # unpack.
68 vcs-snapshot_src_unpack() {
69 debug-print-function ${FUNCNAME} "${@}"
70
71 + local renamed_any=
72 local f
73
74 for f in ${A}
75 do
76 case "${f}" in
77 *.tar|*.tar.gz|*.tar.bz2|*.tar.xz)
78 local destdir=${WORKDIR}/${f%.tar*}
79
80 debug-print "${FUNCNAME}: unpacking ${f} to ${destdir}"
81
82 local l topdirs=()
83 while read l; do
84 topdirs+=( "${l}" )
85 done < <(tar -t -f "${DISTDIR}/${f}" | cut -d/ -f1 | sort -u)
86 if [[ ${#topdirs[@]} -gt 1 ]]; then
87 eerror "The archive ${f} contains multiple or no top directory."
88 eerror "It is impossible for vcs-snapshot to unpack this correctly."
89 eerror "Top directories found:"
90 local d
91 for d in "${topdirs[@]}"; do
92 eerror " ${d}"
93 done
94 die "${FUNCNAME}: Invalid directory structure in archive ${f}"
95 fi
96 + [[ ${topdirs[0]} != ${f%.tar*} ]] && renamed_any=1
97
98 mkdir "${destdir}" || die
99 # -o (--no-same-owner) to avoid restoring original owner
100 einfo "Unpacking ${f}"
101 tar -C "${destdir}" -x -o --strip-components 1 \
102 -f "${DISTDIR}/${f}" || die
103 ;;
104 *)
105 debug-print "${FUNCNAME}: falling back to unpack for ${f}"
106
107 # fall back to the default method
108 unpack "${f}"
109 ;;
110 esac
111 done
112 +
113 + if [[ ! ${renamed_any} ]]; then
114 + local w=eerror
115 + [[ ${EAPI} == [0123456] ]] && w=eqawarn
116 + "${w}" "${FUNCNAME} did not find any archives that needed renaming."
117 + "${w}" "Please verify that its usage is really necessary, and remove"
118 + "${w}" "the inherit if it is not."
119 +
120 + [[ ${w} == eerror ]] && die "${FUNCNAME}: Unnecessary usage detected"
121 + fi
122 }
123 --
124 2.22.0