common/bin/compareimage.sh

changeset 425
e1830598f0b7
child 445
efd26e051e50
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/common/bin/compareimage.sh	Tue Apr 10 08:18:28 2012 -0700
     1.3 @@ -0,0 +1,283 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.7 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 +#
     1.9 +# This code is free software; you can redistribute it and/or modify it
    1.10 +# under the terms of the GNU General Public License version 2 only, as
    1.11 +# published by the Free Software Foundation.
    1.12 +#
    1.13 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 +# version 2 for more details (a copy is included in the LICENSE file that
    1.17 +# accompanied this code).
    1.18 +#
    1.19 +# You should have received a copy of the GNU General Public License version
    1.20 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 +#
    1.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 +# or visit www.oracle.com if you need additional information or have any
    1.25 +# questions.
    1.26 +#
    1.27 +
    1.28 +# MANUAL
    1.29 +#
    1.30 +# ./common/bin/compareimages.sh old_jdk_image new_jdk_image
    1.31 +#
    1.32 +# Compare the directory structure.
    1.33 +# Compare the filenames in the directories.
    1.34 +# Compare the contents of the zip archives
    1.35 +# Compare the contents of the jar archives
    1.36 +# Compare the native libraries
    1.37 +# Compare the native executables
    1.38 +# Compare the remaining files
    1.39 +#
    1.40 +# ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]
    1.41 +#
    1.42 +# Compare only the selected subset of the images.
    1.43 +#
    1.44 +# ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar
    1.45 +#
    1.46 +# Compare only the CodePointIM.jar file
    1.47 +# Can be used to compare zips, libraries and executables.
    1.48 +#
    1.49 +
    1.50 +if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
    1.51 +    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image"
    1.52 +    echo ""
    1.53 +    echo "Compare the directory structure."
    1.54 +    echo "Compare the filenames in the directories."
    1.55 +    echo "Compare the contents of the zip archives"
    1.56 +    echo "Compare the contents of the jar archives"
    1.57 +    echo "Compare the native libraries"
    1.58 +    echo "Compare the native executables"
    1.59 +    echo "Compare the remaining files"
    1.60 +    echo ""
    1.61 +    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]"
    1.62 +    echo ""
    1.63 +    echo "Compare only the selected subset of the images."
    1.64 +    echo ""
    1.65 +    echo "./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar"
    1.66 +    echo ""
    1.67 +    echo "Compare only the CodePointIM.jar file"
    1.68 +    echo "Can be used to compare zips, libraries and executables."
    1.69 +    exit 10
    1.70 +fi
    1.71 +
    1.72 +OLD="$1"
    1.73 +NEW="$2"
    1.74 +CMD="$3"
    1.75 +
    1.76 +DIFF_RESULT=0
    1.77 +
    1.78 +CMP_ZIPS=false
    1.79 +CMP_JARS=false
    1.80 +CMP_LIBS=false
    1.81 +CMP_EXECS=false
    1.82 +CMP_OTHER=false
    1.83 +
    1.84 +FILTER="cat"
    1.85 +
    1.86 +if [ -n "$CMD" ]; then
    1.87 +  case "$CMD" in
    1.88 +    zips)
    1.89 +          CMP_ZIPS=true
    1.90 +      ;;
    1.91 +    jars)
    1.92 +          CMP_JARS=true
    1.93 +      ;;
    1.94 +    libs)
    1.95 +          CMP_LIBS=true
    1.96 +      ;;
    1.97 +    execs)
    1.98 +          CMP_EXECS=true
    1.99 +      ;;
   1.100 +    other)
   1.101 +          CMP_OTHER=true
   1.102 +      ;;
   1.103 +    *)
   1.104 +          CMP_ZIPS=true
   1.105 +          CMP_JARS=true
   1.106 +          CMP_LIBS=true
   1.107 +          CMP_EXECS=true
   1.108 +          CMP_OTHER=true
   1.109 +          FILTER="grep $3"
   1.110 +      ;;
   1.111 +  esac
   1.112 +else
   1.113 +    CMP_ZIPS=true
   1.114 +    CMP_JARS=true
   1.115 +    CMP_LIBS=true
   1.116 +    CMP_EXECS=true
   1.117 +    CMP_OTHER=true
   1.118 +fi
   1.119 +
   1.120 +DIFFJARZIP=`dirname $0`/diffjarzip.sh
   1.121 +DIFFLIB=`dirname $0`/difflib.sh
   1.122 +DIFFEXEC=`dirname $0`/diffexec.sh
   1.123 +export COMPARE_ROOT=/tmp/cimages
   1.124 +mkdir -p $COMPARE_ROOT
   1.125 +
   1.126 +# Load the correct exception list.
   1.127 +case "`uname -s`" in
   1.128 +    Linux)
   1.129 +        . `dirname $0`/exception_list_linux
   1.130 +        ;;
   1.131 +esac
   1.132 +
   1.133 +echo
   1.134 +echo Comparing $OLD to $NEW
   1.135 +echo
   1.136 +
   1.137 +(cd $OLD && find . -type d | sort > $COMPARE_ROOT/from_dirs)
   1.138 +(cd $NEW && find . -type d | sort > $COMPARE_ROOT/to_dirs)
   1.139 +
   1.140 +echo -n Directory structure...
   1.141 +if diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs > /dev/null; then
   1.142 +    echo Identical!
   1.143 +else
   1.144 +    echo Differences found.
   1.145 +    DIFF_RESULT=1
   1.146 +    # Differences in directories found.
   1.147 +    ONLY_OLD=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '<')
   1.148 +    if [ "$ONLY_OLD" ]; then
   1.149 +        echo Only in $OLD
   1.150 +        echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
   1.151 +    fi
   1.152 +    # Differences in directories found.
   1.153 +    ONLY_NEW=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '>')
   1.154 +    if [ "$ONLY_NEW" ]; then
   1.155 +        echo Only in $NEW
   1.156 +        echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
   1.157 +    fi
   1.158 +fi
   1.159 +
   1.160 +(cd $OLD && find . -type f | sort > $COMPARE_ROOT/from_files)
   1.161 +(cd $NEW && find . -type f | sort > $COMPARE_ROOT/to_files)
   1.162 +
   1.163 +echo -n File names...
   1.164 +if diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files > /dev/null; then
   1.165 +    echo Identical!
   1.166 +else
   1.167 +    echo Differences found.
   1.168 +    DIFF_RESULT=1
   1.169 +    # Differences in directories found.
   1.170 +    ONLY_OLD=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '<')
   1.171 +    if [ "$ONLY_OLD" ]; then
   1.172 +        echo Only in $OLD
   1.173 +        echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
   1.174 +    fi
   1.175 +    # Differences in directories found.
   1.176 +    ONLY_NEW=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '>')
   1.177 +    if [ "$ONLY_NEW" ]; then
   1.178 +        echo Only in $NEW
   1.179 +        echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
   1.180 +    fi
   1.181 +fi
   1.182 +
   1.183 +if [ "x$CMP_ZIPS" == "xtrue" ]; then
   1.184 +    ZIPS=$(cd $OLD && find . -type f -name "*.zip" | sort | $FILTER)
   1.185 +
   1.186 +    if [ -n "$ZIPS" ]; then
   1.187 +        echo Zip files...
   1.188 +
   1.189 +        for f in $ZIPS
   1.190 +        do
   1.191 +            $DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW 
   1.192 +            if [ "$?" != "0" ]; then
   1.193 +                DIFF_RESULT=1
   1.194 +            fi
   1.195 +        done
   1.196 +   fi        
   1.197 +fi    
   1.198 +
   1.199 +if [ "x$CMP_JARS" == "xtrue" ]; then
   1.200 +    JARS=$(cd $OLD && find . -type f -name "*.jar" | sort | $FILTER)
   1.201 +
   1.202 +    if [ -n "$JARS" ]; then
   1.203 +        echo Jar files...
   1.204 +
   1.205 +        for f in $JARS
   1.206 +        do
   1.207 +            DIFFJAR_OUTPUT=`$DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW`
   1.208 +            DIFFJAR_RESULT=$?
   1.209 +            if [ "$DIFFJAR_RESULT" != "0" ]; then
   1.210 +                for diff in $LIST_DIFF_JAR; do
   1.211 +                    DIFFJAR_OUTPUT=`echo "$DIFFJAR_OUTPUT" | grep -v "$diff"`
   1.212 +                done
   1.213 +                if [ "`echo "$DIFFJAR_OUTPUT" | grep -v "Differing files in"`" != "" ]; then
   1.214 +                    DIFF_RESULT=1
   1.215 +                    echo "$DIFFJAR_OUTPUT"
   1.216 +                fi
   1.217 +            fi
   1.218 +        done
   1.219 +    fi
   1.220 +fi
   1.221 +
   1.222 +if [ "x$FILTER" != "xcat" ]; then
   1.223 +    VIEW=view
   1.224 +else
   1.225 +    VIEW=
   1.226 +fi
   1.227 +
   1.228 +if [ "x$CMP_LIBS" == "xtrue" ]; then
   1.229 +    LIBS=$(cd $OLD && find . -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' | sort | $FILTER)
   1.230 +
   1.231 +    if [ -n "$LIBS" ]; then
   1.232 +        echo Libraries...
   1.233 +        for f in $LIBS
   1.234 +        do
   1.235 +            DIFFLIB_OUTPUT=`$DIFFLIB $OLD/$f $NEW/$f $OLD $NEW $VIEW`
   1.236 +            DIFFLIB_RESULT=$?
   1.237 +            if [ "$DIFFLIB_RESULT" = "0" ]; then
   1.238 +                :
   1.239 +                #echo "OK: $DIFFLIB_OUTPUT"
   1.240 +            elif [ "$DIFFLIB_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   1.241 +                :
   1.242 +                #echo "OK: $DIFFLIB_OUTPUT"
   1.243 +            elif [ "$DIFFLIB_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   1.244 +                :
   1.245 +                #echo "OK: $DIFFLIB_OUTPUT"
   1.246 +            else
   1.247 +                echo "$DIFFLIB_OUTPUT"
   1.248 +                DIFF_RESULT=1
   1.249 +            fi
   1.250 +        done
   1.251 +    fi
   1.252 +fi
   1.253 +
   1.254 +if [ "x$CMP_EXECS" == "xtrue" ]; then
   1.255 +    if [ $OSTYPE == "cygwin" ]; then
   1.256 +        EXECS=$(cd $OLD && find . -type f -name '*.exe' | sort | $FILTER)
   1.257 +    else
   1.258 +        EXECS=$(cd $OLD && find . -type f -perm -100 \! \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' \) | sort | $FILTER)
   1.259 +    fi
   1.260 +
   1.261 +
   1.262 +    if [ -n "$EXECS" ]; then
   1.263 +        echo Executables...
   1.264 +
   1.265 +        for f in $EXECS
   1.266 +        do
   1.267 +            DIFFEXEC_OUTPUT=`$DIFFEXEC $OLD/$f $NEW/$f $OLD $NEW $VIEW`
   1.268 +            DIFFEXEC_RESULT=$?
   1.269 +            if [ "$DIFFEXEC_RESULT" = "0" ]; then
   1.270 +                :
   1.271 +                #echo "OK: $DIFFEXEC_OUTPUT"
   1.272 +            elif [ "$DIFFEXEC_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   1.273 +                :
   1.274 +                #echo "OK: $DIFFEXEC_OUTPUT"
   1.275 +            elif [ "$DIFFEXEC_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   1.276 +                :
   1.277 +                #echo "OK: $DIFFEXEC_OUTPUT"
   1.278 +            else
   1.279 +                echo "$DIFFEXEC_OUTPUT"
   1.280 +                DIFF_RESULT=1
   1.281 +            fi
   1.282 +        done
   1.283 +    fi
   1.284 +fi
   1.285 +
   1.286 +exit $DIFF_RESULT

mercurial