ohair@425: #!/bin/bash ohair@425: # ohair@425: # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. ohair@425: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@425: # ohair@425: # This code is free software; you can redistribute it and/or modify it ohair@425: # under the terms of the GNU General Public License version 2 only, as ohair@425: # published by the Free Software Foundation. ohair@425: # ohair@425: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@425: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@425: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@425: # version 2 for more details (a copy is included in the LICENSE file that ohair@425: # accompanied this code). ohair@425: # ohair@425: # You should have received a copy of the GNU General Public License version ohair@425: # 2 along with this work; if not, write to the Free Software Foundation, ohair@425: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@425: # ohair@425: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@425: # or visit www.oracle.com if you need additional information or have any ohair@425: # questions. ohair@425: # ohair@425: ohair@425: # MANUAL ohair@425: # ohair@425: # ./common/bin/compareimages.sh old_jdk_image new_jdk_image ohair@425: # ohair@425: # Compare the directory structure. ohair@425: # Compare the filenames in the directories. ohair@425: # Compare the contents of the zip archives ohair@425: # Compare the contents of the jar archives ohair@425: # Compare the native libraries ohair@425: # Compare the native executables ohair@425: # Compare the remaining files ohair@425: # ohair@425: # ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other] ohair@425: # ohair@425: # Compare only the selected subset of the images. ohair@425: # ohair@425: # ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar ohair@425: # ohair@425: # Compare only the CodePointIM.jar file ohair@425: # Can be used to compare zips, libraries and executables. ohair@425: # ohair@425: ohair@425: if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ] || [ "x$1" == "x" ]; then erikj@445: echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image" ohair@425: echo "" ohair@425: echo "Compare the directory structure." ohair@425: echo "Compare the filenames in the directories." ohair@425: echo "Compare the contents of the zip archives" ohair@425: echo "Compare the contents of the jar archives" ohair@425: echo "Compare the native libraries" ohair@425: echo "Compare the native executables" ohair@425: echo "Compare the remaining files" ohair@425: echo "" erikj@445: echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image [zips jars libs execs other]" ohair@425: echo "" ohair@425: echo "Compare only the selected subset of the images." ohair@425: echo "" erikj@445: echo "bash ./common/bin/compareimages.sh old_jdk_image new_jdk_image CodePointIM.jar" ohair@425: echo "" ohair@425: echo "Compare only the CodePointIM.jar file" ohair@425: echo "Can be used to compare zips, libraries and executables." ohair@425: exit 10 ohair@425: fi ohair@425: ohair@425: OLD="$1" ohair@425: NEW="$2" ohair@425: CMD="$3" ohair@425: ohair@425: DIFF_RESULT=0 ohair@425: ohair@425: CMP_ZIPS=false ohair@425: CMP_JARS=false ohair@425: CMP_LIBS=false ohair@425: CMP_EXECS=false ohair@425: CMP_OTHER=false ohair@425: ohair@425: FILTER="cat" ohair@425: ohair@425: if [ -n "$CMD" ]; then ohair@425: case "$CMD" in ohair@425: zips) ohair@425: CMP_ZIPS=true ohair@425: ;; ohair@425: jars) ohair@425: CMP_JARS=true ohair@425: ;; ohair@425: libs) ohair@425: CMP_LIBS=true ohair@425: ;; ohair@425: execs) ohair@425: CMP_EXECS=true ohair@425: ;; ohair@425: other) ohair@425: CMP_OTHER=true ohair@425: ;; ohair@425: *) ohair@425: CMP_ZIPS=true ohair@425: CMP_JARS=true ohair@425: CMP_LIBS=true ohair@425: CMP_EXECS=true ohair@425: CMP_OTHER=true ohair@425: FILTER="grep $3" ohair@425: ;; ohair@425: esac ohair@425: else ohair@425: CMP_ZIPS=true ohair@425: CMP_JARS=true ohair@425: CMP_LIBS=true ohair@425: CMP_EXECS=true ohair@425: CMP_OTHER=true ohair@425: fi ohair@425: erikj@445: DIFFJARZIP="/bin/bash `dirname $0`/diffjarzip.sh" erikj@445: DIFFLIB="/bin/bash `dirname $0`/difflib.sh" erikj@445: DIFFEXEC="/bin/bash `dirname $0`/diffexec.sh" erikj@445: export COMPARE_ROOT=/tmp/cimages.$USER ohair@425: mkdir -p $COMPARE_ROOT ohair@425: ohair@425: # Load the correct exception list. ohair@425: case "`uname -s`" in ohair@425: Linux) ohair@425: . `dirname $0`/exception_list_linux ohair@425: ;; ohair@425: esac ohair@425: ohair@425: echo ohair@425: echo Comparing $OLD to $NEW ohair@425: echo ohair@425: ohair@425: (cd $OLD && find . -type d | sort > $COMPARE_ROOT/from_dirs) ohair@425: (cd $NEW && find . -type d | sort > $COMPARE_ROOT/to_dirs) ohair@425: ohair@425: echo -n Directory structure... ohair@425: if diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs > /dev/null; then ohair@425: echo Identical! ohair@425: else ohair@425: echo Differences found. ohair@425: DIFF_RESULT=1 ohair@425: # Differences in directories found. ohair@425: ONLY_OLD=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '<') ohair@425: if [ "$ONLY_OLD" ]; then ohair@425: echo Only in $OLD ohair@425: echo $ONLY_OLD | sed 's|< ./|\t|g' | sed 's/ /\n/g' ohair@425: fi ohair@425: # Differences in directories found. ohair@425: ONLY_NEW=$(diff $COMPARE_ROOT/from_dirs $COMPARE_ROOT/to_dirs | grep '>') ohair@425: if [ "$ONLY_NEW" ]; then ohair@425: echo Only in $NEW ohair@425: echo $ONLY_NEW | sed 's|> ./|\t|g' | sed 's/ /\n/g' ohair@425: fi ohair@425: fi ohair@425: ohair@425: (cd $OLD && find . -type f | sort > $COMPARE_ROOT/from_files) ohair@425: (cd $NEW && find . -type f | sort > $COMPARE_ROOT/to_files) ohair@425: ohair@425: echo -n File names... ohair@425: if diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files > /dev/null; then ohair@425: echo Identical! ohair@425: else ohair@425: echo Differences found. ohair@425: DIFF_RESULT=1 ohair@425: # Differences in directories found. ohair@425: ONLY_OLD=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '<') ohair@425: if [ "$ONLY_OLD" ]; then ohair@425: echo Only in $OLD erikj@445: echo "$ONLY_OLD" | sed 's|< ./| |g' ohair@425: fi ohair@425: # Differences in directories found. ohair@425: ONLY_NEW=$(diff $COMPARE_ROOT/from_files $COMPARE_ROOT/to_files | grep '>') ohair@425: if [ "$ONLY_NEW" ]; then ohair@425: echo Only in $NEW erikj@445: echo "$ONLY_NEW" | sed 's|> ./| |g' ohair@425: fi ohair@425: fi ohair@425: erikj@458: echo -n Permissions... erikj@458: found="" erikj@458: for f in `cd $OLD && find . -type f` erikj@458: do erikj@458: if [ ! -f ${OLD}/$f ]; then continue; fi erikj@458: if [ ! -f ${NEW}/$f ]; then continue; fi erikj@458: OP=`ls -l ${OLD}/$f | awk '{printf("%.10s\n", $1);}'` erikj@458: NP=`ls -l ${NEW}/$f | awk '{printf("%.10s\n", $1);}'` erikj@458: if [ "$OP" != "$NP" ] erikj@458: then erikj@458: if [ -z "$found" ]; then echo ; found="yes"; fi erikj@458: printf "\told: ${OP} new: ${NP}\t$f\n" erikj@458: fi erikj@445: erikj@458: OF=`cd ${OLD} && file $f` erikj@458: NF=`cd ${NEW} && file $f` erikj@458: if [ "$f" = "./src.zip" ] erikj@458: then erikj@458: if [ "`echo $OF | grep -ic zip`" -gt 0 -a "`echo $NF | grep -ic zip`" -gt 0 ] erikj@445: then erikj@458: # the way we produces zip-files make it so that directories are stored in old file erikj@458: # but not in new (only files with full-path) erikj@458: # this makes file-5.09 report them as different erikj@458: continue; erikj@445: fi erikj@458: fi erikj@458: erikj@458: if [ "$OF" != "$NF" ] erikj@458: then erikj@458: if [ -z "$found" ]; then echo ; found="yes"; fi erikj@458: printf "\tFILE: old: ${OF} new: ${NF}\t$f\n" erikj@458: fi erikj@458: done erikj@458: if [ -z "$found" ]; then echo ; found="yes"; fi erikj@445: erikj@445: GENERAL_FILES=$(cd $OLD && find . -type f ! -name "*.so" ! -name "*.jar" ! -name "*.zip" \ erikj@445: ! -name "*.debuginfo" ! -name "*.dylib" ! -name "jexec" \ erikj@458: ! -name "ct.sym" ! -name "*.diz" \ erikj@445: | grep -v "./bin/" | sort | $FILTER) erikj@445: echo General files... erikj@445: for f in $GENERAL_FILES erikj@445: do erikj@445: if [ -e $NEW/$f ]; then erikj@445: DIFF_OUT=$(diff $OLD/$f $NEW/$f 2>&1) erikj@445: if [ -n "$DIFF_OUT" ]; then erikj@445: echo $f erikj@445: echo "$DIFF_OUT" erikj@445: fi erikj@445: fi erikj@445: done erikj@445: erikj@445: ohair@425: if [ "x$CMP_ZIPS" == "xtrue" ]; then ohair@425: ZIPS=$(cd $OLD && find . -type f -name "*.zip" | sort | $FILTER) ohair@425: ohair@425: if [ -n "$ZIPS" ]; then ohair@425: echo Zip files... ohair@425: ohair@425: for f in $ZIPS ohair@425: do ohair@425: $DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW ohair@425: if [ "$?" != "0" ]; then ohair@425: DIFF_RESULT=1 ohair@425: fi ohair@425: done ohair@425: fi ohair@425: fi ohair@425: ohair@425: if [ "x$CMP_JARS" == "xtrue" ]; then erikj@445: JARS=$(cd $OLD && find . -type f -name "*.jar" -o -name "ct.sym" | sort | $FILTER) ohair@425: ohair@425: if [ -n "$JARS" ]; then ohair@425: echo Jar files... ohair@425: ohair@425: for f in $JARS ohair@425: do ohair@425: DIFFJAR_OUTPUT=`$DIFFJARZIP $OLD/$f $NEW/$f $OLD $NEW` ohair@425: DIFFJAR_RESULT=$? ohair@425: if [ "$DIFFJAR_RESULT" != "0" ]; then ohair@425: for diff in $LIST_DIFF_JAR; do ohair@425: DIFFJAR_OUTPUT=`echo "$DIFFJAR_OUTPUT" | grep -v "$diff"` ohair@425: done ohair@425: if [ "`echo "$DIFFJAR_OUTPUT" | grep -v "Differing files in"`" != "" ]; then ohair@425: DIFF_RESULT=1 ohair@425: echo "$DIFFJAR_OUTPUT" ohair@425: fi ohair@425: fi ohair@425: done ohair@425: fi ohair@425: fi ohair@425: ohair@425: if [ "x$FILTER" != "xcat" ]; then ohair@425: VIEW=view ohair@425: else ohair@425: VIEW= ohair@425: fi ohair@425: ohair@425: if [ "x$CMP_LIBS" == "xtrue" ]; then ohair@425: LIBS=$(cd $OLD && find . -name 'lib*.so' -o -name '*.dylib' -o -name '*.dll' | sort | $FILTER) ohair@425: ohair@425: if [ -n "$LIBS" ]; then ohair@425: echo Libraries... ohair@425: for f in $LIBS ohair@425: do ohair@425: DIFFLIB_OUTPUT=`$DIFFLIB $OLD/$f $NEW/$f $OLD $NEW $VIEW` ohair@425: DIFFLIB_RESULT=$? ohair@425: if [ "$DIFFLIB_RESULT" = "0" ]; then ohair@425: : ohair@425: #echo "OK: $DIFFLIB_OUTPUT" ohair@425: elif [ "$DIFFLIB_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then ohair@425: : ohair@425: #echo "OK: $DIFFLIB_OUTPUT" ohair@425: elif [ "$DIFFLIB_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then ohair@425: : ohair@425: #echo "OK: $DIFFLIB_OUTPUT" ohair@425: else ohair@425: echo "$DIFFLIB_OUTPUT" ohair@425: DIFF_RESULT=1 ohair@425: fi ohair@425: done ohair@425: fi ohair@425: fi ohair@425: ohair@425: if [ "x$CMP_EXECS" == "xtrue" ]; then ohair@425: if [ $OSTYPE == "cygwin" ]; then ohair@425: EXECS=$(cd $OLD && find . -type f -name '*.exe' | sort | $FILTER) ohair@425: else ohair@425: EXECS=$(cd $OLD && find . -type f -perm -100 \! \( -name '*.so' -o -name '*.dylib' -o -name '*.dll' \) | sort | $FILTER) ohair@425: fi ohair@425: ohair@425: ohair@425: if [ -n "$EXECS" ]; then ohair@425: echo Executables... ohair@425: ohair@425: for f in $EXECS ohair@425: do ohair@425: DIFFEXEC_OUTPUT=`$DIFFEXEC $OLD/$f $NEW/$f $OLD $NEW $VIEW` ohair@425: DIFFEXEC_RESULT=$? ohair@425: if [ "$DIFFEXEC_RESULT" = "0" ]; then ohair@425: : ohair@425: #echo "OK: $DIFFEXEC_OUTPUT" ohair@425: elif [ "$DIFFEXEC_RESULT" = "2" ] && [[ "$LIST_DIFF_SIZE $LIST_DIFF_BYTE" == *"${f:2}"* ]]; then ohair@425: : ohair@425: #echo "OK: $DIFFEXEC_OUTPUT" ohair@425: elif [ "$DIFFEXEC_RESULT" = "1" ] && [[ "$LIST_DIFF_BYTE" == *"${f:2}"* ]]; then ohair@425: : ohair@425: #echo "OK: $DIFFEXEC_OUTPUT" ohair@425: else ohair@425: echo "$DIFFEXEC_OUTPUT" ohair@425: DIFF_RESULT=1 ohair@425: fi ohair@425: done ohair@425: fi ohair@425: fi ohair@425: ohair@425: exit $DIFF_RESULT