1 #!/bin/bash
   2 #
   3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 #
   6 # This code is free software; you can redistribute it and/or modify it
   7 # under the terms of the GNU General Public License version 2 only, as
   8 # published by the Free Software Foundation.
   9 #
  10 # This code is distributed in the hope that it will be useful, but WITHOUT
  11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13 # version 2 for more details (a copy is included in the LICENSE file that
  14 # accompanied this code).
  15 #
  16 # You should have received a copy of the GNU General Public License version
  17 # 2 along with this work; if not, write to the Free Software Foundation,
  18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 #
  20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21 # or visit www.oracle.com if you need additional information or have any
  22 # questions.
  23 #
  24 
  25 # This script is processed by configure before it's usable. It is run from 
  26 # the root of the build directory.
  27 
  28 
  29 ##########################################################################################
  30 
  31 # Check that we are run via the wrapper generated by configure
  32 if [ -z "$SRC_ROOT" ]; then
  33     echo "Error: You must run this script using build/[conf]/compare.sh"
  34     exit 1
  35 fi
  36 
  37 if [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
  38     FULLDUMP_CMD="$OTOOL -v -V -h -X -t -d"
  39     LDD_CMD="$OTOOL -L"
  40     DIS_CMD="$OTOOL -v -t"
  41     STAT_PRINT_SIZE="-f %z"
  42 elif [ "$OPENJDK_TARGET_OS" = "windows" ]; then
  43     FULLDUMP_CMD="$DUMPBIN -all"
  44     LDD_CMD="$DUMPBIN -dependants | $GREP .dll"
  45     DIS_CMD="$DUMPBIN -disasm:nobytes"
  46     STAT_PRINT_SIZE="-c %s"
  47 else
  48     FULLDUMP_CMD="$READELF -a"
  49     LDD_CMD="$LDD"
  50     DIS_CMD="$OBJDUMP -d"
  51     STAT_PRINT_SIZE="-c %s"
  52 fi
  53 
  54 UNARCHIVE="$UNZIP -q"
  55 
  56 COMPARE_EXCEPTIONS_INCLUDE="$SRC_ROOT/common/bin/compare_exceptions.sh.incl"
  57 if [ ! -e "$COMPARE_EXCEPTIONS_INCLUDE" ]; then
  58     echo "Error: Cannot locate the exceptions file, it should have been here: $COMPARE_EXCEPTIONS_INCLUDE"
  59     exit 1
  60 fi
  61 # Include exception definitions
  62 . "$COMPARE_EXCEPTIONS_INCLUDE"
  63 
  64 ##########################################################################################
  65 # Compare text files and ignore specific differences:
  66 #
  67 #  * Timestamps in Java sources generated by idl2java
  68 #  * Sorting order and cleanup style in .properties files
  69 
  70 diff_text() {
  71     OTHER_FILE=$1
  72     THIS_FILE=$2
  73 
  74     SUFFIX="${THIS_FILE##*.}"
  75 
  76     TMP=1
  77 
  78     if [[ "$THIS_FILE" = *"META-INF/MANIFEST.MF" ]]; then
  79         TMP=$(LANG=C $DIFF $OTHER_FILE $THIS_FILE | \
  80             $GREP '^[<>]' | \
  81             $SED -e '/[<>] Ant-Version: Apache Ant .*/d' \
  82                  -e '/[<>] Created-By: .* (Oracle Corporation).*/d')
  83     fi
  84     if test "x$SUFFIX" = "xjava"; then
  85         TMP=$(LANG=C $DIFF $OTHER_FILE $THIS_FILE | \
  86             $GREP '^[<>]' | \
  87             $SED -e '/[<>] \* from.*\.idl/d' \
  88                  -e '/[<>] \*.*[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}-b[0-9]\{2\}.*/d' \
  89                  -e '/[<>] \*.*[0-9]\{4\} [0-9][0-9]*:[0-9]\{2\}:[0-9]\{2\}.*/d' \
  90                  -e '/\/\/ Generated from input file.*/d' \
  91                  -e '/\/\/ This file was generated AUTOMATICALLY from a template file.*/d' \
  92                  -e '/\/\/ java GenerateCharacter.*/d')
  93     fi
  94     # Ignore date strings in class files.
  95     # On Macosx the system sources for generated java classes produce different output on 
  96     # consequtive invokations seemingly randomly.
  97     # For example a method parameter randomly named "thePoint" or "aPoint". Ignore this.
  98     if test "x$SUFFIX" = "xclass"; then
  99         # To improve performance when large diffs are found, do a rough filtering of classes
 100         # elibeble for these exceptions
 101         if $GREP -R -e '[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}-b[0-9]\{2\}' -e thePoint -e aPoint -e setItemsPtr ${THIS_FILE} > /dev/null; then
 102             $JAVAP -c -constants -l -p ${OTHER_FILE} >  ${OTHER_FILE}.javap
 103             $JAVAP -c -constants -l -p ${THIS_FILE} > ${THIS_FILE}.javap
 104             TMP=$($DIFF ${OTHER_FILE}.javap ${THIS_FILE}.javap | \
 105                 $GREP '^[<>]' | \
 106                 $SED -e '/[<>].*[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}-b[0-9]\{2\}.*/d' \
 107                      -e '/[<>].*Point   Lcom\/apple\/jobjc\/foundation\/NSPoint;/d' \
 108                      -e '/[<>].*public com\.apple\.jobjc\.Pointer<com\.apple\.jobjc\..*itemsPtr();/d' \
 109                      -e '/[<>].*public void setItemsPtr(com\.apple\.jobjc\.Pointer<com\.apple\.jobjc\..*);/d')
 110         fi
 111     fi
 112     if test "x$SUFFIX" = "xproperties"; then
 113         $CAT $OTHER_FILE | $SED -e 's/\([^\\]\):/\1\\:/g' -e  's/\([^\\]\)=/\1\\=/g' -e 's/#.*/#/g' \
 114             | $SED -f "$SRC_ROOT/common/makefiles/support/unicode2x.sed" \
 115             | $SED -e '/^#/d' -e '/^$/d' \
 116             -e :a -e '/\\$/N; s/\\\n//; ta' \
 117             -e 's/^[ \t]*//;s/[ \t]*$//' \
 118             -e 's/\\=/=/' | LANG=C $SORT > $OTHER_FILE.cleaned
 119         TMP=$(LANG=C $DIFF $OTHER_FILE.cleaned $THIS_FILE)
 120     fi
 121     if test -n "$TMP"; then
 122         echo Files $OTHER_FILE and $THIS_FILE differ
 123         return 1
 124     fi
 125 
 126     return 0
 127 }
 128 
 129 ##########################################################################################
 130 # Compare directory structure
 131 
 132 compare_dirs() {
 133     THIS_DIR=$1
 134     OTHER_DIR=$2
 135     WORK_DIR=$3
 136 
 137     mkdir -p $WORK_DIR
 138 
 139     (cd $OTHER_DIR && $FIND . -type d | $SORT > $WORK_DIR/dirs_other)
 140     (cd $THIS_DIR && $FIND . -type d | $SORT > $WORK_DIR/dirs_this)
 141 
 142     $DIFF $WORK_DIR/dirs_other $WORK_DIR/dirs_other > $WORK_DIR/dirs_diff
 143     
 144     echo -n Directory structure...
 145     if [ -s $WORK_DIR/dirs_diff ]; then
 146         echo Differences found.
 147         REGRESSIONS=true
 148         # Differences in directories found.
 149         ONLY_OTHER=$($GREP '<' $WORK_DIR/dirs_diff)
 150         if [ "$ONLY_OTHER" ]; then
 151             echo Only in $OTHER
 152             $GREP '<' $WORK_DIR/dirs_diff | $SED 's|< ./|    |g'
 153         fi
 154         ONLY_THIS=$($GREP '>' $WORK_DIR/dirs_diff)
 155         if [ "$ONLY_THIS" ]; then
 156             echo Only in $THIS
 157             $GREP '>' $WORK_DIR/dirs_diff | $SED 's|> ./|    |g'
 158         fi
 159     else
 160         echo Identical!
 161     fi
 162 }
 163 
 164 
 165 ##########################################################################################
 166 # Compare file structure
 167 
 168 compare_files() {
 169     THIS_DIR=$1
 170     OTHER_DIR=$2
 171     WORK_DIR=$3
 172 
 173     $MKDIR -p $WORK_DIR
 174 
 175     (cd $OTHER_DIR && $FIND . ! -type d | $SORT > $WORK_DIR/files_other)
 176     (cd $THIS_DIR && $FIND . ! -type d | $SORT > $WORK_DIR/files_this)
 177     
 178     $DIFF $WORK_DIR/files_other $WORK_DIR/files_this > $WORK_DIR/files_diff
 179 
 180     echo -n File names...
 181     if [ -s $WORK_DIR/files_diff ]; then
 182         echo Differences found.
 183         REGRESSIONS=true
 184         # Differences in files found.
 185         ONLY_OTHER=$($GREP '<' $WORK_DIR/files_diff)
 186         if [ "$ONLY_OTHER" ]; then
 187             echo Only in $OTHER
 188             $GREP '<' $WORK_DIR/files_diff | $SED 's|< ./|    |g'
 189         fi
 190         ONLY_THIS=$($GREP '>' $WORK_DIR/files_diff)
 191         if [ "$ONLY_THIS" ]; then
 192             echo Only in $THIS
 193             $GREP '>' $WORK_DIR/files_diff | $SED 's|> ./|    |g'
 194         fi
 195     else
 196         echo Identical!
 197     fi
 198 }
 199 
 200 
 201 ##########################################################################################
 202 # Compare permissions
 203 
 204 compare_permissions() {
 205     THIS_DIR=$1
 206     OTHER_DIR=$2
 207     WORK_DIR=$3
 208 
 209     mkdir -p $WORK_DIR
 210 
 211     echo -n Permissions...
 212     found=""
 213     for f in `cd $OTHER_DIR && $FIND . -type f`
 214     do
 215         if [ ! -f ${OTHER_DIR}/$f ]; then continue; fi
 216         if [ ! -f ${THIS_DIR}/$f ]; then continue; fi
 217         OP=`ls -l ${OTHER_DIR}/$f | awk '{printf("%.10s\n", $1);}'`
 218         TP=`ls -l ${THIS_DIR}/$f | awk '{printf("%.10s\n", $1);}'`
 219         if [ "$OP" != "$TP" ]
 220         then
 221             if [ -z "$found" ]; then echo ; found="yes"; fi
 222             $PRINTF "\told: ${OP} new: ${TP}\t$f\n"
 223         fi
 224     done
 225     if [ -z "$found" ]; then 
 226         echo "Identical!"
 227     else
 228         REGRESSIONS=true
 229     fi
 230 }
 231 
 232 ##########################################################################################
 233 # Compare file command output
 234 
 235 compare_file_types() {
 236     THIS_DIR=$1
 237     OTHER_DIR=$2
 238     WORK_DIR=$3
 239 
 240     $MKDIR -p $WORK_DIR
 241 
 242     echo -n File types...
 243     found=""
 244     for f in `cd $OTHER_DIR && $FIND . ! -type d`
 245     do
 246         if [ ! -f ${OTHER_DIR}/$f ]; then continue; fi
 247         if [ ! -f ${THIS_DIR}/$f ]; then continue; fi
 248         OF=`cd ${OTHER_DIR} && $FILE -h $f`
 249         TF=`cd ${THIS_DIR} && $FILE -h $f`
 250         if [ "$f" = "./src.zip" ] || [[ "$f" = *"/Home/src.zip" ]] || [[ "$f" = *"/lib/JObjC.jar" ]]
 251         then
 252             if [ "`echo $OF | $GREP -ic zip`" -gt 0 -a "`echo $TF | $GREP -ic zip`" -gt 0 ]
 253             then
 254                 # the way we produces zip-files make it so that directories are stored in old file
 255                 # but not in new (only files with full-path)
 256                 # this makes file-5.09 report them as different
 257                 continue;
 258             fi
 259         fi
 260         
 261         if [ "$OF" != "$TF" ]
 262         then
 263             if [ -z "$found" ]; then echo ; found="yes"; fi
 264             $PRINTF "\tother: ${OF}\n\tthis : ${TF}\n"
 265         fi
 266     done
 267     if [ -z "$found" ]; then 
 268         echo "Identical!"
 269     else
 270         REGRESSIONS=true
 271     fi
 272 }
 273 
 274 ##########################################################################################
 275 # Compare the rest of the files
 276 
 277 compare_general_files() {
 278     THIS_DIR=$1
 279     OTHER_DIR=$2
 280     WORK_DIR=$3
 281     
 282     GENERAL_FILES=$(cd $THIS_DIR && $FIND . -type f ! -name "*.so" ! -name "*.jar" ! -name "*.zip" \
 283         ! -name "*.debuginfo" ! -name "*.dylib" ! -name "jexec" \
 284         ! -name "ct.sym" ! -name "*.diz" ! -name "*.dll" \
 285         ! -name "*.pdb" ! -name "*.exp" ! -name "*.ilk" \
 286         ! -name "*.lib" ! -name "*.war" ! -name "JavaControlPanel" \
 287         | $GREP -v "./bin/"  | $SORT | $FILTER)
 288 
 289     echo General files...
 290     for f in $GENERAL_FILES
 291     do
 292         if [ -e $OTHER_DIR/$f ]; then
 293             SUFFIX="${f##*.}"
 294             if [ "$(basename $f)" = "release" ]; then
 295                 # Ignore differences in change numbers in release file.
 296                 OTHER_FILE=$WORK_DIR/$f.other
 297                 THIS_FILE=$WORK_DIR/$f.this
 298                 $MKDIR -p $(dirname $OTHER_FILE)
 299                 $MKDIR -p $(dirname $THIS_FILE)
 300                 $CAT $OTHER_DIR/$f | $SED 's/\:[0-9a-f]\{12,12\}/:CHANGE/g' > $OTHER_FILE
 301                 $CAT $THIS_DIR/$f  | $SED 's/\:[0-9a-f]\{12,12\}/:CHANGE/g' > $THIS_FILE
 302             elif [ "x$SUFFIX" = "xhtml" ]; then
 303                 # Ignore time stamps in docs files
 304                 OTHER_FILE=$WORK_DIR/$f.other
 305                 THIS_FILE=$WORK_DIR/$f.this
 306                 $MKDIR -p $(dirname $OTHER_FILE)
 307                 $MKDIR -p $(dirname $THIS_FILE)
 308                 $CAT $OTHER_DIR/$f | $SED -e 's/\(-- Generated by javadoc \).*\( --\)/\1(removed)\2/' \
 309                                           -e 's/\(<meta name="date" content="\).*\(">\)/\1(removed)\2/' \
 310                                           -e 's/\(Monday\|Tuesday\|Wednesday\|Thursday\|Friday\|Saturday\|Sunday\), [A-Z][a-z]* [0-9][0-9]*, [12][0-9]* [0-9][0-9:]* \(AM\|PM\) [A-Z][A-Z]*/(removed)/' \
 311                                           -e 's/^\( from \).*\(\.idl\)$/\1(removed)\2/' \
 312                     > $OTHER_FILE
 313                 $CAT $THIS_DIR/$f  | $SED -e 's/\(-- Generated by javadoc \).*\( --\)/\1(removed)\2/' \
 314                                           -e 's/\(<meta name="date" content="\).*\(">\)/\1(removed)\2/' \
 315                                           -e 's/\(Monday\|Tuesday\|Wednesday\|Thursday\|Friday\|Saturday\|Sunday\), [A-Z][a-z]* [0-9][0-9]*, [12][0-9]* [0-9][0-9:]* \(AM\|PM\) [A-Z][A-Z]*/(removed)/' \
 316                                           -e 's/^\( from \).*\(\.idl\)$/\1(removed)\2/' \
 317                     > $THIS_FILE
 318             else
 319                 OTHER_FILE=$OTHER_DIR/$f
 320                 THIS_FILE=$THIS_DIR/$f
 321             fi
 322             DIFF_OUT=$($DIFF $OTHER_FILE $THIS_FILE 2>&1)
 323             if [ -n "$DIFF_OUT" ]; then
 324                 echo $f
 325                 REGRESSIONS=true
 326                 if [ "$SHOW_DIFFS" = "true" ]; then
 327                     echo "$DIFF_OUT"
 328                 fi
 329             fi
 330         fi
 331     done
 332 
 333 
 334 }
 335 
 336 ##########################################################################################
 337 # Compare zip file
 338 
 339 compare_zip_file() {
 340     THIS_DIR=$1
 341     OTHER_DIR=$2
 342     WORK_DIR=$3
 343     ZIP_FILE=$4
 344 
 345     THIS_ZIP=$THIS_DIR/$ZIP_FILE
 346     OTHER_ZIP=$OTHER_DIR/$ZIP_FILE
 347 
 348     THIS_SUFFIX="${THIS_ZIP##*.}"
 349     OTHER_SUFFIX="${OTHER_ZIP##*.}"
 350     if [ "$THIS_SUFFIX" != "$OTHER_SUFFIX" ]; then
 351         echo The files do not have the same suffix type!
 352         return 2
 353     fi
 354 
 355     TYPE="$THIS_SUFFIX"
 356 
 357     if $CMP $OTHER_ZIP $THIS_ZIP > /dev/null
 358     then
 359         return 0
 360     fi
 361     # Not quite identical, the might still contain the same data.
 362     # Unpack the jar/zip files in temp dirs
 363     
 364     THIS_UNZIPDIR=$WORK_DIR/$ZIP_FILE.this
 365     OTHER_UNZIPDIR=$WORK_DIR/$ZIP_FILE.other
 366     $RM -rf $THIS_UNZIPDIR $OTHER_UNZIPDIR
 367     $MKDIR -p $THIS_UNZIPDIR
 368     $MKDIR -p $OTHER_UNZIPDIR
 369     (cd $THIS_UNZIPDIR && $UNARCHIVE $THIS_ZIP)
 370     (cd $OTHER_UNZIPDIR && $UNARCHIVE $OTHER_ZIP)
 371 
 372     # Find all archives inside and unzip them as well to compare the contents rather than
 373     # the archives.
 374     EXCEPTIONS=""
 375     for pack in $($FIND $THIS_UNZIPDIR -name "*.pack" -o -name "*.pack.gz"); do
 376         ($UNPACK200 $pack $pack.jar)
 377         # Filter out the unzipped archives from the diff below.
 378         EXCEPTIONS="$EXCEPTIONS $pack $pack.jar"
 379     done
 380     for pack in $($FIND $OTHER_UNZIPDIR -name "*.pack" -o -name "*.pack.gz"); do
 381         ($UNPACK200 $pack $pack.jar)
 382         EXCEPTIONS="$EXCEPTIONS $pack $pack.jar"
 383     done
 384     for zip in $($FIND $THIS_UNZIPDIR -name "*.jar" -o -name "*.zip"); do
 385         $MKDIR $zip.unzip
 386         (cd $zip.unzip && $UNARCHIVE $zip)
 387         EXCEPTIONS="$EXCEPTIONS $zip"
 388     done
 389     for zip in $($FIND $OTHER_UNZIPDIR -name "*.jar" -o -name "*.zip"); do
 390         $MKDIR $zip.unzip
 391         (cd $zip.unzip && $UNARCHIVE $zip)
 392         EXCEPTIONS="$EXCEPTIONS $zip"
 393     done
 394 
 395     CONTENTS_DIFF_FILE=$WORK_DIR/$ZIP_FILE.diff
 396     # On solaris, there is no -q option.
 397     if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 398         LANG=C $DIFF -r $OTHER_UNZIPDIR $THIS_UNZIPDIR \
 399             | $GREP -v -e "^<" -e "^>" -e "^Common subdirectories:" \
 400             > $CONTENTS_DIFF_FILE
 401     else
 402         LANG=C $DIFF -rq $OTHER_UNZIPDIR $THIS_UNZIPDIR > $CONTENTS_DIFF_FILE
 403     fi
 404 
 405     ONLY_OTHER=$($GREP "^Only in $OTHER_UNZIPDIR" $CONTENTS_DIFF_FILE)
 406     ONLY_THIS=$($GREP "^Only in $THIS_UNZIPDIR" $CONTENTS_DIFF_FILE)
 407 
 408     return_value=0
 409 
 410     if [ -n "$ONLY_OTHER" ]; then
 411         echo "        Only OTHER $ZIP_FILE contains:"
 412         echo "$ONLY_OTHER" | sed "s|Only in $OTHER_UNZIPDIR|            |"g | sed 's|: |/|g'
 413         return_value=1
 414     fi
 415 
 416     if [ -n "$ONLY_THIS" ]; then
 417         echo "        Only THIS $ZIP_FILE contains:"
 418         echo "$ONLY_THIS" | sed "s|Only in $THIS_UNZIPDIR|            |"g | sed 's|: |/|g'
 419         return_value=1
 420     fi
 421 
 422     if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 423         DIFFING_FILES=$($GREP -e "differ$" -e "^diff " $CONTENTS_DIFF_FILE \
 424             | $CUT -f 3 -d ' ' | $SED "s|$OTHER_UNZIPDIR/||g")
 425     else
 426         DIFFING_FILES=$($GREP -e "differ$" $CONTENTS_DIFF_FILE \
 427             | $CUT -f 2 -d ' ' | $SED "s|$OTHER_UNZIPDIR/||g")
 428     fi
 429 
 430     $RM -f $WORK_DIR/$ZIP_FILE.diffs
 431     for file in $DIFFING_FILES; do
 432         if [[ "$ACCEPTED_JARZIP_CONTENTS $EXCEPTIONS" != *"$file"* ]]; then
 433             diff_text $OTHER_UNZIPDIR/$file $THIS_UNZIPDIR/$file >> $WORK_DIR/$ZIP_FILE.diffs
 434         fi
 435     done
 436 
 437     if [ -s "$WORK_DIR/$ZIP_FILE.diffs" ]; then
 438         return_value=1
 439         echo "        Differing files in $ZIP_FILE"
 440         $CAT $WORK_DIR/$ZIP_FILE.diffs | $GREP differ | cut -f 2 -d ' ' | \
 441             $SED "s|$OTHER_UNZIPDIR|            |g" > $WORK_DIR/$ZIP_FILE.difflist
 442         $CAT $WORK_DIR/$ZIP_FILE.difflist
 443 
 444         if [ -n "$SHOW_DIFFS" ]; then
 445             for i in $(cat $WORK_DIR/$ZIP_FILE.difflist) ; do
 446                 if [ -f "${OTHER_UNZIPDIR}/$i.javap" ]; then
 447                     LANG=C $DIFF ${OTHER_UNZIPDIR}/$i.javap ${THIS_UNZIPDIR}/$i.javap
 448                 elif [ -f "${OTHER_UNZIPDIR}/$i.cleaned" ]; then
 449                     LANG=C $DIFF ${OTHER_UNZIPDIR}/$i.cleaned ${THIS_UNZIPDIR}/$i
 450                 else
 451                     LANG=C $DIFF ${OTHER_UNZIPDIR}/$i ${THIS_UNZIPDIR}/$i
 452                 fi
 453             done
 454         fi
 455     fi
 456 
 457     return $return_value
 458 }
 459 
 460 
 461 ##########################################################################################
 462 # Compare all zip files
 463 
 464 compare_all_zip_files() {
 465     THIS_DIR=$1
 466     OTHER_DIR=$2
 467     WORK_DIR=$3
 468 
 469     ZIPS=$(cd $THIS_DIR && $FIND . -type f -name "*.zip" | $SORT | $FILTER )
 470 
 471     if [ -n "$ZIPS" ]; then
 472         echo Zip files...
 473 
 474         return_value=0
 475         for f in $ZIPS; do
 476             if [ -f "$OTHER_DIR/$f" ]; then
 477                 compare_zip_file $THIS_DIR $OTHER_DIR $WORK_DIR $f
 478                 if [ "$?" != "0" ]; then
 479                     return_value=1
 480                     REGRESSIONS=true
 481                 fi
 482             fi
 483         done
 484     fi
 485 
 486     return $return_value
 487 }
 488 
 489 ##########################################################################################
 490 # Compare all jar files
 491 
 492 compare_all_jar_files() {
 493     THIS_DIR=$1
 494     OTHER_DIR=$2
 495     WORK_DIR=$3
 496 
 497     # TODO filter?
 498     ZIPS=$(cd $THIS_DIR && $FIND . -type f -name "*.jar" -o -name "*.war" | $SORT | $FILTER)
 499 
 500     if [ -n "$ZIPS" ]; then
 501         echo Jar files...
 502 
 503         return_value=0
 504         for f in $ZIPS; do
 505             if [ -f "$OTHER_DIR/$f" ]; then
 506                 compare_zip_file $THIS_DIR $OTHER_DIR $WORK_DIR $f
 507                 if [ "$?" != "0" ]; then
 508                     return_value=1
 509                     REGRESSIONS=true
 510                 fi
 511             fi
 512         done
 513     fi
 514 
 515     return $return_value
 516 }
 517 
 518 ##########################################################################################
 519 # Compare binary (executable/library) file
 520 
 521 compare_bin_file() {
 522     THIS_DIR=$1
 523     OTHER_DIR=$2
 524     WORK_DIR=$3
 525     BIN_FILE=$4
 526 
 527     THIS_FILE=$THIS_DIR/$BIN_FILE
 528     OTHER_FILE=$OTHER_DIR/$BIN_FILE
 529     NAME=$(basename $BIN_FILE)
 530     WORK_FILE_BASE=$WORK_DIR/$BIN_FILE
 531     FILE_WORK_DIR=$(dirname $WORK_FILE_BASE)
 532 
 533     $MKDIR -p $FILE_WORK_DIR
 534 
 535     ORIG_THIS_FILE="$THIS_FILE"
 536     ORIG_OTHER_FILE="$OTHER_FILE"
 537 
 538     if [[ "$STRIP_BEFORE_COMPARE" = *"$BIN_FILE"* ]]; then
 539         THIS_STRIPPED_FILE=$FILE_WORK_DIR/this/$NAME
 540         OTHER_STRIPPED_FILE=$FILE_WORK_DIR/other/$NAME
 541         $MKDIR -p $FILE_WORK_DIR/this $FILE_WORK_DIR/other
 542         $CP $THIS_FILE $THIS_STRIPPED_FILE
 543         $CP $OTHER_FILE $OTHER_STRIPPED_FILE
 544         $STRIP $THIS_STRIPPED_FILE
 545         $STRIP $OTHER_STRIPPED_FILE
 546         THIS_FILE="$THIS_STRIPPED_FILE"
 547         OTHER_FILE="$OTHER_STRIPPED_FILE"
 548     fi
 549 
 550     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 551         unset _NT_SYMBOL_PATH
 552         # On windows we need to unzip the debug symbols, if present
 553         OTHER_FILE_BASE=${OTHER_FILE/.dll/}
 554         OTHER_FILE_BASE=${OTHER_FILE_BASE/.exe/}
 555         DIZ_NAME=$(basename $OTHER_FILE_BASE).diz
 556         # java.exe and java.dll diz files will have the same name. Have to
 557         # make sure java.exe gets the right one. This is only needed for 
 558         # OTHER since in the new build, all pdb files are left around.
 559         if [ "$NAME" = "java.exe" ] && [ -f "$OTHER/tmp/java/java/obj64/java.diz" ]; then
 560             OTHER_DIZ_FILE="$OTHER/tmp/java/java/obj64/java.diz"
 561         elif [ -f "${OTHER_FILE_BASE}.diz" ]; then
 562             OTHER_DIZ_FILE=${OTHER_FILE_BASE}.diz
 563         else
 564             # Some files, jli.dll, appears twice in the image but only one of
 565             # thme has a diz file next to it.
 566             OTHER_DIZ_FILE="$($FIND $OTHER_DIR -name $DIZ_NAME | $SED 1q)"
 567             if [ ! -f "$OTHER_DIZ_FILE" ]; then
 568                 # As a last resort, look for diz file in the whole build output
 569                 # dir.
 570                 OTHER_DIZ_FILE="$($FIND $OTHER -name $DIZ_NAME | $SED 1q)"
 571             fi
 572         fi
 573         if [ -n "$OTHER_DIZ_FILE" ]; then
 574             $MKDIR -p $FILE_WORK_DIR/other
 575             (cd $FILE_WORK_DIR/other ; $UNARCHIVE -o $OTHER_DIZ_FILE)
 576             export _NT_SYMBOL_PATH="$FILE_WORK_DIR/other"
 577         fi
 578         THIS_FILE_BASE=${THIS_FILE/.dll/}
 579         THIS_FILE_BASE=${THIS_FILE_BASE/.exe/}
 580         if [ -f "${THIS_FILE/.dll/}.diz" ]; then
 581             THIS_DIZ_FILE=${THIS_FILE/.dll/}.diz
 582         else
 583             THIS_DIZ_FILE="$($FIND $THIS_DIR -name $DIZ_NAME | $SED 1q)"
 584             if [ ! -f "$THIS_DIZ_FILE" ]; then
 585                 # As a last resort, look for diz file in the whole build output
 586                 # dir.
 587                 THIS_DIZ_FILE="$($FIND $THIS -name $DIZ_NAME | $SED 1q)"
 588             fi
 589         fi
 590         if [ -n "$THIS_DIZ_FILE" ]; then
 591             $MKDIR -p $FILE_WORK_DIR/this
 592             (cd $FILE_WORK_DIR/this ; $UNARCHIVE -o $THIS_DIZ_FILE)
 593             export _NT_SYMBOL_PATH="$_NT_SYMBOL_PATH;$FILE_WORK_DIR/this"
 594         fi
 595     fi
 596 
 597     if [ -z "$SKIP_BIN_DIFF" ]; then
 598         if cmp $OTHER_FILE $THIS_FILE > /dev/null; then
 599         # The files were bytewise identical.
 600             if [ -n "$VERBOSE" ]; then
 601                 echo "        :           :         :         :          : $BIN_FILE"
 602             fi
 603             return 0
 604         fi
 605         BIN_MSG=" diff "
 606         if [[ "$ACCEPTED_BIN_DIFF" != *"$BIN_FILE"* ]]; then
 607             DIFF_BIN=true
 608             if [[ "$KNOWN_BIN_DIFF" != *"$BIN_FILE"* ]]; then
 609                 BIN_MSG="*$BIN_MSG*"
 610                 REGRESSIONS=true
 611             else
 612                 BIN_MSG=" $BIN_MSG "
 613             fi
 614         else
 615             BIN_MSG="($BIN_MSG)"
 616             DIFF_BIN=
 617         fi
 618     fi
 619 
 620     if [ -n "$STAT" ]; then
 621         THIS_SIZE=$($STAT $STAT_PRINT_SIZE "$THIS_FILE")
 622         OTHER_SIZE=$($STAT $STAT_PRINT_SIZE "$OTHER_FILE")
 623     else
 624         THIS_SIZE=$(ls -l "$THIS_FILE" | awk '{ print $5 }')
 625         OTHER_SIZE=$(ls -l "$OTHER_FILE" | awk '{ print $5 }')
 626     fi
 627     if [ $THIS_SIZE -ne $OTHER_SIZE ]; then
 628         DIFF_SIZE_NUM=$($EXPR $THIS_SIZE - $OTHER_SIZE)
 629         DIFF_SIZE_REL=$($EXPR $THIS_SIZE \* 100 / $OTHER_SIZE)
 630         SIZE_MSG=$($PRINTF "%3d%% %4d" $DIFF_SIZE_REL $DIFF_SIZE_NUM)
 631         if [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* ]] && [ "$DIFF_SIZE_REL" -gt 98 ] \
 632             && [ "$DIFF_SIZE_REL" -lt 102 ]; then
 633             SIZE_MSG="($SIZE_MSG)"
 634             DIFF_SIZE=
 635         elif [ "$OPENJDK_TARGET_OS" = "windows" ] \
 636             && [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* ]] \
 637             && [ "$DIFF_SIZE_NUM" = 512 ]; then
 638             # On windows, size of binaries increase in 512 increments.
 639             SIZE_MSG="($SIZE_MSG)"
 640             DIFF_SIZE=
 641         elif [ "$OPENJDK_TARGET_OS" = "windows" ] \
 642             && [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* ]] \
 643             && [ "$DIFF_SIZE_NUM" = -512 ]; then
 644             # On windows, size of binaries increase in 512 increments.
 645             SIZE_MSG="($SIZE_MSG)"
 646             DIFF_SIZE=
 647         else
 648             if [[ "$ACCEPTED_SIZE_DIFF" != *"$BIN_FILE"* ]]; then
 649                 DIFF_SIZE=true
 650                 if [[ "$KNOWN_SIZE_DIFF" != *"$BIN_FILE"* ]]; then
 651                     SIZE_MSG="*$SIZE_MSG*"
 652                     REGRESSIONS=true
 653                 else
 654                     SIZE_MSG=" $SIZE_MSG "
 655                 fi
 656             else
 657                 SIZE_MSG="($SIZE_MSG)"
 658                 DIFF_SIZE=
 659             fi
 660         fi
 661     else
 662         SIZE_MSG="           "
 663         DIFF_SIZE=
 664         if [[ "$KNOWN_SIZE_DIFF $ACCEPTED_SIZE_DIFF" = *"$BIN_FILE"* ]]; then
 665             SIZE_MSG="     !     "
 666         fi
 667     fi
 668 
 669     if [[ "$SORT_SYMBOLS" = *"$BIN_FILE"* ]]; then
 670         SYM_SORT_CMD="sort"
 671     else
 672         SYM_SORT_CMD="cat"
 673     fi
 674 
 675     # Check symbols
 676     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 677         # The output from dumpbin on windows differs depending on if the debug symbol
 678         # files are still around at the location the binary is pointing too. Need
 679         # to filter out that extra information.
 680         $DUMPBIN -exports $OTHER_FILE | $GREP  -E '^ +[0-9A-F]+ +[0-9A-F]+ [0-9A-F]+' | sed 's/ = .*//g' | cut -c27- | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 681         $DUMPBIN -exports $THIS_FILE  | $GREP  -E '^ +[0-9A-F]+ +[0-9A-F]+ [0-9A-F]+' | sed 's/ = .*//g' | cut -c27- | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 682     elif [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 683         # Some symbols get seemingly random 15 character prefixes. Filter them out.
 684         $NM -a $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SED 's/^\([a-zA-Z] [\.\$]\)[a-zA-Z0-9_\$]\{15,15\}\./\1./g' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 685         $NM -a $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SED 's/^\([a-zA-Z] [\.\$]\)[a-zA-Z0-9_\$]\{15,15\}\./\1./g' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 686     else
 687         $NM -a $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 688         $NM -a $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 689     fi
 690     
 691     LANG=C $DIFF $WORK_FILE_BASE.symbols.other $WORK_FILE_BASE.symbols.this > $WORK_FILE_BASE.symbols.diff
 692     if [ -s $WORK_FILE_BASE.symbols.diff ]; then
 693         SYM_MSG=" diff  "
 694         if [[ "$ACCEPTED_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 695             DIFF_SYM=true
 696             if [[ "$KNOWN_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 697                 SYM_MSG="*$SYM_MSG*"
 698                 REGRESSIONS=true
 699             else
 700                 SYM_MSG=" $SYM_MSG "
 701             fi
 702         else
 703             SYM_MSG="($SYM_MSG)"            
 704             DIFF_SYM=
 705         fi
 706     else
 707         SYM_MSG="         "
 708         DIFF_SYM=
 709         if [[ "$KNOWN_SYM_DIFF $ACCEPTED_SYM_DIFF" = *"$BIN_FILE"* ]]; then
 710             SYM_MSG="    !    "
 711         fi
 712     fi
 713 
 714     # Check dependencies
 715     if [ -n "$LDD_CMD" ]; then
 716         (cd $FILE_WORK_DIR && $CP $OTHER_FILE . && $LDD_CMD $NAME 2>/dev/null | $AWK '{ print $1;}' | $SORT | $TEE $WORK_FILE_BASE.deps.other | $UNIQ > $WORK_FILE_BASE.deps.other.uniq)
 717         (cd $FILE_WORK_DIR && $CP $THIS_FILE . && $LDD_CMD $NAME 2</dev/null | $AWK '{ print $1;}' | $SORT | $TEE $WORK_FILE_BASE.deps.this | $UNIQ > $WORK_FILE_BASE.deps.this.uniq)
 718         (cd $FILE_WORK_DIR && $RM -f $NAME)
 719         
 720         LANG=C $DIFF $WORK_FILE_BASE.deps.other $WORK_FILE_BASE.deps.this > $WORK_FILE_BASE.deps.diff
 721         LANG=C $DIFF $WORK_FILE_BASE.deps.other.uniq $WORK_FILE_BASE.deps.this.uniq > $WORK_FILE_BASE.deps.diff.uniq
 722         
 723         if [ -s $WORK_FILE_BASE.deps.diff ]; then
 724             if [ -s $WORK_FILE_BASE.deps.diff.uniq ]; then
 725                 DEP_MSG=" diff  "
 726             else
 727                 DEP_MSG=" redun "
 728             fi
 729             if [[ "$ACCEPTED_DEP_DIFF" != *"$BIN_FILE"* ]]; then
 730                 DIFF_DEP=true
 731                 if [[ "$KNOWN_DEP_DIFF" != *"$BIN_FILE"* ]]; then
 732                     DEP_MSG="*$DEP_MSG*"
 733                     REGRESSIONS=true
 734                 else
 735                     DEP_MSG=" $DEP_MSG "
 736                 fi
 737             else
 738                 DEP_MSG="($DEP_MSG)"
 739                 DIFF_DEP=
 740             fi
 741         else
 742             DEP_MSG="         "
 743             DIFF_DEP=
 744             if [[ "$KNOWN_DEP_DIFF $ACCEPTED_DEP_DIFF" = *"$BIN_FILE"* ]]; then
 745                 DEP_MSG="     !      "
 746             fi
 747         fi
 748     else
 749         DEP_MSG="    -    "
 750     fi
 751     
 752     # Compare fulldump output
 753     if [ -n "$FULLDUMP_CMD" ] && [ -z "$SKIP_FULLDUMP_DIFF" ]; then
 754         $FULLDUMP_CMD $OTHER_FILE > $WORK_FILE_BASE.fulldump.other 2>&1
 755         $FULLDUMP_CMD $THIS_FILE > $WORK_FILE_BASE.fulldump.this 2>&1
 756         LANG=C $DIFF $WORK_FILE_BASE.fulldump.other $WORK_FILE_BASE.fulldump.this > $WORK_FILE_BASE.fulldump.diff
 757         
 758         if [ -s $WORK_FILE_BASE.fulldump.diff ]; then
 759             ELF_DIFF_SIZE=$(ls -n $WORK_FILE_BASE.fulldump.diff | awk '{print $5}')
 760             ELF_MSG=$($PRINTF "%8d" $ELF_DIFF_SIZE)
 761             if [[ "$ACCEPTED_ELF_DIFF" != *"$BIN_FILE"* ]]; then
 762                 DIFF_ELF=true
 763                 if [[ "$KNOWN_ELF_DIFF" != *"$BIN_FILE"* ]]; then
 764                     ELF_MSG="*$ELF_MSG*"
 765                     REGRESSIONS=true
 766                 else
 767                     ELF_MSG=" $ELF_MSG "
 768                 fi
 769             else
 770                 ELF_MSG="($ELF_MSG)"
 771                 DIFF_ELF=
 772             fi
 773         else
 774             ELF_MSG="          "
 775             DIFF_ELF=
 776             if [[ "$KNOWN_DEP_DIFF $ACCEPTED_DEP_DIFF" = *"$BIN_FILE"* ]]; then
 777                 ELF_MSG="    !    "
 778             fi
 779         fi
 780     fi
 781 
 782     # Compare disassemble output
 783     if [ -n "$DIS_CMD" ] && [ -z "$SKIP_DIS_DIFF" ]; then
 784         if [ -z "$DIS_DIFF_FILTER" ]; then
 785             DIS_DIFF_FILTER="$CAT"
 786         fi
 787         $DIS_CMD $OTHER_FILE | $GREP -v $NAME | $DIS_DIFF_FILTER > $WORK_FILE_BASE.dis.other 2>&1
 788         $DIS_CMD $THIS_FILE  | $GREP -v $NAME | $DIS_DIFF_FILTER > $WORK_FILE_BASE.dis.this  2>&1
 789         
 790         LANG=C $DIFF $WORK_FILE_BASE.dis.other $WORK_FILE_BASE.dis.this > $WORK_FILE_BASE.dis.diff
 791         
 792         if [ -s $WORK_FILE_BASE.dis.diff ]; then
 793             DIS_DIFF_SIZE=$(ls -n $WORK_FILE_BASE.dis.diff | awk '{print $5}')
 794             DIS_MSG=$($PRINTF "%8d" $DIS_DIFF_SIZE)
 795             if [[ "$ACCEPTED_DIS_DIFF" != *"$BIN_FILE"* ]]; then
 796                 DIFF_DIS=true
 797                 if [[ "$KNOWN_DIS_DIFF" != *"$BIN_FILE"* ]]; then
 798                     DIS_MSG="*$DIS_MSG*"
 799                     REGRESSIONS=true
 800                 else
 801                     DIS_MSG=" $DIS_MSG "
 802                 fi
 803             else
 804                 DIS_MSG="($DIS_MSG)"
 805                 DIFF_DIS=
 806             fi
 807         else
 808             DIS_MSG="          "
 809             DIFF_DIS=
 810             if [[ "$KNOWN_DEP_DIFF $ACCEPTED_DEP_DIFF" = *"$BIN_FILE"* ]]; then
 811                 DIS_MSG="    !    "
 812             fi
 813         fi
 814     fi
 815 
 816 
 817     if [ -n "$DIFF_BIN$DIFF_SIZE$DIFF_SYM$DIFF_DEP$DIFF_ELF$DIFF_DIS" ] || [ -n "$VERBOSE" ]; then
 818         if [ -n "$BIN_MSG" ]; then echo -n "$BIN_MSG:"; fi
 819         if [ -n "$SIZE_MSG" ]; then echo -n "$SIZE_MSG:"; fi
 820         if [ -n "$SYM_MSG" ]; then echo -n "$SYM_MSG:"; fi
 821         if [ -n "$DEP_MSG" ]; then echo -n "$DEP_MSG:"; fi
 822         if [ -n "$ELF_MSG" ]; then echo -n "$ELF_MSG:"; fi
 823         if [ -n "$DIS_MSG" ]; then echo -n "$DIS_MSG:"; fi
 824         echo " $BIN_FILE"
 825         if [ "$SHOW_DIFFS" = "true" ]; then
 826             if [ -s "$WORK_FILE_BASE.symbols.diff" ]; then
 827                 echo "Symbols diff:"
 828                 $CAT $WORK_FILE_BASE.symbols.diff
 829             fi
 830             if [ -s "$WORK_FILE_BASE.deps.diff" ]; then
 831                 echo "Deps diff:"
 832                 $CAT $WORK_FILE_BASE.deps.diff
 833             fi
 834             if [ -s "$WORK_FILE_BASE.fulldump.diff" ]; then
 835                 echo "Fulldump diff:"
 836                 $CAT $WORK_FILE_BASE.fulldump.diff
 837             fi
 838             if [ -s "$WORK_FILE_BASE.dis.diff" ]; then
 839                 echo "Disassembly diff:"
 840                 $CAT $WORK_FILE_BASE.dis.diff
 841             fi
 842         fi
 843         return 1
 844     fi
 845     return 0
 846 }
 847 
 848 ##########################################################################################
 849 # Print binary diff header
 850 
 851 print_binary_diff_header() {
 852     if [ -z "$SKIP_BIN_DIFF" ]; then echo -n " Binary :"; fi
 853     if [ -z "$SKIP_SIZE_DIFF" ]; then echo -n "   Size    :"; fi
 854     if [ -z "$SKIP_SYM_DIFF" ]; then echo -n " Symbols :"; fi
 855     if [ -z "$SKIP_DEP_DIFF" ]; then echo -n "  Deps   :"; fi
 856     if [ -z "$SKIP_FULLDUMP_DIFF" ]; then echo -n " Fulldump :"; fi
 857     if [ -z "$SKIP_DIS_DIFF" ]; then echo -n " Disass   :"; fi
 858     echo
 859 }
 860 
 861 ##########################################################################################
 862 # Compare all libraries
 863 
 864 compare_all_libs() {
 865     THIS_DIR=$1
 866     OTHER_DIR=$2
 867     WORK_DIR=$3
 868 
 869     LIBS=$(cd $THIS_DIR && $FIND . -type f \( -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' -o -name 'JavaControlPanel' \) | $SORT | $FILTER)
 870 
 871     if [ -n "$LIBS" ]; then
 872         echo Libraries...
 873         print_binary_diff_header
 874         for l in $LIBS; do
 875             if [ -f "$OTHER_DIR/$l" ]; then
 876                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $l
 877                 if [ "$?" != "0" ]; then
 878                     return_value=1
 879                 fi
 880             fi
 881         done
 882     fi
 883 
 884     return $return_value
 885 }
 886 
 887 ##########################################################################################
 888 # Compare all executables
 889 
 890 compare_all_execs() {
 891     THIS_DIR=$1
 892     OTHER_DIR=$2
 893     WORK_DIR=$3
 894 
 895     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 896         EXECS=$(cd $THIS_DIR && $FIND . -type f -name '*.exe' | $SORT | $FILTER)
 897     else
 898         EXECS=$(cd $THIS_DIR && $FIND . -name db -prune -o -type f -perm -100 \! \
 899             \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' -o -name '*.cgi' \
 900             -o -name '*.jar' -o -name '*.diz' -o -name 'jcontrol' -o -name '*.properties' \
 901             -o -name '*.data' -o -name '*.bfc' -o -name '*.src' -o -name '*.txt' \
 902             -o -name '*.cfg' -o -name 'meta-index' -o -name '*.properties.ja' \
 903             -o -name 'classlist' \) | $SORT | $FILTER)
 904     fi
 905 
 906     if [ -n "$EXECS" ]; then
 907         echo Executables...
 908         print_binary_diff_header
 909         for e in $EXECS; do
 910             if [ -f "$OTHER_DIR/$e" ]; then
 911                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $e
 912                 if [ "$?" != "0" ]; then
 913                     return_value=1
 914                 fi
 915             fi
 916         done
 917     fi
 918 
 919     return $return_value
 920 }
 921 
 922 ##########################################################################################
 923 # Initiate configuration
 924 
 925 COMPARE_ROOT=/tmp/cimages.$USER
 926 $MKDIR -p $COMPARE_ROOT
 927 if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 928     if [ "$(uname -o)" = "Cygwin" ]; then
 929         COMPARE_ROOT=$(cygpath -msa $COMPARE_ROOT)
 930     fi
 931 fi
 932 
 933 THIS="$( cd "$( dirname "$0" )" && pwd )"
 934 echo "$THIS"
 935 THIS_SCRIPT="$0"
 936 
 937 if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "/h" ] || [ "$1" = "/?" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
 938     echo "bash ./compare.sh [OPTIONS] [FILTER]"
 939     echo ""
 940     echo "-all                Compare all files in all known ways"
 941     echo "-names              Compare the file names and directory structure"
 942     echo "-perms              Compare the permission bits on all files and directories"
 943     echo "-types              Compare the output of the file command on all files"
 944     echo "-general            Compare the files not convered by the specialized comparisons"
 945     echo "-zips               Compare the contents of all zip files"
 946     echo "-jars               Compare the contents of all jar files"
 947     echo "-libs               Compare all native libraries"
 948     echo "-execs              Compare all executables"
 949     echo "-v                  Verbose output, does not hide known differences"
 950     echo "-vv                 More verbose output, shows diff output of all comparisons"
 951     echo "-o [OTHER]          Compare with build in other directory. Will default to the old build directory"
 952     echo ""
 953     echo "[FILTER]            List filenames in the image to compare, works for jars, zips, libs and execs"
 954     echo "Example:"
 955     echo "bash ./common/bin/compareimages.sh CodePointIM.jar"
 956     exit 10
 957 fi
 958 
 959 CMP_NAMES=false
 960 CMP_PERMS=false
 961 CMP_TYPES=false
 962 CMP_GENERAL=false
 963 CMP_ZIPS=false
 964 CMP_JARS=false
 965 CMP_LIBS=false
 966 CMP_EXECS=false
 967 
 968 while [ -n "$1" ]; do
 969     case "$1" in
 970         -v)
 971             VERBOSE=true
 972             ;;
 973         -vv)
 974             VERBOSE=true
 975             SHOW_DIFFS=true
 976             ;;
 977         -o)
 978             OTHER="$2"
 979             shift
 980             ;;
 981         -all)
 982             CMP_NAMES=true
 983             if [ "$OPENJDK_TARGET_OS" != "windows" ]; then
 984                 CMP_PERMS=true
 985             fi
 986             CMP_TYPES=true
 987             CMP_GENERAL=true
 988             CMP_ZIPS=true
 989             CMP_JARS=true
 990             CMP_LIBS=true
 991             CMP_EXECS=true
 992             ;;
 993         -names)
 994             CMP_NAMES=true
 995             ;;
 996         -perms)
 997             CMP_PERMS=true
 998             ;;
 999         -types)
