Adjust code format and remove unused code.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1181 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong
2006-08-03 04:34:39 +00:00
parent a390c35d8a
commit e6225e3c73
5 changed files with 212 additions and 171 deletions

View File

@ -32,6 +32,9 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
/**
*
*/
public class CommandLineUserDefine { public class CommandLineUserDefine {
String includePathDelimiter = null; String includePathDelimiter = null;
@ -44,8 +47,7 @@ public class CommandLineUserDefine {
Project project = cctask.getProject(); Project project = cctask.getProject();
if (userdefine.getWorkdir() == null) { if (userdefine.getWorkdir() == null) {
workdir = new File("."); workdir = new File(".");
} } else {
else {
workdir = userdefine.getWorkdir(); workdir = userdefine.getWorkdir();
} }
@ -58,14 +60,6 @@ public class CommandLineUserDefine {
Vector endargsWithoutSpace = new Vector(); Vector endargsWithoutSpace = new Vector();
Vector includePath = new Vector(); Vector includePath = new Vector();
//
// Generate cmdline = command +
// general args +
// outputflag + outputfile
// includpath +
// endargs +
//
// //
// get Args. // get Args.
// //
@ -83,13 +77,7 @@ public class CommandLineUserDefine {
// //
String[] incPath = userdefine.getActiveIncludePaths(); String[] incPath = userdefine.getActiveIncludePaths();
for (int j = 0; j < incPath.length; j++) { for (int j = 0; j < incPath.length; j++) {
if(incPath[j].indexOf(' ') >= 0) {
includePath.addElement(includePathDelimiter + incPath[j]); includePath.addElement(includePathDelimiter + incPath[j]);
//includePath.addElement( includePathDelimiter + "\"" + incPath[j] + "\"");
}
else {
includePath.addElement( includePathDelimiter + incPath[j]);
}
} }
// //
@ -114,8 +102,9 @@ public class CommandLineUserDefine {
// //
// command + args + endargs + includepath + sourcefile // command + args + endargs + includepath + sourcefile
// //
cmdLen = 1 + argsWithoutSpace.size() + endargsWithoutSpace.size() + includePath.size() + 1; cmdLen = 1 + argsWithoutSpace.size() + endargsWithoutSpace.size()
String[] libSet = userdefine.get_libset(); + includePath.size() + 1;
String[] libSet = userdefine.getLibset();
if (libSet != null && libSet.length > 0) { if (libSet != null && libSet.length > 0) {
cmdLen = cmdLen + libSet.length; cmdLen = cmdLen + libSet.length;
if (isGccCommand) { if (isGccCommand) {
@ -124,10 +113,12 @@ public class CommandLineUserDefine {
} }
// //
// In gcc the "cr" flag should follow space then add outputfile name, otherwise // In gcc the "cr" flag should follow space then add outputfile name,
// otherwise
// it will pop error. // it will pop error.
// TBD // TBD
if (outputDelimiter != null && userdefine.getOutputFile() != null && outputDelimiter.trim().length() > 0){ if (outputDelimiter != null && userdefine.getOutputFile() != null
&& outputDelimiter.trim().length() > 0) {
if (outputDelimiter.trim().equalsIgnoreCase("-cr")) { if (outputDelimiter.trim().equalsIgnoreCase("-cr")) {
cmdLen = cmdLen + 2; cmdLen = cmdLen + 2;
} else { } else {
@ -140,31 +131,36 @@ public class CommandLineUserDefine {
// if file is header file, just skip it (add later) // if file is header file, just skip it (add later)
// //
Vector srcSets = userdefine.getSrcSets(); Vector srcSets = userdefine.getSrcSets();
// System.out.println("##" + userdefine.getSrcSets());
// //
// if have source file append source file in command land. // if have source file append source file in command line.
// //
Set allSrcFiles = new LinkedHashSet(); Set allSrcFiles = new LinkedHashSet();
for (int i = 0; i < srcSets.size(); i++) { for (int i = 0; i < srcSets.size(); i++) {
ConditionalFileSet srcSet = (ConditionalFileSet) srcSets ConditionalFileSet srcSet = (ConditionalFileSet) srcSets
.elementAt(i); .elementAt(i);
if (srcSet.isActive()) { if (srcSet.isActive()) {
//
// Find matching source files // Find matching source files
//
DirectoryScanner scanner = srcSet.getDirectoryScanner(project); DirectoryScanner scanner = srcSet.getDirectoryScanner(project);
//
// Check each source file - see if it needs compilation // Check each source file - see if it needs compilation
//
String[] fileNames = scanner.getIncludedFiles(); String[] fileNames = scanner.getIncludedFiles();
for (int j = 0; j < fileNames.length; j++) { for (int j = 0; j < fileNames.length; j++) {
// execute the command
allSrcFiles.add(scanner.getBasedir() + "/" + fileNames[j]); allSrcFiles.add(scanner.getBasedir() + "/" + fileNames[j]);
if (isGccCommand) { if (isGccCommand) {
System.out.println("[" + userdefine.getType() + "] " + fileNames[j]); System.out.println("[" + userdefine.getType() + "] "
+ fileNames[j]);
} }
} }
} }
} }
String[] fileNames = (String[])allSrcFiles.toArray(new String[allSrcFiles.size()]); String[] fileNames = (String[]) allSrcFiles
.toArray(new String[allSrcFiles.size()]);
String[] cmd = new String[cmdLen - 1 + fileNames.length]; String[] cmd = new String[cmdLen - 1 + fileNames.length];
int index = 0; int index = 0;
cmd[index++] = userdefine.getCmd(); cmd[index++] = userdefine.getCmd();
@ -182,7 +178,8 @@ public class CommandLineUserDefine {
// //
// Add outputFileFlag and output file to cmd // Add outputFileFlag and output file to cmd
// //
if (outputDelimiter != null && userdefine.getOutputFile() != null && outputDelimiter.length()> 0){ if (outputDelimiter != null && userdefine.getOutputFile() != null
&& outputDelimiter.length() > 0) {
if (outputDelimiter.trim().equalsIgnoreCase("-cr")) { if (outputDelimiter.trim().equalsIgnoreCase("-cr")) {
cmd[index++] = outputDelimiter; cmd[index++] = outputDelimiter;
cmd[index++] = userdefine.getOutputFile(); cmd[index++] = userdefine.getOutputFile();
@ -208,16 +205,15 @@ public class CommandLineUserDefine {
} }
} }
for (int j = 0; j < fileNames.length; j++) { for (int j = 0; j < fileNames.length; j++) {
// execute the command
cmd[index++] = fileNames[j]; cmd[index++] = fileNames[j];
} }
int retval = runCommand(cctask, workdir, cmd); int retval = runCommand(cctask, workdir, cmd);
// if with monitor, add more code
if (retval != 0) { if (retval != 0) {
throw new BuildException(userdefine.getCmd() throw new BuildException(userdefine.getCmd()
+ " failed with return code " + retval, + " failed with return code " + retval, cctask
cctask.getLocation()); .getLocation());
} }
} }
@ -226,19 +222,4 @@ public class CommandLineUserDefine {
return CUtil.runCommand(task, workingDir, cmdline, false, null); return CUtil.runCommand(task, workingDir, cmdline, false, null);
} }
protected String getInputFileArgument(File outputDir, String filename,
int index) {
//
// if there is an embedded space,
// must enclose in quotes
if (filename.indexOf(' ') >= 0) {
StringBuffer buf = new StringBuffer("\"");
buf.append(filename);
buf.append("\"");
return buf.toString();
}
return filename;
}
} }

View File

@ -18,6 +18,10 @@ package net.sf.antcontrib.cpptasks.userdefine;
import net.sf.antcontrib.cpptasks.types.CommandLineArgument; import net.sf.antcontrib.cpptasks.types.CommandLineArgument;
/**
* Collect Arguments.
*
*/
public class UserDefineArgument extends CommandLineArgument { public class UserDefineArgument extends CommandLineArgument {
public UserDefineArgument() { public UserDefineArgument() {

View File

@ -18,21 +18,25 @@ package net.sf.antcontrib.cpptasks.userdefine;
import net.sf.antcontrib.cpptasks.CCTask; import net.sf.antcontrib.cpptasks.CCTask;
/**
* Adapter for the User-Defined Compiler
*/
public class UserDefineCompiler extends CommandLineUserDefine { public class UserDefineCompiler extends CommandLineUserDefine {
public UserDefineCompiler (CCTask cctask, UserDefineDef userdefineDef) { public UserDefineCompiler (CCTask cctask, UserDefineDef userdefineDef) {
String cmdType = userdefineDef.getType(); String cmdType = userdefineDef.getType();
String toolchainFamily = userdefineDef.getFamily(); String toolchainFamily = userdefineDef.getFamily();
UserDefineMapping mapping = new UserDefineMapping();
if (userdefineDef.getIncludepathDelimiter() == null) { if (userdefineDef.getIncludePathDelimiter() == null) {
includePathDelimiter = mapping.getIncludePathDelimiter(toolchainFamily, cmdType); includePathDelimiter = UserDefineMapping.getIncludePathDelimiter(
toolchainFamily, cmdType);
} else { } else {
includePathDelimiter = userdefineDef.getIncludepathDelimiter(); includePathDelimiter = userdefineDef.getIncludePathDelimiter();
} }
if (userdefineDef.getOutputDelimiter() == null) { if (userdefineDef.getOutputDelimiter() == null) {
outputDelimiter = mapping.getOutputFileFlag(toolchainFamily, cmdType); outputDelimiter = UserDefineMapping.getOutputFileFlag(
toolchainFamily, cmdType);
} else { } else {
outputDelimiter = userdefineDef.getOutputDelimiter(); outputDelimiter = userdefineDef.getOutputDelimiter();
} }

View File

@ -32,9 +32,17 @@ import net.sf.antcontrib.cpptasks.types.ConditionalPath;
import net.sf.antcontrib.cpptasks.types.IncludePath; import net.sf.antcontrib.cpptasks.types.IncludePath;
import net.sf.antcontrib.cpptasks.types.LibrarySet; import net.sf.antcontrib.cpptasks.types.LibrarySet;
/**
* A userdefinedef definition. userdefine elements may be placed either as
* children of a cc element or the project element. A userdefine element with an
* id attribute may be referenced by userdefine elements with refid or extends
* attributes.
*
*/
public class UserDefineDef extends ProcessorDef { public class UserDefineDef extends ProcessorDef {
public UserDefineDef () {} public UserDefineDef () {
}
private String type = "CC"; private String type = "CC";
@ -42,7 +50,7 @@ public class UserDefineDef extends ProcessorDef{
private String cmd; private String cmd;
private String includepathDelimiter; private String includePathDelimiter;
private String outputDelimiter; private String outputDelimiter;
@ -52,7 +60,7 @@ public class UserDefineDef extends ProcessorDef{
private String outputFile; private String outputFile;
private Vector _libset = new Vector(); private Vector allLibraries = new Vector();
public void addLibset(LibrarySet libset) { public void addLibset(LibrarySet libset) {
if (isReference()) { if (isReference()) {
@ -62,7 +70,7 @@ public class UserDefineDef extends ProcessorDef{
throw new NullPointerException("libset"); throw new NullPointerException("libset");
} }
_libset.add(libset); allLibraries.add(libset);
} }
public void execute() throws org.apache.tools.ant.BuildException { public void execute() throws org.apache.tools.ant.BuildException {
@ -70,7 +78,6 @@ public class UserDefineDef extends ProcessorDef{
"Not an actual task, but looks like one for documentation purposes"); "Not an actual task, but looks like one for documentation purposes");
} }
public void addConfiguredArgument(UserDefineArgument arg) { public void addConfiguredArgument(UserDefineArgument arg) {
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
@ -83,9 +90,6 @@ public class UserDefineDef extends ProcessorDef{
*/ */
public IncludePath createIncludePath() { public IncludePath createIncludePath() {
Project p = getProject(); Project p = getProject();
if (p == null) {
throw new java.lang.IllegalStateException("project must be set");
}
if (isReference()) { if (isReference()) {
throw noChildrenAllowed(); throw noChildrenAllowed();
} }
@ -94,10 +98,13 @@ public class UserDefineDef extends ProcessorDef{
return path; return path;
} }
/** /**
* Add a <includepath> if specify the file attribute * Add a <includepath> if specify the file attribute
* *
* @param activePath
* Active Path Vector
* @param file
* File with multiple path
* @throws BuildException * @throws BuildException
* if the specify file not exist * if the specify file not exist
*/ */
@ -112,7 +119,7 @@ public class UserDefineDef extends ProcessorDef{
fileReader = new FileReader(file); fileReader = new FileReader(file);
in = new BufferedReader(fileReader); in = new BufferedReader(fileReader);
while ((str = in.readLine()) != null) { while ((str = in.readLine()) != null) {
if (str.trim() == "") { if (str.trim().endsWith("")) {
continue; continue;
} }
str = getProject().replaceProperties(str); str = getProject().replaceProperties(str);
@ -125,6 +132,8 @@ public class UserDefineDef extends ProcessorDef{
/** /**
* Returns the specific include path. * Returns the specific include path.
*
* @return All active include paths
*/ */
public String[] getActiveIncludePaths() { public String[] getActiveIncludePaths() {
if (isReference()) { if (isReference()) {
@ -136,11 +145,9 @@ public class UserDefineDef extends ProcessorDef{
private String[] getActivePaths(Vector paths) { private String[] getActivePaths(Vector paths) {
Project p = getProject(); Project p = getProject();
if (p == null) {
throw new java.lang.IllegalStateException("project not set");
}
Vector activePaths = new Vector(paths.size()); Vector activePaths = new Vector(paths.size());
for (int i = 0; i < paths.size(); i++) { int length = paths.size();
for (int i = 0; i < length; i++) {
ConditionalPath path = (ConditionalPath) paths.elementAt(i); ConditionalPath path = (ConditionalPath) paths.elementAt(i);
if (path.isActive(p)) { if (path.isActive(p)) {
if (path.getFile() == null) { if (path.getFile() == null) {
@ -158,21 +165,37 @@ public class UserDefineDef extends ProcessorDef{
return pathNames; return pathNames;
} }
public String getIncludepathDelimiter() { /**
* Get include path delimiter.
*
* @return Include Path Delimiter
*/
public String getIncludePathDelimiter() {
if (isReference()) { if (isReference()) {
return ((UserDefineDef) getCheckedRef(UserDefineDef.class, return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
"UserDefineDef")).getIncludepathDelimiter(); "UserDefineDef")).getIncludePathDelimiter();
} }
return includepathDelimiter; return includePathDelimiter;
} }
public void setIncludepathDelimiter(String includepathDelimiter) { /**
* Set include path delimiter.
*
* @param includePathDelimiter
* include path delimiter
*/
public void setIncludePathDelimiter(String includePathDelimiter) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
} }
this.includepathDelimiter = includepathDelimiter; this.includePathDelimiter = includePathDelimiter;
} }
/**
* Get type.
*
* @return type
*/
public String getType() { public String getType() {
if (isReference()) { if (isReference()) {
return ((UserDefineDef) getCheckedRef(UserDefineDef.class, return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
@ -181,6 +204,12 @@ public class UserDefineDef extends ProcessorDef{
return type; return type;
} }
/**
* Set type.
*
* @param type
* Type
*/
public void setType(String type) { public void setType(String type) {
if (isReference()) { if (isReference()) {
throw tooManyAttributes(); throw tooManyAttributes();
@ -232,9 +261,9 @@ public class UserDefineDef extends ProcessorDef{
this.workdir = workdir; this.workdir = workdir;
} }
public String[] get_libset() { public String[] getLibset() {
Set libs = new LinkedHashSet(); Set libs = new LinkedHashSet();
Iterator iter = _libset.iterator(); Iterator iter = allLibraries.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
LibrarySet librarySet = (LibrarySet) iter.next(); LibrarySet librarySet = (LibrarySet) iter.next();
File basedir = librarySet.getDir(getProject()); File basedir = librarySet.getDir(getProject());
@ -244,12 +273,11 @@ public class UserDefineDef extends ProcessorDef{
File libFile = new File(libStrArray[i]); File libFile = new File(libStrArray[i]);
if (libFile.isAbsolute()) { if (libFile.isAbsolute()) {
libs.add(libFile.getPath()); libs.add(libFile.getPath());
} else {
libs.add(basedir.getPath() + File.separatorChar
+ libFile.getPath());
} }
else { } else {
libs.add(basedir.getPath() + File.separatorChar + libFile.getPath());
}
}
else {
libs.add(libStrArray[i]); libs.add(libStrArray[i]);
} }
} }

View File

@ -15,31 +15,46 @@
* limitations under the License. * limitations under the License.
*/ */
package net.sf.antcontrib.cpptasks.userdefine; package net.sf.antcontrib.cpptasks.userdefine;
/**
* Relationship between {family, command type} and flags
*
*/
public class UserDefineMapping { public class UserDefineMapping {
/**
* Mapping info: include path delimiter <--> family (vendor) + command type
*/
public static final String[][] includePathFlag = { { "MSFT_CC", "/I" },
{ "GCC_CC", "-I" }, { "INTEL_CC", "/I" },
{ "WINDDK_CC", "/I" }, { "MSFT_ASM", "/I" },
{ "GCC_ASM", "-I" }, { "WINDDK_CC", "/I" },
{ "MSFT_PP", "/I" }, { "GCC_PP", "-I" },
{ "WINDDK_PP", "/I" } };
// list of Vendor: Microsoft, Intel, Gcc /**
public final String[] families = { "MSFT", "INTEL", "GCC"}; * Mapping info: output file flag <--> family (vendor) + command type
*/
public static final String[][] outputFileFlag = { { "MSFT_CC", "/Fo" },
{ "GCC_CC", "-o" }, { "INTEL_CC", "/Fo" },
{ "WINDDK_CC", "/Fo" }, { "MSFT_SLINK", "/OUT:" },
{ "GCC_SLINK", "-cr" }, { "INTEL_SLINK", "/OUT:" },
{ "WINDDK_SLINK", "/OUT:" }, { "MSFT_DLINK", "/OUT:" },
{ "GCC_DLINK", "-o" }, { "INTEL_DLINK", "/OUT:" },
{ "WINDDK_DLINK", "/OUT:" }, { "MSFT_ASM", "/Fo" },
{ "GCC_ASM", "-o" }, { "WINDDK_ASM", "/Fo" },
{ "WINDDK_IPF_ASM", "-o" } };
// list of Command Type: CC, SLINK, DLINK, ASL, ASM, ASMLINK, PP /**
public final String[] commandType = { "CC", "SLINK", "DLINK", "ASL", * Get include delimiter with vendow and command type.
"ASM", "ASMLINK", "PP" }; *
* @param vendor
public final String[][] includePathFlag = { { "MSFT_CC", "/I" }, * Vendor
{ "GCC_CC", "-I" }, { "INTEL_CC", "/I" }, { "WINDDK_CC", "/I" }, * @param commandType
{ "MSFT_ASM", "/I" }, { "GCC_ASM", "-I" }, { "WINDDK_CC", "/I" }, * Command Type
{ "MSFT_PP", "/I" }, { "GCC_PP", "-I" }, { "WINDDK_PP", "/I" } }; * @return include path delimiter
*/
public final String[][] outputFileFlag = { { "MSFT_CC", "/Fo" }, public static String getIncludePathDelimiter(String vendor,
{ "GCC_CC", "-o" }, { "INTEL_CC", "/Fo" }, { "WINDDK_CC", "/Fo" },
{ "MSFT_SLINK", "/OUT:" }, { "GCC_SLINK", "-cr" },
{ "INTEL_SLINK", "/OUT:" }, { "WINDDK_SLINK", "/OUT:" },
{ "MSFT_DLINK", "/OUT:" }, { "GCC_DLINK", "-o" },
{ "INTEL_DLINK", "/OUT:" }, { "WINDDK_DLINK", "/OUT:" },
{ "MSFT_ASM", "/Fo" }, { "GCC_ASM", "-o" },
{ "WINDDK_ASM", "/Fo" },{"WINDDK_IPF_ASM", "-o"} };
public String getIncludePathDelimiter(String vendor,
String commandType) { String commandType) {
String key = vendor + "_" + commandType; String key = vendor + "_" + commandType;
for (int i = 0; i < includePathFlag.length; i++) { for (int i = 0; i < includePathFlag.length; i++) {
@ -50,7 +65,16 @@ public class UserDefineMapping {
return "/I"; return "/I";
} }
public String getOutputFileFlag(String vendor, String commandType) { /**
* Get Output Flag with vendor and command type.
*
* @param vendor
* Vendor
* @param commandType
* Command Type
* @return Output File Flag
*/
public static String getOutputFileFlag(String vendor, String commandType) {
String key = vendor + "_" + commandType; String key = vendor + "_" + commandType;
for (int i = 0; i < outputFileFlag.length; i++) { for (int i = 0; i < outputFileFlag.length; i++) {
if (outputFileFlag[i][0].equalsIgnoreCase(key)) { if (outputFileFlag[i][0].equalsIgnoreCase(key)) {