1 #!/bin/bash
   2 #
   3 # Copyright (c) 2012, 2018, 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 "$TOPDIR" ]; 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 -d"
  39     LDD_CMD="$OTOOL -L"
  40     DIS_CMD="$OTOOL -v -V -t"
  41     STAT_PRINT_SIZE="-f %z"
  42 elif [ "$OPENJDK_TARGET_OS" = "windows" ]; then
  43     FULLDUMP_CMD="$DUMPBIN -all"
  44     LDD_CMD="$DUMPBIN -dependents"
  45     DIS_CMD="$DUMPBIN -disasm:nobytes"
  46     STAT_PRINT_SIZE="-c %s"
  47 elif [ "$OPENJDK_TARGET_OS" = "aix" ]; then
  48     FULLDUMP_CMD="dump -h -r -t -n -X64"
  49     LDD_CMD="$LDD"
  50     DIS_CMD="$OBJDUMP -d"
  51     STAT_PRINT_SIZE="-c %s"
  52 else
  53     FULLDUMP_CMD="$READELF -a"
  54     LDD_CMD="$LDD"
  55     DIS_CMD="$OBJDUMP -d"
  56     STAT_PRINT_SIZE="-c %s"
  57 fi
  58 
  59 COMPARE_EXCEPTIONS_INCLUDE="$TOPDIR/make/scripts/compare_exceptions.sh.incl"
  60 if [ ! -e "$COMPARE_EXCEPTIONS_INCLUDE" ]; then
  61     echo "Error: Cannot locate the exceptions file, it should have been here: $COMPARE_EXCEPTIONS_INCLUDE"
  62     exit 1
  63 fi
  64 # Include exception definitions
  65 . "$COMPARE_EXCEPTIONS_INCLUDE"
  66 
  67 ################################################################################
  68 #
  69 # Disassembly diff filters. These filters try to filter out ephemeral parts of the
  70 # disassembly, such as hard-coded addresses, to be able to catch "actual" differences.
  71 
  72 if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
  73   if [ "$OPENJDK_TARGET_CPU" = "sparcv9" ]; then
  74     DIS_DIFF_FILTER="$SED \
  75         -e 's/^[0-9a-f]\{16\}/<ADDR>:/' \
  76         -e 's/^ *[0-9a-f]\{3,12\}:/  <ADDR>:/' \
  77         -e 's/: [0-9a-f][0-9a-f]\( [0-9a-f][0-9a-f]\)\{2,10\}/: <NUMS>/' \
  78         -e 's/\$[a-zA-Z0-9_\$]\{15\}\./<SYM>./' \
  79         -e 's/, [0-9a-fx\-]\{1,8\}/, <ADDR>/g' \
  80         -e 's/0x[0-9a-f]\{1,8\}/<HEX>/g' \
  81         -e 's/\! [0-9a-f]\{1,8\} /! <ADDR> /' \
  82         -e 's/call  [0-9a-f]\{4,7\}/call  <ADDR>/' \
  83         -e 's/%hi(0),/%hi(<HEX>),/' \
  84         "
  85   elif [ "$OPENJDK_TARGET_CPU" = "x86_64" ]; then
  86     # Random strings looking like this differ: <.XAKoKoPIac2W0OA.
  87     DIS_DIFF_FILTER="$SED \
  88         -e 's/<\.[A-Za-z0-9]\{\15}\./<.SYM./' \
  89         "
  90   fi
  91 elif [ "$OPENJDK_TARGET_OS" = "windows" ]; then
  92   if [ "$OPENJDK_TARGET_CPU" = "x86" ]; then
  93     DIS_DIFF_FILTER="$SED -r \
  94         -e 's/^  [0-9A-F]{16}: //' \
  95         -e 's/^  [0-9A-F]{8}: /  <ADDR>: /' \
  96         -e 's/(offset \?\?)_C@_.*/\1<SYM>/' \
  97         -e 's/[@?][A-Za-z0-9_]{1,25}/<SYM>/' \
  98         -e 's/([-,+])[0-9A-F]{2,16}/\1<HEXSTR>/g' \
  99         -e 's/\[[0-9A-F]{4,16}h\]/[<HEXSTR>]/' \
 100         -e 's/: ([a-z]{2}[a-z ]{2})        [0-9A-F]{2,16}h?$/: \1        <HEXSTR>/' \
 101         -e 's/_20[0-9]{2}_[0-1][0-9]_[0-9]{2}/_<DATE>/' \
 102         "
 103   elif [ "$OPENJDK_TARGET_CPU" = "x86_64" ]; then
 104     DIS_DIFF_FILTER="$SED -r \
 105         -e 's/^  [0-9A-F]{16}: //' \
 106         -e 's/\[[0-9A-F]{4,16}h\]/[<HEXSTR>]/' \
 107         -e 's/([,+])[0-9A-F]{2,16}h/\1<HEXSTR>/' \
 108         -e 's/([a-z]{2}[a-z ]{2})        [0-9A-F]{4,16}$/\1        <HEXSTR>/' \
 109         -e 's/\[\?\?_C@_.*/[<SYM>]/' \
 110         "
 111   fi
 112 elif [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
 113   DIS_DIFF_FILTER="LANG=C $SED \
 114       -e 's/0x[0-9a-f]\{3,16\}/<HEXSTR>/g' -e 's/^[0-9a-f]\{12,20\}/<ADDR>/' \
 115       -e 's/-20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]-[0-2][0-9]\{5\}/<DATE>/g' \
 116       -e 's/), built on .*/), <DATE>/' \
 117       "
 118 fi
 119 
 120 ################################################################################
 121 # Compare text files and ignore specific differences:
 122 #
 123 #  * Timestamps in Java sources generated by idl2java
 124 #  * Sorting order and cleanup style in .properties files
 125 
 126 diff_text() {
 127     OTHER_FILE=$1
 128     THIS_FILE=$2
 129 
 130     SUFFIX="${THIS_FILE##*.}"
 131     NAME="${THIS_FILE##*/}"
 132 
 133     TMP=1
 134 
 135     if [[ "$THIS_FILE" = *"META-INF/MANIFEST.MF" ]]; then
 136         # Filter out date string, ant version and java version differences.
 137         TMP=$(LC_ALL=C $DIFF $OTHER_FILE $THIS_FILE | \
 138             $GREP '^[<>]' | \
 139             $SED -e '/[<>] Ant-Version: Apache Ant .*/d' \
 140                  -e '/[<>] Created-By: .* (Oracle [Corpatin)]*/d' \
 141                  -e '/[<>]  [Corpatin]*)/d' \
 142                  -e '/[<>].*[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}-b[0-9]\{2\}.*/d')
 143     fi
 144     if test "x$SUFFIX" = "xjava"; then
 145         TMP=$(LC_ALL=C $DIFF $OTHER_FILE $THIS_FILE | \
 146             $GREP '^[<>]' | \
 147             $SED -e '/[<>] \* from.*\.idl/d' \
 148                  -e '/[<>] .*[0-9]\{4\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}-b[0-9]\{2\}.*/d' \
 149                  -e '/[<>] .*[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.*/d' \
 150                  -e '/[<>] \*.*[0-9]\{4\} \(at \)*[0-9][0-9]*:[0-9]\{2\}:[0-9]\{2\}.*/d' \
 151                  -e '/\/\/ Generated from input file.*/d' \
 152                  -e '/\/\/ This file was generated AUTOMATICALLY from a template file.*/d' \
 153                  -e '/\/\/ java GenerateCharacter.*/d')
 154     fi
 155     # Ignore date strings in class files.
 156     # Anonymous lambda classes get randomly assigned counters in their names.
 157     if test "x$SUFFIX" = "xclass"; then
 158         if [ "$NAME" = "SystemModules\$all.class" ] \
 159            || [ "$NAME" = "SystemModules\$default.class" ]; then
 160             # The SystemModules\$*.classes are not comparable as they contain the
 161             # module hashes which would require a whole other level of
 162             # reproducible builds to get reproducible. There is also random
 163             # order of map initialization.
 164             TMP=""
 165         elif [ "$NAME" = "module-info.class" ]; then
 166             # The module-info.class have several issues with random ordering of
 167             # elements in HashSets.
 168             MODULES_CLASS_FILTER="$SED \
 169                 -e 's/,$//' \
 170                 -e 's/;$//' \
 171                 -e 's/^ *[0-9]*://' \
 172                 -e 's/#[0-9]* */#/' \
 173                 -e 's/ *\/\// \/\//' \
 174                 -e 's/aload *[0-9]*/aload X/' \
 175                 -e 's/ldc_w/ldc  /' \
 176                 | $SORT \
 177                 "
 178             $JAVAP -c -constants -l -p "${OTHER_FILE}" \
 179                 | eval "$MODULES_CLASS_FILTER" >  ${OTHER_FILE}.javap &
 180             $JAVAP -c -constants -l -p "${THIS_FILE}" \
 181                 | eval "$MODULES_CLASS_FILTER" > ${THIS_FILE}.javap &
 182             wait
 183             TMP=$($DIFF ${OTHER_FILE}.javap ${THIS_FILE}.javap)
 184         # To improve performance when large diffs are found, do a rough filtering of classes
 185         # elibeble for these exceptions
 186         elif $GREP -R -e '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}' \
 187                 -e 'lambda\$[a-zA-Z0-9]*\$[0-9]' ${THIS_FILE} > /dev/null
 188         then
 189             $JAVAP -c -constants -l -p "${OTHER_FILE}" >  ${OTHER_FILE}.javap &
 190             $JAVAP -c -constants -l -p "${THIS_FILE}" > ${THIS_FILE}.javap &
 191             wait
 192             TMP=$($DIFF ${OTHER_FILE}.javap ${THIS_FILE}.javap | \
 193                 $GREP '^[<>]' | \
 194                 $SED -e '/[<>].*[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.*/d' \
 195                      -e '/[<>].*lambda\$[a-zA-Z0-9]*\$[0-9]*/d')
 196         fi
 197     fi
 198     if test "x$SUFFIX" = "xproperties"; then
 199         # Filter out date string differences.
 200         TMP=$(LC_ALL=C $DIFF $OTHER_FILE $THIS_FILE | \
 201             $GREP '^[<>]' | \
 202             $SED -e '/[<>].*[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}.*/d')
 203     fi
 204     if test "x$SUFFIX" = "xhtml"; then
 205         # Some javadoc versions do not put quotes around font size
 206         HTML_FILTER="$SED \
 207             -e 's/<font size=-1>/<font size=\"-1\">/g'"
 208         $CAT $THIS_FILE | eval "$HTML_FILTER" > $THIS_FILE.filtered
 209         $CAT $OTHER_FILE | eval "$HTML_FILTER" > $OTHER_FILE.filtered
 210         TMP=$(LC_ALL=C $DIFF $OTHER_FILE.filtered $THIS_FILE.filtered | \
 211             $GREP '^[<>]' | \
 212             $SED -e '/[<>] <!-- Generated by javadoc .* on .* -->/d' \
 213                  -e '/[<>] <meta name="date" content=".*">/d' )
 214     fi
 215     if test "$NAME" = "BenchmarkList"; then
 216         $SORT $THIS_FILE > $THIS_FILE.sorted
 217         $SORT $OTHER_FILE > $OTHER_FILE.sorted
 218         TMP=$($DIFF $THIS_FILE.sorted $OTHER_FILE.sorted)
 219     fi
 220     if test -n "$TMP"; then
 221         echo Files $OTHER_FILE and $THIS_FILE differ
 222         return 1
 223     fi
 224 
 225     return 0
 226 }
 227 
 228 ################################################################################
 229 # Compare directory structure
 230 
 231 compare_dirs() {
 232     THIS_DIR=$1
 233     OTHER_DIR=$2
 234     WORK_DIR=$3
 235 
 236     mkdir -p $WORK_DIR
 237 
 238     (cd $OTHER_DIR && $FIND . -type d | $SORT > $WORK_DIR/dirs_other)
 239     (cd $THIS_DIR && $FIND . -type d | $SORT > $WORK_DIR/dirs_this)
 240 
 241     $DIFF $WORK_DIR/dirs_other $WORK_DIR/dirs_this > $WORK_DIR/dirs_diff
 242 
 243     echo -n Directory structure...
 244     if [ -s $WORK_DIR/dirs_diff ]; then
 245         echo Differences found.
 246         REGRESSIONS=true
 247         # Differences in directories found.
 248         ONLY_OTHER=$($GREP '<' $WORK_DIR/dirs_diff)
 249         if [ "$ONLY_OTHER" ]; then
 250             echo Only in $OTHER
 251             $GREP '<' $WORK_DIR/dirs_diff | $SED 's|< ./|    |g'
 252         fi
 253         ONLY_THIS=$($GREP '>' $WORK_DIR/dirs_diff)
 254         if [ "$ONLY_THIS" ]; then
 255             echo Only in $THIS
 256             $GREP '>' $WORK_DIR/dirs_diff | $SED 's|> ./|    |g'
 257         fi
 258     else
 259         echo Identical!
 260     fi
 261 }
 262 
 263 
 264 ################################################################################
 265 # Compare file structure
 266 
 267 compare_files() {
 268     THIS_DIR=$1
 269     OTHER_DIR=$2
 270     WORK_DIR=$3
 271 
 272     $MKDIR -p $WORK_DIR
 273 
 274     (cd $OTHER_DIR && $FIND . ! -type d | $SORT > $WORK_DIR/files_other)
 275     (cd $THIS_DIR && $FIND . ! -type d | $SORT > $WORK_DIR/files_this)
 276 
 277     $DIFF $WORK_DIR/files_other $WORK_DIR/files_this > $WORK_DIR/files_diff
 278 
 279     echo -n File names...
 280     if [ -s $WORK_DIR/files_diff ]; then
 281         echo Differences found.
 282         REGRESSIONS=true
 283         # Differences in files found.
 284         ONLY_OTHER=$($GREP '<' $WORK_DIR/files_diff)
 285         if [ "$ONLY_OTHER" ]; then
 286             echo Only in $OTHER
 287             $GREP '<' $WORK_DIR/files_diff | $SED 's|< ./|    |g'
 288         fi
 289         ONLY_THIS=$($GREP '>' $WORK_DIR/files_diff)
 290         if [ "$ONLY_THIS" ]; then
 291             echo Only in $THIS
 292             $GREP '>' $WORK_DIR/files_diff | $SED 's|> ./|    |g'
 293         fi
 294     else
 295         echo Identical!
 296     fi
 297 }
 298 
 299 
 300 ################################################################################
 301 # Compare permissions
 302 
 303 compare_permissions() {
 304     THIS_DIR=$1
 305     OTHER_DIR=$2
 306     WORK_DIR=$3
 307 
 308     mkdir -p $WORK_DIR
 309 
 310     echo -n Permissions...
 311     found=""
 312     for f in `cd $OTHER_DIR && $FIND . -type f`
 313     do
 314         if [ ! -f ${OTHER_DIR}/$f ]; then continue; fi
 315         if [ ! -f ${THIS_DIR}/$f ]; then continue; fi
 316         OP=`ls -l ${OTHER_DIR}/$f | awk '{printf("%.10s\n", $1);}'`
 317         TP=`ls -l ${THIS_DIR}/$f | awk '{printf("%.10s\n", $1);}'`
 318         if [ "$OP" != "$TP" ]
 319         then
 320             if [ -z "$found" ]; then echo ; found="yes"; fi
 321             $PRINTF "\tother: ${OP} this: ${TP}\t$f\n"
 322         fi
 323     done
 324     if [ -z "$found" ]; then
 325         echo "Identical!"
 326     else
 327         REGRESSIONS=true
 328     fi
 329 }
 330 
 331 ################################################################################
 332 # Compare file command output
 333 
 334 compare_file_types() {
 335     THIS_DIR=$1
 336     OTHER_DIR=$2
 337     WORK_DIR=$3
 338 
 339     $MKDIR -p $WORK_DIR
 340 
 341     FILE_TYPES_FILTER="$SED \
 342         -e 's/BuildID[^,]*//' \
 343         -e 's/last modified: .*//' \
 344         "
 345 
 346     echo -n File types...
 347     found=""
 348     # The file command does not know about jmod files and this sometimes results
 349     # in different types being detected more or less randomly.
 350     for f in $(cd $OTHER_DIR && $FIND . ! -type d -a ! -name "*.jmod")
 351     do
 352         if [ ! -f ${OTHER_DIR}/$f ]; then continue; fi
 353         if [ ! -f ${THIS_DIR}/$f ]; then continue; fi
 354         OF=$(cd ${OTHER_DIR} && $FILE -h $f | eval $FILE_TYPES_FILTER)
 355         TF=$(cd ${THIS_DIR} && $FILE -h $f | eval $FILE_TYPES_FILTER)
 356         if [ "$OF" != "$TF" ]
 357         then
 358             if [ "`echo $OF | $GREP -c 'Zip archive data'`" -gt 0 ] \
 359                 && [ "`echo $TF | $GREP -c 'Zip archive data'`" -gt 0 ]
 360             then
 361                 # the way we produce zip-files make it so that directories are stored in
 362                 # old file but not in new (only files with full-path) this makes file
 363                 # report them as different
 364                 continue
 365             else
 366                 if [ -z "$found" ]; then echo ; found="yes"; fi
 367                 $PRINTF "\tother: ${OF}\n\tthis : ${TF}\n"
 368             fi
 369         fi
 370     done
 371     if [ -z "$found" ]; then
 372         echo "Identical!"
 373     else
 374         REGRESSIONS=true
 375     fi
 376 }
 377 
 378 ################################################################################
 379 # Compare the rest of the files
 380 
 381 compare_general_files() {
 382     THIS_DIR=$1
 383     OTHER_DIR=$2
 384     WORK_DIR=$3
 385 
 386     GENERAL_FILES=$(cd $THIS_DIR && $FIND . -type f ! -name "*.so" ! -name "*.jar" \
 387         ! -name "*.zip" ! -name "*.debuginfo" ! -name "*.dylib" ! -name "jexec" \
 388         ! -name "modules" ! -name "ct.sym" ! -name "*.diz" ! -name "*.dll" \
 389         ! -name "*.cpl" ! -name "*.pdb" ! -name "*.exp" ! -name "*.ilk" \
 390         ! -name "*.lib" ! -name "*.war" ! -name "*.jmod" ! -name "*.exe" \
 391         ! -name "*.obj" ! -name "*.o" ! -name "jspawnhelper" ! -name "*.a" \
 392         ! -name "*.tar.gz" ! -name "classes.jsa" ! -name "gtestLauncher" \
 393         ! -name "*.map" \
 394         | $GREP -v "./bin/"  | $SORT | $FILTER)
 395 
 396     echo Other files with binary differences...
 397     for f in $GENERAL_FILES
 398     do
 399         # Skip all files in test/*/native
 400         if [[ "$f" == */native/* ]]; then
 401             continue
 402         fi
 403         if [ -e $OTHER_DIR/$f ]; then
 404             SUFFIX="${f##*.}"
 405             if [ "$(basename $f)" = "release" ]; then
 406                 # In release file, ignore differences in change numbers and order
 407                 # of modules in list.
 408                 OTHER_FILE=$WORK_DIR/$f.other
 409                 THIS_FILE=$WORK_DIR/$f.this
 410                 $MKDIR -p $(dirname $OTHER_FILE)
 411                 $MKDIR -p $(dirname $THIS_FILE)
 412                 RELEASE_FILTER="$SED \
 413                     -e 's/\:[0-9a-f]\{12,12\}/:CHANGE/g' \
 414                     -e 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6\}/<DATE>/g' \
 415                     -e 's/^#.*/#COMMENT/g' \
 416                     -e 's/MODULES=/MODULES=\'$'\n/' \
 417                     -e 's/,/\'$'\n/g' \
 418                     | $SORT
 419                     "
 420                 $CAT $OTHER_DIR/$f | eval "$RELEASE_FILTER" > $OTHER_FILE
 421                 $CAT $THIS_DIR/$f  | eval "$RELEASE_FILTER" > $THIS_FILE
 422             elif [ "x$SUFFIX" = "xhtml" ]; then
 423                 # Ignore time stamps in docs files
 424                 OTHER_FILE=$WORK_DIR/$f.other
 425                 THIS_FILE=$WORK_DIR/$f.this
 426                 $MKDIR -p $(dirname $OTHER_FILE) $(dirname $THIS_FILE)
 427                 # Older versions of compare might have left soft links with
 428                 # these names.
 429                 $RM $OTHER_FILE $THIS_FILE
 430                 #Note that | doesn't work on mac sed.
 431                 HTML_FILTER="$SED \
 432                     -e 's/20[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{6,7\}/<DATE>/g' \
 433                     -e 's/20[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}/<DATE>/g' \
 434                     -e 's/\(-- Generated by javadoc \).*\( --\)/\1(removed)\2/' \
 435                     -e 's/[A-Z][a-z]*, [A-Z][a-z]* [0-9][0-9]*, [0-9]\{4\} [0-9][0-9:]* [AMP]\{2,2\} [A-Z][A-Z]*/<DATE>/' \
 436                     -e 's/from .*\.idl/\.idl/' \
 437                     "
 438                 $CAT $OTHER_DIR/$f | eval "$HTML_FILTER" > $OTHER_FILE &
 439                 $CAT $THIS_DIR/$f  | eval "$HTML_FILTER" > $THIS_FILE &
 440                 wait
 441             elif [[ "$f" = *"/lib/classlist" ]] || [ "$SUFFIX" = "jar_contents" ]; then
 442                 # The classlist files may have some lines in random order
 443                 OTHER_FILE=$WORK_DIR/$f.other
 444                 THIS_FILE=$WORK_DIR/$f.this
 445                 $MKDIR -p $(dirname $OTHER_FILE) $(dirname $THIS_FILE)
 446                 $RM $OTHER_FILE $THIS_FILE
 447                 $CAT $OTHER_DIR/$f | $SORT > $OTHER_FILE
 448                 $CAT $THIS_DIR/$f  | $SORT > $THIS_FILE
 449             else
 450                 OTHER_FILE=$OTHER_DIR/$f
 451                 THIS_FILE=$THIS_DIR/$f
 452             fi
 453             DIFF_OUT=$($DIFF $OTHER_FILE $THIS_FILE 2>&1)
 454             if [ -n "$DIFF_OUT" ]; then
 455                 echo $f
 456                 REGRESSIONS=true
 457                 if [ "$SHOW_DIFFS" = "true" ]; then
 458                     echo "$DIFF_OUT"
 459                 fi
 460             fi
 461         fi
 462     done
 463 
 464 
 465 }
 466 
 467 ################################################################################
 468 # Compare zip file
 469 
 470 compare_zip_file() {
 471     THIS_DIR=$1
 472     OTHER_DIR=$2
 473     WORK_DIR=$3
 474     ZIP_FILE=$4
 475     # Optionally provide different name for other zipfile
 476     OTHER_ZIP_FILE=$5
 477 
 478     THIS_ZIP=$THIS_DIR/$ZIP_FILE
 479     if [ -n "$OTHER_ZIP_FILE" ]; then
 480         OTHER_ZIP=$OTHER_DIR/$OTHER_ZIP_FILE
 481     else
 482         OTHER_ZIP=$OTHER_DIR/$ZIP_FILE
 483     fi
 484 
 485     THIS_SUFFIX="${THIS_ZIP##*.}"
 486     OTHER_SUFFIX="${OTHER_ZIP##*.}"
 487     if [ "$THIS_SUFFIX" != "$OTHER_SUFFIX" ]; then
 488         echo "The files do not have the same suffix type! ($THIS_SUFFIX != $OTHER_SUFFIX)"
 489         return 2
 490     fi
 491 
 492     TYPE="$THIS_SUFFIX"
 493 
 494     if $CMP $OTHER_ZIP $THIS_ZIP > /dev/null
 495     then
 496         return 0
 497     fi
 498     # Not quite identical, the might still contain the same data.
 499     # Unpack the jar/zip files in temp dirs
 500 
 501     THIS_UNZIPDIR=$WORK_DIR/$ZIP_FILE.this
 502     OTHER_UNZIPDIR=$WORK_DIR/$ZIP_FILE.other
 503     $RM -rf $THIS_UNZIPDIR $OTHER_UNZIPDIR
 504     $MKDIR -p $THIS_UNZIPDIR
 505     $MKDIR -p $OTHER_UNZIPDIR
 506     if [ "$TYPE" = "jar" -o "$TYPE" = "war" -o "$TYPE" = "zip" ]
 507     then
 508         (cd $THIS_UNZIPDIR && $UNARCHIVE $THIS_ZIP)
 509         (cd $OTHER_UNZIPDIR && $UNARCHIVE $OTHER_ZIP)
 510     elif [ "$TYPE" = "gz" ]
 511     then
 512         (cd $THIS_UNZIPDIR && $GUNZIP -c $THIS_ZIP | $TAR xf -)
 513         (cd $OTHER_UNZIPDIR && $GUNZIP -c $OTHER_ZIP | $TAR xf -)
 514     elif [ "$TYPE" = "jmod" ]
 515     then
 516         (cd $THIS_UNZIPDIR && $JMOD extract $THIS_ZIP)
 517         (cd $OTHER_UNZIPDIR && $JMOD extract $OTHER_ZIP)
 518     else
 519         (cd $THIS_UNZIPDIR && $JIMAGE extract $THIS_ZIP)
 520         (cd $OTHER_UNZIPDIR && $JIMAGE extract $OTHER_ZIP)
 521     fi
 522 
 523     # Find all archives inside and unzip them as well to compare the contents rather than
 524     # the archives. pie.jar.pack.gz i app3.war is corrupt, skip it.
 525     EXCEPTIONS="pie.jar.pack.gz jdk.pack"
 526     for pack in $($FIND $THIS_UNZIPDIR \( -name "*.pack" -o -name "*.pack.gz" \) -a \
 527                         ! -name pie.jar.pack.gz -a ! -name jdk.pack); do
 528         ($UNPACK200 $pack $pack.jar)
 529         # Filter out the unzipped archives from the diff below.
 530         EXCEPTIONS="$EXCEPTIONS $pack $pack.jar"
 531     done
 532     for pack in $($FIND $OTHER_UNZIPDIR \( -name "*.pack" -o -name "*.pack.gz" \) -a \
 533                         ! -name pie.jar.pack.gz -a ! -name jdk.pack); do
 534         ($UNPACK200 $pack $pack.jar)
 535         EXCEPTIONS="$EXCEPTIONS $pack $pack.jar"
 536     done
 537     for zip in $($FIND $THIS_UNZIPDIR -name "*.jar" -o -name "*.zip"); do
 538         $MKDIR $zip.unzip
 539         (cd $zip.unzip && $UNARCHIVE $zip)
 540         EXCEPTIONS="$EXCEPTIONS $zip"
 541     done
 542     for zip in $($FIND $OTHER_UNZIPDIR -name "*.jar" -o -name "*.zip"); do
 543         $MKDIR $zip.unzip
 544         (cd $zip.unzip && $UNARCHIVE $zip)
 545         EXCEPTIONS="$EXCEPTIONS $zip"
 546     done
 547 
 548     CONTENTS_DIFF_FILE=$WORK_DIR/$ZIP_FILE.diff
 549     # On solaris, there is no -q option.
 550     if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 551         LC_ALL=C $DIFF -r $OTHER_UNZIPDIR $THIS_UNZIPDIR \
 552             | $GREP -v -e "^<" -e "^>" -e "^Common subdirectories:" \
 553             > $CONTENTS_DIFF_FILE
 554     else
 555         LC_ALL=C $DIFF -rq $OTHER_UNZIPDIR $THIS_UNZIPDIR > $CONTENTS_DIFF_FILE
 556     fi
 557 
 558     ONLY_OTHER=$($GREP "^Only in $OTHER_UNZIPDIR" $CONTENTS_DIFF_FILE)
 559     ONLY_THIS=$($GREP "^Only in $THIS_UNZIPDIR" $CONTENTS_DIFF_FILE)
 560 
 561     return_value=0
 562 
 563     if [ -n "$ONLY_OTHER" ]; then
 564         echo "        Only OTHER $ZIP_FILE contains:"
 565         echo "$ONLY_OTHER" | sed "s|Only in $OTHER_UNZIPDIR|            |"g | sed 's|: |/|g'
 566         return_value=1
 567     fi
 568 
 569     if [ -n "$ONLY_THIS" ]; then
 570         echo "        Only THIS $ZIP_FILE contains:"
 571         echo "$ONLY_THIS" | sed "s|Only in $THIS_UNZIPDIR|            |"g | sed 's|: |/|g'
 572         return_value=1
 573     fi
 574 
 575     if [ "$CMP_ZIPS_CONTENTS" = "true" ]; then
 576         if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 577             DIFFING_FILES=$($GREP -e 'differ$' -e '^diff ' $CONTENTS_DIFF_FILE \
 578                 | $SED -e 's/^Files //g' -e 's/diff -r //g' | $CUT -f 1 -d ' ' \
 579                 | $SED "s|$OTHER_UNZIPDIR/||g")
 580         else
 581             DIFFING_FILES=$($GREP -e "differ$" $CONTENTS_DIFF_FILE \
 582                 | $CUT -f 2 -d ' ' | $SED "s|$OTHER_UNZIPDIR/||g")
 583         fi
 584 
 585         $RM -f $WORK_DIR/$ZIP_FILE.diffs
 586         for file in $DIFFING_FILES; do
 587             if [[ "$ACCEPTED_JARZIP_CONTENTS $EXCEPTIONS" != *"$file"* ]]; then
 588                 diff_text $OTHER_UNZIPDIR/$file $THIS_UNZIPDIR/$file >> $WORK_DIR/$ZIP_FILE.diffs
 589             fi
 590         done
 591 
 592         if [ -s "$WORK_DIR/$ZIP_FILE.diffs" ]; then
 593             return_value=1
 594             echo "        Differing files in $ZIP_FILE"
 595             $CAT $WORK_DIR/$ZIP_FILE.diffs | $GREP 'differ$' | cut -f 2 -d ' ' | \
 596                 $SED "s|$OTHER_UNZIPDIR|            |g" > $WORK_DIR/$ZIP_FILE.difflist
 597             $CAT $WORK_DIR/$ZIP_FILE.difflist
 598 
 599             if [ -n "$SHOW_DIFFS" ]; then
 600                 for i in $(cat $WORK_DIR/$ZIP_FILE.difflist) ; do
 601                     if [ -f "${OTHER_UNZIPDIR}/$i.javap" ]; then
 602                         LC_ALL=C $DIFF ${OTHER_UNZIPDIR}/$i.javap ${THIS_UNZIPDIR}/$i.javap
 603                     elif [ -f "${OTHER_UNZIPDIR}/$i.cleaned" ]; then
 604                         LC_ALL=C $DIFF ${OTHER_UNZIPDIR}/$i.cleaned ${THIS_UNZIPDIR}/$i
 605                     else
 606                         LC_ALL=C $DIFF ${OTHER_UNZIPDIR}/$i ${THIS_UNZIPDIR}/$i
 607                     fi
 608                 done
 609             fi
 610         fi
 611     fi
 612 
 613     return $return_value
 614 }
 615 
 616 ################################################################################
 617 # Compare jmod file
 618 
 619 compare_jmod_file() {
 620     THIS_DIR=$1
 621     OTHER_DIR=$2
 622     WORK_DIR=$3
 623     JMOD_FILE=$4
 624 
 625     THIS_JMOD=$THIS_DIR/$JMOD_FILE
 626     OTHER_JMOD=$OTHER_DIR/$JMOD_FILE
 627 
 628     if $CMP $OTHER_JMOD $THIS_JMOD > /dev/null; then
 629         return 0
 630     fi
 631 
 632     THIS_JMOD_LIST=$WORK_DIR/$JMOD_FILE.list.this
 633     OTHER_JMOD_LIST=$WORK_DIR/$JMOD_FILE.list.other
 634     mkdir -p $(dirname $THIS_JMOD_LIST) $(dirname $OTHER_JMOD_LIST)
 635 
 636     $JMOD list $THIS_JMOD | sort > $THIS_JMOD_LIST
 637     $JMOD list $OTHER_JMOD | sort > $OTHER_JMOD_LIST
 638     JMOD_LIST_DIFF_FILE=$WORK_DIR/$JMOD_FILE.list.diff
 639     LC_ALL=C $DIFF $THIS_JMOD_LIST $OTHER_JMOD_LIST > $JMOD_LIST_DIFF_FILE
 640 
 641     ONLY_THIS=$($GREP "^<" $JMOD_LIST_DIFF_FILE)
 642     ONLY_OTHER=$($GREP "^>" $JMOD_LIST_DIFF_FILE)
 643 
 644     if [ -n "$ONLY_OTHER" ]; then
 645         echo "        Only OTHER $JMOD_FILE contains:"
 646         echo "$ONLY_OTHER" | sed "s|^>|            |"g | sed 's|: |/|g'
 647         return_value=1
 648     fi
 649 
 650     if [ -n "$ONLY_THIS" ]; then
 651         echo "        Only THIS $JMOD_FILE contains:"
 652         echo "$ONLY_THIS" | sed "s|^<|            |"g | sed 's|: |/|g'
 653         return_value=1
 654     fi
 655 
 656     return $return_value
 657 }
 658 
 659 ################################################################################
 660 # Compare all zip files
 661 
 662 compare_all_zip_files() {
 663     THIS_DIR=$1
 664     OTHER_DIR=$2
 665     WORK_DIR=$3
 666 
 667     ZIPS=$(cd $THIS_DIR && $FIND . -type f -name "*.zip" -o -name "*.tar.gz" \
 668         | $SORT | $FILTER )
 669 
 670     if [ -n "$ZIPS" ]; then
 671         echo Zip/tar.gz files...
 672 
 673         return_value=0
 674         for f in $ZIPS; do
 675             if [ -f "$OTHER_DIR/$f" ]; then
 676                 compare_zip_file $THIS_DIR $OTHER_DIR $WORK_DIR $f
 677                 if [ "$?" != "0" ]; then
 678                     return_value=1
 679                     REGRESSIONS=true
 680                 fi
 681             fi
 682         done
 683     fi
 684 
 685     return $return_value
 686 }
 687 
 688 ################################################################################
 689 # Compare all jmod files
 690 
 691 compare_all_jmod_files() {
 692     THIS_DIR=$1
 693     OTHER_DIR=$2
 694     WORK_DIR=$3
 695 
 696     JMODS=$(cd $THIS_DIR && $FIND . -type f -name "*.jmod" | $SORT | $FILTER )
 697 
 698     if [ -n "$JMODS" ]; then
 699         echo Jmod files...
 700 
 701         return_value=0
 702         for f in $JMODS; do
 703             if [ -f "$OTHER_DIR/$f" ]; then
 704                 compare_jmod_file $THIS_DIR $OTHER_DIR $WORK_DIR $f
 705                 if [ "$?" != "0" ]; then
 706                     return_value=1
 707                     REGRESSIONS=true
 708                 fi
 709             fi
 710         done
 711     fi
 712 
 713     return $return_value
 714 }
 715 
 716 ################################################################################
 717 # Compare all jar files
 718 
 719 compare_all_jar_files() {
 720     THIS_DIR=$1
 721     OTHER_DIR=$2
 722     WORK_DIR=$3
 723 
 724     # TODO filter?
 725     ZIPS=$(cd $THIS_DIR && $FIND . -type f -name "*.jar" -o -name "*.war" \
 726         -o -name "modules" | $SORT | $FILTER)
 727 
 728     if [ -n "$ZIPS" ]; then
 729         echo Jar files...
 730 
 731         return_value=0
 732         for f in $ZIPS; do
 733             if [ -f "$OTHER_DIR/$f" ]; then
 734                 compare_zip_file $THIS_DIR $OTHER_DIR $WORK_DIR $f
 735                 if [ "$?" != "0" ]; then
 736                     return_value=1
 737                     REGRESSIONS=true
 738                 fi
 739             fi
 740         done
 741     fi
 742 
 743     return $return_value
 744 }
 745 
 746 ################################################################################
 747 # Compare binary (executable/library) file
 748 
 749 compare_bin_file() {
 750     THIS_DIR=$1
 751     OTHER_DIR=$2
 752     WORK_DIR=$3
 753     BIN_FILE=$4
 754     OTHER_BIN_FILE=$5
 755 
 756     THIS_FILE=$THIS_DIR/$BIN_FILE
 757     if [ -n "$OTHER_BIN_FILE" ]; then
 758         OTHER_FILE=$OTHER_DIR/$OTHER_BIN_FILE
 759     else
 760         OTHER_FILE=$OTHER_DIR/$BIN_FILE
 761     fi
 762     NAME=$(basename $BIN_FILE)
 763     WORK_FILE_BASE=$WORK_DIR/$BIN_FILE
 764     FILE_WORK_DIR=$(dirname $WORK_FILE_BASE)
 765 
 766     $MKDIR -p $FILE_WORK_DIR
 767 
 768     # Make soft links to original files from work dir to facilitate debugging
 769     $LN -f -s $THIS_FILE $WORK_FILE_BASE.this
 770     $LN -f -s $OTHER_FILE $WORK_FILE_BASE.other
 771 
 772     ORIG_THIS_FILE="$THIS_FILE"
 773     ORIG_OTHER_FILE="$OTHER_FILE"
 774 
 775     if [ "$STRIP_ALL" = "true" ] || [[ "$STRIP_BEFORE_COMPARE" = *"$BIN_FILE"* ]]; then
 776         THIS_STRIPPED_FILE=$FILE_WORK_DIR/this/$NAME
 777         OTHER_STRIPPED_FILE=$FILE_WORK_DIR/other/$NAME
 778         $MKDIR -p $FILE_WORK_DIR/this $FILE_WORK_DIR/other
 779         $CP $THIS_FILE $THIS_STRIPPED_FILE
 780         $CP $OTHER_FILE $OTHER_STRIPPED_FILE
 781         $STRIP $THIS_STRIPPED_FILE
 782         $STRIP $OTHER_STRIPPED_FILE
 783         THIS_FILE="$THIS_STRIPPED_FILE"
 784         OTHER_FILE="$OTHER_STRIPPED_FILE"
 785     fi
 786 
 787     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 788         unset _NT_SYMBOL_PATH
 789         if [ "$(uname -o)" = "Cygwin" ]; then
 790             THIS=$(cygpath -msa $THIS)
 791             OTHER=$(cygpath -msa $OTHER)
 792         fi
 793         # Build an _NT_SYMBOL_PATH that contains all known locations for
 794         # pdb files.
 795         PDB_DIRS="$(ls -d \
 796             {$OTHER,$THIS}/support/modules_{cmds,libs}/{*,*/*} \
 797             {$OTHER,$THIS}/support/native/java.base/java_objs \
 798             )"
 799         export _NT_SYMBOL_PATH="$(echo $PDB_DIRS | tr ' ' ';')"
 800     fi
 801 
 802     if cmp $OTHER_FILE $THIS_FILE > /dev/null; then
 803         # The files were bytewise identical.
 804         if [ -n "$VERBOSE" ]; then
 805             echo "        :           :         :         :          :          : $BIN_FILE"
 806         fi
 807         return 0
 808     fi
 809     if [ -z "$SKIP_BIN_DIFF" ]; then
 810         BIN_MSG=" diff "
 811         if [[ "$ACCEPTED_BIN_DIFF" != *"$BIN_FILE"* ]]; then
 812             DIFF_BIN=true
 813             if [[ "$KNOWN_BIN_DIFF" != *"$BIN_FILE"* ]]; then
 814                 BIN_MSG="*$BIN_MSG*"
 815                 REGRESSIONS=true
 816             else
 817                 BIN_MSG=" $BIN_MSG "
 818             fi
 819         else
 820             BIN_MSG="($BIN_MSG)"
 821             DIFF_BIN=
 822         fi
 823     fi
 824 
 825     if [ -n "$STAT" ]; then
 826         THIS_SIZE=$($STAT $STAT_PRINT_SIZE "$THIS_FILE")
 827         OTHER_SIZE=$($STAT $STAT_PRINT_SIZE "$OTHER_FILE")
 828     else
 829         THIS_SIZE=$(ls -l "$THIS_FILE" | awk '{ print $5 }')
 830         OTHER_SIZE=$(ls -l "$OTHER_FILE" | awk '{ print $5 }')
 831     fi
 832     if [ $THIS_SIZE -ne $OTHER_SIZE ]; then
 833         DIFF_SIZE_NUM=$($EXPR $THIS_SIZE - $OTHER_SIZE)
 834         DIFF_SIZE_REL=$($EXPR $THIS_SIZE \* 100 / $OTHER_SIZE)
 835         SIZE_MSG=$($PRINTF "%3d%% %4d" $DIFF_SIZE_REL $DIFF_SIZE_NUM)
 836         if [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* || "$ACCEPTED_SMALL_SIZE_DIFF" = "true" ]] \
 837             && [ "$DIFF_SIZE_REL" -gt 98 ] \
 838             && [ "$DIFF_SIZE_REL" -lt 102 ]; then
 839             SIZE_MSG="($SIZE_MSG)"
 840             DIFF_SIZE=
 841         elif [ "$OPENJDK_TARGET_OS" = "windows" ] \
 842             && [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* ]] \
 843             && [ "$DIFF_SIZE_NUM" = 512 ]; then
 844             # On windows, size of binaries increase in 512 increments.
 845             SIZE_MSG="($SIZE_MSG)"
 846             DIFF_SIZE=
 847         elif [ "$OPENJDK_TARGET_OS" = "windows" ] \
 848             && [[ "$ACCEPTED_SMALL_SIZE_DIFF" = *"$BIN_FILE"* ]] \
 849             && [ "$DIFF_SIZE_NUM" = -512 ]; then
 850             # On windows, size of binaries increase in 512 increments.
 851             SIZE_MSG="($SIZE_MSG)"
 852             DIFF_SIZE=
 853         else
 854             if [[ "$ACCEPTED_SIZE_DIFF" != *"$BIN_FILE"* ]]; then
 855                 DIFF_SIZE=true
 856                 if [[ "$KNOWN_SIZE_DIFF" != *"$BIN_FILE"* ]]; then
 857                     SIZE_MSG="*$SIZE_MSG*"
 858                     REGRESSIONS=true
 859                 else
 860                     SIZE_MSG=" $SIZE_MSG "
 861                 fi
 862             else
 863                 SIZE_MSG="($SIZE_MSG)"
 864                 DIFF_SIZE=
 865             fi
 866         fi
 867     else
 868         SIZE_MSG="           "
 869         DIFF_SIZE=
 870         if [[ "$KNOWN_SIZE_DIFF $ACCEPTED_SIZE_DIFF" = *"$BIN_FILE"* ]]; then
 871             SIZE_MSG="     !     "
 872         fi
 873     fi
 874 
 875     if [ "$SORT_ALL_SYMBOLS" = "true" ] || [[ "$SORT_SYMBOLS" = *"$BIN_FILE"* ]]; then
 876         SYM_SORT_CMD="sort"
 877     else
 878         SYM_SORT_CMD="cat"
 879     fi
 880 
 881     if [ -n "$SYMBOLS_DIFF_FILTER" ] && [ -z "$NEED_SYMBOLS_DIFF_FILTER" ] \
 882             || [[ "$NEED_SYMBOLS_DIFF_FILTER" = *"$BIN_FILE"* ]]; then
 883         this_SYMBOLS_DIFF_FILTER="$SYMBOLS_DIFF_FILTER"
 884     else
 885         this_SYMBOLS_DIFF_FILTER="$CAT"
 886     fi
 887 
 888     # Check symbols
 889     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 890         # The output from dumpbin on windows differs depending on if the debug symbol
 891         # files are still around at the location the binary is pointing too. Need
 892         # to filter out that extra information.
 893         $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
 894         $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
 895     elif [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 896         # Some symbols get seemingly random 15 character prefixes. Filter them out.
 897         $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
 898         $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
 899     elif [ "$OPENJDK_TARGET_OS" = "aix" ]; then
 900         $OBJDUMP -T $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 901         $OBJDUMP -T $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 902     elif [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
 903         $NM -j $ORIG_OTHER_FILE 2> /dev/null | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 904         $NM -j $ORIG_THIS_FILE  2> /dev/null | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 905     else
 906         $NM -a $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME \
 907             | $AWK '{print $2, $3, $4, $5}' \
 908             | eval "$this_SYMBOLS_DIFF_FILTER" \
 909             | $SYM_SORT_CMD \
 910             > $WORK_FILE_BASE.symbols.other
 911         $NM -a $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME \
 912             | $AWK '{print $2, $3, $4, $5}' \
 913             | eval "$this_SYMBOLS_DIFF_FILTER" \
 914             | $SYM_SORT_CMD \
 915             > $WORK_FILE_BASE.symbols.this
 916     fi
 917 
 918     LC_ALL=C $DIFF $WORK_FILE_BASE.symbols.other $WORK_FILE_BASE.symbols.this > $WORK_FILE_BASE.symbols.diff
 919     if [ -s $WORK_FILE_BASE.symbols.diff ]; then
 920         SYM_MSG=" diff  "
 921         if [[ "$ACCEPTED_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 922             DIFF_SYM=true
 923             if [[ "$KNOWN_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 924                 SYM_MSG="*$SYM_MSG*"
 925                 REGRESSIONS=true
 926             else
 927                 SYM_MSG=" $SYM_MSG "
 928             fi
 929         else
 930             SYM_MSG="($SYM_MSG)"
 931             DIFF_SYM=
 932         fi
 933     else
 934         SYM_MSG="         "
 935         DIFF_SYM=
 936         if [[ "$KNOWN_SYM_DIFF $ACCEPTED_SYM_DIFF" = *"$BIN_FILE"* ]]; then
 937             SYM_MSG="    !    "
 938         fi
 939     fi
 940 
 941     # Check dependencies
 942     if [ -n "$LDD_CMD" ]; then
 943         if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 944             LDD_FILTER="$GREP \.dll"
 945         else
 946             LDD_FILTER="$CAT"
 947         fi
 948         (cd $FILE_WORK_DIR && $CP $OTHER_FILE . && $LDD_CMD $NAME 2>/dev/null \
 949                     | $LDD_FILTER | $AWK '{ print $1;}' | $SORT \
 950                     | $TEE $WORK_FILE_BASE.deps.other \
 951                     | $UNIQ > $WORK_FILE_BASE.deps.other.uniq)
 952         (cd $FILE_WORK_DIR && $CP $THIS_FILE . && $LDD_CMD $NAME 2</dev/null \
 953                     | $LDD_FILTER | $AWK '{ print $1;}' | $SORT \
 954                     | $TEE $WORK_FILE_BASE.deps.this \
 955                     | $UNIQ > $WORK_FILE_BASE.deps.this.uniq)
 956         (cd $FILE_WORK_DIR && $RM -f $NAME)
 957 
 958         LC_ALL=C $DIFF $WORK_FILE_BASE.deps.other $WORK_FILE_BASE.deps.this \
 959               > $WORK_FILE_BASE.deps.diff
 960         LC_ALL=C $DIFF $WORK_FILE_BASE.deps.other.uniq $WORK_FILE_BASE.deps.this.uniq \
 961               > $WORK_FILE_BASE.deps.diff.uniq
 962 
 963         if [ -s $WORK_FILE_BASE.deps.diff ]; then
 964             if [ -s $WORK_FILE_BASE.deps.diff.uniq ]; then
 965                 DEP_MSG=" diff  "
 966             else
 967                 DEP_MSG=" redun "
 968             fi
 969             if [[ "$ACCEPTED_DEP_DIFF" != *"$BIN_FILE"* ]]; then
 970                 DIFF_DEP=true
 971                 if [[ "$KNOWN_DEP_DIFF" != *"$BIN_FILE"* ]]; then
 972                     DEP_MSG="*$DEP_MSG*"
 973                     REGRESSIONS=true
 974                 else
 975                     DEP_MSG=" $DEP_MSG "
 976                 fi
 977             else
 978                 DEP_MSG="($DEP_MSG)"
 979                 DIFF_DEP=
 980             fi
 981         else
 982             DEP_MSG="         "
 983             DIFF_DEP=
 984             if [[ "$KNOWN_DEP_DIFF $ACCEPTED_DEP_DIFF" = *"$BIN_FILE"* ]]; then
 985                 DEP_MSG="     !      "
 986             fi
 987         fi
 988     else
 989         DEP_MSG="    -    "
 990     fi
 991 
 992     # Some linux compilers add a unique Build ID
 993     if [ "$OPENJDK_TARGET_OS" = "linux" ]; then
 994       BUILD_ID_FILTER="$SED -r 's/(Build ID:) [0-9a-f]{40}/\1/'"
 995     else
 996       BUILD_ID_FILTER="$CAT"
 997     fi
 998 
 999     # Compare fulldump output
1000     if [ -n "$FULLDUMP_CMD" ] && [ -z "$SKIP_FULLDUMP_DIFF" ]; then
1001         if [ -z "$FULLDUMP_DIFF_FILTER" ]; then
1002             FULLDUMP_DIFF_FILTER="$CAT"
1003         fi
1004         $FULLDUMP_CMD $OTHER_FILE | eval "$BUILD_ID_FILTER" | eval "$FULLDUMP_DIFF_FILTER" \
1005             > $WORK_FILE_BASE.fulldump.other 2>&1 &
1006         $FULLDUMP_CMD $THIS_FILE  | eval "$BUILD_ID_FILTER" | eval "$FULLDUMP_DIFF_FILTER" \
1007             > $WORK_FILE_BASE.fulldump.this  2>&1 &
1008         wait
1009 
1010         LC_ALL=C $DIFF $WORK_FILE_BASE.fulldump.other $WORK_FILE_BASE.fulldump.this \
1011             > $WORK_FILE_BASE.fulldump.diff
1012 
1013         if [ -s $WORK_FILE_BASE.fulldump.diff ]; then
1014             FULLDUMP_DIFF_SIZE=$(ls -n $WORK_FILE_BASE.fulldump.diff | awk '{print $5}')
1015             FULLDUMP_MSG=$($PRINTF "%8d" $FULLDUMP_DIFF_SIZE)
1016             if [[ "$ACCEPTED_FULLDUMP_DIFF" != *"$BIN_FILE"* ]]; then
1017                 DIFF_FULLDUMP=true
1018                 if [[ "$KNOWN_FULLDUMP_DIFF" != *"$BIN_FILE"* ]]; then
1019                     FULLDUMP_MSG="*$FULLDUMP_MSG*"
1020                     REGRESSIONS=true
1021                 else
1022                     FULLDUMP_MSG=" $FULLDUMP_MSG "
1023                 fi
1024             else
1025                 FULLDUMP_MSG="($FULLDUMP_MSG)"
1026                 DIFF_FULLDUMP=
1027             fi
1028         else
1029             FULLDUMP_MSG="          "
1030             DIFF_FULLDUMP=
1031             if [[ "$KNOWN_FULLDUMP_DIFF $ACCEPTED_FULLDUMP_DIFF" = *"$BIN_FILE"* ]]; then
1032                 FULLDUMP_MSG="    !    "
1033             fi
1034         fi
1035     fi
1036 
1037     # Compare disassemble output
1038     if [ -n "$DIS_CMD" ] && [ -z "$SKIP_DIS_DIFF" ]; then
1039         this_DIS_DIFF_FILTER="$CAT"
1040         if [ -n "$DIS_DIFF_FILTER" ]; then
1041             if [ -z "$NEED_DIS_DIFF_FILTER" ] \
1042                 || [[ "$NEED_DIS_DIFF_FILTER" = *"$BIN_FILE"* ]]; then
1043                 this_DIS_DIFF_FILTER="$DIS_DIFF_FILTER"
1044             fi
1045         fi
1046         if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1047             DIS_GREP_ARG=-a
1048         else
1049             DIS_GREP_ARG=
1050         fi
1051         $DIS_CMD $OTHER_FILE | $GREP $DIS_GREP_ARG -v $NAME \
1052             | eval "$this_DIS_DIFF_FILTER" > $WORK_FILE_BASE.dis.other 2>&1 &
1053         $DIS_CMD $THIS_FILE  | $GREP $DIS_GREP_ARG -v $NAME \
1054             | eval "$this_DIS_DIFF_FILTER" > $WORK_FILE_BASE.dis.this  2>&1 &
1055         wait
1056 
1057         LC_ALL=C $DIFF $WORK_FILE_BASE.dis.other $WORK_FILE_BASE.dis.this > $WORK_FILE_BASE.dis.diff
1058 
1059         if [ -s $WORK_FILE_BASE.dis.diff ]; then
1060             DIS_DIFF_SIZE=$(ls -n $WORK_FILE_BASE.dis.diff | awk '{print $5}')
1061             DIS_MSG=$($PRINTF "%8d" $DIS_DIFF_SIZE)
1062             if [[ "$ACCEPTED_DIS_DIFF" != *"$BIN_FILE"* ]]; then
1063                 DIFF_DIS=true
1064                 if [ "$MAX_KNOWN_DIS_DIFF_SIZE" = "" ]; then
1065                     MAX_KNOWN_DIS_DIFF_SIZE="0"
1066                 fi
1067                 if [[ "$KNOWN_DIS_DIFF" = *"$BIN_FILE"* ]] \
1068                     && [ "$DIS_DIFF_SIZE" -lt "$MAX_KNOWN_DIS_DIFF_SIZE" ]; then
1069                     DIS_MSG=" $DIS_MSG "
1070                 else
1071                     DIS_MSG="*$DIS_MSG*"
1072                     REGRESSIONS=true
1073                 fi
1074             else
1075                 DIS_MSG="($DIS_MSG)"
1076                 DIFF_DIS=
1077             fi
1078         else
1079             DIS_MSG="          "
1080             DIFF_DIS=
1081             if [[ "$KNOWN_DEP_DIFF $ACCEPTED_DEP_DIFF" = *"$BIN_FILE"* ]]; then
1082                 DIS_MSG="    !    "
1083             fi
1084         fi
1085     fi
1086 
1087 
1088     if [ -n "$DIFF_BIN$DIFF_SIZE$DIFF_SYM$DIFF_DEP$DIFF_FULLDUMP$DIFF_DIS" ] || [ -n "$VERBOSE" ]; then
1089         if [ -n "$BIN_MSG" ]; then echo -n "$BIN_MSG:"; fi
1090         if [ -n "$SIZE_MSG" ]; then echo -n "$SIZE_MSG:"; fi
1091         if [ -n "$SYM_MSG" ]; then echo -n "$SYM_MSG:"; fi
1092         if [ -n "$DEP_MSG" ]; then echo -n "$DEP_MSG:"; fi
1093         if [ -n "$FULLDUMP_MSG" ]; then echo -n "$FULLDUMP_MSG:"; fi
1094         if [ -n "$DIS_MSG" ]; then echo -n "$DIS_MSG:"; fi
1095         echo " $BIN_FILE"
1096         if [ "$SHOW_DIFFS" = "true" ]; then
1097             if [ -s "$WORK_FILE_BASE.symbols.diff" ]; then
1098                 echo "Symbols diff:"
1099                 $CAT $WORK_FILE_BASE.symbols.diff
1100             fi
1101             if [ -s "$WORK_FILE_BASE.deps.diff" ]; then
1102                 echo "Deps diff:"
1103                 $CAT $WORK_FILE_BASE.deps.diff
1104             fi
1105             if [ -s "$WORK_FILE_BASE.fulldump.diff" ]; then
1106                 echo "Fulldump diff:"
1107                 $CAT $WORK_FILE_BASE.fulldump.diff
1108             fi
1109             if [ -s "$WORK_FILE_BASE.dis.diff" ]; then
1110                 echo "Disassembly diff:"
1111                 $CAT $WORK_FILE_BASE.dis.diff
1112             fi
1113         fi
1114         return 1
1115     fi
1116     return 0
1117 }
1118 
1119 ################################################################################
1120 # Print binary diff header
1121 
1122 print_binary_diff_header() {
1123     if [ -z "$SKIP_BIN_DIFF" ]; then echo -n " Binary :"; fi
1124     if [ -z "$SKIP_SIZE_DIFF" ]; then echo -n "   Size    :"; fi
1125     if [ -z "$SKIP_SYM_DIFF" ]; then echo -n " Symbols :"; fi
1126     if [ -z "$SKIP_DEP_DIFF" ]; then echo -n "  Deps   :"; fi
1127     if [ -z "$SKIP_FULLDUMP_DIFF" ]; then echo -n " Fulldump :"; fi
1128     if [ -z "$SKIP_DIS_DIFF" ]; then echo -n " Disass   :"; fi
1129     echo
1130 }
1131 
1132 ################################################################################
1133 # Compare all libraries
1134 
1135 compare_all_libs() {
1136     THIS_DIR=$1
1137     OTHER_DIR=$2
1138     WORK_DIR=$3
1139 
1140     LIBS=$(cd $THIS_DIR && $FIND . -type f \( -name 'lib*.so' -o -name '*.dylib' \
1141         -o -name '*.dll' -o -name '*.obj' -o -name '*.o' -o -name '*.a' \
1142         -o -name '*.cpl' \) | $SORT | $FILTER)
1143 
1144     # On macos, filter out the dSYM debug symbols files as they are also
1145     # named *.dylib.
1146     if [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
1147         LIBS=$(echo "$LIBS" | $GREP -v '\.dSYM/')
1148     fi
1149 
1150     if [ -n "$LIBS" ]; then
1151         echo Libraries...
1152         print_binary_diff_header
1153         for l in $LIBS; do
1154             if [ -f "$OTHER_DIR/$l" ]; then
1155                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $l
1156                 if [ "$?" != "0" ]; then
1157                     return_value=1
1158                 fi
1159             fi
1160         done
1161     fi
1162 
1163     return $return_value
1164 }
1165 
1166 ################################################################################
1167 # Compare all executables
1168 
1169 compare_all_execs() {
1170     THIS_DIR=$1
1171     OTHER_DIR=$2
1172     WORK_DIR=$3
1173 
1174     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1175         EXECS=$(cd $THIS_DIR && $FIND . -type f -name '*.exe' | $SORT | $FILTER)
1176     else
1177         EXECS=$(cd $THIS_DIR && $FIND . -name db -prune -o -type f -perm -100 \! \
1178             \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' -o -name '*.cgi' \
1179             -o -name '*.jar' -o -name '*.diz' -o -name 'jcontrol' -o -name '*.properties' \
1180             -o -name '*.data' -o -name '*.bfc' -o -name '*.src' -o -name '*.txt' \
1181             -o -name '*.cfg' -o -name 'meta-index' -o -name '*.properties.ja' \
1182             -o -name '*.xml' -o -name '*.html' -o -name '*.png' -o -name 'README' \
1183             -o -name '*.zip' -o -name '*.jimage' -o -name '*.java' -o -name '*.mf' \
1184             -o -name '*.jpg' -o -name '*.wsdl' -o -name '*.js' -o -name '*.sh' \
1185             -o -name '*.bat' -o -name '*LICENSE' -o -name '*.d' -o -name '*store' \
1186             -o -name 'blacklist' -o -name '*certs' -o -name '*.ttf' \
1187             -o -name '*.jfc' -o -name '*.dat'  -o -name 'release' -o -name '*.dir'\
1188             -o -name '*.sym' -o -name '*.idl' -o -name '*.h' -o -name '*.access' \
1189             -o -name '*.template' -o -name '*.policy' -o -name '*.security' \
1190             -o -name 'COPYRIGHT' -o -name '*.1' -o -name '*.debuginfo' \
1191             -o -name 'classlist' \) | $SORT | $FILTER)
1192     fi
1193 
1194     if [ -n "$EXECS" ]; then
1195         echo Executables...
1196         print_binary_diff_header
1197         for e in $EXECS; do
1198             if [ -f "$OTHER_DIR/$e" ]; then
1199                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $e
1200                 if [ "$?" != "0" ]; then
1201                     return_value=1
1202                 fi
1203             fi
1204         done
1205     fi
1206 
1207     return $return_value
1208 }
1209 
1210 ################################################################################
1211 # Initiate configuration
1212 
1213 THIS="$SCRIPT_DIR"
1214 echo "$THIS"
1215 THIS_SCRIPT="$0"
1216 
1217 if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "/h" ] || [ "$1" = "/?" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
1218     echo "bash ./compare.sh [OPTIONS] [FILTER]"
1219     echo ""
1220     echo "-all                Compare all files in all known ways"
1221     echo "-names              Compare the file names and directory structure"
1222     echo "-perms              Compare the permission bits on all files and directories"
1223     echo "-types              Compare the output of the file command on all files"
1224     echo "-general            Compare the files not convered by the specialized comparisons"
1225     echo "-zips               Compare the contents of all zip files and files in them"
1226     echo "-zips-names         Compare the file names inside all zip files"
1227     echo "-jars               Compare the contents of all jar files"
1228     echo "-jmods              Compare the listings of all jmod files"
1229     echo "-libs               Compare all native libraries"
1230     echo "-execs              Compare all executables"
1231     echo "-v                  Verbose output, does not hide known differences"
1232     echo "-vv                 More verbose output, shows diff output of all comparisons"
1233     echo "-o [OTHER]          Compare with build in other directory. Will default to the old build directory"
1234     echo ""
1235     echo "--sort-symbols      Sort all symbols before comparing"
1236     echo "--strip             Strip all binaries before comparing"
1237     echo "--clean             Clean all previous comparison results first"
1238     echo ""
1239     echo "[FILTER]            List filenames in the image to compare, works for jars, zips, libs and execs"
1240     echo "Example:"
1241     echo "bash ./make/scripts/compareimages.sh CodePointIM.jar"
1242     echo ""
1243     echo "-2zips <file1> <file2> Compare two zip files only"
1244     echo "-2bins <file1> <file2> Compare two binary files only"
1245     echo "-2dirs <dir1> <dir2> Compare two directories as if they were images"
1246     echo ""
1247     exit 10
1248 fi
1249 
1250 CMP_NAMES=false
1251 CMP_PERMS=false
1252 CMP_TYPES=false
1253 CMP_GENERAL=false
1254 CMP_ZIPS=false
1255 CMP_ZIPS_CONTENTS=true
1256 CMP_JARS=false
1257 CMP_JMODS=false
1258 CMP_LIBS=false
1259 CMP_EXECS=false
1260 
1261 while [ -n "$1" ]; do
1262     case "$1" in
1263         -v)
1264             VERBOSE=true
1265             ;;
1266         -vv)
1267             VERBOSE=true
1268             SHOW_DIFFS=true
1269             ;;
1270         -o)
1271             OTHER="$2"
1272             shift
1273             ;;
1274         -all)
1275             CMP_NAMES=true
1276             if [ "$OPENJDK_TARGET_OS" != "windows" ]; then
1277                 CMP_PERMS=true
1278             fi
1279             CMP_TYPES=true
1280             CMP_GENERAL=true
1281             CMP_ZIPS=true
1282             CMP_JARS=true
1283             CMP_JMODS=true
1284             CMP_LIBS=true
1285             CMP_EXECS=true
1286             ;;
1287         -names)
1288             CMP_NAMES=true
1289             ;;
1290         -perms)
1291             CMP_PERMS=true
1292             ;;
1293         -types)
1294             CMP_TYPES=true
1295             ;;
1296         -general)
1297             CMP_GENERAL=true
1298             ;;
1299         -zips)
1300             CMP_ZIPS=true
1301             CMP_ZIPS_CONTENTS=true
1302             ;;
1303         -zips-names)
1304             CMP_ZIPS=true
1305             CMP_ZIPS_CONTENTS=false
1306             ;;
1307         -jars)
1308             CMP_JARS=true
1309             ;;
1310         -jmods)
1311             CMP_JMODS=true
1312             ;;
1313         -libs)
1314             CMP_LIBS=true
1315             ;;
1316         -execs)
1317             CMP_EXECS=true
1318             ;;
1319         -2dirs)
1320             THIS="$(cd "$2" > /dev/null && pwd )"
1321             OTHER="$(cd "$3" > /dev/null && pwd )"
1322             THIS_BASE_DIR="$THIS"
1323             OTHER_BASE_DIR="$OTHER"
1324             SKIP_DEFAULT=true
1325             shift
1326             shift
1327             ;;
1328         -2zips)
1329             CMP_2_ZIPS=true
1330             THIS_FILE=$2
1331             OTHER_FILE=$3
1332             shift
1333             shift
1334             ;;
1335         -2bins)
1336             CMP_2_BINS=true
1337             THIS_FILE=$2
1338             OTHER_FILE=$3
1339             shift
1340             shift
1341             ;;
1342         --sort-symbols)
1343             SORT_ALL_SYMBOLS=true
1344             ;;
1345         --strip)
1346             STRIP_ALL=true
1347             ;;
1348         --clean)
1349             CLEAN_OUTPUT=true
1350             ;;
1351         *)
1352             CMP_NAMES=false
1353             CMP_PERMS=false
1354             CMP_TYPES=false
1355             CMP_ZIPS=true
1356             CMP_JARS=true
1357             CMP_JMODS=true
1358             CMP_LIBS=true
1359             CMP_EXECS=true
1360 
1361             if [ -z "$FILTER" ]; then
1362                 FILTER="$GREP"
1363             fi
1364             FILTER="$FILTER -e $1"
1365             ;;
1366     esac
1367     shift
1368 done
1369 
1370 if [ "$STRIP_ALL" = "true" ] && [ -z "$STRIP" ]; then
1371   echo Warning: Not stripping even with --strip, since strip is missing on this platform
1372   STRIP_ALL=false
1373 fi
1374 
1375 COMPARE_ROOT=$OUTPUTDIR/compare-support
1376 if [ "$CLEAN_OUTPUT" = "true" ]; then
1377     echo Cleaning old output in $COMPARE_ROOT.
1378     $RM -rf $COMPARE_ROOT
1379 fi
1380 $MKDIR -p $COMPARE_ROOT
1381 if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1382     if [ "$(uname -o)" = "Cygwin" ]; then
1383         COMPARE_ROOT=$(cygpath -msa $COMPARE_ROOT)
1384     fi
1385 fi
1386 
1387 if [ "$CMP_2_ZIPS" = "true" ]; then
1388     THIS_DIR="$(dirname $THIS_FILE)"
1389     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1390     OTHER_DIR="$(dirname $OTHER_FILE)"
1391     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1392     THIS_FILE_NAME="$(basename $THIS_FILE)"
1393     OTHER_FILE_NAME="$(basename $OTHER_FILE)"
1394     echo Comparing $THIS_DIR/$THIS_FILE_NAME and $OTHER_DIR/$OTHER_FILE_NAME
1395     compare_zip_file $THIS_DIR $OTHER_DIR $COMPARE_ROOT/2zips $THIS_FILE_NAME $OTHER_FILE_NAME
1396     exit
1397 fi
1398 
1399 if [ "$CMP_2_BINS" = "true" ]; then
1400     THIS_DIR="$(dirname $THIS_FILE)"
1401     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1402     OTHER_DIR="$(dirname $OTHER_FILE)"
1403     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1404     THIS_FILE_NAME="$(basename $THIS_FILE)"
1405     OTHER_FILE_NAME="$(basename $OTHER_FILE)"
1406     echo Comparing $THIS_DIR/$THIS_FILE_NAME and $OTHER_DIR/$OTHER_FILE_NAME
1407     compare_bin_file $THIS_DIR $OTHER_DIR $COMPARE_ROOT/2bins $THIS_FILE_NAME $OTHER_FILE_NAME
1408     exit
1409 fi
1410 
1411 if [ "$CMP_NAMES" = "false" ] \
1412        && [ "$CMP_TYPES" = "false" ] \
1413        && [ "$CMP_PERMS" = "false" ] \
1414        && [ "$CMP_GENERAL" = "false" ] \
1415        && [ "$CMP_ZIPS" = "false" ] \
1416        && [ "$CMP_JARS" = "false" ] \
1417        && [ "$CMP_JMODS" = "false" ] \
1418        && [ "$CMP_LIBS" = "false" ] \
1419        && [ "$CMP_EXECS" = "false" ]; then
1420     CMP_NAMES=true
1421     CMP_PERMS=true
1422     CMP_TYPES=true
1423     CMP_GENERAL=true
1424     CMP_ZIPS=true
1425     CMP_JARS=true
1426     CMP_JMODS=true
1427     CMP_LIBS=true
1428     CMP_EXECS=true
1429 fi
1430 
1431 if [ -z "$FILTER" ]; then
1432     FILTER="$CAT"
1433 fi
1434 
1435 if [ "$SKIP_DEFAULT" != "true" ]; then
1436     if [ -z "$OTHER" ]; then
1437         echo "Nothing to compare to, set with -o"
1438         exit 1
1439     else
1440         if [ ! -d "$OTHER" ]; then
1441             echo "Other build directory does not exist:"
1442             echo "$OTHER"
1443             exit 1
1444         fi
1445         OTHER="$( cd "$OTHER" > /dev/null && pwd )"
1446         echo "Comparing to:"
1447         echo "$OTHER"
1448         echo
1449     fi
1450 
1451     # Find the common images to compare, prioritizing later build stages
1452     if [ -d "$THIS/images/jdk" ] && [ -d "$OTHER/images/jdk" ]; then
1453         THIS_JDK="$THIS/images/jdk"
1454         OTHER_JDK="$OTHER/images/jdk"
1455         echo "Selecting normal images for JDK compare"
1456     elif [ -d "$(ls -d $THIS/licensee-src/build/*/images/jdk 2> /dev/null)" ] \
1457         && [ -d "$(ls -d $OTHER/licensee-src/build/*/images/jdk 2> /dev/null)" ]
1458     then
1459         echo "Selecting licensee images for compare"
1460         # Simply override the THIS and OTHER dir with the build dir from
1461         # the nested licensee source build for the rest of the script
1462         # execution.
1463         OLD_THIS="$THIS"
1464         OLD_OTHER="$OTHER"
1465         THIS="$(ls -d $THIS/licensee-src/build/*)"
1466         OTHER="$(ls -d $OTHER/licensee-src/build/*)"
1467         THIS_JDK="$THIS/images/jdk"
1468         OTHER_JDK="$OTHER/images/jdk"
1469         # Rewrite the path to tools that are used from the build
1470         JIMAGE="$(echo "$JIMAGE" | $SED "s|$OLD_THIS|$THIS|g")"
1471         JMOD="$(echo "$JMOD" | $SED "s|$OLD_THIS|$THIS|g")"
1472         JAVAP="$(echo "$JAVAP" | $SED "s|$OLD_THIS|$THIS|g")"
1473     else
1474         echo "No common images found."
1475         exit 1
1476     fi
1477     echo "  $THIS_JDK"
1478     echo "  $OTHER_JDK"
1479 
1480     if [ -d "$THIS/images/jdk-bundle" -o -d "$THIS/deploy/images/jdk-bundle" ] \
1481              && [ -d "$OTHER/images/jdk-bundle" -o -d "$OTHER/deploy/images/jdk-bundle" ]; then
1482         if [ -d "$THIS/deploy/images/jdk-bundle" ]; then
1483             THIS_JDK_BUNDLE="$THIS/deploy/images/jdk-bundle"
1484         else
1485             THIS_JDK_BUNDLE="$THIS/images/jdk-bundle"
1486         fi
1487         if [ -d "$OTHER/deploy/images/jdk-bundle" ]; then
1488             OTHER_JDK_BUNDLE="$OTHER/deploy/images/jdk-bundle"
1489         else
1490             OTHER_JDK_BUNDLE="$OTHER/images/jdk-bundle"
1491         fi
1492         echo "Also comparing jdk macosx bundles"
1493         echo "  $THIS_JDK_BUNDLE"
1494         echo "  $OTHER_JDK_BUNDLE"
1495     fi
1496 
1497     THIS_SEC_DIR="$THIS/images"
1498     OTHER_SEC_DIR="$OTHER/images"
1499     if [ -f "$THIS_SEC_DIR/sec-bin.zip" ] && [ -f "$OTHER_SEC_DIR/sec-bin.zip" ]; then
1500         OTHER_SEC_BIN="$OTHER_SEC_DIR/sec-bin.zip"
1501         THIS_SEC_BIN="$THIS_SEC_DIR/sec-bin.zip"
1502         if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1503             if [ "$OPENJDK_TARGET_CPU" = "x86_64" ]; then
1504                 JGSS_WINDOWS_BIN="jgss-windows-x64-bin.zip"
1505             else
1506                 JGSS_WINDOWS_BIN="jgss-windows-i586-bin.zip"
1507             fi
1508             OTHER_SEC_WINDOWS_BIN="$OTHER_SEC_DIR/sec-windows-bin.zip"
1509             OTHER_JGSS_WINDOWS_BIN="$OTHER_SEC_DIR/$JGSS_WINDOWS_BIN"
1510             THIS_SEC_WINDOWS_BIN="$THIS_SEC_DIR/sec-windows-bin.zip"
1511             THIS_JGSS_WINDOWS_BIN="$THIS_SEC_DIR/$JGSS_WINDOWS_BIN"
1512         fi
1513     fi
1514 
1515     if [ -d "$THIS/images/docs" ] && [ -d "$OTHER/images/docs" ]; then
1516         THIS_DOCS="$THIS/images/docs"
1517         OTHER_DOCS="$OTHER/images/docs"
1518         echo "Also comparing docs"
1519     else
1520         echo "WARNING! Docs haven't been built and won't be compared."
1521     fi
1522 
1523     if [ -d "$THIS/images/test" ] && [ -d "$OTHER/images/test" ]; then
1524         THIS_TEST="$THIS/images/test"
1525         OTHER_TEST="$OTHER/images/test"
1526         echo "Also comparing test image"
1527     else
1528         echo "WARNING! Test haven't been built and won't be compared."
1529     fi
1530 fi
1531 
1532 ################################################################################
1533 # Do the work
1534 
1535 if [ "$CMP_NAMES" = "true" ]; then
1536     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1537         echo -n "JDK "
1538         compare_dirs $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1539         echo -n "JDK "
1540         compare_files $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1541     fi
1542     if [ -n "$THIS_JDK_BUNDLE" ] && [ -n "$OTHER_JDK_BUNDLE" ]; then
1543         echo -n "JDK Bundle "
1544         compare_dirs $THIS_JDK_BUNDLE $OTHER_JDK_BUNDLE $COMPARE_ROOT/jdk-bundle
1545 
1546         echo -n "JDK Bundle "
1547         compare_files $THIS_JDK_BUNDLE $OTHER_JDK_BUNDLE $COMPARE_ROOT/jdk-bundle
1548     fi
1549     if [ -n "$THIS_DOCS" ] && [ -n "$OTHER_DOCS" ]; then
1550         echo -n "Docs "
1551         compare_dirs $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1552         echo -n "Docs "
1553         compare_files $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1554     fi
1555     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1556         echo -n "Test "
1557         compare_dirs $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1558         echo -n "Test "
1559         compare_files $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1560     fi
1561     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1562         compare_dirs $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1563         compare_files $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1564     fi
1565 fi
1566 
1567 if [ "$CMP_LIBS" = "true" ]; then
1568     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1569         echo -n "JDK "
1570         compare_all_libs $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1571     fi
1572     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1573         echo -n "Test "
1574         # Test native libs are never stripped so will not compare well.
1575         SKIP_BIN_DIFF="true"
1576         ACCEPTED_SMALL_SIZE_DIFF_bak="$ACCEPTED_SMALL_SIZE_DIFF"
1577         if [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
1578             ACCEPTED_SMALL_SIZE_DIFF="true"
1579         fi
1580         compare_all_libs $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1581         SKIP_BIN_DIFF="false"
1582         ACCEPTED_SMALL_SIZE_DIFF="$ACCEPTED_SMALL_SIZE_DIFF_bak"
1583     fi
1584     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1585         compare_all_libs $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1586     fi
1587 fi
1588 
1589 if [ "$CMP_EXECS" = "true" ]; then
1590     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1591         echo -n "JDK "
1592         compare_all_execs $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1593     fi
1594     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1595         echo -n "Test "
1596         # Test native executables are never stripped so will not compare well.
1597         SKIP_BIN_DIFF="true"
1598         compare_all_execs $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1599         SKIP_BIN_DIFF="false"
1600     fi
1601     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1602         compare_all_execs $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1603     fi
1604 fi
1605 
1606 if [ "$CMP_GENERAL" = "true" ]; then
1607     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1608         echo -n "JDK "
1609         compare_general_files $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1610     fi
1611     if [ -n "$THIS_JDK_BUNDLE" ] && [ -n "$OTHER_JDK_BUNDLE" ]; then
1612         echo -n "JDK Bundle "
1613         compare_general_files $THIS_JDK_BUNDLE $OTHER_JDK_BUNDLE $COMPARE_ROOT/jdk-bundle
1614     fi
1615     if [ -n "$THIS_DOCS" ] && [ -n "$OTHER_DOCS" ]; then
1616         echo -n "Docs "
1617         compare_general_files $THIS_DOCS $OTHER_DOCS $COMPARE_ROOT/docs
1618     fi
1619     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1620         echo -n "Test "
1621         compare_general_files $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1622     fi
1623     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1624         compare_general_files $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1625     fi
1626 fi
1627 
1628 if [ "$CMP_ZIPS" = "true" ]; then
1629     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1630         echo -n "JDK "
1631         compare_all_zip_files $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1632     fi
1633     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1634         echo -n "Test "
1635         compare_all_zip_files $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1636     fi
1637     if [ -n "$THIS_SEC_BIN" ] && [ -n "$OTHER_SEC_BIN" ]; then
1638         if [ -n "$(echo $THIS_SEC_BIN | $FILTER)" ]; then
1639             echo "sec-bin.zip..."
1640             compare_zip_file $THIS_SEC_DIR $OTHER_SEC_DIR $COMPARE_ROOT/sec-bin sec-bin.zip
1641         fi
1642     fi
1643     if [ -n "$THIS_SEC_WINDOWS_BIN" ] && [ -n "$OTHER_SEC_WINDOWS_BIN" ]; then
1644         if [ -n "$(echo $THIS_SEC_WINDOWS_BIN | $FILTER)" ]; then
1645             echo "sec-windows-bin.zip..."
1646             compare_zip_file $THIS_SEC_DIR $OTHER_SEC_DIR $COMPARE_ROOT/sec-bin sec-windows-bin.zip
1647         fi
1648     fi
1649     if [ -n "$THIS_JGSS_WINDOWS_BIN" ] && [ -n "$OTHER_JGSS_WINDOWS_BIN" ]; then
1650         if [ -n "$(echo $THIS_JGSS_WINDOWS_BIN | $FILTER)" ]; then
1651             echo "$JGSS_WINDOWS_BIN..."
1652             compare_zip_file $THIS_SEC_DIR $OTHER_SEC_DIR $COMPARE_ROOT/sec-bin $JGSS_WINDOWS_BIN
1653         fi
1654     fi
1655     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1656         compare_all_zip_files $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1657     fi
1658 fi
1659 
1660 if [ "$CMP_JARS" = "true" ]; then
1661     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1662         echo -n "JDK "
1663         compare_all_jar_files $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1664     fi
1665     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1666         echo -n "Test "
1667         compare_all_jar_files $THIS_TEST $OTHER_TEST $COMPARE_ROOT/test
1668     fi
1669     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1670         compare_all_jar_files $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1671     fi
1672 fi
1673 
1674 if [ "$CMP_JMODS" = "true" ]; then
1675     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1676         compare_all_jmod_files $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1677     fi
1678     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1679         compare_all_jmod_files $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1680     fi
1681 fi
1682 
1683 if [ "$CMP_PERMS" = "true" ]; then
1684     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1685         echo -n "JDK "
1686         compare_permissions $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1687     fi
1688     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1689         compare_permissions $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1690     fi
1691 fi
1692 
1693 if [ "$CMP_TYPES" = "true" ]; then
1694     if [ -n "$THIS_JDK" ] && [ -n "$OTHER_JDK" ]; then
1695         echo -n "JDK "
1696         compare_file_types $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1697     fi
1698     if [ -n "$THIS_JDK_BUNDLE" ] && [ -n "$OTHER_JDK_BUNDLE" ]; then
1699         echo -n "JDK Bundle "
1700         compare_file_types $THIS_JDK_BUNDLE $OTHER_JDK_BUNDLE $COMPARE_ROOT/jdk-bundle
1701     fi
1702     if [ -n "$THIS_TEST" ] && [ -n "$OTHER_TEST" ]; then
1703         echo -n "Test "
1704         compare_file_types $THIS_JDK $OTHER_JDK $COMPARE_ROOT/jdk
1705     fi
1706     if [ -n "$THIS_BASE_DIR" ] && [ -n "$OTHER_BASE_DIR" ]; then
1707         compare_file_types $THIS_BASE_DIR $OTHER_BASE_DIR $COMPARE_ROOT/base_dir
1708     fi
1709 fi
1710 
1711 echo
1712 
1713 if [ -n "$REGRESSIONS" ]; then
1714     echo "REGRESSIONS FOUND!"
1715     echo
1716     exit 1
1717 else
1718     echo "No regressions found"
1719     echo
1720     exit 0
1721 fi