]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/TargetMatcher.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / TargetMatcher.java
1 /*
2 *
3 * Copyright 2002-2004 The Ant-Contrib project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package net.sf.antcontrib.cpptasks;
18 import java.io.File;
19 import java.util.Hashtable;
20 import java.util.Vector;
21
22 import net.sf.antcontrib.cpptasks.compiler.LinkerConfiguration;
23 import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
24
25 import org.apache.tools.ant.BuildException;
26 /**
27 * This class matches each visited file with an appropriate compiler
28 *
29 * @author Curt Arnold
30 */
31 public final class TargetMatcher implements FileVisitor {
32 private LinkerConfiguration linker;
33 private Vector objectFiles;
34 private File outputDir;
35 private ProcessorConfiguration[] processors;
36 private final File sourceFiles[] = new File[1];
37 private Hashtable targets;
38 private CCTask task;
39 public TargetMatcher(CCTask task, File outputDir,
40 ProcessorConfiguration[] processors, LinkerConfiguration linker,
41 Vector objectFiles, Hashtable targets) {
42 this.task = task;
43 this.outputDir = outputDir;
44 this.processors = processors;
45 this.targets = targets;
46 this.linker = linker;
47 this.objectFiles = objectFiles;
48 }
49 public void visit(File parentDir, String filename) throws BuildException {
50 //
51 // see if any processor wants to bid
52 // on this one
53 ProcessorConfiguration selectedCompiler = null;
54 int bid = 0;
55 if (processors != null) {
56 for (int k = 0; k < processors.length; k++) {
57 int newBid = processors[k].bid(filename);
58 if (newBid > bid) {
59 bid = newBid;
60 selectedCompiler = processors[k];
61 }
62 }
63 }
64 //
65 // no processor interested in file
66 // log diagnostic message
67 if (bid <= 0) {
68 if (linker != null) {
69 int linkerbid = linker.bid(filename);
70 if (linkerbid > 0) {
71 File objFile = new File(parentDir, filename);
72 objectFiles.addElement(objFile);
73 if (linkerbid == 1) {
74 task.log("Unrecognized file type " + objFile.toString()
75 + " will be passed to linker");
76 }
77 }
78 }
79 } else {
80 //
81 // get output file name
82 //
83 String outputFileName = selectedCompiler
84 .getOutputFileName(filename);
85 //
86 // if there is some output for this task
87 // (that is a source file and not an header file)
88 //
89 if (outputFileName != null) {
90 sourceFiles[0] = new File(parentDir, filename);
91 //
92 // see if the same output file has already been registered
93 //
94 TargetInfo previousTarget = (TargetInfo) targets
95 .get(outputFileName);
96 if (previousTarget == null) {
97 targets.put(outputFileName, new TargetInfo(
98 selectedCompiler, sourceFiles, null, new File(
99 outputDir, outputFileName),
100 selectedCompiler.getRebuild()));
101 } else {
102 if (!previousTarget.getSources()[0].equals(sourceFiles[0])) {
103 StringBuffer builder = new StringBuffer(
104 "Output filename conflict: ");
105 builder.append(outputFileName);
106 builder.append(" would be produced from ");
107 builder.append(previousTarget.getSources()[0]
108 .toString());
109 builder.append(" and ");
110 builder.append(filename);
111 throw new BuildException(builder.toString());
112 }
113 }
114 }
115 }
116 }
117 }