]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/TargetMatcher.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / TargetMatcher.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/TargetMatcher.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/TargetMatcher.java
new file mode 100644 (file)
index 0000000..2574e15
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+ * \r
+ * Copyright 2002-2004 The Ant-Contrib project\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package net.sf.antcontrib.cpptasks;\r
+import java.io.File;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
+\r
+import net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration;\r
+import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+/**\r
+ * This class matches each visited file with an appropriate compiler\r
+ * \r
+ * @author Curt Arnold\r
+ */\r
+public final class TargetMatcher implements FileVisitor {\r
+    private LinkerConfiguration linker;\r
+    private Vector objectFiles;\r
+    private File outputDir;\r
+    private ProcessorConfiguration[] processors;\r
+    private final File sourceFiles[] = new File[1];\r
+    private Hashtable targets;\r
+    private CCTask task;\r
+    public TargetMatcher(CCTask task, File outputDir,\r
+            ProcessorConfiguration[] processors, LinkerConfiguration linker,\r
+            Vector objectFiles, Hashtable targets) {\r
+        this.task = task;\r
+        this.outputDir = outputDir;\r
+        this.processors = processors;\r
+        this.targets = targets;\r
+        this.linker = linker;\r
+        this.objectFiles = objectFiles;\r
+    }\r
+    public void visit(File parentDir, String filename) throws BuildException {\r
+        //\r
+        //   see if any processor wants to bid\r
+        //       on this one\r
+        ProcessorConfiguration selectedCompiler = null;\r
+        int bid = 0;\r
+        if (processors != null) {\r
+            for (int k = 0; k < processors.length; k++) {\r
+                int newBid = processors[k].bid(filename);\r
+                if (newBid > bid) {\r
+                    bid = newBid;\r
+                    selectedCompiler = processors[k];\r
+                }\r
+            }\r
+        }\r
+        //\r
+        //   no processor interested in file\r
+        //      log diagnostic message\r
+        if (bid <= 0) {\r
+            if (linker != null) {\r
+                int linkerbid = linker.bid(filename);\r
+                if (linkerbid > 0) {\r
+                    File objFile = new File(parentDir, filename);\r
+                    objectFiles.addElement(objFile);\r
+                    if (linkerbid == 1) {\r
+                        task.log("Unrecognized file type " + objFile.toString()\r
+                                + " will be passed to linker");\r
+                    }\r
+                }\r
+            }\r
+        } else {\r
+            //\r
+            //  get output file name\r
+            //\r
+            String outputFileName = selectedCompiler\r
+                    .getOutputFileName(filename);\r
+            //\r
+            //   if there is some output for this task\r
+            //      (that is a source file and not an header file)\r
+            //\r
+            if (outputFileName != null) {\r
+                sourceFiles[0] = new File(parentDir, filename);\r
+                //\r
+                //   see if the same output file has already been registered\r
+                //\r
+                TargetInfo previousTarget = (TargetInfo) targets\r
+                        .get(outputFileName);\r
+                if (previousTarget == null) {\r
+                    targets.put(outputFileName, new TargetInfo(\r
+                            selectedCompiler, sourceFiles, null, new File(\r
+                                    outputDir, outputFileName),\r
+                            selectedCompiler.getRebuild()));\r
+                } else {\r
+                    if (!previousTarget.getSources()[0].equals(sourceFiles[0])) {\r
+                        StringBuffer builder = new StringBuffer(\r
+                                "Output filename conflict: ");\r
+                        builder.append(outputFileName);\r
+                        builder.append(" would be produced from ");\r
+                        builder.append(previousTarget.getSources()[0]\r
+                                .toString());\r
+                        builder.append(" and ");\r
+                        builder.append(filename);\r
+                        throw new BuildException(builder.toString());\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+}\r