1000             CMP_TYPES=true
1001             ;;
1002         -general)
1003             CMP_GENERAL=true
1004             ;;
1005         -zips)
1006             CMP_ZIPS=true
1007             ;;
1008         -jars)
1009             CMP_JARS=true
1010             ;;
1011         -libs)
1012             CMP_LIBS=true
1013             ;;
1014         -execs)
1015             CMP_EXECS=true
1016             ;;
1017         *)
1018             CMP_NAMES=false
1019             CMP_PERMS=false
1020             CMP_TYPES=false
1021             CMP_ZIPS=true
1022             CMP_JARS=true
1023             CMP_LIBS=true
1024             CMP_EXECS=true
1025             
1026             if [ -z "$FILTER" ]; then
1027                 FILTER="$GREP"
1028             fi
1029             FILTER="$FILTER -e $1"
1030             ;;
1031     esac
1032     shift
1033 done
1034 
1035 if [ "$CMP_NAMES" = "false" ] && [ "$CMP_TYPES" = "false" ] && [ "$CMP_PERMS" = "false" ] && [ "$CMP_GENERAL" = "false" ] && [ "$CMP_ZIPS" = "false" ] && [ "$CMP_JARS" = "false" ] && [ "$CMP_LIBS" = "false" ] && [ "$CMP_EXECS" = "false" ]; then
1036     CMP_NAMES=true
1037     CMP_PERMS=true
1038     CMP_TYPES=true
1039     CMP_GENERAL=true
1040     CMP_ZIPS=true
1041     CMP_JARS=true
1042     CMP_LIBS=true
1043     CMP_EXECS=true
1044 fi
1045 
1046 if [ -z "$FILTER" ]; then
1047     FILTER="$CAT"
1048 fi
1049 
1050 if [ -z "$OTHER" ]; then
1051     OTHER="$THIS/../$LEGACY_BUILD_DIR"
1052     if [ -d "$OTHER" ]; then
1053         OTHER="$( cd "$OTHER" && pwd )"
1054     else
1055         echo "Default old build directory does not exist:"
1056         echo "$OTHER"
1057         exit 1
1058     fi
1059     echo "Comparing to default old build:"
1060     echo "$OTHER"
1061     echo
1062 else
1063     if [ ! -d "$OTHER" ]; then
1064         echo "Other build directory does not exist:"
1065         echo "$OTHER"
1066         exit 1
1067     fi
1068     OTHER="$( cd "$OTHER" && pwd )"
1069     echo "Comparing to:"
1070     echo "$OTHER"
1071     echo
1072 fi
1073 
1074 
1075 # Figure out the layout of the this build. Which kinds of images have been produced
1076 if [ -d "$THIS/deploy/j2sdk-image" ]; then
1077     THIS_J2SDK="$THIS/deploy/j2sdk-image"
1078     THIS_J2RE="$THIS/deploy/j2re-image"
1079     echo "Comparing deploy images"
1080 elif [ -d "$THIS/images/j2sdk-image" ]; then
1081     THIS_J2SDK="$THIS/images/j2sdk-image"
1082     THIS_J2RE="$THIS/images/j2re-image"
1083 fi
1084 if [ -d "$THIS/images/j2sdk-overlay-image" ]; then
1085     THIS_J2SDK_OVERLAY="$THIS/images/j2sdk-overlay-image"
1086     THIS_J2RE_OVERLAY="$THIS/images/j2re-overlay-image"
1087 fi
1088 
1089 if [ -d "$THIS/images/j2sdk-bundle" ]; then
1090     THIS_J2SDK_BUNDLE="$THIS/images/j2sdk-bundle"
1091     THIS_J2RE_BUNDLE="$THIS/images/j2re-bundle"
1092 fi
1093 
1094 # Figure out the layout of the other build (old or new, normal or overlay image)
1095 if [ -d "$OTHER/j2sdk-image" ]; then
1096     if [ -f "$OTHER/j2sdk-image/LICENSE" ]; then
1097         OTHER_J2SDK="$OTHER/j2sdk-image"
1098         OTHER_J2RE="$OTHER/j2re-image"
1099     else
1100         OTHER_J2SDK_OVERLAY="$OTHER/j2sdk-image"
1101         OTHER_J2RE_OVERLAY="$OTHER/j2re-image"
1102     fi
1103 
1104 fi
1105 
1106 if [ -d "$OTHER/j2sdk-bundle" ]; then
1107     OTHER_J2SDK_BUNDLE="$OTHER/j2sdk-bundle"
1108     OTHER_J2RE_BUNDLE="$OTHER/j2re-bundle"
1109 elif [ -d "$OTHER/images/j2sdk-bundle" ]; then
1110     OTHER_J2SDK_BUNDLE="$OTHER/images/j2sdk-bundle"
1111     OTHER_J2RE_BUNDLE="$OTHER/images/j2re-bundle"
1112 fi
1113 
1114 if [ -z "$THIS_J2SDK" ] || [ -z "$THIS_J2RE" ]; then
1115     if [ -z "$THIS_J2SDK_OVERLAY" ]; then
1116         echo "Cannot locate images for this build. Are you sure you have run 'make images'?"
1117         exit 1
1118     fi
1119 fi
1120 
1121 if [ -z "$OTHER_J2SDK" ] && [ -n "$OTHER_J2SDK_OVERLAY" ] && [ -z "$THIS_J2SDK_OVERLAY" ]; then
1122     echo "OTHER build only has an overlay image while this build does not. Nothing to compare!"
1123     exit 1
1124 fi
1125 
1126 if [ -z "$THIS_J2SDK_BUNDLE" ] && [ -n "$OTHER_J2SDK_BUNDLE" ]; then
1127     echo "WARNING! OTHER build has bundles built while this build does not."
1128     echo "Skipping bundle compare!"
1129 fi
1130 
1131 if [ -d "$THIS/docs" ]; then
1132     THIS_DOCS="$THIS/docs"
1133 fi
1134 
1135 if [ -d "$OTHER/docs" ]; then
1136     OTHER_DOCS="$OTHER/docs"
1137 fi
1138 
1139 if [ -z "$THIS_DOCS" ]; then
1140     echo "WARNING! Docs haven't been built and won't be compared."
1141 fi
1142 
1143 if [ -z "$OTHER_DOCS" ]; then
1144     echo "WARNING! Other build doesn't contain docs, skipping doc compare."
1145 fi
1146 
1147 ##########################################################################################
1148 # Do the work
1149 
1150 if [ "$CMP_NAMES" = "true" ]; then
1151     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1152         echo -n "J2SDK "
1153         compare_dirs $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1154         echo -n "J2RE  "
1155         compare_dirs $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1156         
1157         echo -n "J2SDK "
1158         compare_files $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1159         echo -n "J2RE  "
1160         compare_files $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1161     fi
1162     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1163         echo -n "J2SDK Overlay "
1164         compare_dirs $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1165         echo -n "J2RE  Overlay "
1166         compare_dirs $THIS_J2RE_OVERLAY $OTHER_J2RE_OVERLAY $COMPARE_ROOT/j2re-overlay
1167         
1168         echo -n "J2SDK Overlay "
1169         compare_files $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1170         echo -n "J2RE  Overlay "
1171         compare_files $THIS_J2RE_OVERLAY $OTHER_J2RE_OVERLAY $COMPARE_ROOT/j2re-overlay
1172     fi
1173     if [ -n "$THIS_J2SDK_BUNDLE" ] && [ -n "$OTHER_J2SDK_BUNDLE" ]; then
1174         echo -n "J2SDK Bundle "
1175         compare_dirs $THIS_J2SDK_BUNDLE $OTHER_J2SDK_BUNDLE $COMPARE_ROOT/j2sdk-bundle
1176         echo -n "J2RE  Bundle "
1177         compare_dirs $THIS_J2RE_BUNDLE $OTHER_J2RE_BUNDLE $COMPARE_ROOT/j2re-bundle
1178         
1179         echo -n "J2SDK Bundle "
1180         compare_files $THIS_J2SDK_BUNDLE $OTHER_J2SDK_BUNDLE $COMPARE_ROOT/j2sdk-bundle
1181         echo -n "J2RE  Bundle "
1182         compare_files $THIS_J2RE_BUNDLE $OTHER_J2RE_BUNDLE $COMPARE_ROOT/j2re-bundle
1183     fi
1184     if [ -n "$THIS_DOCS" ] && [ -n "$OTHER_DOCS" ]; then
1185         echo -n "Docs "
1186         compare_dirs $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1187         echo -n "Docs "
1188         compare_files $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1189     fi
1190 fi
1191 
1192 if [ "$CMP_PERMS" = "true" ]; then
1193     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1194         echo -n "J2SDK "
1195         compare_permissions $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1196         echo -n "J2RE  "
1197         compare_permissions $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1198     fi
1199     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1200         echo -n "J2SDK Overlay "
1201         compare_permissions $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1202         echo -n "J2RE  Overlay "
1203         compare_permissions $THIS_J2RE_OVERLAY $OTHER_J2RE_OVERLAY $COMPARE_ROOT/j2re-overlay
1204     fi
1205     if [ -n "$THIS_J2SDK_BUNDLE" ] && [ -n "$OTHER_J2SDK_BUNDLE" ]; then
1206         echo -n "J2SDK Bundle "
1207         compare_permissions $THIS_J2SDK_BUNDLE $OTHER_J2SDK_BUNDLE $COMPARE_ROOT/j2sdk-bundle
1208         echo -n "J2RE  Bundle "
1209         compare_permissions $THIS_J2RE_BUNDLE $OTHER_J2RE_BUNDLE $COMPARE_ROOT/j2re-bundle
1210     fi
1211 fi
1212 
1213 if [ "$CMP_TYPES" = "true" ]; then
1214     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1215         echo -n "J2SDK "
1216         compare_file_types $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1217         echo -n "J2RE  "
1218         compare_file_types $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1219     fi
1220     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1221         echo -n "J2SDK Overlay "
1222         compare_file_types $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1223         echo -n "J2RE  Overlay "
1224         compare_file_types $THIS_J2RE_OVERLAY $OTHER_J2RE_OVERLAY $COMPARE_ROOT/j2re-overlay
1225     fi
1226     if [ -n "$THIS_J2SDK_BUNDLE" ] && [ -n "$OTHER_J2SDK_BUNDLE" ]; then
1227         echo -n "J2SDK Bundle "
1228         compare_file_types $THIS_J2SDK_BUNDLE $OTHER_J2SDK_BUNDLE $COMPARE_ROOT/j2sdk-bundle
1229         echo -n "J2RE  Bundle "
1230         compare_file_types $THIS_J2RE_BUNDLE $OTHER_J2RE_BUNDLE $COMPARE_ROOT/j2re-bundle
1231     fi
1232 fi
1233 
1234 if [ "$CMP_GENERAL" = "true" ]; then
1235     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1236         echo -n "J2SDK "
1237         compare_general_files $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1238         echo -n "J2RE  "
1239         compare_general_files $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1240     fi
1241     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1242         echo -n "J2SDK Overlay "
1243         compare_general_files $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1244         echo -n "J2RE  Overlay "
1245         compare_general_files $THIS_J2RE_OVERLAY $OTHER_J2RE_OVERLAY $COMPARE_ROOT/j2re-overlay
1246     fi
1247     if [ -n "$THIS_J2SDK_BUNDLE" ] && [ -n "$OTHER_J2SDK_BUNDLE" ]; then
1248         echo -n "J2SDK Bundle "
1249         compare_general_files $THIS_J2SDK_BUNDLE $OTHER_J2SDK_BUNDLE $COMPARE_ROOT/j2sdk-bundle
1250         echo -n "J2RE  Bundle "
1251         compare_general_files $THIS_J2RE_BUNDLE $OTHER_J2RE_BUNDLE $COMPARE_ROOT/j2re-bundle
1252     fi
1253     if [ -n "$THIS_DOCS" ] && [ -n "$OTHER_DOCS" ]; then
1254         echo -n "Docs "
1255         compare_general_files $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1256     fi
1257 fi
1258 
1259 if [ "$CMP_ZIPS" = "true" ]; then
1260     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1261         compare_all_zip_files $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1262     fi
1263 fi
1264 
1265 if [ "$CMP_JARS" = "true" ]; then
1266     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1267         compare_all_jar_files $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1268     fi
1269 fi
1270 
1271 if [ "$CMP_LIBS" = "true" ]; then
1272     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1273         echo -n "J2SDK "
1274         compare_all_libs $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1275         if [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
1276             echo -n "J2RE  "
1277             compare_all_libs $THIS_J2RE $OTHER_J2RE $COMPARE_ROOT/j2re
1278         fi
1279     fi
1280     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1281         echo -n "Bundle   "
1282         compare_all_libs $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1283     fi
1284 fi
1285 
1286 if [ "$CMP_EXECS" = "true" ]; then
1287     if [ -n "$THIS_J2SDK" ] && [ -n "$OTHER_J2SDK" ]; then
1288         compare_all_execs $THIS_J2SDK $OTHER_J2SDK $COMPARE_ROOT/j2sdk
1289     fi
1290     if [ -n "$THIS_J2SDK_OVERLAY" ] && [ -n "$OTHER_J2SDK_OVERLAY" ]; then
1291         echo -n "Overlay "
1292         compare_all_execs $THIS_J2SDK_OVERLAY $OTHER_J2SDK_OVERLAY $COMPARE_ROOT/j2sdk-overlay
1293     fi
1294 fi
1295 
1296 echo
1297 
1298 if [ -n "$REGRESSIONS" ]; then
1299     echo "REGRESSIONS FOUND!"
1300     echo
1301     exit 1
1302 else
1303     echo "No regressions found"
1304     echo
1305     exit 0
1306 fi