I'm checking this in.

This hugely speeds up the split-for-gcj script.  On my machine it goes
from more than two minutes to about 6 seconds.  (We could probably do
even better but this script should be very portable...)

This also fixes a bug.  I noticed that source files could be
classified into more than one .list file, eg a gnu/java/beans file
would end up in both the gnu-java-beans and java-beans lists.  This
meant that such files were compiled more than once.

gcj folks, I will check this in to svn trunk soon, and probably the
4.1 branch for good measure.

Tom

Index: ChangeLog
from  Tom Tromey  <[EMAIL PROTECTED]>

        * lib/split-for-gcj.sh: Updated for multi-field format.
        * lib/Makefile.am (CLEANFILES): Added classes.2.
        * lib/gen-classlist.sh.in (GCJ): Removed.  Create classes.1 and
        classes.2 using multiple fields.

Index: lib/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/lib/Makefile.am,v
retrieving revision 1.113
diff -u -r1.113 Makefile.am
--- lib/Makefile.am 24 Mar 2006 17:04:21 -0000 1.113
+++ lib/Makefile.am 31 Mar 2006 22:21:58 -0000
@@ -155,7 +155,7 @@
 
 EXTRA_DIST = standard.omit mkcollections.pl.in Makefile.gcj split-for-gcj.sh
 CLEANFILES = compile-classes resources classes \
-       glibj.zip classes.1 \
+       glibj.zip classes.1 classes.2 \
        $(top_builddir)/gnu/java/locale/LocaleData.java \
        $(JAVA_DEPEND)
 
Index: lib/gen-classlist.sh.in
===================================================================
RCS file: /cvsroot/classpath/classpath/lib/gen-classlist.sh.in,v
retrieving revision 1.33
diff -u -r1.33 gen-classlist.sh.in
--- lib/gen-classlist.sh.in 13 Feb 2006 19:13:16 -0000 1.33
+++ lib/gen-classlist.sh.in 31 Mar 2006 22:21:58 -0000
@@ -7,16 +7,34 @@
 LC_ALL=C; export LC_ALL
 LANG=C; export LANG
 
-# We use this to decide whether we need to invoke the split script.
-GCJ="@GCJ@"
-
 echo "Adding java source files from srcdir '@top_srcdir@'."
[EMAIL PROTECTED]@ @top_srcdir@/java @top_srcdir@/javax @top_srcdir@/gnu \
-       @top_srcdir@/org \
-       @top_srcdir@/external/w3c_dom @top_srcdir@/external/sax \
-       @top_srcdir@/external/relaxngDatatype \
-       -follow -type f -print | sort -r | grep '\.java$' \
-       > ${top_builddir}/lib/classes.1
+# We construct 'classes.1' as a series of lines.  Each line
+# has three fields, which are separated by spaces.  The first
+# field is the package of this class (separated by "/"s).
+# The second field is the name of the top-level directory for
+# this file, relative to the build directory.  E.g., it might
+# look like "../../classpath/vm/reference".
+# The third field is the file name, like "java/lang/Object.java".
+# We do this because it makes splitting for the gcj build much
+# cheaper.
+(cd @top_srcdir@
+ @FIND@ java javax gnu org -follow -name '*.java' -print |
+ sort -r | sed -e 's,/\([^/]*\)$, \1,' |
+ while read pkg file; do
+    echo $pkg @top_srcdir@ $pkg/$file
+ done) > ${top_builddir}/lib/classes.1
+
+# The same, but for the external code.
+# Right now all external code is in org/.
+for dir in @top_srcdir@/external/w3c_dom \
+   @top_srcdir@/external/sax @top_srcdir@/external/relaxngDatatype; do
+  (cd $dir
+  @FIND@ org -follow -name '*.java' -print |
+  sort -r | sed -e 's,/\([^/]*\)$, \1,' |
+  while read pkg file; do
+     echo $pkg $dir $pkg/$file
+  done)
+done >> ${top_builddir}/lib/classes.1
 
 # Generate files for the VM classes.
 : > vm.omit
@@ -29,18 +47,19 @@
       if test -d $subdir; then
         @FIND@ $subdir -name '*.java' -print
       fi
-   done) |
-   while read f; do
-      echo $dir/$f >> vm.add
-      echo $f >> vm.omit
+   done) | sed -e 's,/\([^/]*\)$, \1,' |
+   while read pkg file; do
+      echo $pkg $dir $pkg/$file >> vm.add
+      echo $pkg/$file >> vm.omit
    done
 done
 
 # Only include generated files once.
 if test ! "${top_builddir}" -ef "@top_srcdir@"; then
   echo "Adding generated files in builddir '${top_builddir}'."
