update tizen version to tizen20221207
[tools/build.git] / build-recipe-spec
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         echo "Error: TOPDIR empty"
28         cleanup_and_exit 1
29     fi
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
34              done
35     fi
36
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/
40 }
41
42 recipe_prepare_spec() {
43     args=()
44     if test -n "$RELEASE"; then
45         args=(--release "$RELEASE")
46     fi
47
48     rawcfgmacros=.rpmmacros
49     test "$BUILDTYPE" = debbuild && rawcfgmacros=.debmacros
50
51     # fixup specfile
52     CHANGELOGARGS=
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
55
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
61     fi
62     if test "$DO_BUILD" = false ; then
63         cleanup_and_exit 0
64     fi
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
68         echo '
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 \
74 %debug_package
75
76 ' >> $BUILD_ROOT/root/$rawcfgmacros
77     fi
78
79     if test -n "$BUILD_JOBS" ; then
80         cat >> $BUILD_ROOT/root/$rawcfgmacros <<-EOF
81                 %jobs $BUILD_JOBS
82                 %_smp_mflags -j$BUILD_JOBS
83                 EOF
84     fi
85     test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/$rawcfgmacros $BUILD_ROOT/home/abuild/$rawcfgmacros
86
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
90
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"
94     fi
95
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
106         else
107             rm -f $BUILD_ROOT/.spec.new
108         fi
109     fi
110 }
111
112 recipe_build_spec() {
113     test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
114
115     rpmbuild=rpmbuild
116     test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
117     test "$BUILDTYPE" = debbuild && rpmbuild=debbuild
118
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"
124         else
125             echo "warning: --nocheck is not supported by this $rpmbuild version"
126         fi
127     fi
128     if test "$rpmbuild" == "rpmbuild" ; then
129             # use only --nosignature for rpm v4
130         rpmbopts[${#rpmbopts[@]}]="--nosignature"
131     fi
132     if test -n "$ABUILD_TARGET" ; then
133         rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
134     fi
135     if test -n "$BUILD_DEBUG" ; then
136         rpmbopts[${#rpmbopts[@]}]='--define'
137         rpmbopts[${#rpmbopts[@]}]="_build_create_debug 1"
138     fi
139     if test -n "$DISTURL" ; then
140         rpmbopts[${#rpmbopts[@]}]='--define'
141         rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
142     fi
143     if test -n "$RSYNCDONE" ; then
144         rpmbopts[${#rpmbopts[@]}]='--define'
145         rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
146     fi
147
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[@]}" \
154                     "${rpmbopts[@]}" \
155                     "$TOPDIR/SOURCES/$RECIPEFILE" \
156                     > $BUILD_ROOT/.build.command
157         else
158             rpmbopts[${#rpmbopts[@]}]='--short-circuit'
159             buildopts="-bc -bi -bb -bs"
160             cmds=""
161             echo "#!/bin/sh -x" >$BUILD_ROOT/.build.command
162             echo "set -e" >>$BUILD_ROOT/.build.command
163             for opt in $buildopts
164             do
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
172             done
173         fi
174         
175     chmod 755 $BUILD_ROOT/.build.command
176     check_exit
177     if test -n "$RUN_SHELL"; then
178         chroot $BUILD_ROOT su -
179     else
180         chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
181     fi
182 }
183
184 recipe_resultdirs_spec() {
185     echo RPMS SRPMS
186 }
187
188 recipe_unpack_srcrpm() {
189     test -n "$LIST_STATE" || echo "processing src rpm $SRCDIR/$RECIPEFILE ..."
190     MYSRCDIR="$BUILD_ROOT/.build-srcdir"
191     rm -rf "$MYSRCDIR"
192     mkdir -p "$MYSRCDIR"
193     cd $MYSRCDIR || cleanup_and_exit 1
194     $BUILD_DIR/unrpm -q $SRCDIR/$RECIPEFILE || {
195         echo "could not unpack $RECIPEFILE."
196         cleanup_and_exit 1
197     }
198     for RECIPEFILE in *.spec ; do : ; done
199 }
200
201 # post build functions... move somewhere else?
202
203 recipe_check_file_owners() {
204     echo "... checking for files with abuild user/group"
205     BADFILE=
206     while read un gn fn ; do
207         if test "$un" = abuild -o "$gn" = abuild -o "$un" = ${ABUILD_UID} -o "$gn" = ${ABUILD_GID} ; then
208             echo "  $un $gn $fn"
209             BADFILE=true
210         fi
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)"
214         cleanup_and_exit 1
215     fi
216 }
217
218 recipe_run_rpmlint() {
219     if ! test -x "$BUILD_ROOT/opt/testing/bin/rpmlint" ; then 
220         return
221     fi
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"))
228     echo 
229     echo "RPMLINT report:"
230     echo "==============="
231     rpmlint_logfile=$TOPDIR/OTHER/rpmlint.log
232     rm -f "$BUILD_ROOT$rpmlint_logfile"
233     ret=0
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
238     echo
239     umount -n $BUILD_ROOT/proc 2>/dev/null || true 
240     if test "$ret" = 1 ; then 
241         cleanup_and_exit 1
242     fi   
243 }
244
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 
254                 exitcode=2
255             fi
256         fi
257         umount -n $BUILD_ROOT/proc 2>/dev/null || true 
258     fi   
259 }
260
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}"
266     fi
267 }