add some features:

1. display current settings in target.txt by ContextTool
2. display help information with arguments, such as: ContextTool -h, arguments include -h, /h, -?, /?, -help, /help
3. display current setting by ContextTool -x
4. display possible setting by ContextTool -x ?
5. clean current setting by ContextTool -x 0
6. merge new setting to current setting by ContextTool -x new
x is the setting argument, such as p, a, n, m, t, c.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1746 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jjin9 2006-10-14 08:22:12 +00:00
parent 9c0e70cb4a
commit f337986f8e
4 changed files with 328 additions and 77 deletions

View File

@ -16,11 +16,28 @@ public class ContextMain {
public static void main(String[] args) {
if (TargetFile.validateFilename("target.txt") == false) {
System.out.printf("%n%s", "Target.txt can't be found in WorkSpace. Please check it!");
System.exit(0);
}
if(ParseParameter.checkParameter(args) == false){
System.exit(0);
}
if (TargetFile.parsePath("target.txt") == false) {
if (TargetFile.readFile() == false){
System.exit(0);
}
if (ParseParameter.standardizeParameter(args) > 0){
System.exit(0);
}
if (TargetFile.createTempFile("target.txt") == false){
System.exit(0);
}
if (TargetFile.readwriteFile() == false){
System.exit(0);
}

View File

@ -102,7 +102,7 @@ public class HelpInfo {
private static final String AString = "-a <list of Arch>";
private static final String AStringInfo = "what kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values.";
private static final String AStringInfo = "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values.";
private static final String CString = "-c <tool_definition_file.txt>";
@ -122,7 +122,7 @@ public class HelpInfo {
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 MStringInfo = "The number of concurrent threads. Default is 2. Recommend to set this value to one more than the number of your compurter cores or CPUs. 0 will disable MULTIPLE_THREAD and clean MAX_CONCURRENT_THREAD_NUMBER.";
private static final String[] UsageString = { HString, AString, CString,
NString, PString, TString, MString };

View File

@ -24,24 +24,31 @@ public class ParseParameter {
public static boolean checkParameter(String[] args) {
if(args.length == 0){
HelpInfo.outputUsageInfo();
TargetFile.readFile();
outputCurSetting();
return false;
} else {
if( args[0].charAt(0) != '-' ){
if( (args[0].compareToIgnoreCase("-h") == 0) || (args[0].compareToIgnoreCase("/h") == 0) ||
(args[0].compareToIgnoreCase("-?") == 0) || (args[0].compareToIgnoreCase("/?") == 0) ||
(args[0].compareToIgnoreCase("-help") == 0) || (args[0].compareToIgnoreCase("/help") == 0) ){
HelpInfo.outputUsageInfo();
return false;
}
if( args[0].charAt(0) != '-' ){
System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");
return false;
}
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) != 'm')))){
HelpInfo.outputUsageInfo();
if( (args[i].startsWith("-") &&
((args[i].compareTo("-a") != 0) && (args[i].compareTo("-c") != 0) &&
(args[i].compareTo("-n") != 0) && (args[i].compareTo("-p") != 0) &&
(args[i].compareTo("-t") != 0) && (args[i].compareTo("-m") != 0)))){
System.out.printf("%s\n", "Error arguments! Please type \"ContextTool -h\" for helpinfo.");
return false;
}
}
}
standardizeParameter(args);
return true;
}
@ -50,12 +57,8 @@ public class ParseParameter {
* @param args -- user's input
* @return no return value
**/
private static void standardizeParameter(String[] args) {
public static int standardizeParameter(String[] args) {
//
// the parameters's length are same.
//
length = pstr.length();
StringBuffer InputData = new StringBuffer();
for (int i = 0; i < args.length; i++) {
@ -70,34 +73,138 @@ public class ParseParameter {
j = InputData.length();
String argstr = InputData.substring(i, j);
i = j;
if (argstr.charAt(1) == 'p') {
pstr += argstr.substring(2);
// pstr += "\n";
//
// argstr is "-p ", display current setting
//
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curpstr);
return 1;
}
//
//argstr is "-p ?", display possible setting
//
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "assign the platform FPD file's relative path to WORKSPACE" );
return 2;
}
//
//argstr is "-p 0", clean current setting
//
if(argstr.length() < 6 && argstr.charAt(3) == '0'){
curpstr = pstr;
continue;
}
curpstr = mergeSetting(curpstr, argstr);
} else if (argstr.charAt(1) == 't') {
tstr += argstr.substring(2);
// tstr += "\n";
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curtstr);
return 1;
}
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "What kind of the version is the binary target, such as DEBUG, RELEASE" );
return 2;
}
if(argstr.length() < 6 && argstr.charAt(3) == '0'){
curtstr = tstr;
continue;
}
curtstr = mergeSetting(curtstr, argstr);
} else if (argstr.charAt(1) == 'a') {
astr += argstr.substring(2);
// astr += "\n";
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curastr);
return 1;
}
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "What kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM" );
return 2;
}
if(argstr.length() < 6 && argstr.charAt(3) == '0'){
curastr = astr;
continue;
}
curastr = mergeSetting(curastr, argstr);
} else if (argstr.charAt(1) == 'c') {
cstr += argstr.substring(2);
// cstr += "\n";
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curcstr);
return 1;
}
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "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/" );
return 2;
}
if(argstr.length() < 6 && argstr.charAt(3) == '0'){
curcstr = cstr;
continue;
}
curcstr = mergeSetting(curcstr, argstr);
} else if (argstr.charAt(1) == 'n') {
nstr += argstr.substring(2);
// nstr += "\n";
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curnstr);
return 1;
}
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "Specify the TagName, such as GCC, MSFT" );
return 2;
}
if(argstr.length() < 6 && argstr.charAt(3) == '0'){
curnstr = nstr;
continue;
}
curnstr = mergeSetting(curnstr, argstr);
} else if (argstr.charAt(1) == 'm') {
if(argstr.length() < 4 && argstr.charAt(2) == ' '){
System.out.printf("%s\n", curmstr);
return 1;
}
if(argstr.length() < 6 && argstr.charAt(3) == '?'){
System.out.printf( "%s\n", "The number of concurrent threads. Default is 2. Recommend to set this value to one more than the number of your compurter cores or CPUs." );
return 2;
}
mstr += argstr.substring(2);
// mstr += "\n";
curmstr = mstr;
if (argstr.charAt(3) == '0'){
mestr += " Disable";
} else {
mestr += " Enable";
}
}
i = j;
curmestr = mestr;
}
}
return 0;
}
public static String mergeSetting( String S1, String S2){
String[] S = S2.split(" ");
if(S1 == null){
S1 = tstr.concat(S2.substring(2));
}else{
for(int i = 1; i < S.length; i++){
if( S1.contains(S[i]) == false ){
S1 = S1.concat(S[i]).concat(" ");
}
}
}
return S1;
}
public static boolean outputCurSetting(){
System.out.printf( "%s\n", "The current setting is:" );
System.out.printf( "%s\n", curpstr );
System.out.printf( "%s\n", curtstr );
System.out.printf( "%s\n", curastr );
System.out.printf( "%s\n", curcstr );
System.out.printf( "%s\n", curnstr );
System.out.printf( "%s\n", curmstr );
System.out.printf( "%s\n", curmestr );
return true;
}
public static int length = 0;
@ -108,5 +215,21 @@ public class ParseParameter {
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 = ");
public static String curpstr = null;
public static String curtstr = null;
public static String curastr = null;
public static String curcstr = null;
public static String curnstr = null;
public static String curmstr = null;
public static String curmestr = null;
public static int plength = 0;
public static int tlength = 0;
public static int alength = 0;
public static int clength = 0;
public static int nlength = 0;
public static int mlength = 0;
public static int melength = 0;
}

