To fix EDKT284.

1.support multi thread
2.fix bug

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1636 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jjin9 2006-09-27 15:30:31 +00:00
parent ffacf6dc2f
commit 2c71f6e5ab
3 changed files with 226 additions and 41 deletions

View File

@ -24,10 +24,11 @@ public class HelpInfo {
* @return no return value
**/
public static void outputUsageInfo() {
System.out.printf("\n%s", DescripationString);
System.out.printf("\n%s", UsageInfoString);
System.out.printf("\n%s", DetailOfOptionString);
for (int i = 0; i < 6; i++) {
for (int i = 0; i < settingnum; i++) {
outputSubUsageInfo(UsageString[i], UsageStringInfo[i]);
}
@ -84,16 +85,20 @@ public class HelpInfo {
private static LinkedList<String> List = new LinkedList<String>();
private static final int MaxSrtingLength = 40;
private static final int settingnum = 7;
private static final String DescripationString = "The purpose of this tool is modifying the settings in target.txt";
private static final String UsageInfoString = "Usage: ContextTool [-option1] [args] [-option2] [args] ...";
private static final String DetailOfOptionString = "Where options include:";
private static final String ExampleString = "Example: ContextTool -a IA32 IA64 EBC -c Tools/Conf/tools_def.txt -t DEBUG";
private static final String ExampleString = "Example: ContextTool -a IA32 IA64 EBC -c Tools/Conf/tools_def.txt -t DEBUG -n GCC -p EdkNt32Pkg/Nt32.fpd -m 2\n";
private static final String HString = "-h";
private static final String HStringInfo = "print this help message";
private static final String HStringInfo = "print usage info";
private static final String AString = "-a <list of Arch>";
@ -101,7 +106,7 @@ public class HelpInfo {
private static final String CString = "-c <tool_definition_file.txt>";
private static final String CStringInfo = "Assign a txt file, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/. If no file is specified, the default filename is \"tools_def.txt\"";
private static final String CStringInfo = "Assign a txt file with the relative path to WORKSPACE, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/. If no file is specified, the default filename is \"tools_def.txt\"";
private static final String NString = "-n <list of TagNames>";
@ -115,9 +120,13 @@ public class HelpInfo {
private static final String TStringInfo = "What kind of the version is the binary target, such as DEBUG, RELEASE. Multiple values can be specified on a single line, using space to separate the values.";
private static final String MString = "-m <num of Threads>";
private static final String MStringInfo = "number should GE 0. 0 clears both MULTIPLE_THREAD and MAX_CONCURRENT_THREAD_NUMBER, others enable MULTIPLE_THREAD and set MAX_CONCURRENT_THREAD_NUMBER.";
private static final String[] UsageString = { HString, AString, CString,
NString, PString, TString };
NString, PString, TString, MString };
private static final String[] UsageStringInfo = { HStringInfo, AStringInfo,
CStringInfo, NStringInfo, PStringInfo, TStringInfo };
CStringInfo, NStringInfo, PStringInfo, TStringInfo, MStringInfo };
}

View File

@ -34,7 +34,7 @@ public class ParseParameter {
for(int i=0; i<args.length; i++){
if( (args[i].compareToIgnoreCase("-h") == 0) ||
(args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c')
&& (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't')))){
&& (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){
HelpInfo.outputUsageInfo();
return false;
}
@ -52,6 +52,9 @@ public class ParseParameter {
**/
private static void standardizeParameter(String[] args) {
//
// the parameters's length are same.
//
length = pstr.length();
StringBuffer InputData = new StringBuffer();
@ -83,17 +86,27 @@ public class ParseParameter {
} else if (argstr.charAt(1) == 'n') {
nstr += argstr.substring(2);
// nstr += "\n";
}
} else if (argstr.charAt(1) == 'm') {
mstr += argstr.substring(2);
// mstr += "\n";
if (argstr.charAt(3) == '0'){
mestr += " Disable";
} else {
mestr += " Enable";
}
}
i = j;
}
}
public static int length = 0;
public static String pstr = new String("ACTIVE_PLATFORM = ");
public static String tstr = new String("TARGET = ");
public static String astr = new String("TARGET_ARCH = ");
public static String cstr = new String("TOOL_CHAIN_CONF = ");
public static String nstr = new String("TOOL_CHAIN_TAG = ");
public static String pstr = new String("ACTIVE_PLATFORM = ");
public static String tstr = new String("TARGET = ");
public static String astr = new String("TARGET_ARCH = ");
public static String cstr = new String("TOOL_CHAIN_CONF = ");
public static String nstr = new String("TOOL_CHAIN_TAG = ");
public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER = ");
public static String mestr = new String("MULTIPLE_THREAD = ");
}

View File

@ -117,51 +117,177 @@ public class TargetFile {
//
try {
while ((textLine = br.readLine()) != null) {
//
// the line is composed of Space
//
if (textLine.trim().compareToIgnoreCase("") == 0) {
bw.write(textLine);
bw.newLine();
} else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){
}
//
// the line starts with "#", and no "="
//
else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){
bw.write(textLine);
bw.newLine();
} else {
//
//modify at the first time, and there should be *ACTIVE_PLATFORM*=* in the line
//
if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {
if(ParseParameter.pstr.length() > ParseParameter.length) {
bw.write(ParseParameter.pstr);
} else {
bw.write(textLine);
if(pflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.pstr.length() > ParseParameter.length) {
bw.write(ParseParameter.pstr);
bw.newLine();
pflag = false;
}
continue;
}
if(ParseParameter.pstr.length() > ParseParameter.length) {
bw.write(ParseParameter.pstr);
} else {
bw.write(textLine);
}
bw.newLine();
pflag = false;
}
bw.newLine();
} else if (textLine.indexOf("TARGET_ARCH") != -1) {
if(ParseParameter.astr.length() > ParseParameter.length) {
bw.write(ParseParameter.astr);
} else {
bw.write(textLine);
if(aflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.astr.length() > ParseParameter.length) {
bw.write(ParseParameter.astr);
bw.newLine();
aflag = false;
}
continue;
}
if(ParseParameter.astr.length() > ParseParameter.length) {
bw.write(ParseParameter.astr);
} else {
bw.write(textLine);
}
bw.newLine();
aflag = false;
}
bw.newLine();
} else if (textLine.indexOf("TARGET") != -1) {
if(ParseParameter.tstr.length() > ParseParameter.length) {
bw.write(ParseParameter.tstr);
} else {
bw.write(textLine);
if(tflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.tstr.length() > ParseParameter.length) {
bw.write(ParseParameter.tstr);
bw.newLine();
tflag = false;
}
continue;
}
if(ParseParameter.tstr.length() > ParseParameter.length) {
bw.write(ParseParameter.tstr);
} else {
bw.write(textLine);
}
bw.newLine();
tflag = false;
}
bw.newLine();
} else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {
if(ParseParameter.cstr.length() > ParseParameter.length) {
bw.write(ParseParameter.cstr);
} else {
bw.write(textLine);
if(cflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.cstr.length() > ParseParameter.length) {
bw.write(ParseParameter.cstr);
bw.newLine();
cflag = false;
}
continue;
}
if(ParseParameter.cstr.length() > ParseParameter.length) {
bw.write(ParseParameter.cstr);
} else {
bw.write(textLine);
}
bw.newLine();
cflag = false;
}
bw.newLine();
} else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {
if(ParseParameter.nstr.length() > ParseParameter.length) {
bw.write(ParseParameter.nstr);
} else {
bw.write(textLine);
if(nflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.nstr.length() > ParseParameter.length) {
bw.write(ParseParameter.nstr);
bw.newLine();
nflag = false;
}
continue;
}
if(ParseParameter.nstr.length() > ParseParameter.length) {
bw.write(ParseParameter.nstr);
} else {
bw.write(textLine);
}
bw.newLine();
nflag = false;
}
} else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {
if(mflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.mstr.length() > ParseParameter.length) {
bw.write(ParseParameter.mstr);
bw.newLine();
mflag = false;
}
continue;
}
if(ParseParameter.mstr.length() > ParseParameter.length) {
bw.write(ParseParameter.mstr);
} else {
bw.write(textLine);
}
bw.newLine();
mflag = false;
}
}else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {
if(meflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.mestr.length() > ParseParameter.length) {
bw.write(ParseParameter.mestr);
bw.newLine();
meflag = false;
}
continue;
}
if(ParseParameter.mestr.length() > ParseParameter.length) {
bw.write(ParseParameter.mestr);
} else {
bw.write(textLine);
}
bw.newLine();
meflag = false;
}
bw.newLine();
}
}
}
//
//user maybe delete the line *ACTIVE_PLATFORM*=*
//
if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.pstr);
bw.newLine();
} else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.tstr);
bw.newLine();
} else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){
bw.write(ParseParameter.astr);
bw.newLine();
} else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.cstr);
bw.newLine();
} else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.nstr);
bw.newLine();
} else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){
bw.write(ParseParameter.mestr);
bw.newLine();
} else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.mstr);
bw.newLine();
}
} catch (IOException e) {
System.out.println("\n# read or write file error!");
return false;
@ -208,18 +334,22 @@ public class TargetFile {
}
FileChannel outputChannel = outputFile.getChannel();
ByteBuffer[] buffers = new ByteBuffer[5];
ByteBuffer[] buffers = new ByteBuffer[7];
buffers[0] = ByteBuffer.allocate(ParseParameter.pstr.toString().length());
buffers[1] = ByteBuffer.allocate(ParseParameter.tstr.toString().length());
buffers[2] = ByteBuffer.allocate(ParseParameter.astr.toString().length());
buffers[3] = ByteBuffer.allocate(ParseParameter.cstr.toString().length());
buffers[4] = ByteBuffer.allocate(ParseParameter.nstr.toString().length());
buffers[5] = ByteBuffer.allocate(ParseParameter.mestr.toString().length());
buffers[6] = ByteBuffer.allocate(ParseParameter.mstr.toString().length());
buffers[0].put(ParseParameter.pstr.toString().getBytes()).flip();
buffers[1].put(ParseParameter.tstr.toString().getBytes()).flip();
buffers[2].put(ParseParameter.astr.toString().getBytes()).flip();
buffers[3].put(ParseParameter.cstr.toString().getBytes()).flip();
buffers[4].put(ParseParameter.nstr.toString().getBytes()).flip();
buffers[5].put(ParseParameter.mestr.toString().getBytes()).flip();
buffers[6].put(ParseParameter.mstr.toString().getBytes()).flip();
try {
ByteBuffer bufofCP = ByteBuffer.allocate(Copyright.length());
@ -255,6 +385,16 @@ public class TargetFile {
outputChannel.write(buffer4);
outputChannel.write(buffers[4]);
ByteBuffer buffer5 = ByteBuffer.allocate(meusage.length());
buffer4.put(meusage.getBytes()).flip();
outputChannel.write(buffer5);
outputChannel.write(buffers[5]);
ByteBuffer buffer6 = ByteBuffer.allocate(musage.length());
buffer4.put(musage.getBytes()).flip();
outputChannel.write(buffer6);
outputChannel.write(buffers[6]);
outputFile.close();
} catch (IOException e) {
System.out.println("\n# The operations of file failed !");
@ -272,6 +412,17 @@ public class TargetFile {
/// point to target.txt.
///
private static File Fd;
///
/// when the flag is true, the corresponding str should be add at the end of file.
///
private static boolean pflag = true;
private static boolean tflag = true;
private static boolean aflag = true;
private static boolean cflag = true;
private static boolean nflag = true;
private static boolean mflag = true;
private static boolean meflag = true;
private static final String Copyright = "#\n"
+ "# Copyright (c) 2006, Intel Corporation\n"
@ -331,4 +482,16 @@ public class TargetFile {
+ "# TAGNAME List Optional Specify the name(s) of the tools_def.txt TagName to use.\n"
+ "# If not specified, all applicable TagName tools will be \n"
+ "# used for the build. The list uses space character separation.\n";
private static final String musage = "\n\n"
+ "# MULTIPLE_THREAD FLAG Optional Flag to enable multi-thread build. If not specified, default\n"
+ "# is \"Disable\". If your computer is multi-core or multiple CPUs,\n"
+ "# enabling this feature will bring much benefit. For multi-thread\n"
+ "# built, the log will write to ${BUILD_DIR}/build.log.\n"
+ "# This feature is only for PLATFORM build, and clean, cleanall or\n"
+ "# stand-alone module build is still using the normal way.\n";
private static final String meusage = "\n\n"
+ "# MAX_CONCURRENT_THREAD_NUMBER NUMBER Optional The number of concurrent threads. Default is 2. Recommend to\n"
+ "# set this value to one more than the number of your compurter\n"
+ "# cores or CPUs.\n";
}