dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[gentoo.git] / eclass / rpm.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: rpm.eclass
5 # @MAINTAINER:
6 # base-system@gentoo.org
7 # @BLURB: convenience class for extracting RPMs
8
9 inherit estack eutils
10
11 case "${EAPI:-0}" in
12         [0-6]) DEPEND=">=app-arch/rpm2targz-9.0.0.3g" ;;
13         *) BDEPEND=">=app-arch/rpm2targz-9.0.0.3g" ;;
14 esac
15
16 # @FUNCTION: rpm_unpack
17 # @USAGE: <rpms>
18 # @DESCRIPTION:
19 # Unpack the contents of the specified rpms like the unpack() function.
20 rpm_unpack() {
21         [[ $# -eq 0 ]] && set -- ${A}
22         local a
23         for a in "$@" ; do
24                 echo ">>> Unpacking ${a} to ${PWD}"
25                 if [[ ${a} == ./* ]] ; then
26                         : nothing to do -- path is local
27                 elif [[ ${a} == ${DISTDIR}/* ]] ; then
28                         ewarn 'QA: do not use ${DISTDIR} with rpm_unpack -- it is added for you'
29                 elif [[ ${a} == /* ]] ; then
30                         ewarn 'QA: do not use full paths with rpm_unpack -- use ./ paths instead'
31                 else
32                         a="${DISTDIR}/${a}"
33                 fi
34                 rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
35         done
36 }
37
38 # @FUNCTION: srcrpm_unpack
39 # @USAGE: <rpms>
40 # @DESCRIPTION:
41 # Unpack the contents of the specified rpms like the unpack() function as well
42 # as any archives that it might contain.  Note that the secondary archive
43 # unpack isn't perfect in that it simply unpacks all archives in the working
44 # directory (with the assumption that there weren't any to start with).
45 srcrpm_unpack() {
46         [[ $# -eq 0 ]] && set -- ${A}
47         rpm_unpack "$@"
48
49         # no .src.rpm files, then nothing to do
50         [[ "$* " != *".src.rpm " ]] && return 0
51
52         eshopts_push -s nullglob
53
54         # unpack everything
55         local a
56         for a in *.tar.{gz,bz2,xz} *.t{gz,bz2,xz,pxz} *.zip *.ZIP ; do
57                 unpack "./${a}"
58                 rm -f "${a}"
59         done
60
61         eshopts_pop
62
63         return 0
64 }
65
66 # @FUNCTION: rpm_src_unpack
67 # @DESCRIPTION:
68 # Automatically unpack all archives in ${A} including rpms.  If one of the
69 # archives in a source rpm, then the sub archives will be unpacked as well.
70 rpm_src_unpack() {
71         local a
72         for a in ${A} ; do
73                 case ${a} in
74                 *.rpm) srcrpm_unpack "${a}" ;;
75                 *)     unpack "${a}" ;;
76                 esac
77         done
78 }
79
80 # @FUNCTION: rpm_spec_epatch
81 # @USAGE: [spec]
82 # @DESCRIPTION:
83 # Read the specified spec (defaults to ${PN}.spec) and attempt to apply
84 # all the patches listed in it.  If the spec does funky things like moving
85 # files around, well this won't handle that.
86 rpm_spec_epatch() {
87         local p spec=$1
88         local dir
89
90         if [[ -z ${spec} ]] ; then
91                 # search likely places for the spec file
92                 for spec in "${PWD}" "${S}" "${WORKDIR}" ; do
93                         spec+="/${PN}.spec"
94                         [[ -e ${spec} ]] && break
95                 done
96         fi
97         [[ ${spec} == */* ]] \
98                 && dir=${spec%/*} \
99                 || dir=
100
101         ebegin "Applying patches from ${spec}"
102
103         grep '^%patch' "${spec}" | \
104         while read line ; do
105                 # expand the %patch line
106                 set -- ${line}
107                 p=$1
108                 shift
109
110                 # process the %patch arguments
111                 local arg
112                 EPATCH_OPTS=
113                 for arg in "$@" ; do
114                         case ${arg} in
115                         -b) EPATCH_OPTS+=" --suffix" ;;
116                         *)  EPATCH_OPTS+=" ${arg}" ;;
117                         esac
118                 done
119
120                 # extract the patch name from the Patch# line
121                 set -- $(grep "^P${p#%p}: " "${spec}")
122                 shift
123                 epatch "${dir:+${dir}/}$*"
124         done
125
126         eend
127 }
128
129 EXPORT_FUNCTIONS src_unpack