From 836ecd4574bcd7f0db9b32ee2f64db8bb466a057 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Fri, 27 Nov 2009 14:20:19 +0100 Subject: Fixed NAR-109 --- .../java/net/sf/antcontrib/cpptasks/CCTask.java | 113 +++++++++++++++------ .../net/sf/antcontrib/cpptasks/CompilerDef.java | 15 +++ .../sf/antcontrib/cpptasks/TargetHistoryTable.java | 10 +- .../net/sf/antcontrib/cpptasks/TargetMatcher.java | 6 +- .../cpptasks/apple/XcodeProjectWriter.java | 37 +++---- .../cpptasks/borland/CBuilderXProjectWriter.java | 6 +- .../cpptasks/devstudio/DevStudioProjectWriter.java | 8 +- .../devstudio/VisualStudioNETProjectWriter.java | 32 +++--- .../net/sf/antcontrib/cpptasks/ide/ProjectDef.java | 15 +-- .../sf/antcontrib/cpptasks/ide/ProjectWriter.java | 5 +- 10 files changed, 161 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java b/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java index ab40e95..62a8e6d 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/CCTask.java @@ -19,11 +19,13 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.util.ArrayList; +import java.util.Comparator; import java.util.Enumeration; -import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; -import java.util.Set; +import java.util.Map; +import java.util.TreeMap; import java.util.Vector; import net.sf.antcontrib.cpptasks.compiler.CompilerConfiguration; @@ -171,11 +173,11 @@ public class CCTask extends Task { * Builds a Hashtable to targets needing to be rebuilt keyed by compiler * configuration */ - public static Hashtable getTargetsToBuildByConfiguration(Hashtable targets) { + public static Hashtable getTargetsToBuildByConfiguration(Map targets) { Hashtable targetsByConfig = new Hashtable(); - Enumeration targetEnum = targets.elements(); - while (targetEnum.hasMoreElements()) { - TargetInfo target = (TargetInfo) targetEnum.nextElement(); + Iterator targetEnum = targets.values().iterator(); + while (targetEnum.hasNext()) { + TargetInfo target = (TargetInfo) targetEnum.next(); if (target.getRebuild()) { Vector targetsForSameConfig = (Vector) targetsByConfig .get(target.getConfiguration()); @@ -193,6 +195,7 @@ public class CCTask extends Task { } // FREEHEP private int maxCores = 0; + private boolean ordered = false; /** The compiler definitions. */ private Vector _compilers = new Vector(); /** The output file type. */ @@ -395,12 +398,12 @@ public class CCTask extends Task { * @return total number of targets to be rebuilt * */ - protected int checkForChangedIncludeFiles(Hashtable targets) { + protected int checkForChangedIncludeFiles(Map targets) { int potentialTargets = 0; int definiteTargets = 0; - Enumeration targetEnum = targets.elements(); - while (targetEnum.hasMoreElements()) { - TargetInfo target = (TargetInfo) targetEnum.nextElement(); + Iterator targetEnum = targets.values().iterator(); + while (targetEnum.hasNext()) { + TargetInfo target = (TargetInfo) targetEnum.next(); if (!target.getRebuild()) { potentialTargets++; } else { @@ -420,9 +423,9 @@ public class CCTask extends Task { } catch (Exception ex) { log("Problem reading dependencies.xml: " + ex.toString()); } - targetEnum = targets.elements(); - while (targetEnum.hasMoreElements()) { - TargetInfo target = (TargetInfo) targetEnum.nextElement(); + targetEnum = targets.values().iterator(); + while (targetEnum.hasNext()) { + TargetInfo target = (TargetInfo) targetEnum.next(); if (!target.getRebuild()) { if (dependencyTable.needsRebuild(this, target, dependencyDepth)) { @@ -436,9 +439,9 @@ public class CCTask extends Task { // count files being rebuilt now // int currentTargets = 0; - targetEnum = targets.elements(); - while (targetEnum.hasMoreElements()) { - TargetInfo target = (TargetInfo) targetEnum.nextElement(); + targetEnum = targets.values().iterator(); + while (targetEnum.hasNext()) { + TargetInfo target = (TargetInfo) targetEnum.next(); if (target.getRebuild()) { currentTargets++; } @@ -631,7 +634,7 @@ public class CCTask extends Task { // Assemble hashtable of all files // that we know how to compile (keyed by output file name) // - Hashtable targets = getTargets(linkerConfig, objectFiles, versionInfo, _outfile); + Map targets = getTargets(linkerConfig, objectFiles, versionInfo, _outfile); TargetInfo linkTarget = null; // // if output file is not specified, @@ -750,11 +753,14 @@ public class CCTask extends Task { noOfCores = noOfFiles; log("Limited used processors to "+noOfCores); } + if (ordered) { + noOfCores = 1; + log("Limited processors to 1 due to ordering of source files"); + } - Set[] sourceFiles = new HashSet[noOfCores]; + List[] sourceFiles = new List[noOfCores]; for (int j = 0; j < sourceFiles.length; j++) { - sourceFiles[j] = new HashSet(noOfFiles - / sourceFiles.length); + sourceFiles[j] = new ArrayList(noOfFiles / sourceFiles.length); } Enumeration targetsEnum = targetsForConfig.elements(); index = 0; @@ -956,13 +962,13 @@ public class CCTask extends Task { private CCTask task; private CompilerConfiguration config; private File objDir; - private Set sourceFiles; + private List sourceFiles; private boolean relentless; private CCTaskProgressMonitor monitor; private Exception compileException; Core(CCTask task, int coreNo, CompilerConfiguration config, File objDir, - Set set, boolean relentless, + List set, boolean relentless, CCTaskProgressMonitor monitor) { super("Core "+coreNo); this.task = task; @@ -982,6 +988,7 @@ public class CCTask extends Task { try { String[] sources = new String[sourceFiles.size()]; sources = (String[]) sourceFiles.toArray(sources); + config.compile(task, objDir, sources, relentless, monitor); } catch (Exception ex) { if (compileException == null) { @@ -1066,7 +1073,7 @@ public class CCTask extends Task { } protected TargetInfo getLinkTarget(LinkerConfiguration linkerConfig, Vector objectFiles, Vector sysObjectFiles, - Hashtable compileTargets, VersionInfo versionInfo) { + Map compileTargets, VersionInfo versionInfo) { // // walk the compile phase targets and // add those sources that have already been @@ -1074,10 +1081,10 @@ public class CCTask extends Task { // our output files the linker knows how to consume // files the linker knows how to consume // - Enumeration compileTargetsEnum = compileTargets.elements(); - while (compileTargetsEnum.hasMoreElements()) { - TargetInfo compileTarget = (TargetInfo) compileTargetsEnum - .nextElement(); + Iterator compileTargetsIterator = compileTargets.values().iterator(); + while (compileTargetsIterator.hasNext()) { + TargetInfo compileTarget = (TargetInfo) compileTargetsIterator + .next(); // // output of compile tasks // @@ -1113,9 +1120,48 @@ public class CCTask extends Task { * appropriate compiler configurations for their possible compilation * */ - private Hashtable getTargets(LinkerConfiguration linkerConfig, + private Map getTargets(LinkerConfiguration linkerConfig, Vector objectFiles, VersionInfo versionInfo, File outputFile) { - Hashtable targets = new Hashtable(1000); + // FREEHEP + final List order = new ArrayList(); + + Map targets = new TreeMap(new Comparator() { + // Order according to "order" List followed by alphabetical order + public int compare( Object arg0, Object arg1 ) { + String f0 = (String)arg0; + f0 = f0.lastIndexOf('.') < 0 ? f0 : f0.substring(0, f0.lastIndexOf('.')); + String f1 = (String)arg1; + f1 = f1.lastIndexOf('.') < 0 ? f1 : f1.substring(0, f1.lastIndexOf('.')); + + if (order.isEmpty()) return f0.compareTo(f1); + + // make sure we use only one core + ordered = true; + + // order according to list or alphabetical + int i0 = order.indexOf(f0); + int i1 = order.indexOf(f1); + + if (i0 < 0) { + if (i1 < 0) { + // none in list + return f0.compareTo(f1); + } else { + // i1 in list + return +1; + } + } else { + if (i1 < 0) { + // i0 in list + return -1; + } else { + // both in list + return i0 == i1 ? 0 : i0 < i1 ? -1 : +1; + } + } + } + }); + TargetDef targetPlatform = getTargetPlatform(); // // find active (specialized) compilers @@ -1180,6 +1226,15 @@ public class CCTask extends Task { localConfigs[1] = config; } } + // BEGINFREEHEP + // a little trick here, the inner function needs the list to be final, so we repopulate it + order.clear(); + List newOrder = currentCompilerDef.getOrder(); + if (newOrder != null) { + order.addAll(newOrder); + } + // ENDFREEHEP + // // if the compiler has a fileset // then allow it to add its files diff --git a/src/main/java/net/sf/antcontrib/cpptasks/CompilerDef.java b/src/main/java/net/sf/antcontrib/cpptasks/CompilerDef.java index 313d3ac..cccc067 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/CompilerDef.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/CompilerDef.java @@ -16,6 +16,7 @@ */ package net.sf.antcontrib.cpptasks; import java.util.Enumeration; +import java.util.List; import java.util.Vector; import net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler; @@ -49,6 +50,7 @@ public final class CompilerDef extends ProcessorDef { private final Vector sysIncludePaths = new Vector(); private OptimizationEnum optimization; private int warnings = -1; + private List order; public CompilerDef() { } /** @@ -499,4 +501,17 @@ public final class CompilerDef extends ProcessorDef { } this.optimization = value; } + + // FREEHEP + /** + * List of source filenames without extensions + * @param asList + */ + public void setOrder(List/**/ order) { + this.order = order; + } + + public List getOrder() { + return order; + } } diff --git a/src/main/java/net/sf/antcontrib/cpptasks/TargetHistoryTable.java b/src/main/java/net/sf/antcontrib/cpptasks/TargetHistoryTable.java index 1a6eda1..80d1dc6 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/TargetHistoryTable.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/TargetHistoryTable.java @@ -23,6 +23,8 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; import java.util.Vector; import javax.xml.parsers.SAXParser; @@ -317,10 +319,10 @@ public final class TargetHistoryTable { } return targetHistory; } - public void markForRebuild(Hashtable targetInfos) { - Enumeration targetInfoEnum = targetInfos.elements(); - while (targetInfoEnum.hasMoreElements()) { - markForRebuild((TargetInfo) targetInfoEnum.nextElement()); + public void markForRebuild(Map targetInfos) { + Iterator targetInfoEnum = targetInfos.values().iterator(); + while (targetInfoEnum.hasNext()) { + markForRebuild((TargetInfo) targetInfoEnum.next()); } } // FREEHEP added synchronized diff --git a/src/main/java/net/sf/antcontrib/cpptasks/TargetMatcher.java b/src/main/java/net/sf/antcontrib/cpptasks/TargetMatcher.java index 9260f77..137773f 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/TargetMatcher.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/TargetMatcher.java @@ -16,7 +16,7 @@ */ package net.sf.antcontrib.cpptasks; import java.io.File; -import java.util.Hashtable; +import java.util.Map; import java.util.Vector; import net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration; @@ -34,12 +34,12 @@ public final class TargetMatcher implements FileVisitor { private File outputDir; private ProcessorConfiguration[] processors; private final File sourceFiles[] = new File[1]; - private Hashtable targets; + private Map targets; private VersionInfo versionInfo; private CCTask task; public TargetMatcher(CCTask task, File outputDir, ProcessorConfiguration[] processors, LinkerConfiguration linker, - Vector objectFiles, Hashtable targets, + Vector objectFiles, Map targets, VersionInfo versionInfo) { this.task = task; this.outputDir = outputDir; diff --git a/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java index f901b4d..1701506 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java @@ -16,20 +16,6 @@ */ package net.sf.antcontrib.cpptasks.apple; -import net.sf.antcontrib.cpptasks.CCTask; -import net.sf.antcontrib.cpptasks.CUtil; -import net.sf.antcontrib.cpptasks.TargetInfo; -import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration; -import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; -import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration; -import net.sf.antcontrib.cpptasks.gcc.GccCCompiler; -import net.sf.antcontrib.cpptasks.ide.DependencyDef; -import net.sf.antcontrib.cpptasks.ide.ProjectDef; -import net.sf.antcontrib.cpptasks.ide.ProjectWriter; -import org.apache.tools.ant.BuildException; -import org.xml.sax.SAXException; - -import javax.xml.transform.TransformerConfigurationException; import java.io.File; import java.io.IOException; import java.text.NumberFormat; @@ -38,12 +24,27 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import javax.xml.transform.TransformerConfigurationException; + +import net.sf.antcontrib.cpptasks.CCTask; +import net.sf.antcontrib.cpptasks.CUtil; +import net.sf.antcontrib.cpptasks.TargetInfo; +import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration; +import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; +import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration; +import net.sf.antcontrib.cpptasks.gcc.GccCCompiler; +import net.sf.antcontrib.cpptasks.ide.DependencyDef; +import net.sf.antcontrib.cpptasks.ide.ProjectDef; +import net.sf.antcontrib.cpptasks.ide.ProjectWriter; + +import org.apache.tools.ant.BuildException; +import org.xml.sax.SAXException; + /** * Writes a Apple Xcode 2.1+ project directory. XCode stores project @@ -74,7 +75,7 @@ public final class XcodeProjectWriter final CCTask task, final ProjectDef projectDef, final List sources, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) throws IOException { File xcodeDir = new File(fileName + ".xcodeproj"); @@ -337,7 +338,7 @@ public final class XcodeProjectWriter private List addSources(final Map objects, final String sourceTree, final String basePath, - final Hashtable targets) { + final Map targets) { List sourceGroupChildren = new ArrayList(); ArrayList sourceList = new ArrayList(targets.size()); @@ -988,7 +989,7 @@ public final class XcodeProjectWriter * @return representative (hopefully) compiler configuration */ private CommandLineCompilerConfiguration - getBaseCompilerConfiguration(Hashtable targets) { + getBaseCompilerConfiguration(Map targets) { // // find first target with an GNU C++ compilation // diff --git a/src/main/java/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java index dfe5ec6..e166b63 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/borland/CBuilderXProjectWriter.java @@ -20,10 +20,10 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Map; import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.CUtil; @@ -76,7 +76,7 @@ public final class CBuilderXProjectWriter final CCTask task, final ProjectDef projectDef, final List sources, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) throws IOException, SAXException { @@ -302,7 +302,7 @@ public final class CBuilderXProjectWriter * @return representative (hopefully) compiler configuration */ private CommandLineCompilerConfiguration - getBaseCompilerConfiguration(final Hashtable targets) { + getBaseCompilerConfiguration(final Map targets) { // // find first target with an gcc or bcc compilation // diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java index 51ab1dd..88f3a72 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/DevStudioProjectWriter.java @@ -91,7 +91,7 @@ public final class DevStudioProjectWriter final CCTask task, final ProjectDef projectDef, final List files, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) throws IOException { // @@ -255,7 +255,7 @@ public final class DevStudioProjectWriter final String basePath, CommandLineCompilerConfiguration compilerConfig, TargetInfo linkTarget, - Hashtable targets) throws IOException { + Map targets) throws IOException { writer.write("# PROP BASE Use_MFC 0\r\n"); String configType = "Release"; @@ -478,7 +478,7 @@ public final class DevStudioProjectWriter * @return representative (hopefully) compiler configuration */ private CommandLineCompilerConfiguration - getBaseCompilerConfiguration(final Hashtable targets) { + getBaseCompilerConfiguration(final Map targets) { // // find first target with an DevStudio C compilation // @@ -614,7 +614,7 @@ public final class DevStudioProjectWriter final List dependencies, final String basePath, final TargetInfo linkTarget, - final Hashtable targets) throws IOException { + final Map targets) throws IOException { StringBuffer baseOptions = new StringBuffer(100); StringBuffer options = new StringBuffer(100); diff --git a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java index f554e09..f975f49 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/devstudio/VisualStudioNETProjectWriter.java @@ -16,16 +16,27 @@ */ package net.sf.antcontrib.cpptasks.devstudio; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.CUtil; import net.sf.antcontrib.cpptasks.TargetInfo; import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration; -import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration; import net.sf.antcontrib.cpptasks.compiler.CommandLineLinkerConfiguration; -import net.sf.antcontrib.cpptasks.ide.ProjectDef; +import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration; import net.sf.antcontrib.cpptasks.ide.CommentDef; -import net.sf.antcontrib.cpptasks.ide.ProjectWriter; import net.sf.antcontrib.cpptasks.ide.DependencyDef; +import net.sf.antcontrib.cpptasks.ide.ProjectDef; +import net.sf.antcontrib.cpptasks.ide.ProjectWriter; + import org.apache.tools.ant.BuildException; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; @@ -33,17 +44,6 @@ import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /** * Writes a Visual Studio.NET project file. * @@ -647,7 +647,7 @@ public final class VisualStudioNETProjectWriter final CCTask task, final ProjectDef projectDef, final List sources, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) throws IOException, SAXException { @@ -840,7 +840,7 @@ public final class VisualStudioNETProjectWriter * @return representative (hopefully) compiler configuration */ private CommandLineCompilerConfiguration - getBaseCompilerConfiguration(final Hashtable targets) { + getBaseCompilerConfiguration(final Map targets) { // // get the first target and assume that it is representative // diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java index 8883ebb..9779e15 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectDef.java @@ -16,19 +16,20 @@ */ package net.sf.antcontrib.cpptasks.ide; +import java.io.File; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.CUtil; import net.sf.antcontrib.cpptasks.TargetInfo; + import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.DataType; -import java.io.File; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; - /** * Requests the creation of an IDE project file. Experimental. * @@ -294,7 +295,7 @@ public final class ProjectDef */ public void execute(final CCTask task, final List sources, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) { try { projectWriter.writeProject(outFile, diff --git a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java index c4c144d..2429941 100644 --- a/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java +++ b/src/main/java/net/sf/antcontrib/cpptasks/ide/ProjectWriter.java @@ -18,11 +18,12 @@ package net.sf.antcontrib.cpptasks.ide; import java.io.File; import java.io.IOException; -import java.util.Hashtable; import java.util.List; +import java.util.Map; import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.TargetInfo; + import org.xml.sax.SAXException; /** @@ -47,7 +48,7 @@ public interface ProjectWriter { final CCTask task, final ProjectDef projectDef, final List files, - final Hashtable targets, + final Map targets, final TargetInfo linkTarget) throws IOException, SAXException; } -- cgit v1.2.3