Added Support for OPTIONAL property: MULTIPLE_THREAD = enable tag (if not present...
authorlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Aug 2006 20:58:03 +0000 (20:58 +0000)
committerlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Aug 2006 20:58:03 +0000 (20:58 +0000)
Added Support for OPTIONAL property: MAX_CONCURRENT_THREAD_NUMBER = #  (if MULTIPLE_THREAD is not present, then this should be ignored! - wizard will remove this line if MULTIPLE_THREAD is not enabled.)

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1388 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/toolchain/Preferences.java

index 1082cc3..d7edcf9 100644 (file)
@@ -25,9 +25,10 @@ import java.awt.event.ActionEvent;
 import java.io.*;\r
 import java.util.Vector;\r
 import java.util.Iterator;\r
+import java.util.Scanner;\r
 \r
 import javax.swing.*;\r
-// import javax.swing.JScrollPane;\r
+import javax.swing.JScrollPane;\r
 import javax.swing.JTextField;\r
 import javax.swing.JFrame;\r
 \r
@@ -78,7 +79,9 @@ public class Preferences extends IFrame {
 \r
     private final int rowFive = rowFour + threeRowHeight + sepHeight;\r
 \r
-    private final int buttonRow = rowFive + oneRowHeight + sepHeight + sepHeight;\r
+    private final int rowSix = rowFive + oneRowHeight + sepHeight;\r
+\r
+    private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;\r
 \r
     private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;\r
 \r
@@ -97,6 +100,22 @@ public class Preferences extends IFrame {
 \r
     private JFrame frame;\r
 \r
+    private final int activePlatformId = 0;\r
+\r
+    private final int buildTargetId = 1;\r
+\r
+    private final int targetArchId = 2;\r
+\r
+    private final int toolDefFileId = 3;\r
+\r
+    private final int tagNameId = 4;\r
+\r
+    private final int threadEnableId = 5;\r
+\r
+    private final int threadCountId = 6;\r
+\r
+    private final int maxTargetLines = threadCountId + 1;\r
+\r
     private JPanel jContentPane = null;\r
 \r
     private JLabel jLabelToolsConfigFile = null;\r
@@ -105,14 +124,10 @@ public class Preferences extends IFrame {
 \r
     private final int toolConfigFileRow = rowOne;\r
 \r
-    private final int toolDefFileId = 3;\r
-\r
     private JLabel jLabelActivePlatform = null;\r
 \r
     private JComboBox jComboBoxActivePlatform = null;\r
 \r
-    private final int activePlatformId = 0;\r
-\r
     private final int activePlatformRow = rowTwo;\r
 \r
     private JLabel jLabelToolChainTagName = null;\r
@@ -123,8 +138,6 @@ public class Preferences extends IFrame {
 \r
     private final int toolChainTagNameRow = rowThree;\r
 \r
-    private final int tagNameId = 4;\r
-\r
     private JLabel jLabelBuildTarget = null;\r
 \r
     private JScrollPane jScrollPaneBuildTarget = null;\r
@@ -133,15 +146,25 @@ public class Preferences extends IFrame {
 \r
     private final int buildTargetRow = rowFour;\r
 \r
-    private final int buildTargetId = 1;\r
-\r
     private JLabel jLabelTargetArch = null;\r
 \r
     private ArchCheckBox jArchCheckBox = null;\r
 \r
     private final int targetArchRow = rowFive;\r
 \r
-    private final int targetArchId = 2;\r
+    private JLabel jLabelEnableThreads = null;\r
+\r
+    private JLabel jLabelThreadCount = null;\r
+\r
+    private final int threadRow = rowSix;\r
+\r
+    private JCheckBox jCheckBoxEnableThreads = null;\r
+\r
+    private JTextField jTextFieldThreadCount = null;\r
+    \r
+    private String threadCount;\r
+    \r
+    private boolean threadEnabled = false;\r
 \r
     private JButton jButtonBrowse = null;\r
 \r
@@ -174,9 +197,9 @@ public class Preferences extends IFrame {
 \r
     // private String[] toolsConfContents;\r
 \r
-    private String[] targetLines = new String[5];\r
+    private String[] targetLines = new String[maxTargetLines];\r
 \r
-    private int targetLineNumber[] = new int[5];\r
+    private int targetLineNumber[] = new int[maxTargetLines];\r
 \r
     private String toolsConfFile;\r
 \r
@@ -195,6 +218,8 @@ public class Preferences extends IFrame {
     private String toolsDefIdentifier = null;\r
 \r
     private int targetLineNumberMax;\r
+    \r
+    private final int toolDefFieldCount = 5;\r
 \r
     private Vector<String> vArchList = null;\r
 \r
@@ -359,6 +384,31 @@ public class Preferences extends IFrame {
         return jScrollPaneBuildTarget;\r
     }\r
 \r
+    private JCheckBox getCheckBoxEnableThreads() {\r
+        if (jCheckBoxEnableThreads == null) {\r
+            jCheckBoxEnableThreads = new JCheckBox();\r
+            jCheckBoxEnableThreads.setBounds(valueColumn, threadRow, 20, oneRowHeight);\r
+            jCheckBoxEnableThreads.setToolTipText("Select this if you want to enable parallel compilation.");\r
+            jCheckBoxEnableThreads.setSelected(threadEnabled);\r
+            jCheckBoxEnableThreads.addActionListener(this);\r
+            \r
+        }\r
+        return jCheckBoxEnableThreads;\r
+    }\r
+\r
+    private JTextField getTextFieldThreadCount() {\r
+        if (jTextFieldThreadCount == null) {\r
+            jTextFieldThreadCount = new JTextField();\r
+            jTextFieldThreadCount.setBounds(valueColumn + 215, threadRow, 30, oneRowHeight);\r
+            if (threadCount.length() > 0)\r
+                jTextFieldThreadCount.setText(threadCount);\r
+            jTextFieldThreadCount.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");\r
+            // If CheckBoxEnableThreads is selected, then enable editing\r
+\r
+        }\r
+        return jTextFieldThreadCount;\r
+    }\r
+\r
     private ICheckBoxList getICheckBoxListBuildTarget() {\r
         if (iCheckBoxListBuildTarget == null) {\r
 \r
@@ -498,7 +548,7 @@ public class Preferences extends IFrame {
      */\r
     private void init() {\r
 \r
-        for (int i = 0; i < 5; i++) {\r
+        for (int i = 0; i < maxTargetLines; i++) {\r
             targetLines[i] = null;\r
             targetLineNumber[i] = -1;\r
         }\r
@@ -578,8 +628,8 @@ public class Preferences extends IFrame {
         } else {\r
             toolsConfFile = defaultToolsConf;\r
         }\r
-        String[] toolsDefFields = new String[5];\r
-        for (int i = 0; i < 5; i++)\r
+        String[] toolsDefFields = new String[toolDefFieldCount];\r
+        for (int i = 0; i < toolDefFieldCount; i++)\r
             toolsDefFields[i] = null;\r
         File toolDefFile = new File(toolsConfFile);\r
         if (toolDefFile.exists()) {\r
@@ -695,6 +745,23 @@ public class Preferences extends IFrame {
                             targetLines[tagNameId] = rLine.trim();\r
                         targetLineNumber[tagNameId] = targetLineNumberMax;\r
                     }\r
+                    \r
+                    if (rLine.startsWith("MULTIPLE_THREAD")) {\r
+                        // Handle Thread Enable flag\r
+                        targetLines[threadEnableId] = rLine.trim();\r
+                        targetLineNumber[threadEnableId] = targetLineNumberMax;\r
+                        if ((rLine.trim().toLowerCase().contains("enabled")) || (rLine.trim().toLowerCase().contains("true"))) { \r
+                            threadEnabled = true;\r
+                        } else {\r
+                            threadEnabled = false;\r
+                        }\r
+                    }\r
+                    \r
+                    if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {\r
+                        // Handle Thread Enable flag\r
+                        targetLines[threadCountId] = rLine.trim();\r
+                        targetLineNumber[threadCountId] = targetLineNumberMax;\r
+                    }\r
                     targetLineNumberMax++;\r
                 }\r
                 reader.close();\r
@@ -709,11 +776,17 @@ public class Preferences extends IFrame {
                     }\r
                 }\r
 \r
+                if (targetLines[threadCountId] != null) {\r
+                    String tcLine[] = new String[2];\r
+                    tcLine = targetLines[threadCountId].trim().split("=");\r
+                    threadCount = tcLine[1];\r
+                } else\r
+                    threadCount = "";\r
+                \r
                 if (Debug == true)\r
-                    for (int i = 0; i <= tagNameId; i++)\r
+                    for (int i = 0; i <= maxTargetLines; i++)\r
                         System.out.println("targetLines[" + i + "] contains: " + targetLines[i] + " index is: "\r
                                            + targetLineNumber[i]);\r
-\r
             } catch (IOException e) {\r
                 Log.log(this.targetFile + " Read Error ", e.getMessage());\r
                 e.printStackTrace();\r
@@ -748,10 +821,19 @@ public class Preferences extends IFrame {
             jLabelTargetArch = new JLabel();\r
             jLabelTargetArch.setBounds(new java.awt.Rectangle(labelColumn, targetArchRow, labelWidth, oneRowHeight));\r
             jLabelTargetArch.setText("Build Architectures");\r
+\r
             jArchCheckBox = new ArchCheckBox();\r
             jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));\r
             jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));\r
 \r
+            jLabelEnableThreads = new JLabel();\r
+            jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));\r
+            jLabelEnableThreads.setText("Enable Compiler Threading");\r
+\r
+            jLabelThreadCount = new JLabel();\r
+            jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));\r
+            jLabelThreadCount.setText("Number of threads to start");\r
+\r
             jContentPane = new JPanel();\r
             jContentPane.setLayout(null);\r
             jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));\r
@@ -775,6 +857,12 @@ public class Preferences extends IFrame {
             jArchCheckBox.setSelectedItems(vArchList);\r
             jContentPane.add(jArchCheckBox, null);\r
 \r
+            jContentPane.add(jLabelEnableThreads, null);\r
+            jContentPane.add(getCheckBoxEnableThreads(), null);\r
+\r
+            jContentPane.add(jLabelThreadCount, null);\r
+            jContentPane.add(getTextFieldThreadCount(), null);\r
+\r
             jContentPane.add(getJButtonSave(), null);\r
             jContentPane.add(getJButtonCancel(), null);\r
         }\r
@@ -807,7 +895,15 @@ public class Preferences extends IFrame {
         if (arg0.getSource() == jButtonCancel) {\r
             this.exit();\r
         }\r
+        \r
+        if (arg0.getSource() == jCheckBoxEnableThreads) {\r
+            if (jCheckBoxEnableThreads.isSelected() == false) {\r
+                threadCount = "";\r
+                jTextFieldThreadCount.setText(threadCount);\r
+            }\r
+        }\r
     }\r
+    \r
 \r
     private void updateActivePlatform() {\r
         int lineAP;\r
@@ -841,10 +937,10 @@ public class Preferences extends IFrame {
         if (Debug)\r
             System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());\r
         if (jTextFieldToolsConfigFile.getText() == null) {\r
-            targetFileContents[lineTDF] = "";\r
+            targetFileContents[lineTDF] = "#MT#";\r
             targetLines[toolDefFileId] = "";\r
         } else {\r
-            targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText() + "\r\n";\r
+            targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();\r
             targetLines[toolDefFileId] = targetFileContents[lineTDF];\r
         }\r
     }\r
@@ -865,10 +961,10 @@ public class Preferences extends IFrame {
             System.out.println("Tag Name(s): " + sTagNames);\r
 \r
         if (sTagNames.length() > 0) {\r
-            targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames + "\r\n";\r
+            targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;\r
             targetLines[tagNameId] = targetFileContents[lineTTN];\r
         } else {\r
-            targetFileContents[lineTTN] = "";\r
+            targetFileContents[lineTTN] = "#MT#";\r
             targetLines[tagNameId] = "";\r
         }\r
     }\r
@@ -887,10 +983,10 @@ public class Preferences extends IFrame {
         if (Debug)\r
             System.out.println("Build Target(s): " + sBuildTargets);\r
         if (sBuildTargets.length() > 0) {\r
-            targetFileContents[lineBT] = "TARGET = " + sBuildTargets + "\r\n";\r
+            targetFileContents[lineBT] = "TARGET = " + sBuildTargets;\r
             targetLines[buildTargetId] = targetFileContents[lineBT];\r
         } else {\r
-            targetFileContents[lineBT] = "";\r
+            targetFileContents[lineBT] = "#MT#";\r
             targetLines[buildTargetId] = "";\r
         }\r
 \r
@@ -911,15 +1007,69 @@ public class Preferences extends IFrame {
             targetLineNumberMax++;\r
         }\r
         if (sArchList == "") {\r
-            targetFileContents[lineSA] = "";\r
+            targetFileContents[lineSA] = "#MT#";\r
             targetLines[targetArchId] = "";\r
         } else {\r
-            targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList + "\r\n";\r
+            targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;\r
             targetLines[targetArchId] = targetFileContents[lineSA];\r
         }\r
 \r
     }\r
 \r
+    private void updateEnableThreads() {\r
+        int lineET;\r
+        if (targetLines[threadEnableId] != null) {\r
+            lineET = targetLineNumber[threadEnableId];\r
+        } else {\r
+            lineET = targetLineNumberMax;\r
+            targetLineNumber[threadEnableId] = lineET;\r
+            targetLineNumberMax++;\r
+        }\r
+        if (jCheckBoxEnableThreads.isSelected() == true) {\r
+            targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";\r
+            targetLines[threadEnableId] = targetFileContents[lineET];\r
+        } else {\r
+            targetFileContents[lineET] = "#MT#";\r
+            targetLines[threadEnableId] = "";\r
+        }\r
+    }\r
+    \r
+    private void updateThreadCount() {\r
+        int lineTC;\r
+\r
+        if (targetLines[threadCountId] != null) {\r
+            lineTC = targetLineNumber[threadCountId];\r
+        } else {\r
+            lineTC = targetLineNumberMax;\r
+            targetLineNumber[threadCountId] = lineTC;\r
+            targetLineNumberMax++;\r
+        }\r
+        if (jCheckBoxEnableThreads.isSelected() == true) {\r
+            // Threading must be enabled\r
+            if (jTextFieldThreadCount.getText().length() > 0) {\r
+                // Thread Count must be greater than 0\r
+                Scanner scan = new Scanner(jTextFieldThreadCount.getText().trim()); \r
+                if (scan.nextInt() > 0) {      \r
+                    targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount.getText().trim();\r
+                    targetLines[threadCountId] = targetFileContents[lineTC];\r
+                } else {\r
+                    Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r
+                    targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
+                    targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
+                }\r
+            } else {\r
+                Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");\r
+                targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
+                targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";\r
+            }\r
+        } else {\r
+            // Don't track threads if threading is not enabled\r
+            targetFileContents[lineTC] = "#MT#";\r
+            targetLines[threadCountId] = "";\r
+            threadCount = "";\r
+        }\r
+        \r
+    }\r
     private String vectorToString(Vector<String> v) {\r
         String s = " ";\r
         for (int i = 0; i < v.size(); ++i) {\r
@@ -947,13 +1097,16 @@ public class Preferences extends IFrame {
         updateToolTagNames();\r
         updateBuildTargets();\r
         updateArchitectures();\r
+        updateEnableThreads();\r
+        updateThreadCount();\r
 \r
         try {\r
             copy(targetFile, targetFile + ".bak");\r
             FileWriter fileWriter = new FileWriter(targetFile);\r
             BufferedWriter writer = new BufferedWriter(fileWriter);\r
             for (int i = 0; i < targetLineNumberMax; i++) {\r
-                writer.write(targetFileContents[i] + "\r\n");\r
+                if (! targetFileContents[i].contains("#MT#"))\r
+                    writer.write(targetFileContents[i] + "\n");\r
             }\r
             writer.close();\r
         } catch (IOException e) {\r