common/bin/compareimage.sh

Fri, 12 Oct 2012 14:46:47 -0700

author
lana
date
Fri, 12 Oct 2012 14:46:47 -0700
changeset 491
ce2b111ee869
parent 458
c8d320b48626
permissions
-rw-r--r--

Merge

     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 #
    25 # MANUAL
    26 #
    27 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image
    28 #
    29 # Compare the directory structure.
    30 # Compare the filenames in the directories.
    31 # Compare the contents of the zip archives
    32 # Compare the contents of the jar archives
    33 # Compare the native libraries
    34 # Compare the native executables
    35 # Compare the remaining files
    36 #
    37 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]
    38 #
    39 # Compare only the selected subset of the images.
    40 #
    41 # ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar
    42 #
    43 # Compare only the CodePointIM.jar file
    44 # Can be used to compare zips, libraries and executables.
    45 #
    47 if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then
    48     echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image"
    49     echo ""
    50     echo "Compare the directory structure."
    51     echo "Compare the filenames in the directories."
    52     echo "Compare the contents of the zip archives"
    53     echo "Compare the contents of the jar archives"
    54     echo "Compare the native libraries"
    55     echo "Compare the native executables"
    56     echo "Compare the remaining files"
    57     echo ""
    58     echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]"
    59     echo ""
    60     echo "Compare only the selected subset of the images."
    61     echo ""
    62     echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar"
    63     echo ""
    64     echo "Compare only the CodePointIM.jar file"
    65     echo "Can be used to compare zips, libraries and executables."
    66     exit 10
    67 fi
    69 OLD="$1"
    70 NEW="$2"
    71 CMD="$3"
    73 DIFF_RESULT=0
    75 CMP_ZIPS=false
    76 CMP_JARS=false
    77 CMP_LIBS=false
    78 CMP_EXECS=false
    79 CMP_OTHER=false
    81 FILTER="cat"
    83 if [ -n "$CMD" ]; then
    84   case "$CMD" in
    85     zips)
    86           CMP_ZIPS=true
    87       ;;
    88     jars)
    89           CMP_JARS=true
    90       ;;
    91     libs)
    92           CMP_LIBS=true
    93       ;;
    94     execs)
    95           CMP_EXECS=true
    96       ;;
    97     other)
    98           CMP_OTHER=true
    99       ;;
   100     *)
   101           CMP_ZIPS=true
   102           CMP_JARS=true
   103           CMP_LIBS=true
   104           CMP_EXECS=true
   105           CMP_OTHER=true
   106           FILTER="grep $3"
   107       ;;
   108   esac
   109 else
   110     CMP_ZIPS=true
   111     CMP_JARS=true
   112     CMP_LIBS=true
   113     CMP_EXECS=true
   114     CMP_OTHER=true
   115 fi
   117 DIFFJARZIP="/bin/bash `dirname $0`/diffjarzip.sh"
   118 DIFFLIB="/bin/bash `dirname $0`/difflib.sh"
   119 DIFFEXEC="/bin/bash `dirname $0`/diffexec.sh"
   120 export COMPARE_ROOT=/tmp/cimages.$USER
   121 mkdir -p $COMPARE_ROOT
   123 # Load the correct exception list.
   124 case "`uname -s`" in
   125     Linux)
   126         . `dirname $0`/exception_list_linux
   127         ;;
   128 esac
   130 echo
   131 echo Comparing $OLD to $NEW
   132 echo
   134 (cd $OLD && find . -type d | sort > $COMPARE_ROOT/from_dirs)
   135 (cd $NEW && find . -type d | sort > $COMPARE_ROOT/to_dirs)
   137 echo -n Directory structure...
   138 if diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs > /dev/null; then
   139     echo Identical!
   140 else
   141     echo Differences found.
   142     DIFF_RESULT=1
   143     # Differences in directories found.
   144     ONLY_OLD=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '<')
   145     if [ "$ONLY_OLD" ]; then
   146         echo Only in $OLD
   147         echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g'
   148     fi
   149     # Differences in directories found.
   150     ONLY_NEW=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '>')
   151     if [ "$ONLY_NEW" ]; then
   152         echo Only in $NEW
   153         echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g'
   154     fi
   155 fi
   157 (cd $OLD && find . -type f | sort > $COMPARE_ROOT/from_files)
   158 (cd $NEW && find . -type f | sort > $COMPARE_ROOT/to_files)
   160 echo -n File names...
   161 if diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files > /dev/null; then
   162     echo Identical!
   163 else
   164     echo Differences found.
   165     DIFF_RESULT=1
   166     # Differences in directories found.
   167     ONLY_OLD=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '<')
   168     if [ "$ONLY_OLD" ]; then
   169         echo Only in $OLD
   170         echo "$ONLY_OLD" | sed 's|< ./|    |g'
   171     fi
   172     # Differences in directories found.
   173     ONLY_NEW=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '>')
   174     if [ "$ONLY_NEW" ]; then
   175         echo Only in $NEW
   176         echo "$ONLY_NEW" | sed 's|> ./|    |g'
   177     fi
   178 fi
   180 echo -n Permissions...
   181 found=""
   182 for f in `cd $OLD && find . -type f`
   183 do
   184     if [ ! -f ${OLD}/$f ]; then continue; fi
   185     if [ ! -f ${NEW}/$f ]; then continue; fi
   186     OP=`ls -l ${OLD}/$f | awk '{printf("%.10s\n", $1);}'`
   187     NP=`ls -l ${NEW}/$f | awk '{printf("%.10s\n", $1);}'`
   188     if [ "$OP" != "$NP" ]
   189     then
   190 	if [ -z "$found" ]; then echo ; found="yes"; fi
   191 	printf "\told: ${OP} new: ${NP}\t$f\n"
   192     fi
   194     OF=`cd ${OLD} && file $f`
   195     NF=`cd ${NEW} && file $f`
   196     if [ "$f" = "./src.zip" ]
   197     then
   198 	if [ "`echo $OF | grep -ic zip`" -gt 0 -a "`echo $NF | grep -ic zip`" -gt 0 ]
   199 	then
   200 	    # the way we produces zip-files make it so that directories are stored in old file
   201 	    # but not in new (only files with full-path)
   202 	    # this makes file-5.09 report them as different
   203 	    continue;
   204 	fi
   205     fi
   207     if [ "$OF" != "$NF" ]
   208     then
   209 	if [ -z "$found" ]; then echo ; found="yes"; fi
   210 	printf "\tFILE: old: ${OF} new: ${NF}\t$f\n"
   211     fi
   212 done
   213 if [ -z "$found" ]; then echo ; found="yes"; fi
   215 GENERAL_FILES=$(cd $OLD && find . -type f ! -name "*.so" ! -name "*.jar" ! -name "*.zip" \
   216                                   ! -name "*.debuginfo" ! -name "*.dylib" ! -name "jexec" \
   217                                   ! -name "ct.sym" ! -name "*.diz" \
   218                               | grep -v "./bin/"  | sort | $FILTER)
   219 echo General files...
   220 for f in $GENERAL_FILES
   221 do
   222     if [ -e $NEW/$f ]; then
   223         DIFF_OUT=$(diff $OLD/$f $NEW/$f 2>&1)
   224         if [ -n "$DIFF_OUT" ]; then
   225             echo $f
   226             echo "$DIFF_OUT"
   227         fi
   228     fi
   229 done
   232 if [ "x$CMP_ZIPS" == "xtrue" ]; then
   233     ZIPS=$(cd $OLD && find . -type f -name "*.zip" | sort | $FILTER)
   235     if [ -n "$ZIPS" ]; then
   236         echo Zip files...
   238         for f in $ZIPS
   239         do
   240             $DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW 
   241             if [ "$?" != "0" ]; then
   242                 DIFF_RESULT=1
   243             fi
   244         done
   245    fi        
   246 fi    
   248 if [ "x$CMP_JARS" == "xtrue" ]; then
   249     JARS=$(cd $OLD && find . -type f -name "*.jar" -o -name "ct.sym" | sort | $FILTER)
   251     if [ -n "$JARS" ]; then
   252         echo Jar files...
   254         for f in $JARS
   255         do
   256             DIFFJAR_OUTPUT=`$DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW`
   257             DIFFJAR_RESULT=$?
   258             if [ "$DIFFJAR_RESULT" != "0" ]; then
   259                 for diff in $LIST_DIFF_JAR; do
   260                     DIFFJAR_OUTPUT=`echo "$DIFFJAR_OUTPUT" | grep -v "$diff"`
   261                 done
   262                 if [ "`echo "$DIFFJAR_OUTPUT" | grep -v "Differing files in"`" != "" ]; then
   263                     DIFF_RESULT=1
   264                     echo "$DIFFJAR_OUTPUT"
   265                 fi
   266             fi
   267         done
   268     fi
   269 fi
   271 if [ "x$FILTER" != "xcat" ]; then
   272     VIEW=view
   273 else
   274     VIEW=
   275 fi
   277 if [ "x$CMP_LIBS" == "xtrue" ]; then
   278     LIBS=$(cd $OLD && find . -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' | sort | $FILTER)
   280     if [ -n "$LIBS" ]; then
   281         echo Libraries...
   282         for f in $LIBS
   283         do
   284             DIFFLIB_OUTPUT=`$DIFFLIB $OLD/$f $NEW/$f $OLD $NEW $VIEW`
   285             DIFFLIB_RESULT=$?
   286             if [ "$DIFFLIB_RESULT" = "0" ]; then
   287                 :
   288                 #echo "OK: $DIFFLIB_OUTPUT"
   289             elif [ "$DIFFLIB_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   290                 :
   291                 #echo "OK: $DIFFLIB_OUTPUT"
   292             elif [ "$DIFFLIB_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   293                 :
   294                 #echo "OK: $DIFFLIB_OUTPUT"
   295             else
   296                 echo "$DIFFLIB_OUTPUT"
   297                 DIFF_RESULT=1
   298             fi
   299         done
   300     fi
   301 fi
   303 if [ "x$CMP_EXECS" == "xtrue" ]; then
   304     if [ $OSTYPE == "cygwin" ]; then
   305         EXECS=$(cd $OLD && find . -type f -name '*.exe' | sort | $FILTER)
   306     else
   307         EXECS=$(cd $OLD && find . -type f -perm -100 \! \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' \) | sort | $FILTER)
   308     fi
   311     if [ -n "$EXECS" ]; then
   312         echo Executables...
   314         for f in $EXECS
   315         do
   316             DIFFEXEC_OUTPUT=`$DIFFEXEC $OLD/$f $NEW/$f $OLD $NEW $VIEW`
   317             DIFFEXEC_RESULT=$?
   318             if [ "$DIFFEXEC_RESULT" = "0" ]; then
   319                 :
   320                 #echo "OK: $DIFFEXEC_OUTPUT"
   321             elif [ "$DIFFEXEC_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   322                 :
   323                 #echo "OK: $DIFFEXEC_OUTPUT"
   324             elif [ "$DIFFEXEC_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then
   325                 :
   326                 #echo "OK: $DIFFEXEC_OUTPUT"
   327             else
   328                 echo "$DIFFEXEC_OUTPUT"
   329                 DIFF_RESULT=1
   330             fi
   331         done
   332     fi
   333 fi
   335 exit $DIFF_RESULT

mercurial