changeset 1897:4afd4198f215

Cleanup #02: Work out whether $JAVAC is ecj or not, and call appropriately in javac.in. Fix some test bugs. 2009-07-21 Andrew John Hughes <ahughes@redhat.com> * acinclude.m4: (AC_FIND_JAVAC): Check whether we are using ecj or javac. Don't fail if no JAVAC is found as ecj.jar can still be used. (IT_FIND_ECJ): Drop -nowarn. (FIND_ECJ_JAR): Only fail if there is no other compiler found. Communalise message output. (IT_LIBRARY_CHECK): Quote output so array brackets are not lost. (IT_SCANNER_CHECK): Likewise, and use return value of javac not grep. (IT_CP_40630): Likewise, and correct bug with classname. (IT_USING_ECJ): Work out whether javac is ecj or not. * javac.in: Move ecj opt generation to a subroutine so it is only performed when needed. Run @JAVAC@ rather than @ECJ@ and vary arguments as needed depending on @USING_ECJ@. Use same warning settings as GNU Classpath.
author Andrew John Hughes <ahughes@redhat.com>
date Tue, 21 Jul 2009 22:49:48 +0100
parents bafcc83b864b
children c43b0d22e99b
files ChangeLog acinclude.m4 javac.in
diffstat 3 files changed, 98 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jul 20 16:01:38 2009 +0100
+++ b/ChangeLog	Tue Jul 21 22:49:48 2009 +0100
@@ -1,3 +1,24 @@
+2009-07-21  Andrew John Hughes  <ahughes@redhat.com>
+
+	* acinclude.m4:
+	(AC_FIND_JAVAC): Check whether we are using
+	ecj or javac.  Don't fail if no JAVAC is found
+	as ecj.jar can still be used.
+	(IT_FIND_ECJ): Drop -nowarn.
+	(FIND_ECJ_JAR): Only fail if there is no other
+	compiler found.  Communalise message output.
+	(IT_LIBRARY_CHECK): Quote output so array brackets
+	are not lost.
+	(IT_SCANNER_CHECK): Likewise, and use return value
+	of javac not grep.
+	(IT_CP_40630): Likewise, and correct bug with classname.
+	(IT_USING_ECJ): Work out whether javac is ecj or not.
+	* javac.in:
+	Move ecj opt generation to a subroutine so it is only
+	performed when needed.  Run @JAVAC@ rather than @ECJ@
+	and vary arguments as needed depending on @USING_ECJ@.
+	Use same warning settings as GNU Classpath.
+
 2009-07-20  Andrew John Hughes  <ahughes@redhat.com>
 
 	* acinclude.m4:
--- a/acinclude.m4	Mon Jul 20 16:01:38 2009 +0100
+++ b/acinclude.m4	Tue Jul 21 22:49:48 2009 +0100
@@ -94,10 +94,8 @@
   JAVAC=${SYSTEM_JDK_DIR}/bin/javac
   IT_FIND_JAVAC
   IT_FIND_ECJ
+  IT_USING_ECJ
 
-  if test "x${JAVAC}" = x; then
-      AC_MSG_ERROR([cannot find a Java compiler, try --with-javac or --with-ecj])
-  fi
   AC_SUBST(JAVAC)
 ])
 
@@ -119,7 +117,7 @@
   ])
   if test "x${JAVAC}" = "x"; then
     if test "x{ECJ}" != "x"; then
-      JAVAC="${ECJ} -nowarn"
+      JAVAC="${ECJ}"
     fi
   fi
 ])
