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