common/bin/diffexec.sh

Thu, 07 Jun 2012 20:25:06 -0700

author
erikj
date
Thu, 07 Jun 2012 20:25:06 -0700
changeset 445
efd26e051e50
parent 425
e1830598f0b7
child 458
c8d320b48626
permissions
-rw-r--r--

7170079: Adjustments to build-infra makefiles
Reviewed-by: ohair, ohrstrom, ihse, jonas
Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>

     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 #
    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
    39 if [ ! -f $1 ]
    40 then
    41   echo $1 does not exist
    42   exit 10
    43 fi
    45 if [ ! -f $2 ]
    46 then
    47   echo $2 does not exist
    48   exit 10
    49 fi
    51 if [ "`uname`" == "SunOS" ]; then
    52     NM=gnm
    53     STAT="gstat -c%s"
    54     LDD=ldd
    55 elif [ $OSTYPE == "cygwin" ]; then
    56     NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe"
    57     NM_ARGS=/exports
    58     STAT="stat -c%s"
    59     LDD=
    60 elif [ "`uname`" == "Darwin" ]; then
    61     NM=nm
    62     STAT="stat -f%z"
    63     LDD="otool -L"
    64 else
    65     NM=nm
    66     STAT="stat -c%s"
    67     LDD=ldd
    68 fi
    70 # Should the differences be viewed?
    71 VIEW=
    72 # You can do export DIFF=meld to view
    73 # any differences using meld instead.
    74 if [ -n "$DIFF" ]; then
    75     DIFF="$DIFF"
    76 else
    77     DIFF=diff
    78 fi
    79 OLD=$(cd $(dirname $1) && pwd)/$(basename $1)
    80 NEW=$(cd $(dirname $2) && pwd)/$(basename $2)
    82 OLD_SIZE=$($STAT "$OLD")
    83 NEW_SIZE=$($STAT "$NEW")
    85 if [ $# -gt 3 ]
    86 then
    87     ROOT1=$(cd $3 && pwd)
    88     ROOT2=$(cd $4 && pwd)
    89     OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||")
    90     NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||")
    91     if [ "x$5" == "xview" ]; then VIEW=view; fi
    92 else
    93     ROOT1=$(dirname $OLD)/
    94     ROOT2=$(dirname $NEW)/
    95     OLD_NAME=$OLD
    96     NEW_NAME=$NEW
    97     if [ "x$3" == "xview" ]; then VIEW=view; fi
    98 fi
   100 if cmp $OLD $NEW > /dev/null
   101 then
   102     # The files were bytewise identical.
   103     echo Identical: $OLD_NAME
   104     exit 0
   105 fi
   107 OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old
   108 NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new
   110 mkdir -p $(dirname $OLD_SYMBOLS)
   111 mkdir -p $(dirname $NEW_SYMBOLS)
   113 if [ $OSTYPE == "cygwin" ]; then
   114     "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS
   115     "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS
   116     "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full
   117     "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full
   118 else
   119     # Strip the addresses, just compare the ordering of the symbols.
   120     $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS
   121     $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS
   122     # But store the full information for easy diff access.
   123     $NM $OLD  > $OLD_SYMBOLS.full
   124     $NM $NEW  > $NEW_SYMBOLS.full
   125 fi
   127 DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS)
   129 if [ "${LDD}" ]
   130 then
   131     NAME=`basename $OLD`
   132     TMP=$COMPARE_ROOT/ldd/ldd.${NAME}
   133     rm -rf "${TMP}"
   134     mkdir -p "${TMP}"
   136     (cd "${TMP}" && cp $OLD . && ${LDD} ${NAME} | awk '{ print $1;}' | sort | tee dep.old | uniq > dep.uniq.old)
   137     (cd "${TMP}" && cp $NEW . && ${LDD} ${NAME} | awk '{ print $1;}' | sort | tee dep.new | uniq > dep.uniq.new)
   138     (cd "${TMP}" && rm -f ${NAME})
   140     DIFFS_DEP=$(LANG=C diff "${TMP}/dep.old" "${TMP}/dep.new")
   141     DIFFS_UNIQ_DEP=$(LANG=C diff "${TMP}/dep.uniq.old" "${TMP}/dep.uniq.new")
   143     DEP_MSG=
   144     if [ -z "${DIFFS_UNIQ_DEP}" -a -z "${DIFFS_DEP}" ]; then
   145        DEP_MSG="Identical dependencies"
   146     elif [ -z "${DIFFS_UNIQ_DEP}" ]; then
   147        DEP_MSG="Redundant duplicate dependencies added"
   148        RES=1
   149     else
   150        DEP_MSG="DIFFERENT dependencies"
   151        RES=1
   152     fi
   153 fi
   155 RESULT=0
   157 if [ -n "$DIFFS" ]; then
   158    if [ $OLD_SIZE -ne $NEW_SIZE ]
   159    then
   160        echo Differences, content AND size     : $DEP_MSG : $OLD_NAME 
   161        RESULT=4
   162    else
   163        echo Differences, content BUT SAME size: $DEP_MSG : $OLD_NAME 
   164        RESULT=3
   165    fi
   166    if [ "x$VIEW" == "xview" ]; then
   167        LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS
   168    fi
   169 else
   170    if [ $OLD_SIZE -ne $NEW_SIZE ]
   171    then
   172        echo Identical symbols BUT NEW size    : $DEP_MSG : $OLD_NAME 
   173        RESULT=2
   174    else
   175        echo Identical symbols AND size, BUT not bytewise identical: $DEP_MSG : $OLD_NAME 
   176        RESULT=1
   177    fi
   178 fi
   180 exit $RESULT

mercurial