< prev index next >

common/bin/compare.sh

Print this page


   1 #!/bin/bash
   2 #
   3 # Copyright (c) 2012, 2015, 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 #


 729     if [ "$SORT_ALL_SYMBOLS" = "true" ] || [[ "$SORT_SYMBOLS" = *"$BIN_FILE"* ]]; then
 730         SYM_SORT_CMD="sort"
 731     else
 732         SYM_SORT_CMD="cat"
 733     fi
 734 
 735     # Check symbols
 736     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 737         # The output from dumpbin on windows differs depending on if the debug symbol
 738         # files are still around at the location the binary is pointing too. Need
 739         # to filter out that extra information.
 740         $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
 741         $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
 742     elif [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 743         # Some symbols get seemingly random 15 character prefixes. Filter them out.
 744         $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
 745         $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
 746     elif [ "$OPENJDK_TARGET_OS" = "aix" ]; then
 747         $OBJDUMP -T $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 748         $OBJDUMP -T $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this



 749     else
 750         $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
 751         $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
 752     fi
 753 
 754     LC_ALL=C $DIFF $WORK_FILE_BASE.symbols.other $WORK_FILE_BASE.symbols.this > $WORK_FILE_BASE.symbols.diff
 755     if [ -s $WORK_FILE_BASE.symbols.diff ]; then
 756         SYM_MSG=" diff  "
 757         if [[ "$ACCEPTED_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 758             DIFF_SYM=true
 759             if [[ "$KNOWN_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 760                 SYM_MSG="*$SYM_MSG*"
 761                 REGRESSIONS=true
 762             else
 763                 SYM_MSG=" $SYM_MSG "
 764             fi
 765         else
 766             SYM_MSG="($SYM_MSG)"
 767             DIFF_SYM=
 768         fi


1003 
1004     if [ -n "$EXECS" ]; then
1005         echo Executables...
1006         print_binary_diff_header
1007         for e in $EXECS; do
1008             if [ -f "$OTHER_DIR/$e" ]; then
1009                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $e
1010                 if [ "$?" != "0" ]; then
1011                     return_value=1
1012                 fi
1013             fi
1014         done
1015     fi
1016 
1017     return $return_value
1018 }
1019 
1020 ################################################################################
1021 # Initiate configuration
1022 
1023 COMPARE_ROOT=/tmp/cimages.$USER
1024 $MKDIR -p $COMPARE_ROOT
1025 if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1026     if [ "$(uname -o)" = "Cygwin" ]; then
1027         COMPARE_ROOT=$(cygpath -msa $COMPARE_ROOT)
1028     fi
1029 fi
1030 
1031 THIS="$SCRIPT_DIR"
1032 echo "$THIS"
1033 THIS_SCRIPT="$0"
1034 
1035 if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "/h" ] || [ "$1" = "/?" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
1036     echo "bash ./compare.sh [OPTIONS] [FILTER]"
1037     echo ""
1038     echo "-all                Compare all files in all known ways"
1039     echo "-names              Compare the file names and directory structure"
1040     echo "-perms              Compare the permission bits on all files and directories"
1041     echo "-types              Compare the output of the file command on all files"
1042     echo "-general            Compare the files not convered by the specialized comparisons"
1043     echo "-zips               Compare the contents of all zip files"
1044     echo "-jars               Compare the contents of all jar files"
1045     echo "-libs               Compare all native libraries"
1046     echo "-execs              Compare all executables"
1047     echo "-v                  Verbose output, does not hide known differences"
1048     echo "-vv                 More verbose output, shows diff output of all comparisons"
1049     echo "-o [OTHER]          Compare with build in other directory. Will default to the old build directory"
1050     echo ""
1051     echo "--sort-symbols      Sort all symbols before comparing"
1052     echo "--strip             Strip all binaries before comparing"

1053     echo ""
1054     echo "[FILTER]            List filenames in the image to compare, works for jars, zips, libs and execs"
1055     echo "Example:"
1056     echo "bash ./common/bin/compareimages.sh CodePointIM.jar"
1057     echo ""
1058     echo "-2zips <file1> <file2> Compare two zip files only"
1059     echo "-2bins <file1> <file2> Compare two binary files only"
1060     echo "-2dirs <dir1> <dir2> Compare two directories as if they were images"
1061     echo ""
1062     exit 10
1063 fi
1064 
1065 CMP_NAMES=false
1066 CMP_PERMS=false
1067 CMP_TYPES=false
1068 CMP_GENERAL=false
1069 CMP_ZIPS=false
1070 CMP_JARS=false
1071 CMP_LIBS=false
1072 CMP_EXECS=false


1132         -2zips)
1133             CMP_2_ZIPS=true
1134             THIS_FILE=$2
1135             OTHER_FILE=$3
1136             shift
1137             shift
1138             ;;
1139         -2bins)
1140             CMP_2_BINS=true
1141             THIS_FILE=$2
1142             OTHER_FILE=$3
1143             shift
1144             shift
1145             ;;
1146         --sort-symbols)
1147             SORT_ALL_SYMBOLS=true
1148             ;;
1149         --strip)
1150             STRIP_ALL=true
1151             ;;



