Tue, 18 Sep 2012 11:29:16 -0700
7197849: Update new build-infra makefiles
Reviewed-by: ihse, erikj, ohrstrom, tbell
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 |
erikj@458 | 52 | if [ -f "`which nm`" ]; then |
erikj@458 | 53 | NM=nm |
erikj@458 | 54 | elif [ -f "`which gnm`" ]; then |
erikj@458 | 55 | NM=gnm |
erikj@458 | 56 | else |
erikj@458 | 57 | echo "No nm command found" |
erikj@458 | 58 | exit 10 |
erikj@458 | 59 | fi |
erikj@445 | 60 | LDD=ldd |
ohair@425 | 61 | elif [ $OSTYPE == "cygwin" ]; then |
ohair@425 | 62 | NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe" |
ohair@425 | 63 | NM_ARGS=/exports |
erikj@445 | 64 | LDD= |
erikj@445 | 65 | elif [ "`uname`" == "Darwin" ]; then |
erikj@445 | 66 | NM=nm |
erikj@445 | 67 | LDD="otool -L" |
ohair@425 | 68 | else |
ohair@425 | 69 | NM=nm |
erikj@445 | 70 | LDD=ldd |
ohair@425 | 71 | fi |
ohair@425 | 72 | |
ohair@425 | 73 | # Should the differences be viewed? |
ohair@425 | 74 | VIEW= |
ohair@425 | 75 | # You can do export DIFF=meld to view |
ohair@425 | 76 | # any differences using meld instead. |
ohair@425 | 77 | if [ -n "$DIFF" ]; then |
ohair@425 | 78 | DIFF="$DIFF" |
ohair@425 | 79 | else |
ohair@425 | 80 | DIFF=diff |
ohair@425 | 81 | fi |
ohair@425 | 82 | OLD=$(cd $(dirname $1) && pwd)/$(basename $1) |
ohair@425 | 83 | NEW=$(cd $(dirname $2) && pwd)/$(basename $2) |
ohair@425 | 84 | |
erikj@458 | 85 | OLD_SIZE=$(ls -l "$OLD" | awk '{ print $5 }') |
erikj@458 | 86 | NEW_SIZE=$(ls -l "$NEW" | awk '{ print $5 }') |
ohair@425 | 87 | |
ohair@425 | 88 | if [ $# -gt 3 ] |
ohair@425 | 89 | then |
ohair@425 | 90 | ROOT1=$(cd $3 && pwd) |
ohair@425 | 91 | ROOT2=$(cd $4 && pwd) |
ohair@425 | 92 | OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||") |
ohair@425 | 93 | NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||") |
ohair@425 | 94 | if [ "x$5" == "xview" ]; then VIEW=view; fi |
ohair@425 | 95 | else |
ohair@425 | 96 | ROOT1=$(dirname $OLD)/ |
ohair@425 | 97 | ROOT2=$(dirname $NEW)/ |
ohair@425 | 98 | OLD_NAME=$OLD |
ohair@425 | 99 | NEW_NAME=$NEW |
ohair@425 | 100 | if [ "x$3" == "xview" ]; then VIEW=view; fi |
ohair@425 | 101 | fi |
ohair@425 | 102 | |
ohair@425 | 103 | if cmp $OLD $NEW > /dev/null |
ohair@425 | 104 | then |
ohair@425 | 105 | # The files were bytewise identical. |
ohair@425 | 106 | echo Identical: $OLD_NAME |
ohair@425 | 107 | exit 0 |
ohair@425 | 108 | fi |
ohair@425 | 109 | |
ohair@425 | 110 | OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old |
ohair@425 | 111 | NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new |
ohair@425 | 112 | |
ohair@425 | 113 | mkdir -p $(dirname $OLD_SYMBOLS) |
ohair@425 | 114 | mkdir -p $(dirname $NEW_SYMBOLS) |
ohair@425 | 115 | |
ohair@425 | 116 | if [ $OSTYPE == "cygwin" ]; then |
ohair@425 | 117 | "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS |
ohair@425 | 118 | "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS |
ohair@425 | 119 | "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full |
ohair@425 | 120 | "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full |
ohair@425 | 121 | else |
ohair@425 | 122 | # Strip the addresses, just compare the ordering of the symbols. |
ohair@425 | 123 | $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS |
ohair@425 | 124 | $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS |
ohair@425 | 125 | # But store the full information for easy diff access. |
ohair@425 | 126 | $NM $OLD > $OLD_SYMBOLS.full |
ohair@425 | 127 | $NM $NEW > $NEW_SYMBOLS.full |
ohair@425 | 128 | fi |
ohair@425 | 129 | |
ohair@425 | 130 | DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS) |
ohair@425 | 131 | |
erikj@445 | 132 | if [ "${LDD}" ] |
erikj@445 | 133 | then |
erikj@445 | 134 | NAME=`basename $OLD` |
erikj@445 | 135 | TMP=$COMPARE_ROOT/ldd/ldd.${NAME} |
erikj@445 | 136 | rm -rf "${TMP}" |
erikj@445 | 137 | mkdir -p "${TMP}" |
erikj@445 | 138 | |
erikj@445 | 139 | (cd "${TMP}" && cp $OLD . && ${LDD} ${NAME} | awk '{ print $1;}' | sort | tee dep.old | uniq > dep.uniq.old) |
erikj@445 | 140 | (cd "${TMP}" && cp $NEW . && ${LDD} ${NAME} | awk '{ print $1;}' | sort | tee dep.new | uniq > dep.uniq.new) |
erikj@445 | 141 | (cd "${TMP}" && rm -f ${NAME}) |
erikj@445 | 142 | |
erikj@445 | 143 | DIFFS_DEP=$(LANG=C diff "${TMP}/dep.old" "${TMP}/dep.new") |
erikj@445 | 144 | DIFFS_UNIQ_DEP=$(LANG=C diff "${TMP}/dep.uniq.old" "${TMP}/dep.uniq.new") |
erikj@445 | 145 | |
erikj@445 | 146 | DEP_MSG= |
erikj@445 | 147 | if [ -z "${DIFFS_UNIQ_DEP}" -a -z "${DIFFS_DEP}" ]; then |
erikj@445 | 148 | DEP_MSG="Identical dependencies" |
erikj@445 | 149 | elif [ -z "${DIFFS_UNIQ_DEP}" ]; then |
erikj@445 | 150 | DEP_MSG="Redundant duplicate dependencies added" |
erikj@445 | 151 | RES=1 |
erikj@445 | 152 | else |
erikj@445 | 153 | DEP_MSG="DIFFERENT dependencies" |
erikj@445 | 154 | RES=1 |
erikj@445 | 155 | fi |
erikj@445 | 156 | fi |
erikj@445 | 157 | |
ohair@425 | 158 | RESULT=0 |
ohair@425 | 159 | |
ohair@425 | 160 | if [ -n "$DIFFS" ]; then |
ohair@425 | 161 | if [ $OLD_SIZE -ne $NEW_SIZE ] |
ohair@425 | 162 | then |
erikj@445 | 163 | echo Differences, content AND size : $DEP_MSG : $OLD_NAME |
ohair@425 | 164 | RESULT=4 |
ohair@425 | 165 | else |
erikj@445 | 166 | echo Differences, content BUT SAME size: $DEP_MSG : $OLD_NAME |
ohair@425 | 167 | RESULT=3 |
ohair@425 | 168 | fi |
ohair@425 | 169 | if [ "x$VIEW" == "xview" ]; then |
ohair@425 | 170 | LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS |
ohair@425 | 171 | fi |
ohair@425 | 172 | else |
ohair@425 | 173 | if [ $OLD_SIZE -ne $NEW_SIZE ] |
ohair@425 | 174 | then |
erikj@445 | 175 | echo Identical symbols BUT NEW size : $DEP_MSG : $OLD_NAME |
ohair@425 | 176 | RESULT=2 |
ohair@425 | 177 | else |
erikj@445 | 178 | echo Identical symbols AND size, BUT not bytewise identical: $DEP_MSG : $OLD_NAME |
ohair@425 | 179 | RESULT=1 |
ohair@425 | 180 | fi |
ohair@425 | 181 | fi |
ohair@425 | 182 | |
ohair@425 | 183 | exit $RESULT |
ohair@425 | 184 | |
ohair@425 | 185 | |
ohair@425 | 186 |