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