Improve `diff_data.sh` robustness and performance
There may be added or removed files between two builds, and without this
change the `stat` and `expr $SIZE2 - $SIZE1` calls could fail, leading
to a lot of noise in the output.
Also, the script spent a lot of time incrementing count using `expr`,
which is made faster using arithmetic expressions. On my machine, the
time goes from 24 to 14 seconds.
ICUROOT was unused and thus removed.
Change-Id: I8ac89249473685319d523e1c6e6840c33b1092d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/deps/icu/+/6888913
Reviewed-by: Koji Ishii <kojii@chromium.org>
diff --git a/scripts/diff_data.sh b/scripts/diff_data.sh
index ad02566..5070d5c 100755
--- a/scripts/diff_data.sh
+++ b/scripts/diff_data.sh
@@ -48,8 +48,6 @@
# set -x
-ICUROOT="$(dirname "$0")/.."
-
if [ $# -lt 3 ];
then
echo "Usage: "$0" (android|cast|chromeos|common|flutter|flutter_desktop|ios) icubuilddir1 icubuilddir2" >&2
@@ -59,6 +57,16 @@
exit 1
fi
+# Helper Functions
+
+size_if_exists() {
+ if [ -f "$1" ]; then
+ stat --printf="%s" "$1"
+ else
+ echo 0
+ fi
+}
+
# Input Parameters
BUILD=$1
DIR1=$2
@@ -82,23 +90,21 @@
diff -u ${SORTED_ICUDATA_LST1} ${SORTED_ICUDATA_LST2}
echo "-------------------------------------------------------"
-
echo -n "> Checking and sorting the diff size ."
SIZEFILE=/tmp/${BUILD}size.txt
SIZESORTEDFILE=/tmp/${BUILD}sizesorted.txt
count=0
rm -rf $SIZEFILE
-for res in $(cat "${SORTED_ICUDATA_LST2}")
+for res in $(cat "$SORTED_ICUDATA_LST1" "$SORTED_ICUDATA_LST2" | sort -u)
do
- # diff the txt file
- STAT1=`stat --printf="%s" ${RESDIR1}/$res`
- STAT2=`stat --printf="%s" ${RESDIR2}/$res`
- SIZEDIFF=`expr $STAT2 - $STAT1`
- echo $SIZEDIFF $STAT1 $STAT2 $res >> $SIZEFILE
- count=`expr $count + 1`
- if [ $count -gt 100 ]
+ # $res may only exist in of the directories
+ SIZE1=`size_if_exists "$RESDIR1/$res"`
+ SIZE2=`size_if_exists "$RESDIR2/$res"`
+ SIZEDIFF=$(($SIZE2 - $SIZE1))
+ echo $SIZEDIFF $SIZE1 $SIZE2 $res >> $SIZEFILE
+ count=$((count + 1))
+ if (( $count % 100 == 0 ))
then
- count=0
echo -n "."
fi
done