compareimage.sh 8.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
#!/bin/bash
#
# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# MANUAL
#
# ./common/bin/compareimages.sh old_jdk_image new_jdk_image
#
# Compare the directory structure.
# Compare the filenames in the directories.
# Compare the contents of the zip archives
# Compare the contents of the jar archives
# Compare the native libraries
# Compare the native executables
# Compare the remaining files
#
# ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]
#
# Compare only the selected subset of the images.
#
# ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar
#
# Compare only the CodePointIM.jar file
# Can be used to compare zips, libraries and executables.
#

if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image"
    echo ""
    echo "Compare the directory structure."
    echo "Compare the filenames in the directories."
    echo "Compare the contents of the zip archives"
    echo "Compare the contents of the jar archives"
    echo "Compare the native libraries"
    echo "Compare the native executables"
    echo "Compare the remaining files"
    echo ""
    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]"
    echo ""
    echo "Compare only the selected subset of the images."
    echo ""
    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar"
    echo ""
    echo "Compare only the CodePointIM.jar file"
    echo "Can be used to compare zips, libraries and executables."
    exit 10
fi

OLD="$1"
NEW="$2"
CMD="$3"

DIFF_RESULT=0

CMP_ZIPS=false
CMP_JARS=false
CMP_LIBS=false
CMP_EXECS=false
CMP_OTHER=false

FILTER="cat"

if [ -n "$CMD" ]; then
  case "$CMD" in
    zips)
          CMP_ZIPS=true
      ;;
    jars)
          CMP_JARS=true
      ;;
    libs)
          CMP_LIBS=true
      ;;
    execs)
          CMP_EXECS=true
      ;;
    other)
          CMP_OTHER=true
      ;;
    *)
          CMP_ZIPS=true
          CMP_JARS=true
          CMP_LIBS=true
          CMP_EXECS=true
          CMP_OTHER=true
          FILTER="grep $3"
      ;;
  esac
else
    CMP_ZIPS=true
    CMP_JARS=true
    CMP_LIBS=true
    CMP_EXECS=true
    CMP_OTHER=true
fi

DIFFJARZIP=`dirname $0`/diffjarzip.sh
DIFFLIB=`dirname $0`/difflib.sh
DIFFEXEC=`dirname $0`/diffexec.sh
export COMPARE_ROOT=/tmp/cimages
mkdir -p $COMPARE_ROOT

# Load the correct exception list.
case "`uname -s`" in
    Linux)
        . `dirname $0`/exception_list_linux
        ;;
esac

echo
echo Comparing $OLD to $NEW
echo

(cd $OLD && find . -type d | sort > $COMPARE_ROOT/from_dirs)
(cd $NEW && find . -type d | sort > $COMPARE_ROOT/to_dirs)

echo -n Directory structure...
if diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs > /dev/null; then
    echo Identical!
else
    echo Differences found.
    DIFF_RESULT=1
    # Differences in directories found.
    ONLY_OLD=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '<')
    if [ "$ONLY_OLD" ]; then
        echo Only in $OLD
        echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
    fi
    # Differences in directories found.
    ONLY_NEW=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '>')
    if [ "$ONLY_NEW" ]; then
        echo Only in $NEW
        echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
    fi
fi

(cd $OLD && find . -type f | sort > $COMPARE_ROOT/from_files)
(cd $NEW && find . -type f | sort > $COMPARE_ROOT/to_files)

echo -n File names...
if diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files > /dev/null; then
    echo Identical!
else
    echo Differences found.
    DIFF_RESULT=1
    # Differences in directories found.
    ONLY_OLD=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '<')
    if [ "$ONLY_OLD" ]; then
        echo Only in $OLD
        echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
    fi
    # Differences in directories found.
    ONLY_NEW=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '>')
    if [ "$ONLY_NEW" ]; then
        echo Only in $NEW
        echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
    fi
fi

if [ "x$CMP_ZIPS" == "xtrue" ]; then
    ZIPS=$(cd $OLD && find . -type f -name "*.zip" | sort | $FILTER)

    if [ -n "$ZIPS" ]; then
        echo Zip files...

        for f in $ZIPS
        do
            $DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW 
            if [ "$?" != "0" ]; then
                DIFF_RESULT=1
            fi
        done
   fi        
fi    

if [ "x$CMP_JARS" == "xtrue" ]; then
    JARS=$(cd $OLD && find . -type f -name "*.jar" | sort | $FILTER)

    if [ -n "$JARS" ]; then
        echo Jar files...

        for f in $JARS
        do
            DIFFJAR_OUTPUT=`$DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW`
            DIFFJAR_RESULT=$?
            if [ "$DIFFJAR_RESULT" != "0" ]; then
                for diff in $LIST_DIFF_JAR; do
                    DIFFJAR_OUTPUT=`echo "$DIFFJAR_OUTPUT" | grep -v "$diff"`
                done
                if [ "`echo "$DIFFJAR_OUTPUT" | grep -v "Differing files in"`" != "" ]; then
                    DIFF_RESULT=1
                    echo "$DIFFJAR_OUTPUT"
                fi
            fi
        done
    fi
fi

if [ "x$FILTER" != "xcat" ]; then
    VIEW=view
else
    VIEW=
fi

if [ "x$CMP_LIBS" == "xtrue" ]; then
    LIBS=$(cd $OLD && find . -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' | sort | $FILTER)

    if [ -n "$LIBS" ]; then
        echo Libraries...
        for f in $LIBS
        do
            DIFFLIB_OUTPUT=`$DIFFLIB $OLD/$f $NEW/$f $OLD $NEW $VIEW`
            DIFFLIB_RESULT=$?
            if [ "$DIFFLIB_RESULT" = "0" ]; then
                :
                #echo "OK: $DIFFLIB_OUTPUT"
            elif [ "$DIFFLIB_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
                :
                #echo "OK: $DIFFLIB_OUTPUT"
            elif [ "$DIFFLIB_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
                :
                #echo "OK: $DIFFLIB_OUTPUT"
            else
                echo "$DIFFLIB_OUTPUT"
                DIFF_RESULT=1
            fi
        done
    fi
fi

if [ "x$CMP_EXECS" == "xtrue" ]; then
    if [ $OSTYPE == "cygwin" ]; then
        EXECS=$(cd $OLD && find . -type f -name '*.exe' | sort | $FILTER)
    else
        EXECS=$(cd $OLD && find . -type f -perm -100 \! \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' \) | sort | $FILTER)
    fi


    if [ -n "$EXECS" ]; then
        echo Executables...

        for f in $EXECS
        do
            DIFFEXEC_OUTPUT=`$DIFFEXEC $OLD/$f $NEW/$f $OLD $NEW $VIEW`
            DIFFEXEC_RESULT=$?
            if [ "$DIFFEXEC_RESULT" = "0" ]; then
                :
                #echo "OK: $DIFFEXEC_OUTPUT"
            elif [ "$DIFFEXEC_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
                :
                #echo "OK: $DIFFEXEC_OUTPUT"
            elif [ "$DIFFEXEC_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
                :
                #echo "OK: $DIFFEXEC_OUTPUT"
            else
                echo "$DIFFEXEC_OUTPUT"
                DIFF_RESULT=1
            fi
        done
    fi
fi

exit $DIFF_RESULT