@@ -229,41 +227,37 @@
 
 AC_DEFUN([FIND_ECJ_JAR],
 [
+  AC_MSG_CHECKING([for an ecj JAR file])
   AC_ARG_WITH([ecj-jar],
               [AS_HELP_STRING(--with-ecj-jar,specify location of the ECJ jar)],
   [
     if test -f "${withval}"; then
-      AC_MSG_CHECKING(for an ecj jar)
       ECJ_JAR="${withval}"
-      AC_MSG_RESULT(${withval})
     fi
   ],
   [
     ECJ_JAR=
   ])
   if test -z "${ECJ_JAR}"; then
-    AC_MSG_CHECKING(for eclipse-ecj.jar)
     if test -e "/usr/share/java/eclipse-ecj.jar"; then
       ECJ_JAR=/usr/share/java/eclipse-ecj.jar
-      AC_MSG_RESULT(${ECJ_JAR})
     elif test -e "/usr/share/java/ecj.jar"; then
       ECJ_JAR=/usr/share/java/ecj.jar
-      AC_MSG_RESULT(${ECJ_JAR})
     elif test -e "/usr/share/eclipse-ecj-3.3/lib/ecj.jar"; then
       ECJ_JAR=/usr/share/eclipse-ecj-3.3/lib/ecj.jar
-      AC_MSG_RESULT(${ECJ_JAR})
     elif test -e "/usr/share/eclipse-ecj-3.2/lib/ecj.jar"; then
       ECJ_JAR=/usr/share/eclipse-ecj-3.2/lib/ecj.jar
-      AC_MSG_RESULT(${ECJ_JAR})
     elif test -e "/usr/share/eclipse-ecj-3.1/lib/ecj.jar"; then
       ECJ_JAR=/usr/share/eclipse-ecj-3.1/lib/ecj.jar
-      AC_MSG_RESULT(${ECJ_JAR})
     else
-      AC_MSG_RESULT(no)
+      ECJ_JAR=no
     fi
   fi
-  if test -z "${ECJ_JAR}"; then
-    AC_MSG_ERROR("A ECJ jar was not found.")
+  AC_MSG_RESULT(${ECJ_JAR})
+  if test "x${ECJ_JAR}" = "xno"; then
+    if test "x${JAVAC}" = "x"; then
+      AC_MSG_ERROR("No compiler or ecj JAR file was found.")
+    fi
   fi
   AC_SUBST(ECJ_JAR)
 ])
@@ -1520,7 +1514,7 @@
 mkdir tmp.$$
 cd tmp.$$
 cat << \EOF > $CLASS
-/* [#]line __oline__ "configure" */
+[/* [#]line __oline__ "configure" */
 import java.io.File;
 import java.io.PrintStream;
 
@@ -1532,10 +1526,10 @@
     PrintStream p = new PrintStream(new File("bluh"), "UTF-8");
     p.close();
   }
-}
+}]
 EOF
-if $JAVAC -cp . $JAVACFLAGS $CLASS >/dev/null 2>&1; then
-  if $JAVA -classpath . $BYTECODE >/dev/null 2>&1; then
+if $JAVAC -cp . $JAVACFLAGS $CLASS >/dev/null 2>&1 ; then
+  if $JAVA -classpath . $BYTECODE >/dev/null 2>&1 ; then
     it_cv_cp40616=no;
   else
     it_cv_cp40616=yes;
@@ -1558,7 +1552,7 @@
 mkdir tmp.$$
 cd tmp.$$
 cat << \EOF > $CLASS
-/* [#]line __oline__ "configure" */
+[/* [#]line __oline__ "configure" */
 public class Test 
 {
   public static void main(String[] args)
@@ -1566,13 +1560,13 @@
   {
     new java.util.Scanner("Hello");
   }
-}
+}]
 EOF
 if $JAVAC -cp . $JAVACFLAGS $CLASS >/dev/null 2>&1; then
-  if $JAVA -classpath . $BYTECODE 2>&1 | grep 'Exception' >/dev/null 2>&1; then
+  if $JAVA -classpath . $BYTECODE; >/dev/null 2>&1; then
+      it_cv_cp30436=no;
+  else
       it_cv_cp30436=yes;
-  else
-      it_cv_cp30436=no;
   fi
 else
   it_cv_cp30436=yes;
@@ -1584,15 +1578,17 @@
 AM_CONDITIONAL([LACKS_JAVA_UTIL_SCANNER], test x"${it_cv_cp30436}" = "xyes")
 AC_PROVIDE([$0])dnl
 ])
-
 AC_DEFUN([IT_PR40630_CHECK],[
 if test "x${it_cv_cp30436}" = "xno"; then
   AC_CACHE_CHECK([if java.util.Scanner exhibits Classpath bug 40630], it_cv_cp40630, [
   CLASS=Test.java
+  BYTECODE=$(echo $CLASS|sed 's#\.java##')
   mkdir tmp.$$
   cd tmp.$$
   cat << \EOF > $CLASS
-  /* [#]line __oline__ "configure" */
+[/* [#]line __oline__ "configure" */
+import java.util.Scanner;
+
 public class Test 
 {
   public static void main(String[] args)
@@ -1603,13 +1599,13 @@
       s.nextLine();
     s.hasNextLine();
   }
-}
+}]
 EOF
   if $JAVAC -cp . $JAVACFLAGS $CLASS >/dev/null 2>&1; then
-    if $JAVA -classpath . $CLASS 2>&1 | grep 'Exception'; then
+    if $JAVA -classpath . $BYTECODE > /dev/null 2>&1; then
+      it_cv_cp40630=no;
+    else
       it_cv_cp40630=yes;
-    else
-      it_cv_cp40630=no;
     fi
   else
     it_cv_cp40630=yes;
@@ -1622,3 +1618,16 @@
 AM_CONDITIONAL([CP40630], test x"${it_cv_cp40630}" = "xyes")
 AC_PROVIDE([$0])dnl
 ])
