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