]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/compiler/CommandLineCompilerConfiguration.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / compiler / CommandLineCompilerConfiguration.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2002-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.compiler;\r
18import java.io.File;\r
19\r
20import net.sf.antcontrib.cpptasks.CCTask;\r
21import net.sf.antcontrib.cpptasks.CompilerParam;\r
22import net.sf.antcontrib.cpptasks.DependencyInfo;\r
23import net.sf.antcontrib.cpptasks.ProcessorParam;\r
24\r
25import org.apache.tools.ant.BuildException;\r
26/**\r
27 * A configuration for a C++ compiler\r
28 * \r
29 * @author Curt Arnold\r
30 */\r
31public final class CommandLineCompilerConfiguration\r
32 implements\r
33 CompilerConfiguration {\r
34 private/* final */String[] args;\r
35 private/* final */CommandLineCompiler compiler;\r
36 private String[] endArgs;\r
37 //\r
38 // include path from environment variable not\r
39 // explicitly stated in Ant script\r
40 private/* final */File[] envIncludePath;\r
41 private String[] exceptFiles;\r
42 private/* final */String identifier;\r
43 private/* final */File[] includePath;\r
44 private/* final */String includePathIdentifier;\r
45 private boolean isPrecompiledHeaderGeneration;\r
46 private/* final */ProcessorParam[] params;\r
47 private/* final */boolean rebuild;\r
48 private/* final */File[] sysIncludePath;\r
49 public CommandLineCompilerConfiguration(CommandLineCompiler compiler,\r
50 String identifier, File[] includePath, File[] sysIncludePath,\r
51 File[] envIncludePath, String includePathIdentifier, String[] args,\r
52 ProcessorParam[] params, boolean rebuild, String[] endArgs) {\r
53 if (compiler == null) {\r
54 throw new NullPointerException("compiler");\r
55 }\r
56 if (identifier == null) {\r
57 throw new NullPointerException("identifier");\r
58 }\r
59 if (includePathIdentifier == null) {\r
60 throw new NullPointerException("includePathIdentifier");\r
61 }\r
62 if (args == null) {\r
63 this.args = new String[0];\r
64 } else {\r
65 this.args = (String[]) args.clone();\r
66 }\r
67 if (includePath == null) {\r
68 this.includePath = new File[0];\r
69 } else {\r
70 this.includePath = (File[]) includePath.clone();\r
71 }\r
72 if (sysIncludePath == null) {\r
73 this.sysIncludePath = new File[0];\r
74 } else {\r
75 this.sysIncludePath = (File[]) sysIncludePath.clone();\r
76 }\r
77 if (envIncludePath == null) {\r
78 this.envIncludePath = new File[0];\r
79 } else {\r
80 this.envIncludePath = (File[]) envIncludePath.clone();\r
81 }\r
82 this.compiler = compiler;\r
83 this.params = (ProcessorParam[]) params.clone();\r
84 this.rebuild = rebuild;\r
85 this.identifier = identifier;\r
86 this.includePathIdentifier = includePathIdentifier;\r
87 this.endArgs = (String[]) endArgs.clone();\r
88 exceptFiles = null;\r
89 isPrecompiledHeaderGeneration = false;\r
90 }\r
91 public CommandLineCompilerConfiguration(\r
92 CommandLineCompilerConfiguration base, String[] additionalArgs,\r
93 String[] exceptFiles, boolean isPrecompileHeaderGeneration) {\r
94 compiler = base.compiler;\r
95 identifier = base.identifier;\r
96 rebuild = base.rebuild;\r
97 includePath = (File[]) base.includePath.clone();\r
98 sysIncludePath = (File[]) base.sysIncludePath.clone();\r
99 endArgs = (String[]) base.endArgs.clone();\r
100 envIncludePath = (File[]) base.envIncludePath.clone();\r
101 includePathIdentifier = base.includePathIdentifier;\r
102 if (exceptFiles != null) {\r
103 this.exceptFiles = (String[]) exceptFiles.clone();\r
104 }\r
105 this.isPrecompiledHeaderGeneration = isPrecompileHeaderGeneration;\r
106 args = new String[base.args.length + additionalArgs.length];\r
107 for (int i = 0; i < base.args.length; i++) {\r
108 args[i] = base.args[i];\r
109 }\r
110 int index = base.args.length;\r
111 for (int i = 0; i < additionalArgs.length; i++) {\r
112 args[index++] = additionalArgs[i];\r
113 }\r
114 }\r
115 public int bid(String inputFile) {\r
116 int compilerBid = compiler.bid(inputFile);\r
117 if (compilerBid > 0 && exceptFiles != null) {\r
118 for (int i = 0; i < exceptFiles.length; i++) {\r
119 if (inputFile.equals(exceptFiles[i])) {\r
120 return 0;\r
121 }\r
122 }\r
123 }\r
124 return compilerBid;\r
125 }\r
126 public void compile(CCTask task, File outputDir, String[] sourceFiles,\r
127 boolean relentless, ProgressMonitor monitor) throws BuildException {\r
128 if (monitor != null) {\r
129 monitor.start(this);\r
130 }\r
131 try {\r
132 compiler.compile(task, outputDir, sourceFiles, args, endArgs,\r
133 relentless, this, monitor);\r
134 if (monitor != null) {\r
135 monitor.finish(this, true);\r
136 }\r
137 } catch (BuildException ex) {\r
138 if (monitor != null) {\r
139 monitor.finish(this, false);\r
140 }\r
141 throw ex;\r
142 }\r
143 }\r
144 /**\r
145 * \r
146 * This method may be used to get two distinct compiler configurations, one\r
147 * for compiling the specified file and producing a precompiled header\r
148 * file, and a second for compiling other files using the precompiled\r
149 * header file.\r
150 * \r
151 * The last (preferrably only) include directive in the prototype file will\r
152 * be used to mark the boundary between pre-compiled and normally compiled\r
153 * headers.\r
154 * \r
155 * @param prototype\r
156 * A source file (for example, stdafx.cpp) that is used to build\r
157 * the precompiled header file. @returns null if precompiled\r
158 * headers are not supported or a two element array containing\r
159 * the precompiled header generation configuration and the\r
160 * consuming configuration\r
161 * \r
162 */\r
163 public CompilerConfiguration[] createPrecompileConfigurations(\r
164 File prototype, String[] nonPrecompiledFiles) {\r
165 if (compiler instanceof PrecompilingCompiler) {\r
166 return ((PrecompilingCompiler) compiler)\r
167 .createPrecompileConfigurations(this, prototype,\r
168 nonPrecompiledFiles);\r
169 }\r
170 return null;\r
171 }\r
172 /**\r
173 * Returns a string representation of this configuration. Should be\r
174 * canonical so that equivalent configurations will have equivalent string\r
175 * representations\r
176 */\r
177 public String getIdentifier() {\r
178 return identifier;\r
179 }\r
180 public String getIncludePathIdentifier() {\r
181 return includePathIdentifier;\r
182 }\r
183 public String getOutputFileName(String inputFile) {\r
184 return compiler.getOutputFileName(inputFile);\r
185 }\r
186 public CompilerParam getParam(String name) {\r
187 for (int i = 0; i < params.length; i++) {\r
188 if (name.equals(params[i].getName()))\r
189 return (CompilerParam) params[i];\r
190 }\r
191 return null;\r
192 }\r
193 public ProcessorParam[] getParams() {\r
194 return params;\r
195 }\r
196 public boolean getRebuild() {\r
197 return rebuild;\r
198 }\r
199 public boolean isPrecompileGeneration() {\r
200 return isPrecompiledHeaderGeneration;\r
201 }\r
202 public DependencyInfo parseIncludes(CCTask task, File baseDir, File source) {\r
203 return compiler.parseIncludes(task, source, includePath,\r
204 sysIncludePath, envIncludePath, baseDir,\r
205 getIncludePathIdentifier());\r
206 }\r
207 public String toString() {\r
208 return identifier;\r
209 }\r
210 public String[] getPreArguments() {\r
211 return (String[]) args.clone();\r
212 }\r
213 public String[] getEndArguments() {\r
214 return (String[]) endArgs.clone();\r
215 }\r
216}\r