common/bin/compareimage.sh

Tue, 18 Sep 2012 11:29:16 -0700

author
ohair
date
Tue, 18 Sep 2012 11:29:16 -0700
changeset 478
2ba6f4da4bf3
parent 458
c8d320b48626
permissions
-rw-r--r--

7197849: Update new build-infra makefiles
Reviewed-by: ihse, erikj, ohrstrom, tbell

ohair@425 1 #!/bin/bash
ohair@425 2 #
ohair@425 3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
ohair@425 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@425 5 #
ohair@425 6 # This code is free software; you can redistribute it and/or modify it
ohair@425 7 # under the terms of the GNU General Public License version 2 only, as
ohair@425 8 # published by the Free Software Foundation.
ohair@425 9 #
ohair@425 10 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@425 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@425 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@425 13 # version 2 for more details (a copy is included in the LICENSE file that
ohair@425 14 # accompanied this code).
ohair@425 15 #
ohair@425 16 # You should have received a copy of the GNU General Public License version
ohair@425 17 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@425 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@425 19 #
ohair@425 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@425 21 # or visit www.oracle.com if you need additional information or have any
ohair@425 22 # questions.
ohair@425 23 #
ohair@425 24
ohair@425 25 # MANUAL
ohair@425 26 #
ohair@425 27 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image
ohair@425 28 #
ohair@425 29 # Compare the directory structure.
ohair@425 30 # Compare the filenames in the directories.
ohair@425 31 # Compare the contents of the zip archives
ohair@425 32 # Compare the contents of the jar archives
ohair@425 33 # Compare the native libraries
ohair@425 34 # Compare the native executables
ohair@425 35 # Compare the remaining files
ohair@425 36 #
ohair@425 37 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]
ohair@425 38 #
ohair@425 39 # Compare only the selected subset of the images.
ohair@425 40 #
ohair@425 41 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar
ohair@425 42 #
ohair@425 43 # Compare only the CodePointIM.jar file
ohair@425 44 # Can be used to compare zips, libraries and executables.
ohair@425 45 #
ohair@425 46
ohair@425 47 if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
erikj@445 48 echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image"
ohair@425 49 echo ""
ohair@425 50 echo "Compare the directory structure."
ohair@425 51 echo "Compare the filenames in the directories."
ohair@425 52 echo "Compare the contents of the zip archives"
ohair@425 53 echo "Compare the contents of the jar archives"
ohair@425 54 echo "Compare the native libraries"
ohair@425 55 echo "Compare the native executables"
ohair@425 56 echo "Compare the remaining files"
ohair@425 57 echo ""
erikj@445 58 echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]"
ohair@425 59 echo ""
ohair@425 60 echo "Compare only the selected subset of the images."
ohair@425 61 echo ""
erikj@445 62 echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar"
ohair@425 63 echo ""
ohair@425 64 echo "Compare only the CodePointIM.jar file"
ohair@425 65 echo "Can be used to compare zips, libraries and executables."
ohair@425 66 exit 10
ohair@425 67 fi
ohair@425 68
ohair@425 69 OLD="$1"
ohair@425 70 NEW="$2"
ohair@425 71 CMD="$3"
ohair@425 72
ohair@425 73 DIFF_RESULT=0
ohair@425 74
ohair@425 75 CMP_ZIPS=false
ohair@425 76 CMP_JARS=false
ohair@425 77 CMP_LIBS=false
ohair@425 78 CMP_EXECS=false
ohair@425 79 CMP_OTHER=false
ohair@425 80
ohair@425 81 FILTER="cat"
ohair@425 82
ohair@425 83 if [ -n "$CMD" ]; then
ohair@425 84 case "$CMD" in
ohair@425 85 zips)
ohair@425 86 CMP_ZIPS=true
ohair@425 87 ;;
ohair@425 88 jars)
ohair@425 89 CMP_JARS=true
ohair@425 90 ;;
ohair@425 91 libs)
ohair@425 92 CMP_LIBS=true
ohair@425 93 ;;
ohair@425 94 execs)
ohair@425 95 CMP_EXECS=true
ohair@425 96 ;;
ohair@425 97 other)
ohair@425 98 CMP_OTHER=true
ohair@425 99 ;;
ohair@425 100 *)
ohair@425 101 CMP_ZIPS=true
ohair@425 102 CMP_JARS=true
ohair@425 103 CMP_LIBS=true
ohair@425 104 CMP_EXECS=true
ohair@425 105 CMP_OTHER=true
ohair@425 106 FILTER="grep $3"
ohair@425 107 ;;
ohair@425 108 esac
ohair@425 109 else
ohair@425 110 CMP_ZIPS=true
ohair@425 111 CMP_JARS=true
ohair@425 112 CMP_LIBS=true
ohair@425 113 CMP_EXECS=true
ohair@425 114 CMP_OTHER=true
ohair@425 115 fi
ohair@425 116
erikj@445 117 DIFFJARZIP="/bin/bash `dirname $0`/diffjarzip.sh"
erikj@445 118 DIFFLIB="/bin/bash `dirname $0`/difflib.sh"
erikj@445 119 DIFFEXEC="/bin/bash `dirname $0`/diffexec.sh"
erikj@445 120 export COMPARE_ROOT=/tmp/cimages.$USER
ohair@425 121 mkdir -p $COMPARE_ROOT
ohair@425 122
ohair@425 123 # Load the correct exception list.
ohair@425 124 case "`uname -s`" in
ohair@425 125 Linux)
ohair@425 126 . `dirname $0`/exception_list_linux
ohair@425 127 ;;
ohair@425 128 esac
ohair@425 129
ohair@425 130 echo
ohair@425 131 echo Comparing $OLD to $NEW
ohair@425 132 echo
ohair@425 133
ohair@425 134 (cd $OLD && find . -type d | sort > $COMPARE_ROOT/from_dirs)
ohair@425 135 (cd $NEW && find . -type d | sort > $COMPARE_ROOT/to_dirs)
ohair@425 136
ohair@425 137 echo -n Directory structure...
ohair@425 138 if diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs > /dev/null; then
ohair@425 139 echo Identical!
ohair@425 140 else
ohair@425 141 echo Differences found.
ohair@425 142 DIFF_RESULT=1
ohair@425 143 # Differences in directories found.
ohair@425 144 ONLY_OLD=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '<')
ohair@425 145 if [ "$ONLY_OLD" ]; then
ohair@425 146 echo Only in $OLD
ohair@425 147 echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
ohair@425 148 fi
ohair@425 149 # Differences in directories found.
ohair@425 150 ONLY_NEW=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '>')
ohair@425 151 if [ "$ONLY_NEW" ]; then
ohair@425 152 echo Only in $NEW
ohair@425 153 echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
ohair@425 154 fi
ohair@425 155 fi
ohair@425 156
ohair@425 157 (cd $OLD && find . -type f | sort > $COMPARE_ROOT/from_files)
ohair@425 158 (cd $NEW && find . -type f | sort > $COMPARE_ROOT/to_files)
ohair@425 159
ohair@425 160 echo -n File names...
ohair@425 161 if diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files > /dev/null; then
ohair@425 162 echo Identical!
ohair@425 163 else
ohair@425 164 echo Differences found.
ohair@425 165 DIFF_RESULT=1
ohair@425 166 # Differences in directories found.
ohair@425 167 ONLY_OLD=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '<')
ohair@425 168 if [ "$ONLY_OLD" ]; then
ohair@425 169 echo Only in $OLD
erikj@445 170 echo "$ONLY_OLD" | sed 's|< ./| |g'
ohair@425 171 fi
ohair@425 172 # Differences in directories found.
ohair@425 173 ONLY_NEW=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '>')
ohair@425 174 if [ "$ONLY_NEW" ]; then
ohair@425 175 echo Only in $NEW
erikj@445 176 echo "$ONLY_NEW" | sed 's|> ./| |g'
ohair@425 177 fi
ohair@425 178 fi
ohair@425 179
erikj@458 180 echo -n Permissions...
erikj@458 181 found=""
erikj@458 182 for f in `cd $OLD && find . -type f`
erikj@458 183 do
erikj@458 184 if [ ! -f ${OLD}/$f ]; then continue; fi
erikj@458 185 if [ ! -f ${NEW}/$f ]; then continue; fi
erikj@458 186 OP=`ls -l ${OLD}/$f | awk '{printf("%.10s\n", $1);}'`
erikj@458 187 NP=`ls -l ${NEW}/$f | awk '{printf("%.10s\n", $1);}'`
erikj@458 188 if [ "$OP" != "$NP" ]
erikj@458 189 then
erikj@458 190 if [ -z "$found" ]; then echo ; found="yes"; fi
erikj@458 191 printf "\told: ${OP} new: ${NP}\t$f\n"
erikj@458 192 fi
erikj@445 193
erikj@458 194 OF=`cd ${OLD} && file $f`
erikj@458 195 NF=`cd ${NEW} && file $f`
erikj@458 196 if [ "$f" = "./src.zip" ]
erikj@458 197 then
erikj@458 198 if [ "`echo $OF | grep -ic zip`" -gt 0 -a "`echo $NF | grep -ic zip`" -gt 0 ]
erikj@445 199 then
erikj@458 200 # the way we produces zip-files make it so that directories are stored in old file
erikj@458 201 # but not in new (only files with full-path)
erikj@458 202 # this makes file-5.09 report them as different
erikj@458 203 continue;
erikj@445 204 fi
erikj@458 205 fi
erikj@458 206
erikj@458 207 if [ "$OF" != "$NF" ]
erikj@458 208 then
erikj@458 209 if [ -z "$found" ]; then echo ; found="yes"; fi
erikj@458 210 printf "\tFILE: old: ${OF} new: ${NF}\t$f\n"
erikj@458 211 fi
erikj@458 212 done
erikj@458 213 if [ -z "$found" ]; then echo ; found="yes"; fi
erikj@445 214
erikj@445 215 GENERAL_FILES=$(cd $OLD && find . -type f ! -name "*.so" ! -name "*.jar" ! -name "*.zip" \
erikj@445 216 ! -name "*.debuginfo" ! -name "*.dylib" ! -name "jexec" \
erikj@458 217 ! -name "ct.sym" ! -name "*.diz" \
erikj@445 218 | grep -v "./bin/" | sort | $FILTER)
erikj@445 219 echo General files...
erikj@445 220 for f in $GENERAL_FILES
erikj@445 221 do
erikj@445 222 if [ -e $NEW/$f ]; then
erikj@445 223 DIFF_OUT=$(diff $OLD/$f $NEW/$f 2>&1)
erikj@445 224 if [ -n "$DIFF_OUT" ]; then
erikj@445 225 echo $f
erikj@445 226 echo "$DIFF_OUT"
erikj@445 227 fi
erikj@445 228 fi
erikj@445 229 done
erikj@445 230
erikj@445 231
ohair@425 232 if [ "x$CMP_ZIPS" == "xtrue" ]; then
ohair@425 233 ZIPS=$(cd $OLD && find . -type f -name "*.zip" | sort | $FILTER)
ohair@425 234
ohair@425 235 if [ -n "$ZIPS" ]; then
ohair@425 236 echo Zip files...
ohair@425 237
ohair@425 238 for f in $ZIPS
ohair@425 239 do
ohair@425 240 $DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW
ohair@425 241 if [ "$?" != "0" ]; then
ohair@425 242 DIFF_RESULT=1
ohair@425 243 fi
ohair@425 244 done
ohair@425 245 fi
ohair@425 246 fi
ohair@425 247
ohair@425 248 if [ "x$CMP_JARS" == "xtrue" ]; then
erikj@445 249 JARS=$(cd $OLD && find . -type f -name "*.jar" -o -name "ct.sym" | sort | $FILTER)
ohair@425 250
ohair@425 251 if [ -n "$JARS" ]; then
ohair@425 252 echo Jar files...
ohair@425 253
ohair@425 254 for f in $JARS
ohair@425 255 do
ohair@425 256 DIFFJAR_OUTPUT=`$DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW`
ohair@425 257 DIFFJAR_RESULT=$?
ohair@425 258 if [ "$DIFFJAR_RESULT" != "0" ]; then
ohair@425 259 for diff in $LIST_DIFF_JAR; do
ohair@425 260 DIFFJAR_OUTPUT=`echo "$DIFFJAR_OUTPUT" | grep -v "$diff"`
ohair@425 261 done
ohair@425 262 if [ "`echo "$DIFFJAR_OUTPUT" | grep -v "Differing files in"`" != "" ]; then
ohair@425 263 DIFF_RESULT=1
ohair@425 264 echo "$DIFFJAR_OUTPUT"
ohair@425 265 fi
ohair@425 266 fi
ohair@425 267 done
ohair@425 268 fi
ohair@425 269 fi
ohair@425 270
ohair@425 271 if [ "x$FILTER" != "xcat" ]; then
ohair@425 272 VIEW=view
ohair@425 273 else
ohair@425 274 VIEW=
ohair@425 275 fi
ohair@425 276
ohair@425 277 if [ "x$CMP_LIBS" == "xtrue" ]; then
ohair@425 278 LIBS=$(cd $OLD && find . -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' | sort | $FILTER)
ohair@425 279
ohair@425 280 if [ -n "$LIBS" ]; then
ohair@425 281 echo Libraries...
ohair@425 282 for f in $LIBS
ohair@425 283 do
ohair@425 284 DIFFLIB_OUTPUT=`$DIFFLIB $OLD/$f $NEW/$f $OLD $NEW $VIEW`
ohair@425 285 DIFFLIB_RESULT=$?
ohair@425 286 if [ "$DIFFLIB_RESULT" = "0" ]; then
ohair@425 287 :
ohair@425 288 #echo "OK: $DIFFLIB_OUTPUT"
ohair@425 289 elif [ "$DIFFLIB_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
ohair@425 290 :
ohair@425 291 #echo "OK: $DIFFLIB_OUTPUT"
ohair@425 292 elif [ "$DIFFLIB_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
ohair@425 293 :
ohair@425 294 #echo "OK: $DIFFLIB_OUTPUT"
ohair@425 295 else
ohair@425 296 echo "$DIFFLIB_OUTPUT"
ohair@425 297 DIFF_RESULT=1
ohair@425 298 fi
ohair@425 299 done
ohair@425 300 fi
ohair@425 301 fi
ohair@425 302
ohair@425 303 if [ "x$CMP_EXECS" == "xtrue" ]; then
ohair@425 304 if [ $OSTYPE == "cygwin" ]; then
ohair@425 305 EXECS=$(cd $OLD && find . -type f -name '*.exe' | sort | $FILTER)
ohair@425 306 else
ohair@425 307 EXECS=$(cd $OLD && find . -type f -perm -100 \! \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' \) | sort | $FILTER)
ohair@425 308 fi
ohair@425 309
ohair@425 310
ohair@425 311 if [ -n "$EXECS" ]; then
ohair@425 312 echo Executables...
ohair@425 313
ohair@425 314 for f in $EXECS
ohair@425 315 do
ohair@425 316 DIFFEXEC_OUTPUT=`$DIFFEXEC $OLD/$f $NEW/$f $OLD $NEW $VIEW`
ohair@425 317 DIFFEXEC_RESULT=$?
ohair@425 318 if [ "$DIFFEXEC_RESULT" = "0" ]; then
ohair@425 319 :
ohair@425 320 #echo "OK: $DIFFEXEC_OUTPUT"
ohair@425 321 elif [ "$DIFFEXEC_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
ohair@425 322 :
ohair@425 323 #echo "OK: $DIFFEXEC_OUTPUT"
ohair@425 324 elif [ "$DIFFEXEC_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
ohair@425 325 :
ohair@425 326 #echo "OK: $DIFFEXEC_OUTPUT"
ohair@425 327 else
ohair@425 328 echo "$DIFFEXEC_OUTPUT"
ohair@425 329 DIFF_RESULT=1
ohair@425 330 fi
ohair@425 331 done
ohair@425 332 fi
ohair@425 333 fi
ohair@425 334
ohair@425 335 exit $DIFF_RESULT

mercurial