+++ /dev/null
-/*\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.compiler;\r
-import java.io.File;\r
-\r
-import net.sf.antcontrib.cpptasks.CCTask;\r
-import net.sf.antcontrib.cpptasks.CompilerParam;\r
-import net.sf.antcontrib.cpptasks.DependencyInfo;\r
-import net.sf.antcontrib.cpptasks.ProcessorParam;\r
-\r
-import org.apache.tools.ant.BuildException;\r
-/**\r
- * A configuration for a C++ compiler\r
- * \r
- * @author Curt Arnold\r
- */\r
-public final class CommandLineCompilerConfiguration\r
- implements\r
- CompilerConfiguration {\r
- private/* final */String[] args;\r
- private/* final */CommandLineCompiler compiler;\r
- private String[] endArgs;\r
- //\r
- // include path from environment variable not\r
- // explicitly stated in Ant script\r
- private/* final */File[] envIncludePath;\r
- private String[] exceptFiles;\r
- private/* final */String identifier;\r
- private/* final */File[] includePath;\r
- private/* final */String includePathIdentifier;\r
- private boolean isPrecompiledHeaderGeneration;\r
- private/* final */ProcessorParam[] params;\r
- private/* final */boolean rebuild;\r
- private/* final */File[] sysIncludePath;\r
- public CommandLineCompilerConfiguration(CommandLineCompiler compiler,\r
- String identifier, File[] includePath, File[] sysIncludePath,\r
- File[] envIncludePath, String includePathIdentifier, String[] args,\r
- ProcessorParam[] params, boolean rebuild, String[] endArgs) {\r
- if (compiler == null) {\r
- throw new NullPointerException("compiler");\r
- }\r
- if (identifier == null) {\r
- throw new NullPointerException("identifier");\r
- }\r
- if (includePathIdentifier == null) {\r
- throw new NullPointerException("includePathIdentifier");\r
- }\r
- if (args == null) {\r
- this.args = new String[0];\r
- } else {\r
- this.args = (String[]) args.clone();\r
- }\r
- if (includePath == null) {\r
- this.includePath = new File[0];\r
- } else {\r
- this.includePath = (File[]) includePath.clone();\r
- }\r
- if (sysIncludePath == null) {\r
- this.sysIncludePath = new File[0];\r
- } else {\r
- this.sysIncludePath = (File[]) sysIncludePath.clone();\r
- }\r
- if (envIncludePath == null) {\r
- this.envIncludePath = new File[0];\r
- } else {\r
- this.envIncludePath = (File[]) envIncludePath.clone();\r
- }\r
- this.compiler = compiler;\r
- this.params = (ProcessorParam[]) params.clone();\r
- this.rebuild = rebuild;\r
- this.identifier = identifier;\r
- this.includePathIdentifier = includePathIdentifier;\r
- this.endArgs = (String[]) endArgs.clone();\r
- exceptFiles = null;\r
- isPrecompiledHeaderGeneration = false;\r
- }\r
- public CommandLineCompilerConfiguration(\r
- CommandLineCompilerConfiguration base, String[] additionalArgs,\r
- String[] exceptFiles, boolean isPrecompileHeaderGeneration) {\r
- compiler = base.compiler;\r
- identifier = base.identifier;\r
- rebuild = base.rebuild;\r
- includePath = (File[]) base.includePath.clone();\r
- sysIncludePath = (File[]) base.sysIncludePath.clone();\r
- endArgs = (String[]) base.endArgs.clone();\r
- envIncludePath = (File[]) base.envIncludePath.clone();\r
- includePathIdentifier = base.includePathIdentifier;\r
- if (exceptFiles != null) {\r
- this.exceptFiles = (String[]) exceptFiles.clone();\r
- }\r
- this.isPrecompiledHeaderGeneration = isPrecompileHeaderGeneration;\r
- args = new String[base.args.length + additionalArgs.length];\r
- for (int i = 0; i < base.args.length; i++) {\r
- args[i] = base.args[i];\r
- }\r
- int index = base.args.length;\r
- for (int i = 0; i < additionalArgs.length; i++) {\r
- args[index++] = additionalArgs[i];\r
- }\r
- }\r
- public int bid(String inputFile) {\r
- int compilerBid = compiler.bid(inputFile);\r
- if (compilerBid > 0 && exceptFiles != null) {\r
- for (int i = 0; i < exceptFiles.length; i++) {\r
- if (inputFile.equals(exceptFiles[i])) {\r
- return 0;\r
- }\r
- }\r
- }\r
- return compilerBid;\r
- }\r
- public void compile(CCTask task, File outputDir, String[] sourceFiles,\r
- boolean relentless, ProgressMonitor monitor) throws BuildException {\r
- if (monitor != null) {\r
- monitor.start(this);\r
- }\r
- try {\r
- compiler.compile(task, outputDir, sourceFiles, args, endArgs,\r
- relentless, this, monitor);\r
- if (monitor != null) {\r
- monitor.finish(this, true);\r
- }\r
- } catch (BuildException ex) {\r
- if (monitor != null) {\r
- monitor.finish(this, false);\r
- }\r
- throw ex;\r
- }\r
- }\r
- /**\r
- * \r
- * This method may be used to get two distinct compiler configurations, one\r
- * for compiling the specified file and producing a precompiled header\r
- * file, and a second for compiling other files using the precompiled\r
- * header file.\r
- * \r
- * The last (preferrably only) include directive in the prototype file will\r
- * be used to mark the boundary between pre-compiled and normally compiled\r
- * headers.\r
- * \r
- * @param prototype\r
- * A source file (for example, stdafx.cpp) that is used to build\r
- * the precompiled header file. @returns null if precompiled\r
- * headers are not supported or a two element array containing\r
- * the precompiled header generation configuration and the\r
- * consuming configuration\r
- * \r
- */\r
- public CompilerConfiguration[] createPrecompileConfigurations(\r
- File prototype, String[] nonPrecompiledFiles) {\r
- if (compiler instanceof PrecompilingCompiler) {\r
- return ((PrecompilingCompiler) compiler)\r
- .createPrecompileConfigurations(this, prototype,\r
- nonPrecompiledFiles);\r
- }\r
- return null;\r
- }\r
- /**\r
- * Returns a string representation of this configuration. Should be\r
- * canonical so that equivalent configurations will have equivalent string\r
- * representations\r
- */\r
- public String getIdentifier() {\r
- return identifier;\r
- }\r
- public String getIncludePathIdentifier() {\r
- return includePathIdentifier;\r
- }\r
- public String getOutputFileName(String inputFile) {\r
- return compiler.getOutputFileName(inputFile);\r
- }\r
- public CompilerParam getParam(String name) {\r
- for (int i = 0; i < params.length; i++) {\r
- if (name.equals(params[i].getName()))\r
- return (CompilerParam) params[i];\r
- }\r
- return null;\r
- }\r
- public ProcessorParam[] getParams() {\r
- return params;\r
- }\r
- public boolean getRebuild() {\r
- return rebuild;\r
- }\r
- public boolean isPrecompileGeneration() {\r
- return isPrecompiledHeaderGeneration;\r
- }\r
- public DependencyInfo parseIncludes(CCTask task, File baseDir, File source) {\r
- return compiler.parseIncludes(task, source, includePath,\r
- sysIncludePath, envIncludePath, baseDir,\r
- getIncludePathIdentifier());\r
- }\r
- public String toString() {\r
- return identifier;\r
- }\r
- public String[] getPreArguments() {\r
- return (String[]) args.clone();\r
- }\r
- public String[] getEndArguments() {\r
- return (String[]) endArgs.clone();\r
- }\r
-}\r