To fix EDKT284.
authorjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Sep 2006 15:30:31 +0000 (15:30 +0000)
committerjjin9 <jjin9@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 27 Sep 2006 15:30:31 +0000 (15:30 +0000)
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

Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java
Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java
Tools/Source/ContextTool/org/tianocore/context/TargetFile.java

index 99af925..b65ee0a 100644 (file)
@@ -24,10 +24,11 @@ public class HelpInfo {
      * @return no return value\r
      **/\r
     public static void outputUsageInfo() {\r
+        System.out.printf("\n%s", DescripationString);\r
         System.out.printf("\n%s", UsageInfoString);\r
         System.out.printf("\n%s", DetailOfOptionString);\r
 \r
-        for (int i = 0; i < 6; i++) {\r
+        for (int i = 0; i < settingnum; i++) {\r
             outputSubUsageInfo(UsageString[i], UsageStringInfo[i]);\r
         }\r
         \r
@@ -84,16 +85,20 @@ public class HelpInfo {
     private static LinkedList<String> List = new LinkedList<String>();\r
 \r
     private static final int MaxSrtingLength = 40;\r
-\r
+    \r
+    private static final int settingnum = 7;\r
+    \r
+    private static final String DescripationString = "The purpose of this tool is modifying the settings in target.txt";\r
+    \r
     private static final String UsageInfoString = "Usage: ContextTool [-option1] [args] [-option2] [args] ...";\r
 \r
     private static final String DetailOfOptionString = "Where options include:";\r
     \r
-    private static final String ExampleString = "Example: ContextTool -a IA32 IA64 EBC -c Tools/Conf/tools_def.txt -t DEBUG";\r
+    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";\r
 \r
     private static final String HString = "-h";\r
 \r
-    private static final String HStringInfo = "print this help message";\r
+    private static final String HStringInfo = "print usage info";\r
 \r
     private static final String AString = "-a  <list of Arch>";\r
 \r
@@ -101,7 +106,7 @@ public class HelpInfo {
 \r
     private static final String CString = "-c  <tool_definition_file.txt>";\r
 \r
-    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\"";\r
+    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\"";\r
 \r
     private static final String NString = "-n  <list of TagNames>";\r
 \r
@@ -115,9 +120,13 @@ public class HelpInfo {
 \r
     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.";\r
 \r
+    private static final String MString = "-m  <num of Threads>";\r
+    \r
+    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.";\r
+    \r
     private static final String[] UsageString = { HString, AString, CString,\r
-            NString, PString, TString };\r
+            NString, PString, TString, MString };\r
 \r
     private static final String[] UsageStringInfo = { HStringInfo, AStringInfo,\r
-            CStringInfo, NStringInfo, PStringInfo, TStringInfo };\r
+            CStringInfo, NStringInfo, PStringInfo, TStringInfo, MStringInfo };\r
 }\r
index a0723b6..2285f21 100644 (file)
@@ -34,7 +34,7 @@ public class ParseParameter {
             for(int i=0; i<args.length; i++){\r
                 if( (args[i].compareToIgnoreCase("-h") == 0) || \r
                     (args[i].startsWith("-") && ((args[i].charAt(1) != 'a') && (args[i].charAt(1) != 'c') \r
-                    && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't')))){\r
+                    && (args[i].charAt(1) != 'n') && (args[i].charAt(1) != 'p') && (args[i].charAt(1) != 't') && (args[i].charAt(1) != 'm')))){\r
                     HelpInfo.outputUsageInfo();\r
                     return false;\r
                 }\r
@@ -52,6 +52,9 @@ public class ParseParameter {
      **/\r
     private static void standardizeParameter(String[] args) {\r
         \r
+        //\r
+        // the parameters's length are same.\r
+        //\r
         length  = pstr.length();\r
         \r
         StringBuffer InputData = new StringBuffer();\r
@@ -83,17 +86,27 @@ public class ParseParameter {
             } else if (argstr.charAt(1) == 'n') {\r
                 nstr += argstr.substring(2);\r
 //                nstr += "\n";\r
-            }\r
+            } else if (argstr.charAt(1) == 'm') {\r
+                mstr += argstr.substring(2);\r
+//              mstr += "\n";\r
+                if (argstr.charAt(3) == '0'){\r
+                    mestr += " Disable";\r
+                } else {\r
+                    mestr += " Enable";\r
+                }\r
+          }\r
             i = j;\r
         }\r
 \r
     }\r
      \r
     public static int length  = 0;\r
-    public static String pstr = new String("ACTIVE_PLATFORM       = ");\r
-    public static String tstr = new String("TARGET                = ");\r
-    public static String astr = new String("TARGET_ARCH           = ");\r
-    public static String cstr = new String("TOOL_CHAIN_CONF       = ");\r
-    public static String nstr = new String("TOOL_CHAIN_TAG        = ");\r
+    public static String pstr = new String("ACTIVE_PLATFORM                     = ");\r
+    public static String tstr = new String("TARGET                              = ");\r
+    public static String astr = new String("TARGET_ARCH                         = ");\r
+    public static String cstr = new String("TOOL_CHAIN_CONF                     = ");\r
+    public static String nstr = new String("TOOL_CHAIN_TAG                      = ");\r
+    public static String mstr = new String("MAX_CONCURRENT_THREAD_NUMBER        = ");\r
+    public static String mestr = new String("MULTIPLE_THREAD                     = ");\r
 \r
 }\r