View File

@ -30,7 +30,7 @@ public class TargetFile {
* @param String filename : the name of target file
* @return true or false
**/
public static boolean parsePath(String filename) {
public static boolean setFile(String filename) {
String workspacePath = System.getenv("WORKSPACE");
@ -55,17 +55,37 @@ public class TargetFile {
TargetFile.writeFile(Fd);
return true;
}
/**
* validate the filename
* @param String filename : the name of target file
*
* @return true or false
**/
public static boolean validateFilename(String filename) {
String workspacePath = System.getenv("WORKSPACE");
Fd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);
if (Fd.exists() == true && Fd.canRead() == true)
return true;
else
return false;
}
/**
* create a empty temp file, which is located at the same directory with target file
* @param String filename : the name of target temp file
* @return true or false
**/
private static boolean createTempFile(String filename) {
public static boolean createTempFile(String filename) {
String workspacePath = System.getenv("WORKSPACE");
TempFd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename);
TempFd = new File(workspacePath + File.separator + "Tools" + File.separator + "Conf" + File.separator + filename + "tmp");
if (TempFd.exists() == true) {
if (TempFd.delete() == false) {
@ -89,7 +109,7 @@ public class TargetFile {
* @param no paremeter
* @return true or false
**/
private static boolean readwriteFile() {
public static boolean readwriteFile() {
if (Fd.canRead() != true)
return false;
@ -137,15 +157,15 @@ public class TargetFile {
if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {
if(pflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.pstr.length() > ParseParameter.length) {
bw.write(ParseParameter.pstr);
if(ParseParameter.curpstr.length() >= ParseParameter.plength) {
bw.write(ParseParameter.curpstr);
bw.newLine();
pflag = false;
}
continue;
}
if(ParseParameter.pstr.length() > ParseParameter.length) {
bw.write(ParseParameter.pstr);
if(ParseParameter.curpstr.length() >= ParseParameter.plength) {
bw.write(ParseParameter.curpstr);
} else {
bw.write(textLine);
}
@ -155,15 +175,15 @@ public class TargetFile {
} else if (textLine.indexOf("TARGET_ARCH") != -1) {
if(aflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.astr.length() > ParseParameter.length) {
bw.write(ParseParameter.astr);
if(ParseParameter.curastr.length() >= ParseParameter.alength) {
bw.write(ParseParameter.curastr);
bw.newLine();
aflag = false;
}
continue;
}
if(ParseParameter.astr.length() > ParseParameter.length) {
bw.write(ParseParameter.astr);
if(ParseParameter.curastr.length() >= ParseParameter.alength) {
bw.write(ParseParameter.curastr);
} else {
bw.write(textLine);
}
@ -173,15 +193,15 @@ public class TargetFile {
} else if (textLine.indexOf("TARGET") != -1) {
if(tflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.tstr.length() > ParseParameter.length) {
bw.write(ParseParameter.tstr);
if(ParseParameter.curtstr.length() >= ParseParameter.tlength) {
bw.write(ParseParameter.curtstr);
bw.newLine();
tflag = false;
}
continue;
}
if(ParseParameter.tstr.length() > ParseParameter.length) {
bw.write(ParseParameter.tstr);
if(ParseParameter.curtstr.length() >= ParseParameter.tlength) {
bw.write(ParseParameter.curtstr);
} else {
bw.write(textLine);
}
@ -191,15 +211,15 @@ public class TargetFile {
} else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {
if(cflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.cstr.length() > ParseParameter.length) {
bw.write(ParseParameter.cstr);
if(ParseParameter.curcstr.length() >= ParseParameter.clength) {
bw.write(ParseParameter.curcstr);
bw.newLine();
cflag = false;
}
continue;
}
if(ParseParameter.cstr.length() > ParseParameter.length) {
bw.write(ParseParameter.cstr);
if(ParseParameter.curcstr.length() >= ParseParameter.clength) {
bw.write(ParseParameter.curcstr);
} else {
bw.write(textLine);
}
@ -209,15 +229,15 @@ public class TargetFile {
} else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {
if(nflag == true){
if(textLine.trim().charAt(0) == '#'){
if(ParseParameter.nstr.length() > ParseParameter.length) {
bw.write(ParseParameter.nstr);
if(ParseParameter.curnstr.length() >= ParseParameter.nlength) {
bw.write(ParseParameter.curnstr);
bw.newLine();
nflag = false;
}
continue;
}
if(ParseParameter.nstr.length() > ParseParameter.length) {
bw.write(ParseParameter.nstr);
if(ParseParameter.curnstr.length() >= ParseParameter.nlength) {
bw.write(ParseParameter.curnstr);
} else {
bw.write(textLine);
}
@ -227,15 +247,15 @@ public class TargetFile {
} 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);
if(ParseParameter.curmstr.length() >= ParseParameter.mlength) {
bw.write(ParseParameter.curmstr);
bw.newLine();
mflag = false;
}
continue;
}
if(ParseParameter.mstr.length() > ParseParameter.length) {
bw.write(ParseParameter.mstr);
if(ParseParameter.curmstr.length() >= ParseParameter.mlength) {
bw.write(ParseParameter.curmstr);
} else {
bw.write(textLine);
}
@ -245,15 +265,15 @@ public class TargetFile {
}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);
if(ParseParameter.curmestr.length() >= ParseParameter.melength) {
bw.write(ParseParameter.curmestr);
bw.newLine();
meflag = false;
}
continue;
}
if(ParseParameter.mestr.length() > ParseParameter.length) {
bw.write(ParseParameter.mestr);
if(ParseParameter.curmestr.length() >= ParseParameter.melength) {
bw.write(ParseParameter.curmestr);
} else {
bw.write(textLine);
}
@ -266,26 +286,26 @@ public class TargetFile {
//
//user maybe delete the line *ACTIVE_PLATFORM*=*
//
if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.pstr);
if( (pflag == true) && (ParseParameter.curpstr.length() >= ParseParameter.plength) ){
bw.write(ParseParameter.curpstr);
bw.newLine();
} else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.tstr);
} else if ( (tflag == true) && (ParseParameter.curtstr.length() >= ParseParameter.tlength) ){
bw.write(ParseParameter.curtstr);
bw.newLine();
} else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){
bw.write(ParseParameter.astr);
} else if ( (aflag == true) && (ParseParameter.curastr.length() >= ParseParameter.alength) ){
bw.write(ParseParameter.curastr);
bw.newLine();
} else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.cstr);
} else if ( (cflag == true) && (ParseParameter.curcstr.length() >= ParseParameter.clength) ){
bw.write(ParseParameter.curcstr);
bw.newLine();
} else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.nstr);
} else if ( (nflag == true) && (ParseParameter.curnstr.length() >= ParseParameter.nlength) ){
bw.write(ParseParameter.curnstr);
bw.newLine();
} else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){
bw.write(ParseParameter.mestr);
} else if ( (meflag == true) && (ParseParameter.curmestr.length() >= ParseParameter.melength) ){
bw.write(ParseParameter.curmestr);
bw.newLine();
} else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){
bw.write(ParseParameter.mstr);
} else if ( (mflag == true) && (ParseParameter.curmstr.length() >= ParseParameter.mlength) ){
bw.write(ParseParameter.curmstr);
bw.newLine();
}
} catch (IOException e) {
@ -313,6 +333,97 @@ public class TargetFile {
return true;
}
/**
* read the file and output the lines which include setting
* @param File fd : the File of the target file
* @return String: the current setting
**/
public static boolean readFile() {
BufferedReader br = null;
String textLine = null;
try {
br = new BufferedReader(new FileReader(Fd));
} catch (FileNotFoundException e) {
System.out
.println("\n# create the BufferedReader failed, because can't find the file:target.txt!");
return false;
}
try {
while ((textLine = br.readLine()) != null) {
//
// the line is composed of Space
//
if (textLine.trim().compareToIgnoreCase("") == 0) {
continue;
}
//
// the line starts with "#"
//
else if ((textLine.trim().charAt(0) == '#')){
continue;
} else {
if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {
ParseParameter.curpstr = textLine;
ParseParameter.plength = textLine.indexOf('=');
} else if (textLine.indexOf("TARGET_ARCH") != -1) {
ParseParameter.curastr = textLine;
ParseParameter.alength = textLine.indexOf('=');
} else if (textLine.indexOf("TARGET") != -1) {
ParseParameter.curtstr = textLine;
ParseParameter.tlength = textLine.indexOf('=');
} else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {
ParseParameter.curcstr = textLine;
ParseParameter.clength = textLine.indexOf('=');
} else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {
ParseParameter.curnstr = textLine;
ParseParameter.nlength = textLine.indexOf('=');
} else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {
ParseParameter.curmstr = textLine;
ParseParameter.mlength = textLine.indexOf('=');
} else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {
ParseParameter.curmestr = textLine;
ParseParameter.melength = textLine.indexOf('=');
}
}
}
} catch (IOException e) {
System.out.println("\n# read file error!");
return false;
}
try {
br.close();
} catch (IOException e) {
System.out
.println("\n# close BufferedReader error");
return false;
}
return true;
}
private static String convertStr(String str){
String convertStr = null;
if( str.compareTo("-p") == 0 ){
convertStr = "ACTIVE_PLATFORM";
}else if( str.compareTo("-a") == 0){
convertStr = "TARGET_ARCH";
}else if( str.compareTo("-t") == 0){
convertStr = "TARGET";
}else if( str.compareTo("-c") == 0){
convertStr = "TOOL_CHAIN_CONF";
}else if( str.compareTo("-n") == 0){
convertStr = "TOOL_CHAIN_TAG";
}else if( str.compareTo("-m") == 0){
convertStr = "MAX_CONCURRENT_THREAD_NUMBER";
}
return convertStr;
}
/**
* according to user's input args, write the file directly