2 # spec specific functions.
4 ################################################################
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
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.
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.
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
22 ################################################################
25 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
26 if test -z "$TOPDIR"; then
27 echo "Error: TOPDIR empty"
30 if [ "$NO_TOPDIR_CLEANUP" = false ]; then
31 rm -rf "$BUILD_ROOT$TOPDIR"
32 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
33 mkdir -p $BUILD_ROOT$TOPDIR/$i
37 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
38 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
39 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
42 recipe_prepare_spec() {
44 if test -n "$RELEASE"; then
45 args=(--release "$RELEASE")
50 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
51 substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
53 # fix rpmrc if we are compiling for i686
54 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
55 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
56 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
57 sed -e 's/^buildarchtranslate: athlon.*/buildarchtranslate: athlon: i686/' -e 's/^buildarchtranslate: i686.*/buildarchtranslate: i686: i686/' < $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 > $BUILD_ROOT/usr/lib/rpm/rpmrc
59 if test "$DO_BUILD" = false ; then
63 # extract macros from configuration
64 queryconfig rawmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/.rpmmacros
65 if test -n "$BUILD_DEBUG" ; then
67 %prep %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%prep
68 %package %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%package
69 %_build_insert_debug_package \
70 %global __debug_package 1 \
71 %undefine _enable_debug_packages \
74 ' >> $BUILD_ROOT/root/.rpmmacros
77 if test -n "$BUILD_JOBS" ; then
78 cat >> $BUILD_ROOT/root/.rpmmacros <<-EOF
80 %_smp_mflags -j$BUILD_JOBS
83 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
85 # extract optflags from configuration
86 queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" optflags ${BUILD_DEBUG:+debug} > $BUILD_ROOT/root/.rpmrc
87 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
89 if test -z "$ABUILD_TARGET"; then
90 ABUILD_TARGET=$(queryconfig target --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
91 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
94 # report specfile changes
95 if test -f $BUILD_ROOT/.spec.new ; then
96 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE $BUILD_ROOT/.spec.new ; then
97 echo -----------------------------------------------------------------
98 echo "I have the following modifications for $RECIPEFILE:"
99 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE > $BUILD_ROOT/.spec.t1
100 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
101 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
102 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
103 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE
105 rm -f $BUILD_ROOT/.spec.new
110 recipe_build_spec() {
111 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
114 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
116 # XXX: move _srcdefattr to macro file?
117 rpmbopts=("--define" "_srcdefattr (-,root,root)")
118 if test "$DO_CHECKS" != true ; then
119 rpmbopts[${#rpmbopts[@]}]="--nocheck"
121 if test "$rpmbuild" == "rpmbuild" ; then
122 # use only --nosignature for rpm v4
123 rpmbopts[${#rpmbopts[@]}]="--nosignature"
125 if test -n "$ABUILD_TARGET" ; then
126 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
128 if test -n "$BUILD_DEBUG" ; then
129 rpmbopts[${#rpmbopts[@]}]='--define'
130 rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
132 if test -n "$DISTURL" ; then
133 rpmbopts[${#rpmbopts[@]}]='--define'
134 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
136 if test -n "$RSYNCDONE" ; then
137 rpmbopts[${#rpmbopts[@]}]='--define'
138 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
141 # su involves a shell which would require even more
142 # complicated quoting to bypass than this
143 if test "$SHORT_CIRCUIT" = false ; then
144 rpmbopts[${#rpmbopts[@]}]="$BUILD_RPM_BUILD_STAGE"
145 toshellscript $rpmbuild \
146 "${definesnstuff[@]}" \
148 "$TOPDIR/SOURCES/$RECIPEFILE" \
149 > $BUILD_ROOT/.build.command
151 rpmbopts[${#rpmbopts[@]}]='--short-circuit'
152 buildopts="-bc -bi -bb -bs"
154 echo "#!/bin/sh -x" >$BUILD_ROOT/.build.command
155 echo "set -e" >>$BUILD_ROOT/.build.command
156 for opt in $buildopts
158 shellquote $rpmbuild \
159 "${definesnstuff[@]}" \
160 "${rpmbopts[@]}" $opt \
161 "$TOPDIR/SOURCES/$RECIPEFILE" \
162 >> $BUILD_ROOT/.build.command
163 echo >>$BUILD_ROOT/.build.command
164 [ "$opt" == "$BUILD_RPM_BUILD_STAGE" ] && break
168 chmod 755 $BUILD_ROOT/.build.command
170 if test -n "$RUN_SHELL"; then
171 chroot $BUILD_ROOT su -
173 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
177 recipe_resultdirs_spec() {
181 recipe_unpack_srcrpm() {
182 test -n "$LIST_STATE" || echo "processing src rpm $SRCDIR/$RECIPEFILE ..."
183 MYSRCDIR="$BUILD_ROOT/.build-srcdir"
186 cd $MYSRCDIR || cleanup_and_exit 1
187 $BUILD_DIR/unrpm -q $SRCDIR/$RECIPEFILE || {
188 echo "could not unpack $RECIPEFILE."
191 for RECIPEFILE in *.spec ; do : ; done
194 # post build functions... move somewhere else?
196 recipe_check_file_owners() {
197 echo "... checking for files with abuild user/group"
199 while read un gn fn ; do
200 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
204 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
205 if test -n "$BADFILE" ; then
206 echo "please fix your filelist (e.g. add defattr)"
211 recipe_run_rpmlint() {
212 if ! test -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
215 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
216 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
217 -o -name "*-32bit-*" -o -name "*-64bit-*" \
218 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
219 -o -type f -name '*.rpm' -print))
220 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
222 echo "RPMLINT report:"
223 echo "==============="
224 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
225 rm -f "$BUILD_ROOT$rpmlint_logfile"
227 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
228 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
229 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
230 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > "$BUILD_ROOT$rpmlint_logfile" || ret=1
231 cat "$BUILD_ROOT$rpmlint_logfile"
233 umount -n $BUILD_ROOT/proc 2>/dev/null || true
234 if test "$ret" = 1 ; then
239 recipe_compare_oldpackages() {
240 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
241 echo "... comparing built packages with the former built"
242 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
243 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
244 chroot $BUILD_ROOT touch /.build/.same_result_marker
245 # XXX: dirty build service hack. fix bs_worker. Search for
246 # 'same_result_marker' for traces of a first try to get rid of this
247 if test -n "$REASON" -a -n "$DISTURL" ; then
251 umount -n $BUILD_ROOT/proc 2>/dev/null || true
255 recipe_create_deltarpms() {
256 if test -x "$BUILD_ROOT/usr/bin/makedeltarpm" -a -x $BUILD_ROOT/usr/lib/build/mkdrpms ; then
257 echo "... creating delta rpms"
258 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
259 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"