update tizen version to tizen20231130
[tools/build.git] / build-pkg-rpm
1 #
2 # RPM specific functions.
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24
25 pkg_initdb_rpm() {
26     echo "initializing rpm db..."
27     mkdir -p "$BUILD_ROOT"/var/lib/rpm
28     # rpm v5 does not have initdb
29     if ! test -e "$BUILD_ROOT"/usr/lib/rpm/cpuinfo.yaml ; then
30         if test -x "$BUILD_ROOT"/usr/bin/rpmdb ; then
31             chroot "$BUILD_ROOT" /usr/bin/rpmdb --initdb || cleanup_and_exit 1
32         else
33             chroot "$BUILD_ROOT" rpm --initdb || cleanup_and_exit 1
34         fi
35     fi
36     # hack: add nofsync to db config to speed up install
37     mkdir -p "$BUILD_ROOT"/root
38     DBI_OTHER=`chroot "$BUILD_ROOT" rpm --eval '%{?__dbi_other}'`
39     echo "%__dbi_other $DBI_OTHER nofsync" > "$BUILD_ROOT"/.rpmmacros
40     echo "%__dbi_other $DBI_OTHER nofsync" > "$BUILD_ROOT"/root/.rpmmacros
41 }
42
43 pkg_prepare_rpm() {
44     rpm_set_checkopts
45     rpm_init_cumulate
46 }
47
48 pkg_erase_rpm() {
49     chroot "$BUILD_ROOT" rpm --nodeps -e $PKG 2>&1 | {
50         local retry
51         while read line; do
52             case "$line" in
53                 r*failed:\ No\ such\ file\ or\ directory) ;;
54                 error:\ failed\ to\ stat\ *:\ No\ such\ file\ or\ directory) ;;
55                 error:\ *scriptlet\ failed*)
56                     echo "$line"
57                     retry=1
58                 ;;
59                 *) echo "$line" ;;
60             esac
61         done
62         if test -n "$retry" ; then
63             echo "re-try deleting $PKG using --noscripts"
64             chroot "$BUILD_ROOT" rpm --nodeps --noscripts -e $PKG || true
65         fi
66     }
67 }
68
69 rpm_set_checkopts() {
70     RPMCHECKOPTS=
71     # on Fedora 10 rpmbuild is in a separate package so we need something else to
72     # detect rpm4
73     test -x "$BUILD_ROOT"/usr/bin/rpmquery && RPMCHECKOPTS="--nodigest --nosignature"
74 }
75
76 rpm_init_cumulate() {
77     cumulate=-1
78     CUMULATED_LIST=()
79     CUMULATED_PIDS=()
80     CUMULATED_HMD5=()
81
82 #    force enable DO_CUMULATE
83 #
84 #    We can't use cumulative install because we don't use %suse_version macro.
85 #    However, our build system is based on openSUSE Build service and we use
86 #    always newer suse version than 1220. Thus, we can always enable cumulative
87 #    install instead of defining the suse_version.
88 #
89 #    ref: https://review.tizen.org/gerrit/#/c/platform/upstream/build/+/25635/
90
91     DO_CUMULATE=true
92
93     local nocumulaterpms=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags nocumulaterpms)
94     if test -n "$nocumulaterpms" ; then
95         test "$nocumulaterpms" != 0 && DO_CUMULATE=false
96     else
97         test "$NOCUMULATE" = true && DO_CUMULATE=false
98     fi
99 }
100
101 pkg_verify_installed_rpm() {
102     chroot "$BUILD_ROOT" rpm --verify $PKG 2>&1 | tee $TMPFILE
103     if grep ^missing $TMPFILE > /dev/null ; then
104         return 1
105     fi
106     return 0
107 }
108
109 pkg_cumulate_rpm() {
110     test "$DO_CUMULATE" = true || return 1
111     # work around for cross-build installs, we must not overwrite the running rpm
112     if test "$PKG" = rpm ; then
113         for i in "$BUILD_ROOT"/.init_b_cache/preinstalls/rpm-x86-* ; do
114             test -e "$i" && return 1
115         done
116     fi
117     let cumulate++
118     CUMULATED_LIST[$cumulate]=".init_b_cache/$PKG.rpm"
119     CUMULATED_PIDS[$cumulate]="$PKGID"
120     CUMULATED_HMD5[$cumulate]="$PKG_HDRMD5"
121     return 0
122 }
123
124 pkg_install_rpm() {
125     ( cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" rpm --ignorearch --nodeps -U --oldpackage --ignoresize $RPMCHECKOPTS \
126                 $ADDITIONAL_PARAMS .init_b_cache/$PKG.rpm 2>&1 || \
127           touch "$BUILD_ROOT"/exit ) | \
128               grep -v "^warning:.*saved as.*rpmorig$"
129 }
130
131 pkg_finalize_rpm() {
132     if test -n "${CUMULATED_LIST[*]}" ; then
133         echo "now installing cumulated packages"
134         for ((num=0; num<=cumulate; num++)) ; do
135             echo ${CUMULATED_LIST[$num]}
136             PKG=${CUMULATED_LIST[$num]##*/}
137             test "$BUILD_ROOT/.init_b_cache/rpms/$PKG" -ef "$BUILD_ROOT/${CUMULATED_LIST[$num]}" && continue
138             rm -f "$BUILD_ROOT"/${CUMULATED_LIST[$num]}
139             cp "$BUILD_ROOT"/.init_b_cache/rpms/$PKG "$BUILD_ROOT"/${CUMULATED_LIST[$num]} || cleanup_and_exit 1
140         done > "$BUILD_ROOT"/.init_b_cache/manifest
141         ( cd "$BUILD_ROOT" && chroot "$BUILD_ROOT" rpm --ignorearch --nodeps -Uh --oldpackage --ignoresize --verbose $RPMCHECKOPTS \
142                 $ADDITIONAL_PARAMS .init_b_cache/manifest 2>&1 || touch "$BUILD_ROOT"/exit )
143         for ((num=0; num<=cumulate; num++)) ; do
144             rm -f "$BUILD_ROOT"/${CUMULATED_LIST[$num]}
145         done
146         rm -f "$BUILD_ROOT"/.init_b_cache/manifest
147         check_exit
148         for ((num=0; num<=cumulate; num++)) ; do
149             PKG=${CUMULATED_LIST[$num]##*/}
150             echo "${CUMULATED_PIDS[$num]}" > "$BUILD_ROOT"/installed-pkg/${PKG%.rpm}
151             test -n "${CUMULATED_HMD5[$num]}" || continue
152             echo "${CUMULATED_HMD5[$num]} ${CUMULATED_PIDS[$num]}" > "$BUILD_ROOT"/.preinstall_image/${PKG%.rpm}
153         done
154     fi
155 }
156
157 pkg_preinstall_rpm() {
158     PAYLOADDECOMPRESS=cat
159     case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm"` in
160         lzma) rpm --showrc | egrep 'PayloadIsLzma|_lzma' > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
161         xz) rpm --showrc | egrep 'PayloadIsXz|_xz' > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
162         zstd) rpm --showrc | egrep 'PayloadIsZstd' > /dev/null || PAYLOADDECOMPRESS="zstd -d" ;;
163     esac
164     if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
165         if ! lzma </dev/null >/dev/null 2>&1 ; then
166             test -f "$BUILD_DIR/lzmadec.sh" || cleanup_and_exit 3 "no lzma decoder available in host system"
167             PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
168         fi
169     fi
170     if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
171         if ! xz </dev/null >/dev/null 2>&1 ; then
172             test -f "$BUILD_DIR/xzdec.sh" || cleanup_and_exit 3 "no xz decoder available in host system"
173             PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
174         fi
175     fi
176     if test "$PAYLOADDECOMPRESS" = "zstd -d" ; then
177         if ! zstd </dev/null >/dev/null 2>&1 ; then
178             test -f "$BUILD_DIR/zstddec.sh" || cleanup_and_exit 3 "no zstd decoder available in host system"
179             PAYLOADDECOMPRESS="bash $BUILD_DIR/zstddec.sh"
180         fi
181     fi
182     if test "$PAYLOADDECOMPRESS" = cat ; then
183         rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" | $CPIO
184     else
185         rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" | $PAYLOADDECOMPRESS | $CPIO
186     fi
187     if test -e ".init_b_cache/scripts/$PKG.run" ; then
188         rpm -qp --nodigest --nosignature --qf "%{PREIN}" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.pre"
189         rpm -qp --nodigest --nosignature --qf "%{PREINPROG}" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.preprog"
190         rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "'$BUILD_ROOT'/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.post"
191         rpm -qp --nodigest --nosignature --qf "%{POSTINPROG}" "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" > ".init_b_cache/scripts/$PKG.postprog"
192         echo -n '(none)' > .init_b_cache/scripts/.none
193         cmp -s ".init_b_cache/scripts/$PKG.pre" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$PKG.pre"
194         cmp -s ".init_b_cache/scripts/$PKG.post" .init_b_cache/scripts/.none && rm -f ".init_b_cache/scripts/$PKG.post"
195         rm -f .init_b_cache/scripts/.none
196     fi
197     # hack for rpm erasures
198     if test -d "$BUILD_ROOT/installed-pkg" ; then
199         # call for rpm-4.x and not rpm-devel
200         test -z "${PKG##rpm-[0-9]*}" && chroot "$BUILD_ROOT" rpm --rebuilddb
201         # also exec for exchanged rpm !  naming is rpm-x86-<target>-<ver>
202         test -z "${PKG##rpm-x86-*[0-9]*}" && chroot "$BUILD_ROOT" rpm --rebuilddb
203     fi
204 }
205
206 pkg_runscripts_rpm() {
207     if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
208         echo "running $PKG preinstall script"
209         local prog
210         read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
211         if test "$prog" = "<lua>" ; then
212             prog="/usr/bin/lua"
213         fi
214         (cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.pre" 0)
215         rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.preprog"
216     fi
217     if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
218         echo "running $PKG postinstall script"
219         local prog
220         read prog < "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
221         if test "$prog" = "<lua>" ; then
222             prog="/usr/bin/lua"
223         fi
224         (cd $BUILD_ROOT && chroot $BUILD_ROOT "${prog:-sh}" ".init_b_cache/scripts/$PKG.post" 1)
225         rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" "$BUILD_ROOT/.init_b_cache/scripts/$PKG.postprog"
226     fi
227 }