From ea74f3c0678d0729a8d6307e35c2d228f665afa3 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 24 Feb 2023 22:25:48 +0800 Subject: [PATCH] Improve Android configury * configure.ac (JAVA_PUSH_LINT): New macro. (JAVAFLAGS): New variable. Check for various lint flags and macros and enable them. * java/Makefile.in (ANDROID_ABI): * java/org/gnu/emacs/EmacsSdk7FontDriver.java: Remove compiler warning. --- configure.ac | 75 ++++++++++++++++++++- java/Makefile.in | 5 +- java/org/gnu/emacs/EmacsSdk7FontDriver.java | 2 +- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 715d8790026..67ee0a1c413 100644 --- a/configure.ac +++ b/configure.ac @@ -739,6 +739,32 @@ AC_ARG_ENABLE([build-details], [test "$enableval" = no && BUILD_DETAILS=--no-build-details]) AC_SUBST([BUILD_DETAILS]) +# JAVA_PUSH_LINT(OPT) +# ------------------- +# Check if javac supports the diagnostic flag -Xlint:OPT. +# If it does, add it to JAVAFLAGS. + +AC_DEFUN([JAVA_PUSH_LINT], +[ + AC_CACHE_CHECK([whether Java compiler accepts -Xlint:$1], + [emacs_cv_javac_knows_lint_$1], + AS_IF([rm -f conftest.class +cat << EOF > conftest.java + +class conftest +{ + +} + +EOF +("$JAVAC" -Xlint:$1 conftest.java 2>&AS_MESSAGE_LOG_FD) \ + && rm -f conftest.class], [emacs_cv_javac_knows_lint_$1=yes], + [emacs_cv_javac_knows_lint_$1=no])) + + AS_IF([test "$emacs_cv_javac_knows_lint_$1" = "yes"], + [JAVAFLAGS="$JAVAFLAGS -Xlint:$1"]) +]) + # Start Android configuration. This is done in three steps: # First, the SDK tools needed to build the Android package on the host @@ -760,6 +786,7 @@ ZIPALIGN= DX= ANDROID_JAR= ANDROID_ABI= +JAVAFLAGS= # This is a list of Makefiles that have alternative versions for # Android. @@ -807,7 +834,7 @@ specify its location before configuring Emacs, like so: JARSIGNER=/opt/jdk/bin/jarsigner ./configure --with-android]) fi - AC_CACHE_CHECK([whether or not the Java compiler works], + AC_CACHE_CHECK([whether the Java compiler works], [emacs_cv_working_javac], AS_IF([rm -f conftest.class cat << EOF > conftest.java @@ -836,7 +863,7 @@ EOF a valid path to android.jar. See config.log for more details.]) fi - AC_CACHE_CHECK([whether or not android.jar is new enough], + AC_CACHE_CHECK([whether android.jar is new enough], [emacs_cv_android_s_or_later], AS_IF([rm -f conftest.class cat << EOF > conftest.java @@ -859,8 +886,52 @@ EOF Android 13 (Tiramisu) or later.]) fi + dnl See if the Java compiler supports the `--release' option which + dnl makes it check for and prevent using features introduced after + dnl Java 1.7. + + AC_CACHE_CHECK([whether javac accepts --release 7], + [emacs_cv_javac_release_7], AS_IF([rm -f conftest.class +cat << EOF > conftest.java + +class conftest +{ + +} + +EOF +("$JAVAC" --release 7 conftest.java 2>&AS_MESSAGE_LOG_FD) \ + && rm -f conftest.class], + [emacs_cv_javac_release_7=yes], + [emacs_cv_javac_release_7=no])) + + if test "$emacs_cv_javac_release_7" = "yes"; then + JAVAFLAGS="$JAVAFLAGS --release 7" + else + dnl If not, just make sure the generated bytecode is correct. + JAVAFLAGS="$JAVAFLAGS -target 1.7 -source 1.7" + fi + + dnl Enable some useful Java linting options. + JAVA_PUSH_LINT([deprecation]) + JAVA_PUSH_LINT([cast]) + JAVA_PUSH_LINT([divzero]) + JAVA_PUSH_LINT([nonempty]) + JAVA_PUSH_LINT([empty]) + JAVA_PUSH_LINT([finally]) + JAVA_PUSH_LINT([overrides]) + JAVA_PUSH_LINT([path]) + JAVA_PUSH_LINT([serial]) + JAVA_PUSH_LINT([unchecked]) + + # Get the name of the android.jar file. ANDROID_JAR="$with_android" + dnl Set up the class path to include android.jar, along with the cwd + dnl (which is $(top_builddir)/java.) + JAVAFLAGS="$JAVAFLAGS -classpath \"$ANDROID_JAR:.\"" + AC_SUBST([JAVAFLAGS]) + AC_PATH_PROGS([AAPT], [aapt], [], "${SDK_BUILD_TOOLS}:$PATH") if test "$AAPT" = ""; then AC_MSG_ERROR([The Android asset packaging tool was not found. diff --git a/java/Makefile.in b/java/Makefile.in index af44d551701..7ba05f6c9a3 100644 --- a/java/Makefile.in +++ b/java/Makefile.in @@ -40,10 +40,7 @@ ANDROID_JAR = @ANDROID_JAR@ ANDROID_ABI = @ANDROID_ABI@ ANDROID_SDK_18_OR_EARLIER = @ANDROID_SDK_18_OR_EARLIER@ ANDROID_SDK_8_OR_EARLIER = @ANDROID_SDK_8_OR_EARLIER@ - -WARN_JAVAFLAGS = -Xlint:deprecation -JAVAFLAGS = -classpath "$(ANDROID_JAR):." -target 1.7 -source 1.7 \ - $(WARN_JAVAFLAGS) +JAVAFLAGS = @JAVAFLAGS@ # Android 4.3 and earlier require Emacs to be signed with a different # digital signature algorithm. diff --git a/java/org/gnu/emacs/EmacsSdk7FontDriver.java b/java/org/gnu/emacs/EmacsSdk7FontDriver.java index a964cadb74c..ba92d4cef49 100644 --- a/java/org/gnu/emacs/EmacsSdk7FontDriver.java +++ b/java/org/gnu/emacs/EmacsSdk7FontDriver.java @@ -325,7 +325,7 @@ public class EmacsSdk7FontDriver extends EmacsFontDriver list.add (new Sdk7FontEntity (typefaceList[i])); } - return (FontEntity[]) list.toArray (new FontEntity[0]); + return list.toArray (new FontEntity[0]); } @Override -- 2.39.5