common/bin/diffexec.sh

changeset 425
e1830598f0b7
child 445
efd26e051e50
equal deleted inserted replaced
419:42f275168fa5 425:e1830598f0b7
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 #
24
25 if [ $# -lt 2 ]
26 then
27 echo "Diff two executables. Return codes:"
28 echo "0 - no diff"
29 echo "1 - Identical symbols AND size, BUT not bytewise identical"
30 echo "2 - Identical symbols BUT NEW size"
31 echo "3 - Differences, content BUT SAME size"
32 echo "4 - Differences, content AND size"
33 echo "10 - Could not perform diff"
34 echo "Use 'quiet' to disable any output."
35 echo "Syntax: $0 file1 file2 [quiet]"
36 exit 10
37 fi
38
39 if [ ! -f $1 ]
40 then
41 echo $1 does not exist
42 exit 10
43 fi
44
45 if [ ! -f $2 ]
46 then
47 echo $2 does not exist
48 exit 10
49 fi
50
51 if [ "`uname`" == "SunOS" ]; then
52 NM=gnm
53 STAT=gstat
54 elif [ $OSTYPE == "cygwin" ]; then
55 NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe"
56 NM_ARGS=/exports
57 STAT=stat
58 else
59 NM=nm
60 STAT=stat
61 fi
62
63 # Should the differences be viewed?
64 VIEW=
65 # You can do export DIFF=meld to view
66 # any differences using meld instead.
67 if [ -n "$DIFF" ]; then
68 DIFF="$DIFF"
69 else
70 DIFF=diff
71 fi
72 OLD=$(cd $(dirname $1) && pwd)/$(basename $1)
73 NEW=$(cd $(dirname $2) && pwd)/$(basename $2)
74
75 OLD_SIZE=$($STAT -c%s "$OLD")
76 NEW_SIZE=$($STAT -c%s "$NEW")
77
78 if [ $# -gt 3 ]
79 then
80 ROOT1=$(cd $3 && pwd)
81 ROOT2=$(cd $4 && pwd)
82 OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||")
83 NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||")
84 if [ "x$5" == "xview" ]; then VIEW=view; fi
85 else
86 ROOT1=$(dirname $OLD)/
87 ROOT2=$(dirname $NEW)/
88 OLD_NAME=$OLD
89 NEW_NAME=$NEW
90 if [ "x$3" == "xview" ]; then VIEW=view; fi
91 fi
92
93 if cmp $OLD $NEW > /dev/null
94 then
95 # The files were bytewise identical.
96 echo Identical: $OLD_NAME
97 exit 0
98 fi
99
100 OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old
101 NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new
102
103 mkdir -p $(dirname $OLD_SYMBOLS)
104 mkdir -p $(dirname $NEW_SYMBOLS)
105
106 if [ $OSTYPE == "cygwin" ]; then
107 "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS
108 "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS
109 "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full
110 "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full
111 else
112 # Strip the addresses, just compare the ordering of the symbols.
113 $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS
114 $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS
115 # But store the full information for easy diff access.
116 $NM $OLD > $OLD_SYMBOLS.full
117 $NM $NEW > $NEW_SYMBOLS.full
118 fi
119
120 DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS)
121
122 RESULT=0
123
124 if [ -n "$DIFFS" ]; then
125 if [ $OLD_SIZE -ne $NEW_SIZE ]
126 then
127 echo Differences, content AND size : $OLD_NAME
128 RESULT=4
129 else
130 echo Differences, content BUT SAME size: $OLD_NAME
131 RESULT=3
132 fi
133 if [ "x$VIEW" == "xview" ]; then
134 LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS
135 fi
136 else
137 if [ $OLD_SIZE -ne $NEW_SIZE ]
138 then
139 echo Identical symbols BUT NEW size : $OLD_NAME
140 RESULT=2
141 else
142 echo Identical symbols AND size, BUT not bytewise identical: $OLD_NAME
143 RESULT=1
144 fi
145 fi
146
147 exit $RESULT
148
149
150

mercurial