check_jni_methods.sh.in 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. # Fail if any command fails
  3. set -e
  4. TMPFILE=/tmp/check-jni-methods.$$.1
  5. TMPFILE2=/tmp/check-jni-methods.$$.2
  6. TMPFILE3=/tmp/check-jni-methods.$$.3
  7. TMPFILE4=/tmp/check-jni-methods.$$.4
  8. # Find all methods defined in the header files generated
  9. # from the java source files.
  10. grep -h '^JNIEXPORT .* Java_' @abs_top_srcdir@/include/*.h | \
  11. LC_ALL=C sed -e 's,.*JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' > $TMPFILE
  12. grep -h '^JNIEXPORT .* Java_' @abs_top_builddir@/include/*.h | \
  13. LC_ALL=C sed -e 's,.*JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' >> $TMPFILE
  14. sort -u $TMPFILE > $TMPFILE4
  15. mv $TMPFILE4 $TMPFILE
  16. # Find all methods in the JNI C source files.
  17. find @abs_top_srcdir@/native/jni -name \*.c | \
  18. xargs grep -h '^Java_' | \
  19. LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\).*$,\1,' > $TMPFILE2
  20. # Or in the the C++ files. (Note that cpp doesn't follow gnu conventions atm)
  21. # So we try to match both GNU style and some other style.
  22. find @abs_top_srcdir@/native/jni -name \*.cpp | \
  23. xargs grep -h '^Java_' | \
  24. LC_ALL=C sed -e 's,^\(Java_[a-z_A-Z0-9]*\).*$,\1,' >> $TMPFILE2
  25. find @abs_top_srcdir@/native/jni -name \*.cpp | \
  26. xargs egrep -h '^(JNIEXPORT .* JNICALL )?Java_' | \
  27. cut -f4 -d\ | \
  28. LC_ALL=C sed -e 's,^\JNIEXPORT .* JNICALL \(Java_[a-z_A-Z0-9]*\).*$,\1,' >> $TMPFILE2
  29. mv $TMPFILE2 $TMPFILE3
  30. sort $TMPFILE3 | uniq > $TMPFILE2
  31. rm $TMPFILE3
  32. # Write temporary ignore file.
  33. cat > $TMPFILE3 << EOF
  34. < Java_gnu_java_awt_peer_gtk_GtkMenuComponentPeer_dispose
  35. < Java_java_lang_VMSystem_arraycopy
  36. < Java_java_lang_VMSystem_identityHashCode
  37. EOF
  38. # Compare again silently.
  39. # Use fgrep and direct the output to /dev/null for compatibility with older
  40. # grep instead of using the non portable -q.
  41. if diff $TMPFILE $TMPFILE2 | grep '^[<>] Java' | \
  42. fgrep -v -f $TMPFILE3 > /dev/null;
  43. then
  44. PROBLEM=1
  45. echo "Found a problem with the JNI methods declared and implemented."
  46. echo "(<) missing in implementation, (>) missing in header files"
  47. # Compare the found method lists.
  48. diff $TMPFILE $TMPFILE2 | grep '^[<>] Java' | fgrep -v -f $TMPFILE3
  49. fi
  50. # Cleanup.
  51. rm -f $TMPFILE $TMPFILE2 $TMPFILE3
  52. if test "$PROBLEM" = "1" ; then
  53. exit 1
  54. fi
  55. exit 0