Debian Codegraph @

build-recipe-spec

raw
1 #
2 # spec 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 recipe_setup_spec() {
25 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
26 if test -z "$TOPDIR"; then
27 cleanup_and_exit 1 "Error: TOPDIR empty"
28 fi
29 test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
30 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT OTHER ; do
31 mkdir -p $BUILD_ROOT$TOPDIR/$i
32 done
33 chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
34 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
35 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
36 }
37
38 recipe_prepare_spec() {
39 # fixup specfile
40 args=()
41 if test -n "$RELEASE" ; then
42 args[${#args[@]}]="--release"
43 args[${#args[@]}]="$RELEASE"
44 fi
45 if test -n "$BUILD_FLAVOR" ; then
46 args[${#args[@]}]="--buildflavor"
47 args[${#args[@]}]="$BUILD_FLAVOR"
48 fi
49 if test -n "$OBS_PACKAGE" ; then
50 args[${#args[@]}]="--obspackage"
51 args[${#args[@]}]="$OBS_PACKAGE"
52 fi
53 if test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" ; then
54 args[${#args[@]}]="--changelog"
55 args[${#args[@]}]="$BUILD_ROOT/.build-changelog"
56 fi
57
58 substitutedeps "${args[@]}" --root "$BUILD_ROOT" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" "$BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
59
60 # fix rpmrc if we are compiling for i686
61 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
62 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
63 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
64 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
65 fi
66
67 # extract macros from configuration
68 rawcfgmacros=.rpmmacros
69 test "$BUILDTYPE" = debbuild && rawcfgmacros=.debmacros
70 queryconfig rawmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" > $BUILD_ROOT/root/$rawcfgmacros
71 if test -n "$BUILD_DEBUG" && test "$BUILDTYPE" != debbuild ; then
72 echo '
73 %prep %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%prep
74 %package %{?!__debug_package:%{?_build_create_debug:%?_build_insert_debug_package}}%%package
75 %_build_insert_debug_package \
76 %global __debug_package 1 \
77 %undefine _enable_debug_packages \
78 %debug_package
79
80 ' >> $BUILD_ROOT/root/$rawcfgmacros
81 fi
82
83 if test -n "$BUILD_JOBS" ; then
84 cat >> $BUILD_ROOT/root/$rawcfgmacros <<-EOF
85 ### from obs-build
86 %jobs $BUILD_JOBS
87 %_smp_mflags -j$BUILD_JOBS
88 EOF
89 fi
90 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/$rawcfgmacros $BUILD_ROOT/home/abuild/$rawcfgmacros
91
92 # extract optflags from configuration
93 queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" optflags ${BUILD_DEBUG:+debug} > $BUILD_ROOT/root/.rpmrc
94 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
95
96 if test -z "$ABUILD_TARGET"; then
97 ABUILD_TARGET=$(queryconfig target --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
98 test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
99 fi
100
101 # report specfile changes
102 if test -f $BUILD_ROOT/.spec.new ; then
103 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE $BUILD_ROOT/.spec.new ; then
104 echo -----------------------------------------------------------------
105 echo "I have the following modifications for $RECIPEFILE:"
106 sed -e "/^%changelog/q" $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE > $BUILD_ROOT/.spec.t1
107 sed -e "/^%changelog/q" $BUILD_ROOT/.spec.new > $BUILD_ROOT/.spec.t2
108 diff $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
109 rm -f $BUILD_ROOT/.spec.t1 $BUILD_ROOT/.spec.t2
110 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE
111 else
112 rm -f $BUILD_ROOT/.spec.new
113 fi
114 fi
115 }
116
117 recipe_build_spec() {
118 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
119
120 rpmbuild=rpmbuild
121 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
122 test "$BUILDTYPE" = debbuild && rpmbuild=debbuild
123
124 HAVE_DYNAMIC_BUILDREQUIRES=
125 if egrep '^%generate_buildrequires' "$BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE" >/dev/null ; then
126 HAVE_DYNAMIC_BUILDREQUIRES=true
127 fi
128
129 # XXX: move _srcdefattr to macro file?
130 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
131 if test "$DO_CHECKS" != true ; then
132 if chroot "$BUILD_ROOT" "$rpmbuild" --nocheck --help >/dev/null 2>&1; then
133 rpmbopts[${#rpmbopts[@]}]="--nocheck"
134 else
135 echo "warning: --nocheck is not supported by this $rpmbuild version"
136 fi
137 fi
138 if test "$rpmbuild" == "debbuild" ; then
139 rpmbopts[${#rpmbopts[@]}]="-vv"
140 fi
141 if test "$rpmbuild" == "rpmbuild" ; then
142 # use only --nosignature for rpm v4
143 rpmbopts[${#rpmbopts[@]}]="--nosignature"
144 fi
145 if test -n "$ABUILD_TARGET" ; then
146 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
147 fi
148 if test -n "$BUILD_DEBUG" ; then
149 rpmbopts[${#rpmbopts[@]}]='--define'
150 rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
151 fi
152 if test -n "$DISTURL" ; then
153 rpmbopts[${#rpmbopts[@]}]='--define'
154 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
155 fi
156 if test -n "$RSYNCDONE" ; then
157 rpmbopts[${#rpmbopts[@]}]='--define'
158 rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
159 fi
160
161 buildrootoverride=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags rpm-buildroot-override)
162 if test -n "$buildrootoverride" ; then
163 rpmbopts[${#rpmbopts[@]}]='--buildroot'
164 rpmbopts[${#rpmbopts[@]}]="$buildrootoverride"
165 fi
166
167 GEN_BUILDREQS_PACKS=()
168 if test -n "$HAVE_DYNAMIC_BUILDREQUIRES" ; then
169 # query dynamic build requires
170 rm -f "$BUILD_ROOT$TOPDIR/SRPMS/"*.buildreqs.nosrc.rpm
171 rpmdynbropts=("${rpmbopts[@]}")
172 rpmdynbropts[0]=-br
173 toshellscript $rpmbuild \
174 --nodeps \
175 "${definesnstuff[@]}" \
176 "${rpmdynbropts[@]}" \
177 "$TOPDIR/SOURCES/$RECIPEFILE" \
178 > $BUILD_ROOT/.build.command
179 chmod 755 $BUILD_ROOT/.build.command
180 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null
181 st=$?
182 if test "$st" != 0 -a "$st" != 11 ; then
183 return
184 fi
185 : > $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs
186 if test "$st" = 11 ; then
187 reqsfile=
188 for i in "$BUILD_ROOT$TOPDIR/SRPMS/"*.buildreqs.nosrc.rpm ; do
189 test -f "$i" && reqsfile=${i##*/}
190 done
191 test -n "$reqsfile" || cleanup_and_exit 1 "no buildreqs.nosrc.rpm file?"
192 chroot $BUILD_ROOT rpm -qp --requires "$TOPDIR/SRPMS/$reqsfile" | grep -v '^rpmlib(' | sort -u > $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs_tmp
193 chroot $BUILD_ROOT rpmspec -q --srpm --requires "$TOPDIR/SOURCES/$RECIPEFILE" >> $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs_tmp || cleanup_and_exit 1 "rpm -q --spec failed"
194 sort < $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs_tmp | uniq -u > $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs
195 rm -f $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs_tmp
196 while read db ; do
197 GEN_BUILDREQS_PACKS[${#GEN_BUILDREQS_PACKS[@]}]="$db"
198 done < $BUILD_ROOT$TOPDIR/OTHER/_generated_buildreqs
199 fi
200 rm -f "$BUILD_ROOT$TOPDIR/SRPMS/"*.buildreqs.nosrc.rpm
201 fi
202
203 # su involves a shell which would require even more
204 # complicated quoting to bypass than this
205 toshellscript $rpmbuild \
206 "${definesnstuff[@]}" \
207 "${rpmbopts[@]}" \
208 "$TOPDIR/SOURCES/$RECIPEFILE" \
209 > $BUILD_ROOT/.build.command
210 chmod 755 $BUILD_ROOT/.build.command
211 check_exit
212 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null
213 st=$?
214 test "$st" = 0 && BUILD_SUCCEEDED=true
215 test "$st" = 11 -a -n "$HAVE_DYNAMIC_BUILDREQUIRES" && BUILD_SUCCEEDED=genbuildreqs
216 }
217
218 recipe_resultdirs_spec() {
219 echo RPMS SRPMS
220 }
221
222 recipe_cleanup_spec() {
223 :
224 }
225
226 recipe_unpack_srcrpm() {
227 test -n "$LIST_STATE" || echo "processing src rpm $SRCDIR/$RECIPEFILE ..."
228 MYSRCDIR="$BUILD_ROOT/.build-srcdir"
229 rm -rf "$MYSRCDIR"
230 mkdir -p "$MYSRCDIR"
231 cd $MYSRCDIR || cleanup_and_exit 1
232 $BUILD_DIR/unrpm -q $SRCDIR/$RECIPEFILE || {
233 cleanup_and_exit 1 "could not unpack $RECIPEFILE."
234 }
235 for RECIPEFILE in *.spec ; do : ; done
236 }
237
238 # post build functions... move somewhere else?
239
240 recipe_check_file_owners() {
241 echo "... checking for files with abuild user/group"
242 BADFILE=
243 while read un gn fn ; do
244 if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
245 echo " $un $gn $fn"
246 BADFILE=true
247 fi
248 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
249 if test -n "$BADFILE" ; then
250 cleanup_and_exit 1 "please fix your filelist (e.g. add defattr)"
251 fi
252 }
253
254 recipe_run_rpmlint() {
255 # SUSE builds are using a special rpmlint binary which is not
256 # pulling in additional dependencies
257 local rpmlint="/opt/testing/bin/rpmlint"
258 if ! test -x "$BUILD_ROOT$rpmlint" ; then
259 # default rpmlint place as fallback
260 rpmlint="/usr/bin/rpmlint"
261 fi
262 if ! test -x "$BUILD_ROOT$rpmlint" ; then
263 return
264 fi
265 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
266 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
267 -o -name "*-32bit-*" -o -name "*-64bit-*" \
268 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
269 -o -type f -name '*.rpm' -print))
270 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
271 echo
272 echo "RPMLINT report:"
273 echo "==============="
274 rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
275 rm -f "$BUILD_ROOT$rpmlint_logfile"
276 ret=0
277 chroot $BUILD_ROOT su -s $rpmlint "$BUILD_USER" -- \
278 --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} \
279 ${SRPM_FILE_LIST[*]#$BUILD_ROOT} > >(tee "$BUILD_ROOT$rpmlint_logfile") 2>&1 || ret=1
280 echo
281 if test "$ret" = 1 ; then
282 cleanup_and_exit 1
283 fi
284 }
285
286 recipe_compare_oldpackages() {
287 if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
288 echo "... comparing built packages with the former built"
289 if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
290 chroot $BUILD_ROOT touch /.build/.same_result_marker
291 # XXX: dirty build service hack. fix bs_worker. Search for
292 # 'same_result_marker' for traces of a first try to get rid of this
293 if test -n "$REASON" -a -n "$DISTURL" ; then
294 exitcode=2
295 fi
296 fi
297 fi
298 }
299
300 recipe_create_deltarpms() {
301 if test -x "$BUILD_ROOT/usr/bin/makedeltarpm" -a -x $BUILD_ROOT/usr/lib/build/mkdrpms ; then
302 echo "... creating delta rpms"
303 ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
304 chroot $BUILD_ROOT /usr/lib/build/mkdrpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
305 fi
306 }
307