3b707a27b927e4aa5288dcf448375f9ad85dc6dd
[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 if test `find $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm' | wc -l` != `find $OLDDIR -name '*.rpm' -and ! -name '*.delta.rpm' | wc -l`; then
34    echo "different number of subpackages"
35    find $OLDDIR $NEWDIRS -name '*.rpm' -and ! -name '*.delta.rpm'
36    exit 1
37 fi
38
39 osrpm=$(find "$OLDDIR" -name \*src.rpm)
40 nsrpm=$(find $NEWDIRS -name \*src.rpm)
41
42 if test ! -f "$osrpm"; then
43   echo no old source rpm in $OLDDIR
44   exit 1
45 fi
46
47 if test ! -f "$nsrpm"; then
48   echo no new source rpm in $NEWDIRS
49   exit 1
50 fi
51
52 echo "compare $osrpm $nsrpm"
53 bash $SCMPSCRIPT "$osrpm" "$nsrpm" || exit 1
54
55 # technically we should not all exclude all -32bit but filter for different archs,
56 # like done with -x86
57 # but it would be better if this script ran earlier in the build
58 # sort the rpms so that both lists have the same order
59 # problem: a package can contain both noarch and arch subpackages, so we have to 
60 # take care of proper sorting of NEWRPMS, e.g. noarch/x.rpm and x86_64/w.rpm since OLDRPMS 
61 # has all the packages in a single directory and would sort this as w.rpm, x.rpm.
62 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'))
63 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'))
64
65 # Get version-release from first RPM and keep for rpmlint check
66 # Remember to quote the "." for future regexes
67 ver_rel1=$(rpm -qp --nodigest --nosignature --qf "%{VERSION}-%{RELEASE}" "${OLDRPMS[0]}"|sed -e 's/\./\\./g')
68 ver_rel2=$(rpm -qp --nodigest --nosignature --qf "%{VERSION}-%{RELEASE}" "${NEWRPMS[0]}"|sed -e 's/\./\\./g')
69
70 SUCCESS=1
71 rpmqp='rpm -qp --qf %{NAME} --nodigest --nosignature '
72 for opac in ${OLDRPMS[*]}; do
73   npac=${NEWRPMS[0]}
74   NEWRPMS=(${NEWRPMS[@]:1}) # shift
75   echo compare "$opac" "$npac"
76   oname=`$rpmqp $opac`
77   nname=`$rpmqp $npac`
78   if test "$oname" != "$nname"; then
79     echo "names differ: $oname $nname"
80     exit 1
81   fi
82   case "$opac" in
83     *debuginfo*)
84       echo "skipping -debuginfo package"
85     ;;
86     *)
87       bash $CMPSCRIPT "$opac" "$npac" || SUCCESS=0
88       if test $SUCCESS -eq 0 -a -z "$check_all"; then
89         echo "differences between $opac and $npac"
90         exit 1
91       fi
92     ;;
93   esac
94 done
95
96 if [ -n "${NEWRPMS[0]}" ]; then
97   echo additional new package
98   exit 1
99 fi
100
101 # Compare rpmlint.log files
102 if test -d /home/abuild/rpmbuild/OTHER; then
103   OTHERDIR=/home/abuild/rpmbuild/OTHER
104 elif test -d /usr/src/packages/OTHER; then
105   OTHERDIR=/usr/src/packages/OTHER
106 else
107   echo "no OTHERDIR"
108   OTHERDIR=
109 fi
110
111 if test -n "$OTHERDIR"; then
112   if test -e $OLDDIR/rpmlint.log -a -e $OTHERDIR/rpmlint.log; then
113     file1=`mktemp`
114     file2=`mktemp`
115     echo "comparing $OLDDIR/rpmlint.log and $OTHERDIR/rpmlint.log"
116     # Sort the files first since the order of messages is not deterministic
117     # Remove release from files
118     sort -u $OLDDIR/rpmlint.log|sed -e "s,$ver_rel1,@VERSION@-@RELEASE@,g" -e "s|/tmp/rpmlint\..*spec|.spec|g" > $file1
119     sort -u $OTHERDIR/rpmlint.log|sed -e "s,$ver_rel2,@VERSION@-@RELEASE@,g" -e "s|/tmp/rpmlint\..*spec|.spec|g"  > $file2
120     if ! cmp -s $file1 $file2; then
121       echo "rpmlint.log files differ:"
122       diff -u $file1 $file2 |head -n 20
123       SUCCESS=0
124     fi
125     rm $file1 $file2
126   elif test -e $OTHERDIR/rpmlint.log; then
127     echo "rpmlint.log is new"
128     SUCCESS=0
129   fi
130
131   appdatas=`cd $OTHERDIR && find . -name *-appdata.xml`
132   for xml in $appdatas; do
133     # compare appstream data
134     if test -e $OLDDIR/$xml -a -e $OTHERDIR/$xml; then
135       file1=$OLDDIR/$xml
136       file2=$OTHERDIR/$xml
137       if ! cmp -s $file1 $file2; then
138         echo "$xml files differ:"
139         diff -u0 $file1 $file2 |head -n 20
140         SUCCESS=0
141       fi
142     elif test -e $OTHERDIR/$xml; then
143       echo "$xml is new"
144       SUCCESS=0
145     fi
146   done
147 fi
148
149 if test $SUCCESS -eq 0; then
150   exit 1
151 fi
152 echo 'compare validated built as identical !'
153 exit 0
154 # vim: tw=666 ts=2 shiftwidth=2 et