1152         *)
1153             CMP_NAMES=false
1154             CMP_PERMS=false
1155             CMP_TYPES=false
1156             CMP_ZIPS=true
1157             CMP_JARS=true
1158             CMP_LIBS=true
1159             CMP_EXECS=true
1160 
1161             if [ -z "$FILTER" ]; then
1162                 FILTER="$GREP"
1163             fi
1164             FILTER="$FILTER -e $1"
1165             ;;
1166     esac
1167     shift
1168 done

















1169 
1170 if [ "$CMP_2_ZIPS" = "true" ]; then
1171     THIS_DIR="$(dirname $THIS_FILE)"
1172     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1173     OTHER_DIR="$(dirname $OTHER_FILE)"
1174     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1175     THIS_FILE_NAME="$(basename $THIS_FILE)"
1176     OTHER_FILE_NAME="$(basename $OTHER_FILE)"
1177     echo Comparing $THIS_DIR/$THIS_FILE_NAME and $OTHER_DIR/$OTHER_FILE_NAME
1178     compare_zip_file $THIS_DIR $OTHER_DIR $COMPARE_ROOT/2zips $THIS_FILE_NAME $OTHER_FILE_NAME
1179     exit
1180 fi
1181 
1182 if [ "$CMP_2_BINS" = "true" ]; then
1183     THIS_DIR="$(dirname $THIS_FILE)"
1184     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1185     OTHER_DIR="$(dirname $OTHER_FILE)"
1186     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1187     THIS_FILE_NAME="$(basename $THIS_FILE)"
1188     OTHER_FILE_NAME="$(basename $OTHER_FILE)"


   1 #!/bin/bash
   2 #
   3 # Copyright (c) 2012, 2016, 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 #


 729     if [ "$SORT_ALL_SYMBOLS" = "true" ] || [[ "$SORT_SYMBOLS" = *"$BIN_FILE"* ]]; then
 730         SYM_SORT_CMD="sort"
 731     else
 732         SYM_SORT_CMD="cat"
 733     fi
 734 
 735     # Check symbols
 736     if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
 737         # The output from dumpbin on windows differs depending on if the debug symbol
 738         # files are still around at the location the binary is pointing too. Need
 739         # to filter out that extra information.
 740         $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
 741         $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
 742     elif [ "$OPENJDK_TARGET_OS" = "solaris" ]; then
 743         # Some symbols get seemingly random 15 character prefixes. Filter them out.
 744         $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
 745         $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
 746     elif [ "$OPENJDK_TARGET_OS" = "aix" ]; then
 747         $OBJDUMP -T $ORIG_OTHER_FILE 2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 748         $OBJDUMP -T $ORIG_THIS_FILE  2> /dev/null | $GREP -v $NAME | $AWK '{print $2, $3, $4, $5}' | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 749     elif [ "$OPENJDK_TARGET_OS" = "macosx" ]; then
 750         $NM -j $ORIG_OTHER_FILE 2> /dev/null | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.other
 751         $NM -j $ORIG_THIS_FILE  2> /dev/null | $SYM_SORT_CMD > $WORK_FILE_BASE.symbols.this
 752     else
 753         $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
 754         $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
 755     fi
 756 
 757     LC_ALL=C $DIFF $WORK_FILE_BASE.symbols.other $WORK_FILE_BASE.symbols.this > $WORK_FILE_BASE.symbols.diff
 758     if [ -s $WORK_FILE_BASE.symbols.diff ]; then
 759         SYM_MSG=" diff  "
 760         if [[ "$ACCEPTED_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 761             DIFF_SYM=true
 762             if [[ "$KNOWN_SYM_DIFF" != *"$BIN_FILE"* ]]; then
 763                 SYM_MSG="*$SYM_MSG*"
 764                 REGRESSIONS=true
 765             else
 766                 SYM_MSG=" $SYM_MSG "
 767             fi
 768         else
 769             SYM_MSG="($SYM_MSG)"
 770             DIFF_SYM=
 771         fi


1006 
1007     if [ -n "$EXECS" ]; then
1008         echo Executables...
1009         print_binary_diff_header
1010         for e in $EXECS; do
1011             if [ -f "$OTHER_DIR/$e" ]; then
1012                 compare_bin_file $THIS_DIR $OTHER_DIR $WORK_DIR $e
1013                 if [ "$?" != "0" ]; then
1014                     return_value=1
1015                 fi
1016             fi
1017         done
1018     fi
1019 
1020     return $return_value
1021 }
1022 
1023 ################################################################################
1024 # Initiate configuration
1025 








1026 THIS="$SCRIPT_DIR"
1027 echo "$THIS"
1028 THIS_SCRIPT="$0"
1029 
1030 if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ] || [ "$1" = "/h" ] || [ "$1" = "/?" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
1031     echo "bash ./compare.sh [OPTIONS] [FILTER]"
1032     echo ""
1033     echo "-all                Compare all files in all known ways"
1034     echo "-names              Compare the file names and directory structure"
1035     echo "-perms              Compare the permission bits on all files and directories"
1036     echo "-types              Compare the output of the file command on all files"
1037     echo "-general            Compare the files not convered by the specialized comparisons"
1038     echo "-zips               Compare the contents of all zip files"
1039     echo "-jars               Compare the contents of all jar files"
1040     echo "-libs               Compare all native libraries"
1041     echo "-execs              Compare all executables"
1042     echo "-v                  Verbose output, does not hide known differences"
1043     echo "-vv                 More verbose output, shows diff output of all comparisons"
1044     echo "-o [OTHER]          Compare with build in other directory. Will default to the old build directory"
1045     echo ""
1046     echo "--sort-symbols      Sort all symbols before comparing"
1047     echo "--strip             Strip all binaries before comparing"
1048     echo "--clean             Clean all previous comparison results first"
1049     echo ""
1050     echo "[FILTER]            List filenames in the image to compare, works for jars, zips, libs and execs"
1051     echo "Example:"
1052     echo "bash ./common/bin/compareimages.sh CodePointIM.jar"
1053     echo ""
1054     echo "-2zips <file1> <file2> Compare two zip files only"
1055     echo "-2bins <file1> <file2> Compare two binary files only"
1056     echo "-2dirs <dir1> <dir2> Compare two directories as if they were images"
1057     echo ""
1058     exit 10
1059 fi
1060 
1061 CMP_NAMES=false
1062 CMP_PERMS=false
1063 CMP_TYPES=false
1064 CMP_GENERAL=false
1065 CMP_ZIPS=false
1066 CMP_JARS=false
1067 CMP_LIBS=false
1068 CMP_EXECS=false


1128         -2zips)
1129             CMP_2_ZIPS=true
1130             THIS_FILE=$2
1131             OTHER_FILE=$3
1132             shift
1133             shift
1134             ;;
1135         -2bins)
1136             CMP_2_BINS=true
1137             THIS_FILE=$2
1138             OTHER_FILE=$3
1139             shift
1140             shift
1141             ;;
1142         --sort-symbols)
1143             SORT_ALL_SYMBOLS=true
1144             ;;
1145         --strip)
1146             STRIP_ALL=true
1147             ;;
1148         --clean)
1149             CLEAN_OUTPUT=true
1150             ;;
1151         *)
1152             CMP_NAMES=false
1153             CMP_PERMS=false
1154             CMP_TYPES=false
1155             CMP_ZIPS=true
1156             CMP_JARS=true
1157             CMP_LIBS=true
1158             CMP_EXECS=true
1159 
1160             if [ -z "$FILTER" ]; then
1161                 FILTER="$GREP"
1162             fi
1163             FILTER="$FILTER -e $1"
1164             ;;
1165     esac
1166     shift
1167 done
1168 
1169 if [ "$STRIP_ALL" = "true" ] && [ -z "$STRIP" ]; then
1170   echo Warning: Not stripping even with --strip, since strip is missing on this platform
1171   STRIP_ALL=false
1172 fi
1173 
1174 COMPARE_ROOT=/tmp/cimages.$USER
1175 if [ "$CLEAN_OUTPUT" = "true" ]; then
1176     echo Cleaning old output in $COMPARE_ROOT.
1177     $RM -rf $COMPARE_ROOT
1178 fi
1179 $MKDIR -p $COMPARE_ROOT
1180 if [ "$OPENJDK_TARGET_OS" = "windows" ]; then
1181     if [ "$(uname -o)" = "Cygwin" ]; then
1182         COMPARE_ROOT=$(cygpath -msa $COMPARE_ROOT)
1183     fi
1184 fi
1185 
1186 if [ "$CMP_2_ZIPS" = "true" ]; then
1187     THIS_DIR="$(dirname $THIS_FILE)"
1188     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1189     OTHER_DIR="$(dirname $OTHER_FILE)"
1190     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1191     THIS_FILE_NAME="$(basename $THIS_FILE)"
1192     OTHER_FILE_NAME="$(basename $OTHER_FILE)"
1193     echo Comparing $THIS_DIR/$THIS_FILE_NAME and $OTHER_DIR/$OTHER_FILE_NAME
1194     compare_zip_file $THIS_DIR $OTHER_DIR $COMPARE_ROOT/2zips $THIS_FILE_NAME $OTHER_FILE_NAME
1195     exit
1196 fi
1197 
1198 if [ "$CMP_2_BINS" = "true" ]; then
1199     THIS_DIR="$(dirname $THIS_FILE)"
1200     THIS_DIR="$(cd "$THIS_DIR" > /dev/null && pwd )"
1201     OTHER_DIR="$(dirname $OTHER_FILE)"
1202     OTHER_DIR="$(cd "$OTHER_DIR" > /dev/null && pwd )"
1203     THIS_FILE_NAME="$(basename $THIS_FILE)"
1204     OTHER_FILE_NAME="$(basename $OTHER_FILE)"


< prev index next >