common/bin/diffexec.sh

Tue, 10 Apr 2012 08:18:28 -0700

author
ohair
date
Tue, 10 Apr 2012 08:18:28 -0700
changeset 425
e1830598f0b7
child 445
efd26e051e50
permissions
-rw-r--r--

7074397: Build infrastructure changes (makefile re-write)
Summary: New makefiles transition, old and new living side by side for now.
Reviewed-by: ohair, jjg, dholmes, ohrstrom, erikj, ihse, tgranat, ykantser
Contributed-by: ohrstrom <fredrik.ohrstrom@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>

ohair@425 1 #!/bin/bash
ohair@425 2 #
ohair@425 3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
ohair@425 4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@425 5 #
ohair@425 6 # This code is free software; you can redistribute it and/or modify it
ohair@425 7 # under the terms of the GNU General Public License version 2 only, as
ohair@425 8 # published by the Free Software Foundation.
ohair@425 9 #
ohair@425 10 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@425 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@425 12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@425 13 # version 2 for more details (a copy is included in the LICENSE file that
ohair@425 14 # accompanied this code).
ohair@425 15 #
ohair@425 16 # You should have received a copy of the GNU General Public License version
ohair@425 17 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@425 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@425 19 #
ohair@425 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@425 21 # or visit www.oracle.com if you need additional information or have any
ohair@425 22 # questions.
ohair@425 23 #
ohair@425 24
ohair@425 25 if [ $# -lt 2 ]
ohair@425 26 then
ohair@425 27 echo "Diff two executables. Return codes:"
ohair@425 28 echo "0 - no diff"
ohair@425 29 echo "1 - Identical symbols AND size, BUT not bytewise identical"
ohair@425 30 echo "2 - Identical symbols BUT NEW size"
ohair@425 31 echo "3 - Differences, content BUT SAME size"
ohair@425 32 echo "4 - Differences, content AND size"
ohair@425 33 echo "10 - Could not perform diff"
ohair@425 34 echo "Use 'quiet' to disable any output."
ohair@425 35 echo "Syntax: $0 file1 file2 [quiet]"
ohair@425 36 exit 10
ohair@425 37 fi
ohair@425 38
ohair@425 39 if [ ! -f $1 ]
ohair@425 40 then
ohair@425 41 echo $1 does not exist
ohair@425 42 exit 10
ohair@425 43 fi
ohair@425 44
ohair@425 45 if [ ! -f $2 ]
ohair@425 46 then
ohair@425 47 echo $2 does not exist
ohair@425 48 exit 10
ohair@425 49 fi
ohair@425 50
ohair@425 51 if [ "`uname`" == "SunOS" ]; then
ohair@425 52 NM=gnm
ohair@425 53 STAT=gstat
ohair@425 54 elif [ $OSTYPE == "cygwin" ]; then
ohair@425 55 NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe"
ohair@425 56 NM_ARGS=/exports
ohair@425 57 STAT=stat
ohair@425 58 else
ohair@425 59 NM=nm
ohair@425 60 STAT=stat
ohair@425 61 fi
ohair@425 62
ohair@425 63 # Should the differences be viewed?
ohair@425 64 VIEW=
ohair@425 65 # You can do export DIFF=meld to view
ohair@425 66 # any differences using meld instead.
ohair@425 67 if [ -n "$DIFF" ]; then
ohair@425 68 DIFF="$DIFF"
ohair@425 69 else
ohair@425 70 DIFF=diff
ohair@425 71 fi
ohair@425 72 OLD=$(cd $(dirname $1) && pwd)/$(basename $1)
ohair@425 73 NEW=$(cd $(dirname $2) && pwd)/$(basename $2)
ohair@425 74
ohair@425 75 OLD_SIZE=$($STAT -c%s "$OLD")
ohair@425 76 NEW_SIZE=$($STAT -c%s "$NEW")
ohair@425 77
ohair@425 78 if [ $# -gt 3 ]
ohair@425 79 then
ohair@425 80 ROOT1=$(cd $3 && pwd)
ohair@425 81 ROOT2=$(cd $4 && pwd)
ohair@425 82 OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||")
ohair@425 83 NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||")
ohair@425 84 if [ "x$5" == "xview" ]; then VIEW=view; fi
ohair@425 85 else
ohair@425 86 ROOT1=$(dirname $OLD)/
ohair@425 87 ROOT2=$(dirname $NEW)/
ohair@425 88 OLD_NAME=$OLD
ohair@425 89 NEW_NAME=$NEW
ohair@425 90 if [ "x$3" == "xview" ]; then VIEW=view; fi
ohair@425 91 fi
ohair@425 92
ohair@425 93 if cmp $OLD $NEW > /dev/null
ohair@425 94 then
ohair@425 95 # The files were bytewise identical.
ohair@425 96 echo Identical: $OLD_NAME
ohair@425 97 exit 0
ohair@425 98 fi
ohair@425 99
ohair@425 100 OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old
ohair@425 101 NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new
ohair@425 102
ohair@425 103 mkdir -p $(dirname $OLD_SYMBOLS)
ohair@425 104 mkdir -p $(dirname $NEW_SYMBOLS)
ohair@425 105
ohair@425 106 if [ $OSTYPE == "cygwin" ]; then
ohair@425 107 "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS
ohair@425 108 "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS
ohair@425 109 "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full
ohair@425 110 "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full
ohair@425 111 else
ohair@425 112 # Strip the addresses, just compare the ordering of the symbols.
ohair@425 113 $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS
ohair@425 114 $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS
ohair@425 115 # But store the full information for easy diff access.
ohair@425 116 $NM $OLD > $OLD_SYMBOLS.full
ohair@425 117 $NM $NEW > $NEW_SYMBOLS.full
ohair@425 118 fi
ohair@425 119
ohair@425 120 DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS)
ohair@425 121
ohair@425 122 RESULT=0
ohair@425 123
ohair@425 124 if [ -n "$DIFFS" ]; then
ohair@425 125 if [ $OLD_SIZE -ne $NEW_SIZE ]
ohair@425 126 then
ohair@425 127 echo Differences, content AND size : $OLD_NAME
ohair@425 128 RESULT=4
ohair@425 129 else
ohair@425 130 echo Differences, content BUT SAME size: $OLD_NAME
ohair@425 131 RESULT=3
ohair@425 132 fi
ohair@425 133 if [ "x$VIEW" == "xview" ]; then
ohair@425 134 LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS
ohair@425 135 fi
ohair@425 136 else
ohair@425 137 if [ $OLD_SIZE -ne $NEW_SIZE ]
ohair@425 138 then
ohair@425 139 echo Identical symbols BUT NEW size : $OLD_NAME
ohair@425 140 RESULT=2
ohair@425 141 else
ohair@425 142 echo Identical symbols AND size, BUT not bytewise identical: $OLD_NAME
ohair@425 143 RESULT=1
ohair@425 144 fi
ohair@425 145 fi
ohair@425 146
ohair@425 147 exit $RESULT
ohair@425 148
ohair@425 149
ohair@425 150

mercurial