common/bin/diffexec.sh
changeset 12258 6ec26f6cc53e
child 12801 948f8ad66ee7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/bin/diffexec.sh	Tue Apr 10 08:18:28 2012 -0700
@@ -0,0 +1,150 @@
+#!/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.
+#
+
+if [ $# -lt 2 ] 
+then
+  echo "Diff two executables. Return codes:"
+  echo "0 - no diff"
+  echo "1 - Identical symbols AND size, BUT not bytewise identical"
+  echo "2 - Identical symbols BUT NEW size"
+  echo "3 - Differences, content BUT SAME size"
+  echo "4 - Differences, content AND size"
+  echo "10 - Could not perform diff"
+  echo "Use 'quiet' to disable any output."
+  echo "Syntax: $0 file1 file2 [quiet]"
+  exit 10
+fi
+
+if [ ! -f $1 ]
+then
+  echo $1 does not exist
+  exit 10
+fi
+
+if [ ! -f $2 ]
+then
+  echo $2 does not exist
+  exit 10
+fi
+
+if [ "`uname`" == "SunOS" ]; then
+    NM=gnm
+    STAT=gstat
+elif [ $OSTYPE == "cygwin" ]; then
+    NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe"
+    NM_ARGS=/exports
+    STAT=stat
+else
+    NM=nm
+    STAT=stat
+fi
+
+# Should the differences be viewed?
+VIEW=
+# You can do export DIFF=meld to view
+# any differences using meld instead.
+if [ -n "$DIFF" ]; then
+    DIFF="$DIFF"
+else
+    DIFF=diff
+fi
+OLD=$(cd $(dirname $1) && pwd)/$(basename $1)
+NEW=$(cd $(dirname $2) && pwd)/$(basename $2)
+
+OLD_SIZE=$($STAT -c%s "$OLD")
+NEW_SIZE=$($STAT -c%s "$NEW")
+
+if [ $# -gt 3 ]
+then
+    ROOT1=$(cd $3 && pwd)
+    ROOT2=$(cd $4 && pwd)
+    OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||")
+    NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||")
+    if [ "x$5" == "xview" ]; then VIEW=view; fi
+else
+    ROOT1=$(dirname $OLD)/
+    ROOT2=$(dirname $NEW)/
+    OLD_NAME=$OLD
+    NEW_NAME=$NEW
+    if [ "x$3" == "xview" ]; then VIEW=view; fi
+fi
+
+if cmp $OLD $NEW > /dev/null
+then
+    # The files were bytewise identical.
+    echo Identical: $OLD_NAME
+    exit 0
+fi
+
+OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old
+NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new
+
+mkdir -p $(dirname $OLD_SYMBOLS)
+mkdir -p $(dirname $NEW_SYMBOLS)
+
+if [ $OSTYPE == "cygwin" ]; then
+    "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS
+    "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS
+    "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full
+    "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full
+else
+    # Strip the addresses, just compare the ordering of the symbols.
+    $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS
+    $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS
+    # But store the full information for easy diff access.
+    $NM $OLD  > $OLD_SYMBOLS.full
+    $NM $NEW  > $NEW_SYMBOLS.full
+fi
+
+DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS)
+
+RESULT=0
+
+if [ -n "$DIFFS" ]; then
+   if [ $OLD_SIZE -ne $NEW_SIZE ]
+   then
+       echo Differences, content AND size     : $OLD_NAME 
+       RESULT=4
+   else
+       echo Differences, content BUT SAME size: $OLD_NAME 
+       RESULT=3
+   fi
+   if [ "x$VIEW" == "xview" ]; then
+       LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS
+   fi
+else
+   if [ $OLD_SIZE -ne $NEW_SIZE ]
+   then
+       echo Identical symbols BUT NEW size    : $OLD_NAME 
+       RESULT=2
+   else
+       echo Identical symbols AND size, BUT not bytewise identical: $OLD_NAME 
+       RESULT=1
+   fi
+fi
+
+exit $RESULT
+
+
+