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,23 +32,25 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
/**
*
*/
public class CommandLineUserDefine {
String includePathDelimiter = null;
String outputDelimiter = null;
public void command(CCTask cctask, UserDefineDef userdefine){
public void command(CCTask cctask, UserDefineDef userdefine) {
boolean isGccCommand = userdefine.getFamily().equalsIgnoreCase("GCC");
File workdir;
Project project = cctask.getProject();
if(userdefine.getWorkdir() == null) {
if (userdefine.getWorkdir() == null) {
workdir = new File(".");
}
else {
} else {
workdir = userdefine.getWorkdir();
}
}
//
// generate cmdline= command + args + includepath + endargs + outfile
//
@ -57,15 +59,7 @@ public class CommandLineUserDefine {
Vector endargs = new Vector();
Vector endargsWithoutSpace = new Vector();
Vector includePath = new Vector();
//
// Generate cmdline = command +
// general args +
// outputflag + outputfile
// includpath +
// endargs +
//
//
// get Args.
//
@ -77,168 +71,155 @@ public class CommandLineUserDefine {
endargs.addElement(argument[j].getValue());
}
}
//
// get include path.
//
String[] incPath = userdefine.getActiveIncludePaths();
for (int j = 0; j < incPath.length; j++) {
if(incPath[j].indexOf(' ') >= 0) {
includePath.addElement( includePathDelimiter + incPath[j]);
//includePath.addElement( includePathDelimiter + "\"" + incPath[j] + "\"");
}
else {
includePath.addElement( includePathDelimiter + incPath[j]);
}
includePath.addElement(includePathDelimiter + incPath[j]);
}
//
// Remove space in args and endargs.
//
for ( int i=0; i < args.size(); i++) {
String str = (String)args.get(i);
for (int i = 0; i < args.size(); i++) {
String str = (String) args.get(i);
StringTokenizer st = new StringTokenizer(str, " \t");
while(st.hasMoreTokens()) {
while (st.hasMoreTokens()) {
argsWithoutSpace.addElement(st.nextToken());
}
}
for ( int i=0; i < endargs.size(); i++) {
String str = (String)endargs.get(i);
for (int i = 0; i < endargs.size(); i++) {
String str = (String) endargs.get(i);
StringTokenizer st = new StringTokenizer(str, " \t");
while(st.hasMoreTokens()) {
while (st.hasMoreTokens()) {
endargsWithoutSpace.addElement(st.nextToken());
}
}
int cmdLen = 0;
//
// command + args + endargs + includepath + sourcefile
//
cmdLen = 1 + argsWithoutSpace.size() + endargsWithoutSpace.size() + includePath.size() + 1;
String[] libSet = userdefine.get_libset();
if (libSet != null && libSet.length > 0){
cmdLen = 1 + argsWithoutSpace.size() + endargsWithoutSpace.size()
+ includePath.size() + 1;
String[] libSet = userdefine.getLibset();
if (libSet != null && libSet.length > 0) {
cmdLen = cmdLen + libSet.length;
if (isGccCommand) {
cmdLen += 2; // we need -( and -) to group libs for GCC
cmdLen += 2; // we need -( and -) to group libs for GCC
}
}
//
// In gcc the "cr" flag should follow space then add outputfile name, otherwise
// it will pop error.
// In gcc the "cr" flag should follow space then add outputfile name,
// otherwise
// it will pop error.
// TBD
if (outputDelimiter != null && userdefine.getOutputFile() != null && outputDelimiter.trim().length() > 0){
if (outputDelimiter.trim().equalsIgnoreCase("-cr")){
if (outputDelimiter != null && userdefine.getOutputFile() != null
&& outputDelimiter.trim().length() > 0) {
if (outputDelimiter.trim().equalsIgnoreCase("-cr")) {
cmdLen = cmdLen + 2;
}else {
} else {
cmdLen++;
}
}
//
// for every source file
// if file is header file, just skip it (add later)
// for every source file
// if file is header file, just skip it (add later)
//
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();
for (int i = 0; i < srcSets.size(); i++) {
ConditionalFileSet srcSet = (ConditionalFileSet) srcSets
.elementAt(i);
.elementAt(i);
if (srcSet.isActive()) {
//
// Find matching source files
//
DirectoryScanner scanner = srcSet.getDirectoryScanner(project);
//
// Check each source file - see if it needs compilation
//
String[] fileNames = scanner.getIncludedFiles();
for (int j = 0; j < fileNames.length; j++){
// execute the command
for (int j = 0; j < fileNames.length; j++) {
allSrcFiles.add(scanner.getBasedir() + "/" + fileNames[j]);
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];
int index = 0;
cmd[index++] = userdefine.getCmd();
Iterator iter = argsWithoutSpace.iterator();
while (iter.hasNext()) {
cmd[index++] = project.replaceProperties((String)iter.next());
cmd[index++] = project.replaceProperties((String) iter.next());
}
iter = endargsWithoutSpace.iterator();
while (iter.hasNext()) {
cmd[index++] = project.replaceProperties((String)iter.next());
cmd[index++] = project.replaceProperties((String) iter.next());
}
//
// Add outputFileFlag and output file to cmd
//
if (outputDelimiter != null && userdefine.getOutputFile() != null && outputDelimiter.length()> 0){
if (outputDelimiter.trim().equalsIgnoreCase("-cr")){
if (outputDelimiter != null && userdefine.getOutputFile() != null
&& outputDelimiter.length() > 0) {
if (outputDelimiter.trim().equalsIgnoreCase("-cr")) {
cmd[index++] = outputDelimiter;
cmd[index++] = userdefine.getOutputFile();
}else {
cmd[index++] = outputDelimiter + userdefine.getOutputFile();
} else {
cmd[index++] = outputDelimiter + userdefine.getOutputFile();
}
}
iter = includePath.iterator();
while (iter.hasNext()) {
cmd[index++] = (String)iter.next();
cmd[index++] = (String) iter.next();
}
if (libSet != null && libSet.length > 0){
if (libSet != null && libSet.length > 0) {
if (isGccCommand) {
cmd[index++] = "-(";
}
for (int k = 0; k < libSet.length ; k++){
for (int k = 0; k < libSet.length; k++) {
cmd[index++] = libSet[k];
}
if (isGccCommand) {
cmd[index++] = "-)";
}
}
for (int j = 0; j < fileNames.length; j++){
// execute the command
for (int j = 0; j < fileNames.length; j++) {
cmd[index++] = fileNames[j];
}
int retval = runCommand(cctask, workdir, cmd);
// if with monitor, add more code
if (retval != 0) {
throw new BuildException(userdefine.getCmd()
+ " failed with return code " + retval,
cctask.getLocation());
throw new BuildException(userdefine.getCmd()
+ " failed with return code " + retval, cctask
.getLocation());
}
}
protected int runCommand(CCTask task, File workingDir, String[] cmdline)
throws BuildException {
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;
/**
* Collect Arguments.
*
*/
public class UserDefineArgument extends CommandLineArgument {
public UserDefineArgument() {

View File

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

View File

@ -32,28 +32,36 @@ import net.sf.antcontrib.cpptasks.types.ConditionalPath;
import net.sf.antcontrib.cpptasks.types.IncludePath;
import net.sf.antcontrib.cpptasks.types.LibrarySet;
public class UserDefineDef extends ProcessorDef{
public UserDefineDef () {}
/**
* 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 UserDefineDef () {
}
private String type = "CC";
private String family = "MSFT";
private String cmd;
private String includepathDelimiter;
private String includePathDelimiter;
private String outputDelimiter;
private File workdir;
private Vector includePaths= new Vector();
private Vector includePaths = new Vector();
private String outputFile;
private Vector _libset = new Vector();
private Vector allLibraries = new Vector();
public void addLibset(LibrarySet libset) {
if (isReference()) {
throw noChildrenAllowed();
@ -61,31 +69,27 @@ public class UserDefineDef extends ProcessorDef{
if (libset == null) {
throw new NullPointerException("libset");
}
_libset.add(libset);
allLibraries.add(libset);
}
public void execute() throws org.apache.tools.ant.BuildException {
throw new org.apache.tools.ant.BuildException(
"Not an actual task, but looks like one for documentation purposes");
}
public void addConfiguredArgument(UserDefineArgument arg) {
if (isReference()) {
throw noChildrenAllowed();
}
addConfiguredProcessorArg(arg);
}
/**
* Creates an include path.
*/
public IncludePath createIncludePath() {
Project p = getProject();
if (p == null) {
throw new java.lang.IllegalStateException("project must be set");
}
if (isReference()) {
throw noChildrenAllowed();
}
@ -93,11 +97,14 @@ public class UserDefineDef extends ProcessorDef{
includePaths.addElement(path);
return path;
}
/**
* Add a <includepath> if specify the file attribute
*
* @param activePath
* Active Path Vector
* @param file
* File with multiple path
* @throws BuildException
* if the specify file not exist
*/
@ -112,7 +119,7 @@ public class UserDefineDef extends ProcessorDef{
fileReader = new FileReader(file);
in = new BufferedReader(fileReader);
while ((str = in.readLine()) != null) {
if (str.trim() == "") {
if (str.trim().endsWith("")) {
continue;
}
str = getProject().replaceProperties(str);
@ -122,9 +129,11 @@ public class UserDefineDef extends ProcessorDef{
throw new BuildException(e.getMessage());
}
}
/**
* Returns the specific include path.
*
* @return All active include paths
*/
public String[] getActiveIncludePaths() {
if (isReference()) {
@ -133,14 +142,12 @@ public class UserDefineDef extends ProcessorDef{
}
return getActivePaths(includePaths);
}
private String[] getActivePaths(Vector paths) {
Project p = getProject();
if (p == null) {
throw new java.lang.IllegalStateException("project not set");
}
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);
if (path.isActive(p)) {
if (path.getFile() == null) {
@ -157,22 +164,38 @@ public class UserDefineDef extends ProcessorDef{
activePaths.copyInto(pathNames);
return pathNames;
}
public String getIncludepathDelimiter() {
/**
* Get include path delimiter.
*
* @return Include Path Delimiter
*/
public String getIncludePathDelimiter() {
if (isReference()) {
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()) {
throw tooManyAttributes();
}
this.includepathDelimiter = includepathDelimiter;
this.includePathDelimiter = includePathDelimiter;
}
/**
* Get type.
*
* @return type
*/
public String getType() {
if (isReference()) {
return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
@ -181,6 +204,12 @@ public class UserDefineDef extends ProcessorDef{
return type;
}
/**
* Set type.
*
* @param type
* Type
*/
public void setType(String type) {
if (isReference()) {
throw tooManyAttributes();
@ -232,29 +261,28 @@ public class UserDefineDef extends ProcessorDef{
this.workdir = workdir;
}
public String[] get_libset() {
public String[] getLibset() {
Set libs = new LinkedHashSet();
Iterator iter = _libset.iterator();
Iterator iter = allLibraries.iterator();
while (iter.hasNext()) {
LibrarySet librarySet = (LibrarySet)iter.next();
LibrarySet librarySet = (LibrarySet) iter.next();
File basedir = librarySet.getDir(getProject());
String[] libStrArray = librarySet.getLibs();
for (int i = 0 ; i < libStrArray.length; i ++) {
for (int i = 0; i < libStrArray.length; i++) {
if (basedir != null) {
File libFile = new File(libStrArray[i]);
if (libFile.isAbsolute()) {
libs.add(libFile.getPath());
} else {
libs.add(basedir.getPath() + File.separatorChar
+ libFile.getPath());
}
else {
libs.add(basedir.getPath() + File.separatorChar + libFile.getPath());
}
}
else {
} else {
libs.add(libStrArray[i]);
}
}
}
return (String[])libs.toArray(new String[libs.size()]);
return (String[]) libs.toArray(new String[libs.size()]);
}
public String getOutputDelimiter() {

View File

@ -15,32 +15,47 @@
* limitations under the License.
*/
package net.sf.antcontrib.cpptasks.userdefine;
/**
* Relationship between {family, command type} and flags
*
*/
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",
"ASM", "ASMLINK", "PP" };
public 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" } };
public 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"} };
public String getIncludePathDelimiter(String vendor,
String commandType) {
/**
* Get include delimiter with vendow and command type.
*
* @param vendor
* Vendor
* @param commandType
* Command Type
* @return include path delimiter
*/
public static String getIncludePathDelimiter(String vendor,
String commandType) {
String key = vendor + "_" + commandType;
for (int i = 0; i < includePathFlag.length; i++) {
if (includePathFlag[i][0].equalsIgnoreCase(key)) {
@ -50,7 +65,16 @@ public class UserDefineMapping {
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;
for (int i = 0; i < outputFileFlag.length; i++) {
if (outputFileFlag[i][0].equalsIgnoreCase(key)) {