-  @FIND@ ${top_builddir}/gnu ${top_builddir}/java -follow -type f -print \
-  | sort | grep '\.java$' >> ${top_builddir}/lib/classes.1
+  # Currently the only generated files are in gnu.*.
+  @FIND@ ${top_builddir}/gnu -follow -name '*.java' -print \
+  | sort >> ${top_builddir}/lib/classes.1
 fi
 
 
@@ -51,6 +70,7 @@
    fi
 done
 
+# FIXME: could be more efficient by constructing a series of greps.
 for filexp in `cat tmp.omit`; do
    grep -v ${filexp} < ${top_builddir}/lib/classes.1 > 
${top_builddir}/lib/classes.2
    mv ${top_builddir}/lib/classes.2 ${top_builddir}/lib/classes.1
@@ -72,18 +92,20 @@
 rm tmp.omit
 
 new=
-if test -e ${top_builddir}/lib/classes; then
-  p=`diff ${top_builddir}/lib/classes ${top_builddir}/lib/classes.1`
+if test -e ${top_builddir}/lib/classes.2; then
+  p=`diff ${top_builddir}/lib/classes.2 ${top_builddir}/lib/classes.1`
   if test "$p" != ""; then
     new="true"
-    cp ${top_builddir}/lib/classes.1 ${top_builddir}/lib/classes
   fi
 else
   new="true"
-  cp ${top_builddir}/lib/classes.1 ${top_builddir}/lib/classes
 fi
 
 if test "$new" = "true"; then
+  cp ${top_builddir}/lib/classes.1 ${top_builddir}/lib/classes.2
+  # Strip the package part.
+  sed -e 's/^[^ ]* //' -e 's, ,/,' < ${top_builddir}/lib/classes.1 \
+     > ${top_builddir}/lib/classes
   echo "JAVA_SRCS = \\" > ${top_builddir}/lib/java.dep
   for i in `cat ${top_builddir}/lib/classes` ; do
     echo $i "\\" >> ${top_builddir}/lib/java.dep
Index: lib/split-for-gcj.sh
===================================================================
RCS file: /cvsroot/classpath/classpath/lib/split-for-gcj.sh,v
retrieving revision 1.7
diff -u -r1.7 split-for-gcj.sh
--- lib/split-for-gcj.sh 21 Sep 2005 20:50:23 -0000 1.7
+++ lib/split-for-gcj.sh 31 Mar 2006 22:21:58 -0000
@@ -22,22 +22,24 @@
 # java/awt/BitwiseXORComposite.class: lists/java-awt.stamp
 # lists/java-awt.list: 
/home/aph/gcc/gcc/libjava/classpath/gnu/java/awt/BitwiseXORComposite.java
 
-# This uses a somewhat hacky procedure for finding the package of a
-# given file.
-
 echo "Splitting for gcj"
 rm -f Makefile.dtmp > /dev/null 2>&1
 test -d lists || mkdir lists
-for dir in java javax gnu org; do
-   fgrep /$dir/ classes | while read file; do
-      pkg=`echo "$file " | sed -n -e "s,^.*/\($dir/.*\)/[^/]*$,\1,p"`
-      list=lists/`echo $pkg | sed -e 's,/,-,g' | cut -f1-3 -d-`
-      echo "$file" >> ${list}.list.1
-      f2=`echo "$file" | sed -n -e "s,^.*/\($dir/.*\)$,\1,p"`
-      f2=`echo "$f2" | sed -e 's/.java$//'`.class
-      echo "$f2: ${list}.stamp" >> Makefile.dtmp
-      echo "${list}.list: $file" >> Makefile.dtmp
-   done
+# Much more efficient to do processing outside the loop...
+# The first expression computes the .class file name.
+# We only want the first three package components, and
+# we want them separated by '-'; this is the remaining expressions.
+sed -e 's, \(.*\)[.]java$, \1.java \1.class,' \
+   -e 's,^\([^/ ]*\)/\([^/ ]*\) ,\1-\2 ,' \
+   -e 's,^\([^/ ]*\)/\([^/ ]*\)/\([^/ ]*\) ,\1-\2-\3 ,' \
+   -e 's,^\([^/ ]*\)/\([^/ ]*\)/\([^/ ]*\)/[^ ]* ,\1-\2-\3 ,' \
+   classes.2 |
+while read pkg dir file f2; do
+   list=lists/$pkg
+   echo "$dir/$file" >> ${list}.list.1
+
+   echo "$f2: ${list}.stamp" >> Makefile.dtmp
+   echo "${list}.list: $dir/$file" >> Makefile.dtmp
 done
 
 # Only update a .list file if it changed.

Reply via email to