index 2b10d7c..3143b8c 100644 (file)
@@ -117,51 +117,177 @@ public class TargetFile {
         //\r
         try {\r
             while ((textLine = br.readLine()) != null) {\r
+                //\r
+                // the line is composed of Space\r
+                //\r
                 if (textLine.trim().compareToIgnoreCase("") == 0) {\r
                     bw.write(textLine);\r
                     bw.newLine();\r
-                } else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){\r
+                } \r
+                //\r
+                // the line starts with "#", and no "="\r
+                //\r
+                else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){\r
                     bw.write(textLine);\r
                     bw.newLine();\r
                 } else {\r
+                    //\r
+                    //modify at the first time, and there should be *ACTIVE_PLATFORM*=* in the line\r
+                    //\r
                     if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {\r
-                        if(ParseParameter.pstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.pstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(pflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.pstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.pstr);\r
+                                    bw.newLine();\r
+                                    pflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.pstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.pstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            pflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TARGET_ARCH") != -1) {\r
-                        if(ParseParameter.astr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.astr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(aflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.astr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.astr);\r
+                                    bw.newLine();\r
+                                    aflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.astr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.astr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            aflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TARGET") != -1) {\r
-                        if(ParseParameter.tstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.tstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(tflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.tstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.tstr);\r
+                                    bw.newLine();\r
+                                    tflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.tstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.tstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            tflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {\r
-                        if(ParseParameter.cstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.cstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(cflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.cstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.cstr);\r
+                                    bw.newLine();\r
+                                    cflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.cstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.cstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            cflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {\r
-                        if(ParseParameter.nstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.nstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(nflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.nstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.nstr);\r
+                                    bw.newLine();\r
+                                    nflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.nstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.nstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            nflag = false;\r
+                        }\r
+                    } else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {\r
+                        if(mflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.mstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.mstr);\r
+                                    bw.newLine();\r
+                                    mflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.mstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.mstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            mflag = false;\r
+                        }\r
+                    }else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {\r
+                        if(meflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.mestr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.mestr);\r
+                                    bw.newLine();\r
+                                    meflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.mestr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.mestr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            meflag = false;\r
                         }\r
-                        bw.newLine();\r
                     }\r
                 }\r
             }\r
+            //\r
+            //user maybe delete the line *ACTIVE_PLATFORM*=*\r
+            //\r
+            if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.pstr);\r
+                bw.newLine();\r
+            } else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.tstr);\r
+                bw.newLine();\r
+            } else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.astr);\r
+                bw.newLine();\r
+            } else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.cstr);\r
+                bw.newLine();\r
+            } else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.nstr);\r
+                bw.newLine();\r
+            } else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.mestr);\r
+                bw.newLine();\r
+            } else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.mstr);\r
+                bw.newLine();\r
+            }\r
         } catch (IOException e) {\r
             System.out.println("\n#  read or write file error!");\r
             return false;\r
@@ -208,18 +334,22 @@ public class TargetFile {
         }\r
         FileChannel outputChannel = outputFile.getChannel();\r
 \r
-        ByteBuffer[] buffers = new ByteBuffer[5];\r
+        ByteBuffer[] buffers = new ByteBuffer[7];\r
         buffers[0] = ByteBuffer.allocate(ParseParameter.pstr.toString().length());\r
         buffers[1] = ByteBuffer.allocate(ParseParameter.tstr.toString().length());\r
         buffers[2] = ByteBuffer.allocate(ParseParameter.astr.toString().length());\r
         buffers[3] = ByteBuffer.allocate(ParseParameter.cstr.toString().length());\r
         buffers[4] = ByteBuffer.allocate(ParseParameter.nstr.toString().length());\r
+        buffers[5] = ByteBuffer.allocate(ParseParameter.mestr.toString().length());\r
+        buffers[6] = ByteBuffer.allocate(ParseParameter.mstr.toString().length());\r
 \r
         buffers[0].put(ParseParameter.pstr.toString().getBytes()).flip();\r
         buffers[1].put(ParseParameter.tstr.toString().getBytes()).flip();\r
         buffers[2].put(ParseParameter.astr.toString().getBytes()).flip();\r
         buffers[3].put(ParseParameter.cstr.toString().getBytes()).flip();\r
         buffers[4].put(ParseParameter.nstr.toString().getBytes()).flip();\r
+        buffers[5].put(ParseParameter.mestr.toString().getBytes()).flip();\r
+        buffers[6].put(ParseParameter.mstr.toString().getBytes()).flip();\r
 \r
         try {\r
             ByteBuffer bufofCP = ByteBuffer.allocate(Copyright.length());\r
@@ -255,6 +385,16 @@ public class TargetFile {
             outputChannel.write(buffer4);\r
             outputChannel.write(buffers[4]);\r
             \r
+            ByteBuffer buffer5 = ByteBuffer.allocate(meusage.length());\r
+            buffer4.put(meusage.getBytes()).flip();\r
+            outputChannel.write(buffer5);\r
+            outputChannel.write(buffers[5]);\r
+            \r
+            ByteBuffer buffer6 = ByteBuffer.allocate(musage.length());\r
+            buffer4.put(musage.getBytes()).flip();\r
+            outputChannel.write(buffer6);\r
+            outputChannel.write(buffers[6]);\r
+            \r
             outputFile.close();\r
         } catch (IOException e) {\r
             System.out.println("\n# The operations of file failed !");\r
@@ -272,6 +412,17 @@ public class TargetFile {
     /// point to target.txt.\r
     ///\r
     private static File Fd;\r
+    \r
+    ///\r
+    /// when the flag is true, the corresponding str should be add at the end of file.\r
+    ///\r
+    private static boolean pflag = true;\r
+    private static boolean tflag = true;\r
+    private static boolean aflag = true;\r
+    private static boolean cflag = true;\r
+    private static boolean nflag = true;\r
+    private static boolean mflag = true;\r
+    private static boolean meflag = true;\r
 \r
     private static final String Copyright = "#\n"\r
             + "#  Copyright (c) 2006, Intel Corporation\n"\r
@@ -331,4 +482,16 @@ public class TargetFile {
             + "#  TAGNAME               List      Optional   Specify the name(s) of the tools_def.txt TagName to use.\n"\r
             + "#                                             If not specified, all applicable TagName tools will be \n"\r
             + "#                                             used for the build.  The list uses space character separation.\n";\r
+    \r
+    private static final String musage = "\n\n"\r
+            + "#  MULTIPLE_THREAD       FLAG      Optional   Flag to enable multi-thread build. If not specified, default\n"\r
+            + "#                                             is \"Disable\". If your computer is multi-core or multiple CPUs,\n" \r
+            + "#                                             enabling this feature will bring much benefit. For multi-thread\n" \r
+            + "#                                             built, the log will write to ${BUILD_DIR}/build.log.\n" \r
+            + "#                                             This feature is only for PLATFORM build, and clean, cleanall or\n"\r
+            + "#                                             stand-alone module build is still using the normal way.\n";\r
+    private static final String meusage = "\n\n"\r
+            + "# MAX_CONCURRENT_THREAD_NUMBER  NUMBER  Optional  The number of concurrent threads. Default is 2. Recommend to\n" \r
+            + "#                                                 set this value to one more than the number of your compurter\n"\r
+            + "#                                                 cores or CPUs.\n";\r
 }\r