Thu, 05 Jul 2012 18:27:07 -0700
7182051: Update of latest build-infra Makefiles (missing files)
Reviewed-by: ohair
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 | # Simple tool to diff two jar or zip files. It unpacks the jar/zip files and |
ohair@425 | 26 | # reports if files differs and if files are new or missing. |
ohair@425 | 27 | # Assumes gnu diff. |
ohair@425 | 28 | |
ohair@425 | 29 | # There are a few source files that have DOS line endings in the |
ohair@425 | 30 | # jaxp/jaxws source drops, when the sources were added to the repository |
ohair@425 | 31 | # the source files were converted to UNIX line endings. |
ohair@425 | 32 | # For now we ignore these differences. |
ohair@425 | 33 | DIFF_FLAGS="--strip-trailing-cr" |
ohair@425 | 34 | #set -x |
ohair@425 | 35 | |
ohair@425 | 36 | if [ $# -lt 2 ] |
ohair@425 | 37 | then |
ohair@425 | 38 | echo "Diff two jar/zip files. Return codes: 0 - no diff, 1 - diff, 2 - couldn't perform diff" |
ohair@425 | 39 | echo "Syntax: $0 old_archive new_archive [old_root new_root]" |
ohair@425 | 40 | exit 2 |
ohair@425 | 41 | fi |
ohair@425 | 42 | |
ohair@425 | 43 | if [ ! -f $1 ] |
ohair@425 | 44 | then |
ohair@425 | 45 | echo $1 does not exist |
ohair@425 | 46 | exit 2 |
ohair@425 | 47 | fi |
ohair@425 | 48 | |
ohair@425 | 49 | if [ ! -f $2 ] |
ohair@425 | 50 | then |
ohair@425 | 51 | echo $2 does not exist |
ohair@425 | 52 | exit 2 |
ohair@425 | 53 | fi |
ohair@425 | 54 | |
ohair@425 | 55 | IGNORES="cat" |
ohair@425 | 56 | OLD=$(cd $(dirname $1) && pwd)/$(basename $1) |
ohair@425 | 57 | NEW=$(cd $(dirname $2) && pwd)/$(basename $2) |
ohair@425 | 58 | |
ohair@425 | 59 | if [ $# -gt 3 ] |
ohair@425 | 60 | then |
ohair@425 | 61 | ROOT1=$(cd $3 && pwd) |
ohair@425 | 62 | ROOT2=$(cd $4 && pwd) |
ohair@425 | 63 | OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||") |
ohair@425 | 64 | NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||") |
ohair@425 | 65 | if [ $# == 5 ]; then IGNORES="$5"; fi |
ohair@425 | 66 | else |
ohair@425 | 67 | ROOT1=$(dirname $OLD)/ |
ohair@425 | 68 | ROOT2=$(dirname $NEW)/ |
ohair@425 | 69 | OLD_NAME=$OLD |
ohair@425 | 70 | NEW_NAME=$NEW |
ohair@425 | 71 | if [ $# == 3 ]; then IGNORES="$3"; fi |
ohair@425 | 72 | fi |
ohair@425 | 73 | |
ohair@425 | 74 | if [ "`uname`" == "SunOS" ]; then |
erikj@458 | 75 | if [ -f "`which gdiff`" ]; then |
erikj@458 | 76 | DIFF=gdiff |
erikj@458 | 77 | else |
erikj@458 | 78 | DIFF=diff |
erikj@458 | 79 | fi |
ohair@425 | 80 | else |
ohair@425 | 81 | DIFF=diff |
ohair@425 | 82 | fi |
ohair@425 | 83 | |
ohair@425 | 84 | OLD_SUFFIX="${OLD##*.}" |
ohair@425 | 85 | NEW_SUFFIX="${NEW##*.}" |
ohair@425 | 86 | if [ "$OLD_SUFFIX" != "$NEW_SUFFIX" ]; then |
ohair@425 | 87 | echo The files do not have the same suffix type! |
ohair@425 | 88 | exit 2 |
ohair@425 | 89 | fi |
ohair@425 | 90 | |
erikj@445 | 91 | if [ "$OLD_SUFFIX" != "zip" ] && [ "$OLD_SUFFIX" != "jar" ] && [ "$OLD_SUFFIX" != "sym" ]; then |
erikj@445 | 92 | echo The files have to be zip, jar or sym! They are $OLD_SUFFIX |
ohair@425 | 93 | exit 2 |
ohair@425 | 94 | fi |
ohair@425 | 95 | |
ohair@425 | 96 | UNARCHIVE="unzip -q" |
ohair@425 | 97 | |
ohair@425 | 98 | TYPE="$OLD_SUFFIX" |
ohair@425 | 99 | |
ohair@425 | 100 | if cmp $OLD $NEW > /dev/null |
ohair@425 | 101 | then |
ohair@425 | 102 | # The files were bytewise identical. |
ohair@425 | 103 | exit 0 |
ohair@425 | 104 | fi |
ohair@425 | 105 | |
ohair@425 | 106 | # Not quite identical, the might still contain the same data. |
ohair@425 | 107 | # Unpack the jar/zip files in temp dirs |
ohair@425 | 108 | if test "x$COMPARE_ROOT" == "x"; then |
ohair@425 | 109 | COMPARE_ROOT=/tmp/compare_root.$$ |
ohair@425 | 110 | REMOVE_COMPARE_ROOT=true |
ohair@425 | 111 | fi |
ohair@425 | 112 | OLD_TEMPDIR=$COMPARE_ROOT/$OLD_NAME.old |
ohair@425 | 113 | NEW_TEMPDIR=$COMPARE_ROOT/$NEW_NAME.new |
ohair@425 | 114 | mkdir -p $OLD_TEMPDIR |
ohair@425 | 115 | mkdir -p $NEW_TEMPDIR |
ohair@425 | 116 | (cd $OLD_TEMPDIR && rm -rf * ; $UNARCHIVE $OLD) |
ohair@425 | 117 | (cd $NEW_TEMPDIR && rm -rf * ; $UNARCHIVE $NEW) |
ohair@425 | 118 | |
ohair@425 | 119 | ONLY1=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR") |
ohair@425 | 120 | |
ohair@425 | 121 | if [ -n "$ONLY1" ]; then |
ohair@425 | 122 | echo " Only the OLD $OLD_NAME contains:" |
ohair@425 | 123 | LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $OLD_TEMPDIR" \ |
ohair@425 | 124 | | sed "s|Only in $OLD_TEMPDIR| |"g | sed 's|: |/|g' |
ohair@425 | 125 | fi |
ohair@425 | 126 | |
ohair@425 | 127 | ONLY2=$(LANG=C $DIFF -rq $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR") |
ohair@425 | 128 | |
ohair@425 | 129 | if [ -n "$ONLY2" ]; then |
ohair@425 | 130 | echo " Only the NEW $NEW_NAME contains:" |
ohair@425 | 131 | LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep "^Only in $NEW_TEMPDIR" \ |
ohair@425 | 132 | | sed "s|Only in $NEW_TEMPDIR| |"g | sed 's|: |/|g' |
ohair@425 | 133 | fi |
ohair@425 | 134 | |
erikj@445 | 135 | DIFFTEXT="/bin/bash `dirname $0`/difftext.sh" |
ohair@425 | 136 | |
ohair@425 | 137 | LANG=C $DIFF -rq $DIFF_FLAGS $OLD_TEMPDIR $NEW_TEMPDIR | grep differ | cut -f 2,4 -d ' ' | \ |
ohair@425 | 138 | awk "{ print \"$DIFFTEXT \"\$1\" \"\$2 }" > $COMPARE_ROOT/diffing |
ohair@425 | 139 | |
ohair@425 | 140 | /bin/bash $COMPARE_ROOT/diffing > $COMPARE_ROOT/diffs |
ohair@425 | 141 | |
ohair@425 | 142 | if [ -s "$COMPARE_ROOT/diffs" ]; then |
ohair@425 | 143 | echo " Differing files in $OLD_NAME" |
ohair@425 | 144 | cat $COMPARE_ROOT/diffs | grep differ | $IGNORES | cut -f 2 -d ' ' | \ |
ohair@425 | 145 | sed "s|$OLD_TEMPDIR| |g" |
ohair@425 | 146 | fi |
ohair@425 | 147 | |
ohair@425 | 148 | # Clean up |
ohair@425 | 149 | |
ohair@425 | 150 | if [ "x$REMOVE_COMPARE_ROOT" == xtrue ]; then |
ohair@425 | 151 | rm -rf $REMOVE_COMPARE_ROOT |
ohair@425 | 152 | fi |
ohair@425 | 153 | |
ohair@425 | 154 | exit 1 |
ohair@425 | 155 |