costin 01/11/16 14:21:03 Modified: jk/jkant/java/org/apache/jk/ant/compilers CompilerAdapter.java Log: Moved functionality from SoCompiler. Easier interfacing with the implementations. Use packages in compilation of the .c files ( using the 'base dir' on the src path to determine the package, same as in javac ) Add a message with the number of files to be compiled. Revision Changes Path 1.6 +135 -6 jakarta-tomcat-connectors/jk/jkant/java/org/apache/jk/ant/compilers/CompilerAdapter.java Index: CompilerAdapter.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/jkant/java/org/apache/jk/ant/compilers/CompilerAdapter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CompilerAdapter.java 2001/11/11 01:09:59 1.5 +++ CompilerAdapter.java 2001/11/16 22:21:03 1.6 @@ -84,6 +84,7 @@ */ public abstract class CompilerAdapter extends SoTask { SoTask so; + Vector compileList; public CompilerAdapter() { so=this; @@ -94,17 +95,145 @@ so.duplicateTo( this ); } - public GlobPatternMapper getOMapper() { - return null; - } +// /** @deprecated +// */ +// public GlobPatternMapper getOMapper() { +// return null; +// } + + /** Return the files that depend on a src file. + * The first item should be the .o file used for linking. + */ + public abstract String[] getTargetFiles( Source src ); public void execute() throws BuildException { - super.findCompileList(); + super.findSourceFiles(); + Vector compileList=findCompileList(srcList); compile( compileList ); } + + /** Verify if a .c file needs compilation. + * As with javac, we assume a fixed build structure, where all .o + * files are in a separate directory from the sources ( no mess ). + * + * XXX Hack makedepend somehow into this. + */ + public boolean needCompile( Source source ) { + // For each .c file we'll have a .o file in the build dir, + // with the same name. + File srcF = source.getFile(); + if( !srcF.exists() ) { + if( debug > 0 ) + log("No source file " + srcF ); + return false; + } + + String targetNames[]= getTargetFiles( source ); + if( targetNames==null || targetNames.length==0 ) { + if( debug > 0 ) + log("No target files " + srcF ); + return true; // strange, probably different extension ? + } + String targetName=targetNames[0]; + + String targetDir=source.getPackage(); + File f1=new File( buildDir, targetDir ); + File target=new File( f1, targetName ); + // System.out.println("XXX " + target ); + if( ! target.exists() ) { + if( debug > 0 ) + log("Target doesn't exist " + target ); + return true; + } + if( oldestO > target.lastModified() ) { + oldestO=target.lastModified(); + oldestOFile=target; + } + if( srcF.lastModified() > target.lastModified() ) + return true; + + if( debug > 0 ) + log("No need to compile " + srcF + " target " + target ); + return false; + } + + /** Remove all generated files, cleanup + */ + public void removeOFiles( Vector srcList ) { + for (int i = 0; i < srcList.size(); i++) { + // log( "Checking " + (Source)srcList.elementAt(i)); + Source source=(Source)srcList.elementAt(i); + String targetNA[]=getTargetFiles(source); + if( targetNA==null ) + continue; + String targetDir=source.getPackage(); + File f1=new File( buildDir, targetDir ); + for( int j=0; j<targetNA.length; j++ ) { + File target=new File( f1, targetNA[j] ); + // Check the dependency + if( target.exists() ) { + // Remove it - we'll do a full build + target.delete(); + log("Removing " + target ); + } + } + } + } + + // XXX modified as side-effect of checking files with needCompile() + long oldestO=System.currentTimeMillis(); + File oldestOFile=null; + + /** Find the subset of the source list that needs compilation. + */ + protected Vector findCompileList(Vector srcList) throws BuildException { + Vector compileList=new Vector(); + + for (int i = 0; i < srcList.size(); i++) { + Source source=(Source)srcList.elementAt(i); + File srcFile=source.getFile(); + + if (!srcFile.exists()) { + throw new BuildException("Source \"" + srcFile.getPath() + + "\" does not exist!", location); + } + + // Check the dependency + if( needCompile( source ) ) + compileList.addElement( source ); + } + + if( checkDepend(oldestO, oldestOFile) ) { + log("Dependency expired, removing " + + srcList.size() + " .o files and doing a full build "); + removeOFiles(srcList); + compileList=new Vector(); + for(int i=0; i<srcList.size(); i++ ) { + Source source=(Source)srcList.elementAt(i); + compileList.addElement( source ); + } + return compileList; + } + + + return compileList; + } + + /** Return the files that were actually compiled + */ + public Vector getCompiledFiles() { + return compileList; + } + + /** Compile the source files. The compiler adapter can override either this method + * ( if it can compile multiple files at once ) or compileSingleFile(). + * Note that the list includes _all_ sources, findCompileList() can be used to + * avoid compiling files that are up-to-date. + */ + public void compile(Vector sourceFiles ) throws BuildException { + compileList=findCompileList(sourceFiles); - public void compile(Vector compileList ) throws BuildException { - so.duplicateTo(this); + log("Compiling " + compileList.size() + " out of " + sourceFiles.size()); Enumeration en=compileList.elements(); while( en.hasMoreElements() ) { Source source=(Source)en.nextElement();
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>