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")
48 rawcfgmacros=.rpmmacros
49 test "$BUILDTYPE" = debbuild && rawcfgmacros=.debmacros
53 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
54 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
56 # fix rpmrc if we are compiling for i686
57 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
58 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
59 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
60 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
62 if test "$DO_BUILD" = false ; then
65 # extract macros from configuration
66 queryconfig rawmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/$rawcfgmacros
67 if test -n "$BUILD_DEBUG" && test "$BUILDTYPE" != debbuild ; then
69 %prep %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%prep
70 %package %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%package
71 %_build_insert_debug_package \
72 %global __debug_package 1 \
73 %undefine _enable_debug_packages \
76 ' >> $BUILD_ROOT/root/$rawcfgmacros
79 if test -n "$BUILD_JOBS" ; then
80 cat >> $BUILD_ROOT/root/$rawcfgmacros <<-EOF
82 %_smp_mflags -j$BUILD_JOBS
85 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/$rawcfgmacros $BUILD_ROOT/home/abuild/$rawcfgmacros
87 # extract optflags from configuration
88 queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" optflags ${BUILD_DEBUG:+debug} > $BUILD_ROOT/root/.rpmrc
89 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
91 if test -z "$ABUILD_TARGET"; then
92 ABUILD_TARGET=$(queryconfig target --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
93 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
96 # report specfile changes
97 if test -f $BUILD_ROOT/.spec.new ; then
98 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE $BUILD_ROOT/.spec.new ; then
99 echo -----------------------------------------------------------------
100 echo "I have the following modifications for $RECIPEFILE:"
101 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE > $BUILD_ROOT/.spec.t1
102 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
103 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
104 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
105 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE
107 rm -f $BUILD_ROOT/.spec.new
112 recipe_build_spec() {
113 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
116 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
117 test "$BUILDTYPE" = debbuild && rpmbuild=debbuild
119 # XXX: move _srcdefattr to macro file?
120 rpmbopts=("--define" "_srcdefattr (-,root,root)")
121 if test "$DO_CHECKS" != true ; then
122 if chroot "$BUILD_ROOT" "$rpmbuild" --nocheck --help >/dev/null 2>&1; then
123 rpmbopts[${#rpmbopts[@]}]="--nocheck"
125 echo "warning: --nocheck is not supported by this $rpmbuild version"
128 if test "$rpmbuild" == "rpmbuild" ; then
129 # use only --nosignature for rpm v4
130 rpmbopts[${#rpmbopts[@]}]="--nosignature"
132 if test -n "$ABUILD_TARGET" ; then
133 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
135 if test -n "$BUILD_DEBUG" ; then
136 rpmbopts[${#rpmbopts[@]}]='--define'
137 rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
139 if test -n "$DISTURL" ; then
140 rpmbopts[${#rpmbopts[@]}]='--define'
141 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
143 if test -n "$RSYNCDONE" ; then
144 rpmbopts[${#rpmbopts[@]}]='--define'
145 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
148 # su involves a shell which would require even more
149 # complicated quoting to bypass than this
150 if test "$SHORT_CIRCUIT" = false ; then
151 rpmbopts[${#rpmbopts[@]}]="$BUILD_RPM_BUILD_STAGE"
152 toshellscript $rpmbuild \
153 "${definesnstuff[@]}" \
155 "$TOPDIR/SOURCES/$RECIPEFILE" \
156 > $BUILD_ROOT/.build.command
158 rpmbopts[${#rpmbopts[@]}]='--short-circuit'
159 buildopts="-bc -bi -bb -bs"
161 echo "#!/bin/sh -x" >$BUILD_ROOT/.build.command
162 echo "set -e" >>$BUILD_ROOT/.build.command
163 for opt in $buildopts
165 shellquote $rpmbuild \
166 "${definesnstuff[@]}" \
167 "${rpmbopts[@]}" $opt \
168 "$TOPDIR/SOURCES/$RECIPEFILE" \
169 >> $BUILD_ROOT/.build.command
170 echo >>$BUILD_ROOT/.build.command
171 [ "$opt" == "$BUILD_RPM_BUILD_STAGE" ] && break
175 chmod 755 $BUILD_ROOT/.build.command
177 if test -n "$RUN_SHELL"; then
178 chroot $BUILD_ROOT su -
180 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
184 recipe_resultdirs_spec() {
188 recipe_unpack_srcrpm() {
189 test -n "$LIST_STATE" || echo "processing src rpm $SRCDIR/$RECIPEFILE ..."
190 MYSRCDIR="$BUILD_ROOT/.build-srcdir"
193 cd $MYSRCDIR || cleanup_and_exit 1
194 $BUILD_DIR/unrpm -q $SRCDIR/$RECIPEFILE || {
195 echo "could not unpack $RECIPEFILE."
198 for RECIPEFILE in *.spec ; do : ; done
201 # post build functions... move somewhere else?
203 recipe_check_file_owners() {
204 echo "... checking for files with abuild user/group"
206 while read un gn fn ; do
207 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
211 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
212 if test -n "$BADFILE" ; then
213 echo "please fix your filelist (e.g. add defattr)"
218 recipe_run_rpmlint() {
219 if ! test -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then
222 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
223 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
224 -o -name "*-32bit-*" -o -name "*-64bit-*" \
225 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
226 -o -type f -name '*.rpm' -print))
227 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
229 echo "RPMLINT report:"
230 echo "==============="
231 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
232 rm -f "$BUILD_ROOT$rpmlint_logfile"
234 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
235 chroot $BUILD_ROOT su -s /opt/testing/bin/rpmlint "$BUILD_USER" -- \
236 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
237 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > >(tee "$BUILD_ROOT$rpmlint_logfile") 2>&1 || ret=1
239 umount -n $BUILD_ROOT/proc 2>/dev/null || true
240 if test "$ret" = 1 ; then
245 recipe_compare_oldpackages() {
246 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
247 echo "... comparing built packages with the former built"
248 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
249 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
250 chroot $BUILD_ROOT touch /.build/.same_result_marker
251 # XXX: dirty build service hack. fix bs_worker. Search for
252 # 'same_result_marker' for traces of a first try to get rid of this
253 if test -n "$REASON" -a -n "$DISTURL" ; then
257 umount -n $BUILD_ROOT/proc 2>/dev/null || true
261 recipe_create_deltarpms() {
262 if test -x "$BUILD_ROOT/usr/bin/makedeltarpm" -a -x $BUILD_ROOT/usr/lib/build/mkdrpms ; then
263 echo "... creating delta rpms"
264 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
265 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"