summaryrefslogtreecommitdiff
path: root/libjava/classpath/scripts/check_jni_methods.sh
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/scripts/check_jni_methods.sh')
-rwxr-xr-xlibjava/classpath/scripts/check_jni_methods.sh41
1 files changed, 29 insertions, 12 deletions
diff --git a/libjava/classpath/scripts/check_jni_methods.sh b/libjava/classpath/scripts/check_jni_methods.sh
index 587b8792bb5..243bb7e4a14 100755
--- a/libjava/classpath/scripts/check_jni_methods.sh
+++ b/libjava/classpath/scripts/check_jni_methods.sh
@@ -1,8 +1,13 @@
#!/bin/sh
-TMPFILE=check-jni-methods.$$.1
-TMPFILE2=check-jni-methods.$$.2
-TMPFILE3=check-jni-methods.$$.3
+# Fail if any command fails
+set -e
+# Don't override existing files
+set -C
+
+TMPFILE=/tmp/check-jni-methods.$$.1
+TMPFILE2=/tmp/check-jni-methods.$$.2
+TMPFILE3=/tmp/check-jni-methods.$$.3
# Find all methods defined in the header files generated
# from the java source files.
@@ -13,8 +18,19 @@ grep -h '^JNIEXPORT .* Java_' include/*.h | \
# Find all methods in the JNI C source files.
find native/jni -name \*.c | \
xargs grep -h '^Java_' | \
- LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' | \
- sort > $TMPFILE2
+ LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' > $TMPFILE2
+# Or in the the C++ files. (Note that cpp doesn't follow gnu conventions atm)
+# So we try to match both GNU style and some other style.
+find native/jni -name \*.cpp | \
+ xargs grep -h '^Java_' | \
+ LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' >> $TMPFILE2
+find native/jni -name \*.cpp | \
+ xargs egrep -h '^(JNIEXPORT .* JNICALL )?Java_' | \
+ cut -f4 -d\ | \
+ LC_ALL=C sed -e 's,^\JNIEXPORT .* JNICALL \(Java_[a-z_A-Z0-9]*\) *(.*$,\1,' >> $TMPFILE2
+mv $TMPFILE2 $TMPFILE3
+sort $TMPFILE3 > $TMPFILE2
+rm $TMPFILE3
# Write temporary ignore file.
cat > $TMPFILE3 << EOF
@@ -24,23 +40,24 @@ cat > $TMPFILE3 << EOF
EOF
# Compare again silently.
-diff -ub -0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | grep -q -v -f $TMPFILE3
-RESULT=$?
-
-if test "$RESULT" = "0" ; then
+# Use fgrep and direct the output to /dev/null for compatibility with older
+# grep instead of using the non portable -q.
+if diff -b -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | \
+ fgrep -v -f $TMPFILE3 > /dev/null;
+then
+ PROBLEM=1
echo "Found a problem with the JNI methods declared and implemented."
echo "(-) missing in implementation, (+) missing in header files"
# Compare the found method lists.
- diff -ub -0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | grep -v -f $TMPFILE3
+ diff -b -U 0 $TMPFILE $TMPFILE2 | grep '^[+-]Java' | fgrep -v -f $TMPFILE3
fi
# Cleanup.
rm -f $TMPFILE $TMPFILE2 $TMPFILE3
-if test "$RESULT" = "0" ; then
+if test "$PROBLEM" = "1" ; then
exit 1
fi
exit 0
-