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