+
+AC_DEFUN([IT_USING_ECJ],[
+AC_CACHE_CHECK([if we are using ecj as javac], it_cv_ecj, [
+if $JAVAC -version 2>&1| grep '^Eclipse' >/dev/null ; then
+  it_cv_ecj=yes;
+else
+  it_cv_ecj=no;
+fi
+])
+USING_ECJ=$it_cv_ecj
+AC_SUBST(USING_ECJ)
+AC_PROVIDE([$0])dnl
+])
--- a/javac.in	Mon Jul 20 16:01:38 2009 +0100
+++ b/javac.in	Tue Jul 21 22:49:48 2009 +0100
@@ -3,44 +3,60 @@
 use constant NO_DUP_ARGS => qw(-source -target -d -encoding);
 use constant STRIP_ARGS => qw(-Werror);
 
+my $ECJ_WARNINGS="-warn:-deprecation,serial,unusedImport";
+my $JAVAC_WARNINGS="-Xlint:unchecked,cast,divzero,empty,finally,overrides";
+
 my @bcoption;
 push @bcoption, '-bootclasspath', glob '@SYSTEM_JDK_DIR@/jre/lib/rt.jar'
     unless grep {$_ eq '-bootclasspath'} @ARGV;
 
 # Work around ecj's inability to handle duplicate command-line
 # options.
-
-my @new_args = @ARGV;
-
-for my $opt (NO_DUP_ARGS) 
+sub gen_ecj_opts
 {
-    my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
-    if (@indices > 1) {
-        shift @indices;    # keep last instance only
-        splice @new_args, $_, 2 for @indices;
+    my @new_args = @{$_[0]};
+
+    for my $opt (NO_DUP_ARGS) 
+    {
+	my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
+	if (@indices > 1) {
+	    shift @indices;    # keep last instance only
+	    splice @new_args, $_, 2 for @indices;
+	}
     }
+
+    for my $opt (STRIP_ARGS) 
+    {
+	my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
+	splice @new_args, $_, 1 for @indices;
+    }
+
+    return @new_args;
 }
 
-for my $opt (STRIP_ARGS) 
-{
-    my @indices = reverse grep {$new_args[$_] eq $opt} 0..$#new_args;
-    splice @new_args, $_, 1 for @indices;
-}
-
-my @CLASSPATH = ('@ECJ_JAR@');
-push @CLASSPATH, split /:/, $ENV{CLASSPATH} if exists $ENV{CLASSPATH};
-$ENV{CLASSPATH} = join ':', @CLASSPATH;
-
 if ( -e "@abs_top_builddir@/native-ecj" )
 {
-    exec '@abs_top_builddir@/native-ecj', '-1.5', '-nowarn', @bcoption, @new_args ;
+    my @ecj_args = gen_ecj_opts( \@ARGV );
+    exec '@abs_top_builddir@/native-ecj', '-1.5', $ECJ_WARNINGS, @bcoption, @ecj_args ;
 }
-elsif ( -e "@ECJ@" )
+elsif ( -e "@JAVAC@" )
 {
-    exec '@ECJ@', '-1.5', '-nowarn', @bcoption, @new_args ;
+    if ("@USING_ECJ@" eq "yes")
+    {
+	my @ecj_args = gen_ecj_opts( \@ARGV );
+	exec '@JAVAC@', '-1.5', $ECJ_WARNINGS, @bcoption, @ecj_args ;
+    }
+    else
+    {
+	exec '@JAVAC@', $JAVAC_WARNINGS, @ARGV ;
+    }
 }
 else
 {
+    my @ecj_args = gen_ecj_opts( \@ARGV );
+    my @CLASSPATH = ('@ECJ_JAR@');
+    push @CLASSPATH, split /:/, $ENV{"CLASSPATH"} if exists $ENV{"CLASSPATH"};
+    $ENV{"CLASSPATH"} = join ':', @CLASSPATH;
     exec '@JAVA@', 'org.eclipse.jdt.internal.compiler.batch.Main', '-1.5',
-    '-nowarn', @bcoption, @new_args;
+    $ECJ_WARNINGS, @bcoption, @ecj_args;
 }