Patches for Rpmbuildstage:bb.
[platform/upstream/build-compare.git] / packaging / same-build-result.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2009, 2010, 2012 SUSE Linux Product GmbH, Germany.
4 # Licensed under GPL v2, see COPYING file for details.
5 #
6 # Written by Adrian Schroeter <adrian@suse.de>
7 # Enhanced by Andreas Jaeger <aj@suse.de>
8 #
9 # The script decides if the new build differes from the former one,
10 # using pkg-diff.sh.
11 # The script is called as part of the build process as:
12 # /usr/lib/build/same-build-result.sh /.build.oldpackages /usr/src/packages/RPMS /usr/src/packages/SRPMS
13
14 CMPSCRIPT=${0%/*}/pkg-diff.sh
15 SCMPSCRIPT=${0%/*}/srpm-check.sh
16
17 check_all=1
18 OLDDIR="$1"
19 shift
20 NEWDIRS="$*"
21
22 echo "$CMPSCRIPT"
23
24 if [ ! -d "$OLDDIR" ]; then
25   echo "No valid directory with old build result given !"
26   exit 1
27 fi
28 if [ -z "$NEWDIRS" ]; then
29   echo "No valid directory with new build result given !"
30   exit 1
31 fi
32
33 first_rpm=$(find $NEWDIRS -name *.rpm | head -1)
34 dist=$(rpm -qp --nodigest --nosignature --qf "%{DISTRIBUTION}" $first_rpm | sed -r 's/(.*)\/.*/\1/')
35 prerelease=0
36 if [[ $dist =~ "prerelease" ]]; then
37   echo "This is a prerelease project. Do not check the existence of source rpm files."
38
39   prerelease=1
40   num_new_pkgs=`find $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm' -and ! -name '*.src.rpm' | wc -l`
41   num_old_pkgs=`find $OLDDIR  -name '*.rpm' -and ! -name '*.delta.rpm' -and ! -name '*.src.rpm' | wc -l`
42   if test $num_new_pkgs != $num_old_pkgs; then
43      echo "different number of subpackages"
44      find $OLDDIR $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm'
45      exit 1
46   fi
47
48 else
49   if test `find $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm' | wc -l` != `find $OLDDIR -name '*.rpm' -and ! -name '*.delta.rpm' | wc -l`; then
50      echo "different number of subpackages"
51      find $OLDDIR $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm'
52      exit 1
53   fi
54
55   osrpm=$(find "$OLDDIR" -name \*src.rpm)
56   nsrpm=$(find $NEWDIRS -name \*src.rpm)
57
58   if test ! -f "$osrpm"; then
59     echo no old source rpm in $OLDDIR
60     exit 1
61   fi
62
63   if test ! -f "$nsrpm"; then
64     echo no new source rpm in $NEWDIRS
65     exit 1
66   fi
67
68   echo "compare $osrpm $nsrpm"
69   bash $SCMPSCRIPT "$osrpm" "$nsrpm" || exit 1
70 fi
71
72 # technically we should not all exclude all -32bit but filter for different archs,
73 # like done with -x86
74 # but it would be better if this script ran earlier in the build
75 # sort the rpms so that both lists have the same order
76 # problem: a package can contain both noarch and arch subpackages, so we have to 
77 # take care of proper sorting of NEWRPMS, e.g. noarch/x.rpm and x86_64/w.rpm since OLDRPMS 
78 # has all the packages in a single directory and would sort this as w.rpm, x.rpm.
79 OLDRPMS=($(find "$OLDDIR" -type f -name \*rpm -a ! -name \*src.rpm  -a ! -name \*.delta.rpm|sort|grep -v -- -32bit-|grep -v -- -64bit-|grep -v -- '-x86-.*\.ia64\.rpm'))
80 NEWRPMS=($(find $NEWDIRS -type f -name \*rpm -a ! -name \*src.rpm -a ! -name \*.delta.rpm|sort --field-separator=/ --key=7|grep -v -- -32bit-|grep -v -- -64bit-|grep -v -- '-x86-.*\.ia64\.rpm'))
81
82 # Get version-release from first RPM and keep for rpmlint check
83 # Remember to quote the "." for future regexes
84 ver_rel1=$(rpm -qp --nodigest --nosignature --qf "%{VERSION}-%{RELEASE}" "${OLDRPMS[0]}"|sed -e 's/\./\\./g')
85 ver_rel2=$(rpm -qp --nodigest --nosignature --qf "%{VERSION}-%{RELEASE}" "${NEWRPMS[0]}"|sed -e 's/\./\\./g')
86
87 SUCCESS=1
88 rpmqp='rpm -qp --qf %{NAME} --nodigest --nosignature '
89 for opac in ${OLDRPMS[*]}; do
90   npac=${NEWRPMS[0]}
91   NEWRPMS=(${NEWRPMS[@]:1}) # shift
92   echo compare "$opac" "$npac"
93   oname=`$rpmqp $opac`
94   nname=`$rpmqp $npac`
95   if test "$oname" != "$nname"; then
96     echo "names differ: $oname $nname"
97     exit 1
98   fi
99   case "$opac" in
100     *debuginfo*)
101       echo "skipping -debuginfo package"
102     ;;
103     *)
104       bash $CMPSCRIPT "$opac" "$npac" || SUCCESS=0
105       if test $SUCCESS -eq 0 -a -z "$check_all"; then
106         echo "differences between $opac and $npac"
107         exit 1
108       fi
109     ;;
110   esac
111 done
112
113 if [ -n "${NEWRPMS[0]}" ]; then
114   echo additional new package
115   exit 1
116 fi
117
118 # Compare rpmlint.log files
119 if test -d /home/abuild/rpmbuild/OTHER; then
120   OTHERDIR=/home/abuild/rpmbuild/OTHER
121 elif test -d /usr/src/packages/OTHER; then
122   OTHERDIR=/usr/src/packages/OTHER
123 else
124   echo "no OTHERDIR"
125   OTHERDIR=
126 fi
127
128 if test -n "$OTHERDIR"; then
129   if [ $prerelease -eq 1 ] ; then
130     echo "do not compare rpmlint.log if it is a prerelease project!"
131   else
132     if test -e $OLDDIR/rpmlint.log -a -e $OTHERDIR/rpmlint.log; then
133       file1=`mktemp`
134       file2=`mktemp`
135       echo "comparing $OLDDIR/rpmlint.log and $OTHERDIR/rpmlint.log"
136       # Sort the files first since the order of messages is not deterministic
137       # Remove release from files
138       sort -u $OLDDIR/rpmlint.log|sed -e "s,$ver_rel1,@VERSION@-@RELEASE@,g" -e "s|/tmp/rpmlint\..*spec|.spec|g" > $file1
139       sort -u $OTHERDIR/rpmlint.log|sed -e "s,$ver_rel2,@VERSION@-@RELEASE@,g" -e "s|/tmp/rpmlint\..*spec|.spec|g"  > $file2
140       if ! cmp -s $file1 $file2; then
141         echo "rpmlint.log files differ:"
142         diff -u $file1 $file2 |head -n 20
143         SUCCESS=0
144       fi
145       rm $file1 $file2
146     elif test -e $OTHERDIR/rpmlint.log; then
147       echo "rpmlint.log is new"
148       SUCCESS=0
149     fi
150   fi
151
152   appdatas=`cd $OTHERDIR && find . -name *-appdata.xml`
153   for xml in $appdatas; do
154     # compare appstream data
155     if test -e $OLDDIR/$xml -a -e $OTHERDIR/$xml; then
156       file1=$OLDDIR/$xml
157       file2=$OTHERDIR/$xml
158       if ! cmp -s $file1 $file2; then
159         echo "$xml files differ:"
160         diff -u0 $file1 $file2 |head -n 20
161         SUCCESS=0
162       fi
163     elif test -e $OTHERDIR/$xml; then
164       echo "$xml is new"
165       SUCCESS=0
166     fi
167   done
168 fi
169
170 if test $SUCCESS -eq 0; then
171   exit 1
172 fi
173 echo 'compare validated built as identical !'
174 exit 0
175 # vim: tw=666 ts=2 shiftwidth=2 et