]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/toolchain/Preferences.java
Added the ToolChainId class which will read the target.txt and tool definition files...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / toolchain / Preferences.java
1 /** @file
2 <<The file is used to update the Build Preferences file, target.txt>>
3
4 <<The program will use target.txt, the tools config file specified in that file,
5 or it will use the default tools_def.txt file, and it will also scan the
6 FrameworkDatabase.db file for certain parameters. >>
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 Package Name: Tools
18 Module Name: FrameworkWizard
19
20 **/
21
22 package org.tianocore.frameworkwizard.toolchain;
23
24 import java.awt.event.ActionEvent;
25 import java.io.*;
26 import java.util.Vector;
27 import java.util.Iterator;
28 import java.util.Scanner;
29
30 import javax.swing.*;
31 import javax.swing.JScrollPane;
32 import javax.swing.JTextField;
33 import javax.swing.JFrame;
34
35 import org.tianocore.frameworkwizard.common.GlobalData;
36 import org.tianocore.frameworkwizard.common.Tools;
37 import org.tianocore.frameworkwizard.common.Log;
38 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
39 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.*;
40 import org.tianocore.frameworkwizard.common.ui.IFrame;
41 import org.tianocore.frameworkwizard.workspace.Workspace;
42 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
43 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
44 import org.tianocore.PlatformSurfaceAreaDocument;
45 import org.tianocore.frameworkwizard.toolchain.ToolChainId;
46
47 /**
48 * The class is used to update the target.txt file.
49 *
50 * It extends IDialog
51 *
52 */
53 public class Preferences extends IFrame {
54
55 // /
56 // / Define class Serial Version UID
57 // /
58 private static final long serialVersionUID = -4777906991966638888L;
59
60 private final boolean Debug = false;
61
62 //
63 // Define class members
64 //
65 private final int oneRowHeight = 20;
66
67 private final int twoRowHeight = 40;
68
69 private final int threeRowHeight = 60;
70
71 private final int sepHeight = 6;
72
73 private final int rowOne = 12;
74
75 private final int rowTwo = rowOne + oneRowHeight + sepHeight;
76
77 private final int rowThree = rowTwo + oneRowHeight + sepHeight;
78
79 private final int rowFour = rowThree + threeRowHeight + sepHeight;
80
81 private final int rowFive = rowFour + threeRowHeight + sepHeight;
82
83 private final int rowSix = rowFive + oneRowHeight + sepHeight;
84
85 private final int buttonRow = rowSix + oneRowHeight + sepHeight + sepHeight;
86
87 private final int dialogHeight = buttonRow + twoRowHeight + twoRowHeight;
88
89 private final int dialogWidth = 540;
90
91 private final int lastButtonXLoc = 430;
92
93 private final int next2LastButtonLoc = 329;
94
95 /*
96 * Define the contents for this dialog box
97 */
98 private static Preferences bTarget = null;
99
100 private WorkspaceTools wt = new WorkspaceTools();
101
102 private JFrame frame;
103
104 private final int activePlatformId = 0;
105
106 private final int buildTargetId = 1;
107
108 private final int targetArchId = 2;
109
110 private final int toolDefFileId = 3;
111
112 private final int tagNameId = 4;
113
114 private final int threadEnableId = 5;
115
116 private final int threadCountId = 6;
117
118 private final int maxTargetLines = threadCountId + 1;
119
120 private JPanel jContentPane = null;
121
122 private JLabel jLabelToolsConfigFile = null;
123
124 private JTextField jTextFieldToolsConfigFile = null;
125
126 private final int toolConfigFileRow = rowOne;
127
128 private JLabel jLabelActivePlatform = null;
129
130 private JComboBox jComboBoxActivePlatform = null;
131
132 private final int activePlatformRow = rowTwo;
133
134 private JLabel jLabelToolChainTagName = null;
135
136 private JScrollPane jScrollPaneTagName = null;
137
138 private ICheckBoxList iCheckBoxListTagName = null;
139
140 private final int toolChainTagNameRow = rowThree;
141
142 private JLabel jLabelBuildTarget = null;
143
144 private JScrollPane jScrollPaneBuildTarget = null;
145
146 private ICheckBoxList iCheckBoxListBuildTarget = null;
147
148 private final int buildTargetRow = rowFour;
149
150 private JLabel jLabelTargetArch = null;
151
152 private ArchCheckBox jArchCheckBox = null;
153
154 private final int targetArchRow = rowFive;
155
156 private JLabel jLabelEnableThreads = null;
157
158 private JLabel jLabelThreadCount = null;
159
160 private final int threadRow = rowSix;
161
162 private JCheckBox jCheckBoxEnableThreads = null;
163
164 private JTextField jTextFieldThreadCount = null;
165
166 private String threadCount;
167
168 private boolean threadEnabled = false;
169
170 private JButton jButtonBrowse = null;
171
172 private JButton jButtonSave = null;
173
174 private JButton jButtonCancel = null;
175
176 private final int labelColumn = 12;
177
178 private final int labelWidth = 155;
179
180 private final int valueColumn = 168;
181
182 private final int valueWidth = 352;
183
184 private final int valueWidthShort = 260;
185
186 private final int buttonWidth = 90;
187
188 private String workspaceDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator");
189
190 private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"
191 + System.getProperty("file.separator") + "Conf";
192
193 private String defaultToolsConf = toolsDir + System.getProperty("file.separator") + "tools_def.txt";
194
195 private String targetFile = toolsDir + System.getProperty("file.separator") + "target.txt";
196
197 private String[] targetFileContents = new String[500];
198
199 // private String[] toolsConfContents;
200
201 private String[] targetLines = new String[maxTargetLines];
202
203 private int targetLineNumber[] = new int[maxTargetLines];
204
205 private String toolsConfFile;
206
207 private String toolsDefTargetNames = null;
208
209 private final int toolsDefTargetNameField = 0;
210
211 private String toolsDefTagNames = null;
212
213 private final int toolsDefTagNameField = 1;
214
215 private String toolsDefArchNames = null;
216
217 private final int toolsDefArchNameField = 2;
218
219 private String toolsDefIdentifier = null;
220
221 private int targetLineNumberMax;
222
223 private final int toolDefFieldCount = 5;
224
225 private Vector<String> vArchList = null;
226
227 private Vector<String> vDisableArchList = null;
228
229 //
230 // Not used by UI
231 //
232 // private Preferences id = null;
233
234 // private EnumerationData ed = new EnumerationData();
235
236 /**
237 This method initializes jTextFieldToolsConfigFile
238
239 @return javax.swing.JTextField jTextFieldToolsConfigFile
240 **/
241 private JTextField getJTextFieldToolsConfigFile() {
242 if (jTextFieldToolsConfigFile == null) {
243 if (targetLines[toolDefFileId] != null) {
244 String sLine[] = targetLines[toolDefFileId].trim().split("=");
245 jTextFieldToolsConfigFile = new JTextField(sLine[1].trim());
246 } else
247 jTextFieldToolsConfigFile = new JTextField();
248
249 jTextFieldToolsConfigFile.setBounds(new java.awt.Rectangle(valueColumn, toolConfigFileRow, valueWidthShort,
250 oneRowHeight));
251 jTextFieldToolsConfigFile.setPreferredSize(new java.awt.Dimension(valueWidthShort, oneRowHeight));
252 jTextFieldToolsConfigFile
253 .setToolTipText("<html>"
254 + "Specify the name of the filename to use for specifying"
255 + "<br>the tools to use for the build. If not specified,"
256 + "<br>tools_def.txt will be used for the build. This file"
257 + "<br>MUST be located in the WORKSPACE/Tools/Conf directory.</html>");
258
259 }
260 return jTextFieldToolsConfigFile;
261 }
262
263 /**
264 * This method initializes jComboBoxActivePlatform
265 *
266 * @return javax.swing.JComboBox jComboBoxActivePlatform
267 *
268 */
269 private JComboBox getActivePlatform() {
270 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
271
272 if (jComboBoxActivePlatform == null) {
273 jComboBoxActivePlatform = new JComboBox();
274 jComboBoxActivePlatform.setBounds(new java.awt.Rectangle(valueColumn, activePlatformRow, valueWidth,
275 oneRowHeight));
276 jComboBoxActivePlatform.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
277 jComboBoxActivePlatform
278 .setToolTipText("<html>Select &quot;Do Not Set&quot; if you want to build a platform"
279 + "<br>from the directory where the FPD file exists,"
280 + "<br>otherwise scroll down to select the platform.</html>");
281
282 /*
283 * Generate the data, selecting what is in target.txt
284 */
285 jComboBoxActivePlatform.addItem("Do Not Set");
286 Iterator<PlatformIdentification> iter = vPlatformId.iterator();
287 while (iter.hasNext()) {
288 PlatformIdentification item = iter.next();
289 String path = item.getPath().trim();
290 String str = path.substring(workspaceDir.length(), path.length());
291 str.replace(System.getProperty("file.separator"), "/");
292 jComboBoxActivePlatform.addItem(str.trim());
293 }
294 if (targetLines[activePlatformId] == null)
295 jComboBoxActivePlatform.setSelectedItem("Do Not Set");
296 else
297 jComboBoxActivePlatform.setSelectedItem(targetLines[activePlatformId]);
298 }
299 return jComboBoxActivePlatform;
300 }
301
302 /**
303 * This method initializes jScrollPaneTagName
304 *
305 * @return javax.swing.JScrollPane jScrollPaneTagName
306 *
307 */
308 private JScrollPane getJScrollPaneTagName() {
309
310 if (jScrollPaneTagName == null) {
311 jScrollPaneTagName = new JScrollPane();
312 jScrollPaneTagName.setBounds(new java.awt.Rectangle(valueColumn, toolChainTagNameRow, valueWidth,
313 threeRowHeight));
314 jScrollPaneTagName.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));
315 jScrollPaneTagName.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
316 jScrollPaneTagName.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
317 jScrollPaneTagName.setViewportView(getICheckBoxListTagName());
318 jScrollPaneTagName.setToolTipText("<html>"
319 + "Specify the TagName(s) from the tool configuration file to use"
320 + "<br>for your builds. If not specified, all applicable TagName"
321 + " <br>tools will be used for the build.</html>");
322 jScrollPaneTagName.setVisible(true);
323
324 }
325 return jScrollPaneTagName;
326 }
327
328 private ICheckBoxList getICheckBoxListTagName() {
329 if (iCheckBoxListTagName == null) {
330 iCheckBoxListTagName = new ICheckBoxList();
331
332 if (toolsDefTagNames != null) {
333 toolsDefTagNames.trim();
334 String aTagNames[] = toolsDefTagNames.trim().split(" ");
335 Vector<String> vTags = new Vector<String>();
336 for (int i = 0; i < aTagNames.length; i++) {
337 vTags.add(aTagNames[i]);
338 }
339 iCheckBoxListTagName.setAllItems(vTags);
340 } else {
341 Vector<String> defaultTags = stringToVector("MYTOOLS");
342 iCheckBoxListTagName.setAllItems(defaultTags);
343 }
344
345 iCheckBoxListTagName.setAllItemsUnchecked();
346 iCheckBoxListTagName.setToolTipText("<html>"
347 + "Specify the TagName(s) from the tool configuration file to use"
348 + "<br>for your builds. If not specified, all applicable TagName"
349 + " <br>tools will be used for the build.</html>");
350 Vector<String> vSelectedTags = new Vector<String>();
351 if (targetLines[tagNameId] != null) {
352 targetLines[tagNameId].trim();
353 String targetTags[] = targetLines[tagNameId].trim().split(" ");
354 for (int j = 0; j < targetTags.length; j++)
355 vSelectedTags.add(targetTags[j]);
356 iCheckBoxListTagName.initCheckedItem(true, vSelectedTags);
357 }
358 }
359 return iCheckBoxListTagName;
360 }
361
362 /**
363 * This method initializes jScrollPaneBuildTarget
364 *
365 * @return javax.swing.JComboBox jScrollPaneBuildTarget
366 *
367 */
368 private JScrollPane getJScrollPaneBuildTarget() {
369 if (jScrollPaneBuildTarget == null) {
370 jScrollPaneBuildTarget = new JScrollPane();
371 jScrollPaneBuildTarget.setBounds(new java.awt.Rectangle(valueColumn, buildTargetRow, valueWidth,
372 threeRowHeight));
373 jScrollPaneBuildTarget.setPreferredSize(new java.awt.Dimension(valueWidth, threeRowHeight));
374 jScrollPaneBuildTarget.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
375 jScrollPaneBuildTarget.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
376 jScrollPaneBuildTarget.setViewportView(getICheckBoxListBuildTarget());
377 jScrollPaneBuildTarget.setVisible(true);
378 jScrollPaneBuildTarget.setToolTipText("<html>"
379 + "Select the TARGET Names that you want to build, such as<BR>"
380 + "BUILD or BUILD and RELEASE"
381 + "<br>If you do not set any of these, all available targets"
382 + "<br>will be built.</html>");
383
384 }
385 return jScrollPaneBuildTarget;
386 }
387
388 private JCheckBox getCheckBoxEnableThreads() {
389 if (jCheckBoxEnableThreads == null) {
390 jCheckBoxEnableThreads = new JCheckBox();
391 jCheckBoxEnableThreads.setBounds(valueColumn, threadRow, 20, oneRowHeight);
392 jCheckBoxEnableThreads.setToolTipText("Select this if you want to enable parallel compilation.");
393 jCheckBoxEnableThreads.setSelected(threadEnabled);
394 jCheckBoxEnableThreads.addActionListener(this);
395
396 }
397 return jCheckBoxEnableThreads;
398 }
399
400 private JTextField getTextFieldThreadCount() {
401 if (jTextFieldThreadCount == null) {
402 jTextFieldThreadCount = new JTextField();
403 jTextFieldThreadCount.setBounds(valueColumn + 215, threadRow, 30, oneRowHeight);
404 if (threadCount.length() > 0)
405 jTextFieldThreadCount.setText(threadCount);
406 jTextFieldThreadCount.setToolTipText("<html>Recommended setting is N+1,<br> where N is the number of physical processors or cores in the system</html>");
407 // If CheckBoxEnableThreads is selected, then enable editing
408
409 }
410 return jTextFieldThreadCount;
411 }
412
413 private ICheckBoxList getICheckBoxListBuildTarget() {
414 if (iCheckBoxListBuildTarget == null) {
415
416 String aBuildTargets[] = toolsDefTargetNames.trim().split(" ");
417 Vector<String> vBuildTargets = new Vector<String>();
418 for (int i = 0; i < aBuildTargets.length; i++) {
419 vBuildTargets.add(aBuildTargets[i]);
420 }
421 iCheckBoxListBuildTarget = new ICheckBoxList();
422 iCheckBoxListBuildTarget.setAllItems(vBuildTargets);
423 iCheckBoxListBuildTarget.setAllItemsUnchecked();
424 iCheckBoxListBuildTarget.setToolTipText("<html>"
425 + "Select the TARGET Names that you want to build, such as<BR>"
426 + "BUILD or BUILD and RELEASE"
427 + "<br>If you do not set any of these, all available targets"
428 + "<br>will be built.</html>");
429
430 Vector<String> vSelectedTags = new Vector<String>();
431 if (targetLines[buildTargetId] != null) {
432 targetLines[buildTargetId].trim();
433 String targetTags[] = targetLines[buildTargetId].trim().split(" ");
434 for (int j = 0; j < targetTags.length; j++)
435 vSelectedTags.add(targetTags[j]);
436 iCheckBoxListBuildTarget.initCheckedItem(true, vSelectedTags);
437 }
438 }
439 return iCheckBoxListBuildTarget;
440 }
441
442 /**
443 This method initializes jButtonBrowse
444
445 @return javax.swing.JButton
446 **/
447 private JButton getJButtonBrowse() {
448 if (jButtonBrowse == null) {
449 jButtonBrowse = new JButton();
450 jButtonBrowse
451 .setBounds(new java.awt.Rectangle(lastButtonXLoc, toolConfigFileRow, buttonWidth, oneRowHeight));
452 jButtonBrowse.setText("Browse");
453 jButtonBrowse.setPreferredSize(new java.awt.Dimension(buttonWidth, oneRowHeight));
454 jButtonBrowse.addActionListener(new AbstractAction() {
455 /**
456 *
457 */
458 private static final long serialVersionUID = 1L;
459
460 public void actionPerformed(ActionEvent e) {
461 //
462 // Select files from current workspace
463 //
464 String dirPrefix = toolsDir + System.getProperty("file.separator");
465 JFileChooser chooser = new JFileChooser(dirPrefix);
466 File theFile = null;
467 // String headerDest = null;
468
469 chooser.setMultiSelectionEnabled(false);
470 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
471 int retval = chooser.showOpenDialog(frame);
472 if (retval == JFileChooser.APPROVE_OPTION) {
473
474 theFile = chooser.getSelectedFile();
475 String file = theFile.getPath();
476 if (!file.startsWith(dirPrefix)) {
477 JOptionPane.showMessageDialog(frame, "You can only select files in the Tools"
478 + System.getProperty("file.separator")
479 + "Conf directory!");
480
481 return;
482 }
483
484 jTextFieldToolsConfigFile.setText("Tools/Conf/" + theFile.getName());
485 } else {
486 return;
487 }
488 }
489 });
490 }
491 return jButtonBrowse;
492 }
493
494 /**
495 * This method initializes jButtonOk
496 *
497 * @return javax.swing.JButton
498 *
499 */
500 private JButton getJButtonSave() {
501 if (jButtonSave == null) {
502 jButtonSave = new JButton();
503 jButtonSave.setBounds(new java.awt.Rectangle(next2LastButtonLoc, buttonRow, buttonWidth, oneRowHeight));
504 jButtonSave.setText("Save");
505 jButtonSave.addActionListener(this);
506 }
507 return jButtonSave;
508 }
509
510 /**
511 * This method initializes jButtonCancel
512 *
513 * @return javax.swing.JButton
514 *
515 */
516 private JButton getJButtonCancel() {
517 if (jButtonCancel == null) {
518 jButtonCancel = new JButton();
519 jButtonCancel.setBounds(new java.awt.Rectangle(lastButtonXLoc, buttonRow, buttonWidth, oneRowHeight));
520 jButtonCancel.setText("Cancel");
521 jButtonCancel.addActionListener(this);
522 }
523 return jButtonCancel;
524 }
525
526 public static void main(String[] args) {
527 // TODO Auto-generated method stub
528
529 }
530
531 public static Preferences getInstance() {
532 if (bTarget == null) {
533 bTarget = new Preferences();
534 }
535 return bTarget;
536 }
537
538 /**
539 * This is the default constructor
540 */
541 public Preferences() {
542 super();
543 init();
544 }
545
546 /**
547 * This method initializes this
548 *
549 */
550 private void init() {
551
552 for (int i = 0; i < maxTargetLines; i++) {
553 targetLines[i] = null;
554 targetLineNumber[i] = -1;
555 }
556 initReadFiles();
557 this.setSize(dialogWidth, dialogHeight);
558 this.setContentPane(getJContentPane());
559 this.setTitle("Build Preferences [" + toolsDefIdentifier + "]");
560 this.setDefaultCloseOperation(IFrame.EXIT_ON_CLOSE);
561 this.centerWindow();
562 this.setVisible(true);
563 }
564
565 /**
566 * This method initializes this Fill values to all fields if these values are
567 * not empty
568 *
569 * @param initReadFiles
570 *
571 */
572 private void initReadFiles() {
573 /*
574 * TODO
575 * Read Current target.txt file first
576 * Read TOOL_CHAIN_CONF file if specified, otherwise use tools_def.txt
577 */
578 readTargetTxtFile();
579 boolean haveBuildTargets = readToolDefinitionFile();
580 if (!haveBuildTargets) {
581 // Lookup Build Targets from the platforms
582 readPlatformFileBuildTargets();
583 }
584 }
585
586 private void readPlatformFileBuildTargets() {
587 Vector<PlatformIdentification> vPlatformId = wt.getAllPlatforms();
588 String sBuildTargets = "";
589
590 // foreach platform, build a list of BuildTargets
591 Iterator<PlatformIdentification> iter = vPlatformId.iterator();
592 while (iter.hasNext()) {
593 PlatformIdentification item = iter.next();
594 PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd = GlobalData.openingPlatformList
595 .getOpeningPlatformById(
596 item)
597 .getXmlFpd();
598 sBuildTargets += fpd.getPlatformDefinitions().getBuildTargets().toString() + " ";
599 }
600 String allTargets[] = sBuildTargets.trim().split(" ");
601 for (int i = 0; i < allTargets.length; i++) {
602 if (!toolsDefTargetNames.contains(allTargets[i])) {
603 toolsDefTargetNames += allTargets[i] + " ";
604 }
605 }
606 }
607
608 private boolean readToolDefinitionFile() {
609
610 // Parse the tool definition file looking for targets and architectures
611 toolsConfFile = null;
612 boolean buildTargetsExist = true;
613
614 if (targetLines[toolDefFileId] != null) {
615 String[] result = new String[2];
616 targetLines[toolDefFileId].trim();
617 result = (targetLines[toolDefFileId]).split("=");
618 String resString = (Tools.convertPathToCurrentOsType(result[1])).trim();
619 toolsConfFile = workspaceDir.trim() + resString.trim();
620 File toolsDefFile = new File(toolsConfFile);
621 if (!toolsDefFile.exists()) {
622 JOptionPane.showMessageDialog(this, "<html>" + "Tool Definition file, " + toolsConfFile
623 + "<br>specified in the target.txt file does not exist!"
624 + "<br>Using the default Tool Definition File:<br>"
625 + defaultToolsConf);
626 toolsConfFile = defaultToolsConf;
627 }
628 } else {
629 toolsConfFile = defaultToolsConf;
630 }
631 String[] toolsDefFields = new String[toolDefFieldCount];
632 for (int i = 0; i < toolDefFieldCount; i++)
633 toolsDefFields[i] = null;
634 File toolDefFile = new File(toolsConfFile);
635 if (toolDefFile.exists()) {
636 try {
637 FileReader fileReader = new FileReader(toolDefFile);
638 BufferedReader reader = new BufferedReader(fileReader);
639 String rLine = null;
640 String result[];
641 int lineCounter = 0;
642 while ((rLine = reader.readLine()) != null) {
643
644 if (rLine.startsWith("IDENTIFIER")) {
645 result = rLine.split("=");
646 toolsDefIdentifier = (result[1]).trim();
647 } else if ((!rLine.startsWith("#")) && (rLine.contains("="))) {
648 result = rLine.split("=");
649 toolsDefFields = ((result[0]).trim()).split("_");
650 if (toolsDefTargetNames == null) {
651 toolsDefTargetNames = (toolsDefFields[toolsDefTargetNameField]).trim() + " ";
652 } else if (!toolsDefTargetNames.contains((toolsDefFields[toolsDefTargetNameField]).trim())) {
653 toolsDefTargetNames += (toolsDefFields[toolsDefTargetNameField]).trim() + " ";
654 }
655 if (toolsDefTagNames == null) {
656 toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).trim() + " ";
657 } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).trim())) {
658 toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).trim() + " ";
659 }
660 if (toolsDefArchNames == null) {
661 toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).trim() + " ";
662 } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).trim())) {
663 toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).trim() + " ";
664 }
665 }
666 lineCounter++;
667 }
668 reader.close();
669 // Only enable Architecture selection based on tool chain installations
670 String turnOff = "";
671 if (!toolsDefArchNames.contains("EBC"))
672 turnOff = "EBC ";
673 if (!toolsDefArchNames.contains("PPC"))
674 turnOff += "PPC ";
675 if (!toolsDefArchNames.contains("IPF"))
676 turnOff += "IPF ";
677 if (!toolsDefArchNames.contains("X64"))
678 turnOff += "X64 ";
679 if (!toolsDefArchNames.contains("IA32"))
680 turnOff += "X64 ";
681 if (!toolsDefArchNames.contains("ARM"))
682 turnOff += "ARM ";
683 turnOff = turnOff.trim();
684 vDisableArchList = stringToVector(turnOff);
685
686 if (!toolsDefTargetNames.matches("[A-Z]+")) {
687 toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();
688 if (Debug)
689 System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames
690 + "'");
691 buildTargetsExist = false;
692 }
693 } catch (IOException e) {
694 Log.log(toolsConfFile + " Read Error ", e.getMessage());
695 e.printStackTrace();
696 }
697 }
698 return buildTargetsExist;
699 }
700
701 private void readTargetTxtFile() {
702 File tFile = new File(targetFile);
703
704 if (tFile.exists()) {
705 try {
706 FileReader fileReader = new FileReader(targetFile);
707 BufferedReader reader = new BufferedReader(fileReader);
708 targetLineNumberMax = 0;
709 String rLine = null;
710 while ((rLine = reader.readLine()) != null) {
711 targetFileContents[targetLineNumberMax] = rLine;
712 if (rLine.startsWith("ACTIVE_PLATFORM")) {
713 // Only one active platform is permitted!
714 targetLines[activePlatformId] = rLine;
715 targetLineNumber[activePlatformId] = targetLineNumberMax;
716 }
717 if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t"))
718 || (rLine.startsWith("TARGET="))) {
719 // Handle multiple Target Names
720 if (rLine.contains(","))
721 targetLines[buildTargetId] = rLine.trim().replaceAll(",", " ");
722 else
723 targetLines[buildTargetId] = rLine.trim();
724 targetLineNumber[buildTargetId] = targetLineNumberMax;
725 }
726 if (rLine.startsWith("TARGET_ARCH")) {
727 // Handle multiple Target Architectures
728 if (rLine.contains(","))
729 targetLines[targetArchId] = rLine.trim().replaceAll(",", " ");
730 else
731 targetLines[targetArchId] = rLine.trim();
732 targetLineNumber[targetArchId] = targetLineNumberMax;
733 }
734 if (rLine.startsWith("TOOL_CHAIN_CONF")) {
735 // Only one file is permitted
736 targetLines[toolDefFileId] = rLine.trim();
737 targetLineNumber[toolDefFileId] = targetLineNumberMax;
738 }
739
740 if (rLine.startsWith("TOOL_CHAIN_TAG")) {
741 // Handle multiple Tool TagNames
742 if (rLine.contains(","))
743 targetLines[tagNameId] = rLine.trim().replaceAll(",", " ");
744 else
745 targetLines[tagNameId] = rLine.trim();
746 targetLineNumber[tagNameId] = targetLineNumberMax;
747 }
748
749 if (rLine.startsWith("MULTIPLE_THREAD")) {
750 // Handle Thread Enable flag
751 targetLines[threadEnableId] = rLine.trim();
752 targetLineNumber[threadEnableId] = targetLineNumberMax;
753 if ((rLine.trim().toLowerCase().contains("enabled")) || (rLine.trim().toLowerCase().contains("true"))) {
754 threadEnabled = true;
755 } else {
756 threadEnabled = false;
757 }
758 }
759
760 if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
761 // Handle Thread Enable flag
762 targetLines[threadCountId] = rLine.trim();
763 targetLineNumber[threadCountId] = targetLineNumberMax;
764 }
765 targetLineNumberMax++;
766 }
767 reader.close();
768 String archLine[] = new String[2];
769 if (targetLines[targetArchId] != null) {
770 if (targetLines[targetArchId].contains("=")) {
771 if (targetLines[targetArchId].contains(","))
772 targetLines[targetArchId] = targetLines[targetArchId].trim().replaceAll(",", " ");
773 if (targetLines[targetArchId].length() > 0)
774 archLine = targetLines[targetArchId].trim().split("=");
775 vArchList = stringToVector(archLine[1]);
776 }
777 }
778
779 if (targetLines[threadCountId] != null) {
780 String tcLine[] = new String[2];
781 tcLine = targetLines[threadCountId].trim().split("=");
782 threadCount = tcLine[1];
783 } else
784 threadCount = "";
785
786 if (Debug == true)
787 for (int i = 0; i <= maxTargetLines; i++)
788 System.out.println("targetLines[" + i + "] contains: " + targetLines[i] + " index is: "
789 + targetLineNumber[i]);
790 } catch (IOException e) {
791 Log.log(this.targetFile + " Read Error ", e.getMessage());
792 e.printStackTrace();
793 }
794 }
795
796 }
797
798 /**
799 * This method initializes jContentPane
800 *
801 * @return javax.swing.JPanel jContentPane
802 *
803 */
804 private JPanel getJContentPane() {
805 if (jContentPane == null) {
806 jLabelToolsConfigFile = new JLabel();
807 jLabelToolsConfigFile.setBounds(new java.awt.Rectangle(labelColumn, toolConfigFileRow, labelWidth,
808 oneRowHeight));
809 jLabelToolsConfigFile.setText("Tool Chain Definition File");
810 jLabelActivePlatform = new JLabel();
811 jLabelActivePlatform.setText("Select Active Platform");
812 jLabelActivePlatform.setBounds(new java.awt.Rectangle(labelColumn, activePlatformRow, labelWidth,
813 oneRowHeight));
814 jLabelToolChainTagName = new JLabel();
815 jLabelToolChainTagName.setBounds(new java.awt.Rectangle(labelColumn, toolChainTagNameRow, labelWidth,
816 oneRowHeight));
817 jLabelToolChainTagName.setText("Select Tool Tag Name");
818 jLabelBuildTarget = new JLabel();
819 jLabelBuildTarget.setBounds(new java.awt.Rectangle(labelColumn, buildTargetRow, labelWidth, oneRowHeight));
820 jLabelBuildTarget.setText("Select Build Target");
821 jLabelTargetArch = new JLabel();
822 jLabelTargetArch.setBounds(new java.awt.Rectangle(labelColumn, targetArchRow, labelWidth, oneRowHeight));
823 jLabelTargetArch.setText("Build Architectures");
824
825 jArchCheckBox = new ArchCheckBox();
826 jArchCheckBox.setBounds(new java.awt.Rectangle(valueColumn, targetArchRow, valueWidth, oneRowHeight));
827 jArchCheckBox.setPreferredSize(new java.awt.Dimension(valueWidth, oneRowHeight));
828
829 jLabelEnableThreads = new JLabel();
830 jLabelEnableThreads.setBounds(new java.awt.Rectangle(labelColumn, threadRow, labelWidth, oneRowHeight));
831 jLabelEnableThreads.setText("Enable Compiler Threading");
832
833 jLabelThreadCount = new JLabel();
834 jLabelThreadCount.setBounds(new java.awt.Rectangle(valueColumn + 60, threadRow, labelWidth, oneRowHeight));
835 jLabelThreadCount.setText("Number of threads to start");
836
837 jContentPane = new JPanel();
838 jContentPane.setLayout(null);
839 jContentPane.setPreferredSize(new java.awt.Dimension(dialogWidth - 10, dialogHeight - 10));
840
841 jContentPane.add(jLabelToolsConfigFile, null);
842 jContentPane.add(getJTextFieldToolsConfigFile(), null);
843 jContentPane.add(getJButtonBrowse(), null);
844
845 jContentPane.add(jLabelActivePlatform, null);
846 jContentPane.add(getActivePlatform(), null);
847
848 jContentPane.add(jLabelToolChainTagName, null);
849 jContentPane.add(getJScrollPaneTagName(), null);
850
851 jContentPane.add(jLabelBuildTarget, null);
852 jContentPane.add(getJScrollPaneBuildTarget(), null);
853
854 jContentPane.add(jLabelTargetArch, null);
855
856 jArchCheckBox.setDisabledItems(vDisableArchList);
857 jArchCheckBox.setSelectedItems(vArchList);
858 jContentPane.add(jArchCheckBox, null);
859
860 jContentPane.add(jLabelEnableThreads, null);
861 jContentPane.add(getCheckBoxEnableThreads(), null);
862
863 jContentPane.add(jLabelThreadCount, null);
864 jContentPane.add(getTextFieldThreadCount(), null);
865
866 jContentPane.add(getJButtonSave(), null);
867 jContentPane.add(getJButtonCancel(), null);
868 }
869 return jContentPane;
870 }
871
872 /*
873 * (non-Javadoc)
874 *
875 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
876 *
877 * Override actionPerformed to listen all actions
878 *
879 */
880 public void actionPerformed(ActionEvent arg0) {
881
882 if (arg0.getSource() == jButtonBrowse) {
883 // TODO: Call file browser, starting in $WORKSPACE/Tools/Conf directory
884
885 }
886
887 if (arg0.getSource() == jButtonSave) {
888 saveTargetFile();
889 JOptionPane.showMessageDialog(this, "<html>The target.txt file has been saved!"
890 + "<br>A copy of the original file, target.txt.bak has"
891 + "<br>also been created.</html>");
892 this.exit();
893 }
894
895 if (arg0.getSource() == jButtonCancel) {
896 this.exit();
897 }
898
899 if (arg0.getSource() == jCheckBoxEnableThreads) {
900 if (jCheckBoxEnableThreads.isSelected() == false) {
901 threadCount = "";
902 jTextFieldThreadCount.setText(threadCount);
903 }
904 }
905 }
906
907
908 private void updateActivePlatform() {
909 int lineAP;
910 if (targetLines[activePlatformId] != null) {
911 lineAP = targetLineNumber[activePlatformId];
912 } else {
913 lineAP = targetLineNumberMax;
914 targetLineNumber[activePlatformId] = lineAP;
915 targetLineNumberMax++;
916 }
917 if (jComboBoxActivePlatform.getSelectedItem() == "Do Not Set") {
918 targetFileContents[lineAP] = "";
919 targetLines[activePlatformId] = "";
920 } else {
921 targetFileContents[lineAP] = "ACTIVE_PLATFORM = " + jComboBoxActivePlatform.getSelectedItem() + "\r\n";
922 targetLines[activePlatformId] = targetFileContents[lineAP];
923 }
924 if (Debug)
925 System.out.println("Active Platform: " + targetFileContents[lineAP]);
926 }
927
928 private void updateToolDefFile() {
929 int lineTDF;
930 if (targetLines[toolDefFileId] != null) {
931 lineTDF = targetLineNumber[toolDefFileId];
932 } else {
933 lineTDF = targetLineNumberMax;
934 targetLineNumber[toolDefFileId] = lineTDF;
935 targetLineNumberMax++;
936 }
937 if (Debug)
938 System.out.println("Tool Config File: " + jTextFieldToolsConfigFile.getText());
939 if (jTextFieldToolsConfigFile.getText() == null) {
940 targetFileContents[lineTDF] = "#MT#";
941 targetLines[toolDefFileId] = "";
942 } else {
943 targetFileContents[lineTDF] = "TOOL_CHAIN_CONF = " + jTextFieldToolsConfigFile.getText();
944 targetLines[toolDefFileId] = targetFileContents[lineTDF];
945 }
946 }
947
948 private void updateToolTagNames() {
949 String sTagNames = vectorToString(iCheckBoxListTagName.getAllCheckedItemsString());
950 int lineTTN;
951
952 if (targetLines[tagNameId] != null) {
953 lineTTN = targetLineNumber[tagNameId];
954 } else {
955 lineTTN = targetLineNumberMax;
956 targetLineNumber[tagNameId] = lineTTN;
957 targetLineNumberMax++;
958 }
959
960 if (Debug)
961 System.out.println("Tag Name(s): " + sTagNames);
962
963 if (sTagNames.length() > 0) {
964 targetFileContents[lineTTN] = "TOOL_CHAIN_TAG = " + sTagNames;
965 targetLines[tagNameId] = targetFileContents[lineTTN];
966 } else {
967 targetFileContents[lineTTN] = "#MT#";
968 targetLines[tagNameId] = "";
969 }
970 }
971
972 private void updateBuildTargets() {
973 String sBuildTargets = vectorToString(iCheckBoxListBuildTarget.getAllCheckedItemsString());
974 int lineBT;
975
976 if (targetLines[buildTargetId] != null) {
977 lineBT = targetLineNumber[buildTargetId];
978 } else {
979 lineBT = targetLineNumberMax;
980 targetLineNumber[buildTargetId] = lineBT;
981 targetLineNumberMax++;
982 }
983 if (Debug)
984 System.out.println("Build Target(s): " + sBuildTargets);
985 if (sBuildTargets.length() > 0) {
986 targetFileContents[lineBT] = "TARGET = " + sBuildTargets;
987 targetLines[buildTargetId] = targetFileContents[lineBT];
988 } else {
989 targetFileContents[lineBT] = "#MT#";
990 targetLines[buildTargetId] = "";
991 }
992
993 }
994
995 private void updateArchitectures() {
996 String sArchList = jArchCheckBox.getSelectedItemsString().trim();
997
998 if (Debug)
999 System.out.println("Architectures: " + sArchList);
1000
1001 int lineSA;
1002 if (targetLines[targetArchId] != null) {
1003 lineSA = targetLineNumber[targetArchId];
1004 } else {
1005 lineSA = targetLineNumberMax;
1006 targetLineNumber[targetArchId] = lineSA;
1007 targetLineNumberMax++;
1008 }
1009 if (sArchList == "") {
1010 targetFileContents[lineSA] = "#MT#";
1011 targetLines[targetArchId] = "";
1012 } else {
1013 targetFileContents[lineSA] = "TARGET_ARCH = " + sArchList;
1014 targetLines[targetArchId] = targetFileContents[lineSA];
1015 }
1016
1017 }
1018
1019 private void updateEnableThreads() {
1020 int lineET;
1021 if (targetLines[threadEnableId] != null) {
1022 lineET = targetLineNumber[threadEnableId];
1023 } else {
1024 lineET = targetLineNumberMax;
1025 targetLineNumber[threadEnableId] = lineET;
1026 targetLineNumberMax++;
1027 }
1028 if (jCheckBoxEnableThreads.isSelected() == true) {
1029 targetFileContents[lineET] = "MULTIPLE_THREAD = enabled";
1030 targetLines[threadEnableId] = targetFileContents[lineET];
1031 } else {
1032 targetFileContents[lineET] = "#MT#";
1033 targetLines[threadEnableId] = "";
1034 }
1035 }
1036
1037 private void updateThreadCount() {
1038 int lineTC;
1039
1040 if (targetLines[threadCountId] != null) {
1041 lineTC = targetLineNumber[threadCountId];
1042 } else {
1043 lineTC = targetLineNumberMax;
1044 targetLineNumber[threadCountId] = lineTC;
1045 targetLineNumberMax++;
1046 }
1047 if (jCheckBoxEnableThreads.isSelected() == true) {
1048 // Threading must be enabled
1049 if (jTextFieldThreadCount.getText().length() > 0) {
1050 // Thread Count must be greater than 0
1051 Scanner scan = new Scanner(jTextFieldThreadCount.getText().trim());
1052 if (scan.nextInt() > 0) {
1053 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = " + jTextFieldThreadCount.getText().trim();
1054 targetLines[threadCountId] = targetFileContents[lineTC];
1055 } else {
1056 Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1057 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1058 targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1059 }
1060 } else {
1061 Log.wrn("Build Preferences", "Threading Enabled, but thread count is not set, setting to default of 1.");
1062 targetFileContents[lineTC] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1063 targetLines[threadCountId] = "MAX_CONCURRENT_THREAD_NUMBER = 1";
1064 }
1065 } else {
1066 // Don't track threads if threading is not enabled
1067 targetFileContents[lineTC] = "#MT#";
1068 targetLines[threadCountId] = "";
1069 threadCount = "";
1070 }
1071
1072 }
1073 private String vectorToString(Vector<String> v) {
1074 String s = " ";
1075 for (int i = 0; i < v.size(); ++i) {
1076 s += v.get(i);
1077 s += " ";
1078 }
1079 return s.trim();
1080 }
1081
1082 protected Vector<String> stringToVector(String s) {
1083 if (s == null) {
1084 return null;
1085 }
1086 String[] sArray = s.split(" ");
1087 Vector<String> v = new Vector<String>();
1088 for (int i = 0; i < sArray.length; ++i) {
1089 v.add(sArray[i]);
1090 }
1091 return v;
1092 }
1093
1094 private void saveTargetFile() {
1095 updateActivePlatform();
1096 updateToolDefFile();
1097 updateToolTagNames();
1098 updateBuildTargets();
1099 updateArchitectures();
1100 updateEnableThreads();
1101 updateThreadCount();
1102
1103 try {
1104 copy(targetFile, targetFile + ".bak");
1105 FileWriter fileWriter = new FileWriter(targetFile);
1106 BufferedWriter writer = new BufferedWriter(fileWriter);
1107 for (int i = 0; i < targetLineNumberMax; i++) {
1108 if (! targetFileContents[i].contains("#MT#"))
1109 writer.write(targetFileContents[i] + "\n");
1110 }
1111 writer.close();
1112 } catch (IOException e) {
1113 Log.err(toolsConfFile + " Write Error ", e.getMessage());
1114 e.printStackTrace();
1115 }
1116 }
1117
1118 private void copy(String txtFile, String bakFile) throws IOException {
1119 File fromFile = new File(txtFile);
1120 File toFile = new File(bakFile);
1121 FileInputStream fromTxt = null;
1122 FileOutputStream toBak = null;
1123 try {
1124 fromTxt = new FileInputStream(fromFile);
1125 toBak = new FileOutputStream(toFile);
1126 byte[] buffer = new byte[4096];
1127 int bytes_read;
1128 while ((bytes_read = fromTxt.read(buffer)) != -1) {
1129 toBak.write(buffer, 0, bytes_read);
1130 }
1131 } finally {
1132 if (fromTxt != null)
1133 try {
1134 fromTxt.close();
1135 } catch (IOException e) {
1136 Log.err(toolsConfFile + " Read Error ", e.getMessage());
1137
1138 }
1139 if (toBak != null)
1140 try {
1141 toBak.close();
1142 } catch (IOException e) {
1143 Log.err(toolsConfFile + ".bak Write Error ", e.getMessage());
1144 }
1145 }
1146 }
1147
1148 private void exit() {
1149 this.setVisible(false);
1150 if (bTarget != null) {
1151 bTarget.dispose();
1152 }
1153 }
1154 }