3 This file is used to init tool chain and tool preference data
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.frameworkwizard
.toolchain
;
19 import java
.lang
.Integer
;
20 import java
.util
.ArrayList
;
22 import javax
.swing
.JOptionPane
;
24 import org
.tianocore
.frameworkwizard
.FrameworkWizardUI
;
25 import org
.tianocore
.frameworkwizard
.common
.DataType
;
26 import org
.tianocore
.frameworkwizard
.common
.Tools
;
27 import org
.tianocore
.frameworkwizard
.common
.Log
;
28 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
30 public class ToolChainId
{
32 // Define class members
35 private final boolean Debug
= false;
37 private String toolDefinitionFile
= null;
39 private final int toolDefFieldCount
= 5;
41 private String toolsDefIdentifier
= null;
43 private String toolsDefTargetNames
= null;
45 private final int toolsDefTargetNameField
= 0;
47 private String toolsDefTagNames
= null;
49 private final int toolsDefTagNameField
= 1;
51 private String toolsDefArchNames
= null;
53 private final int toolsDefArchNameField
= 2;
55 private final int toolsDefToolArgumentField
= 4;
57 private String toolCommandCodes
= null;
59 private final int toolsDefCmdCodeArgumentField
= 3;
62 private String activePlatform
= null;
64 private String targetArchs
= null;
66 private String tagNames
= null;
68 private String buildTargets
= null;
70 private String toolFamilies
= null;
72 private ArrayList
<String
> toolDefinitionContents
= new ArrayList
<String
>(50);
74 private static boolean threadEnabled
= false;
76 private static int maxThreadCount
= 0;
78 private String toolsDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + "Tools"
79 + System
.getProperty("file.separator") + "Conf";
81 private String strTargetFile
= toolsDir
+ DataType
.FILE_SEPARATOR
+ "target.txt";
83 private String defaultToolsConf
= toolsDir
+ DataType
.FILE_SEPARATOR
+ "tools_def.txt";
87 readToolDefinitionFile();
90 public ToolChainId() {
95 public String
getToolDefinitionFile() {
96 return toolDefinitionFile
;
99 public String
getActivePlatform() {
100 return activePlatform
;
103 public String
getBuildTargets() {
107 public String
getTagNames() {
111 public String
getTargetArchitectures() {
115 public boolean getThreadEnabled() {
116 return threadEnabled
;
119 public int getMaxThreadCount() {
120 return maxThreadCount
;
123 public String
getToolFamilies() {
127 public String
getToolDefinitionIdentifier() {
128 return toolsDefIdentifier
;
131 public ArrayList
<String
> getToolDefinitionStatements() {
132 return toolDefinitionContents
;
135 public String
getToolsDefTagNames() {
136 return toolsDefTagNames
;
139 public String
getToolsDefTargetNames() {
140 return toolsDefTargetNames
;
143 public String
getToolsDefCommandCodes() {
144 return toolCommandCodes
;
147 public String
getToolsDefArchNames() {
148 return toolsDefArchNames
;
151 private void readTargetTxtFile() {
152 File tFile
= new File(strTargetFile
);
154 if (tFile
.exists()) {
156 FileReader fileReader
= new FileReader(strTargetFile
);
157 BufferedReader reader
= new BufferedReader(fileReader
);
159 String inLine
[] = new String
[2];
160 while ((rLine
= reader
.readLine()) != null) {
161 if ((rLine
.startsWith("ACTIVE_PLATFORM")) && (activePlatform
== null)) {
162 // Only one active platform is permitted!
163 inLine
= rLine
.trim().split("=");
164 activePlatform
= inLine
[1].trim();
166 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
167 || (rLine
.startsWith("TARGET="))) {
168 // Handle multiple Target Names
169 if (rLine
.contains(",")) {
170 inLine
= rLine
.trim().split("=");
171 buildTargets
= inLine
[1].trim().replaceAll(",", " ");
173 inLine
= rLine
.trim().split("=");
174 buildTargets
= inLine
[1].trim();
177 if (rLine
.startsWith("TARGET_ARCH")) {
178 // Handle multiple Target Architectures
179 if (rLine
.contains(",")) {
180 inLine
= rLine
.trim().split("=");
181 targetArchs
= inLine
[1].trim().replaceAll(",", " ");
183 inLine
= rLine
.trim().split("=");
184 targetArchs
= inLine
[1].trim();
187 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
188 // Only one file is permitted
189 inLine
= rLine
.trim().split("=");
190 toolDefinitionFile
= inLine
[1].trim();
193 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
194 // Handle multiple Tool TagNames
195 if (rLine
.contains(",")) {
196 inLine
= rLine
.trim().split("=");
197 tagNames
= inLine
[1].trim().replaceAll(",", " ");
199 inLine
= rLine
.trim().split("=");
200 tagNames
= inLine
[1].trim();
204 if (rLine
.startsWith("MULTIPLE_THREAD")) {
205 // Handle Thread Enable flag
206 if ((rLine
.trim().toLowerCase().contains("enabled"))
207 || (rLine
.trim().toLowerCase().contains("true"))) {
208 threadEnabled
= true;
210 threadEnabled
= false;
214 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
215 // Handle Thread Enable flag
216 inLine
= rLine
.trim().split("=");
217 maxThreadCount
= Integer
.valueOf(inLine
[1].trim());
221 } catch (IOException e
) {
222 Log
.log(this.strTargetFile
+ " Read Error ", e
.getMessage());
226 JOptionPane
.showMessageDialog(FrameworkWizardUI
.getInstance(), "<html>" + "Tool Preferences file: <br>" + strTargetFile
227 + "<br>does not exist!</html>");
231 private void readToolDefinitionFile() {
233 // Parse the tool definition file looking for targets and architectures
234 String toolsConfFile
= null;
235 if (toolDefinitionFile
!= null) {
236 String resString
= (Tools
.convertPathToCurrentOsType(toolDefinitionFile
)).trim();
237 toolsConfFile
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + resString
.trim();
238 File toolsDefFile
= new File(toolsConfFile
);
239 if (!toolsDefFile
.exists()) {
240 JOptionPane
.showMessageDialog(FrameworkWizardUI
.getInstance(), "<html>" + "Tool Definition file, " + toolDefinitionFile
241 + "<br>specified in the target.txt file does not exist!"
242 + "<br>Using the default Tool Definition File:<br>"
244 toolsConfFile
= defaultToolsConf
;
247 toolsConfFile
= defaultToolsConf
;
249 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
250 for (int i
= 0; i
< toolDefFieldCount
; i
++)
251 toolsDefFields
[i
] = null;
252 File toolDefFile
= new File(toolsConfFile
);
253 if (toolDefFile
.exists()) {
255 FileReader fileReader
= new FileReader(toolDefFile
);
256 BufferedReader reader
= new BufferedReader(fileReader
);
259 while ((rLine
= reader
.readLine()) != null) {
260 if ((rLine
.startsWith("IDENTIFIER")) && (toolsDefIdentifier
== null)) {
261 result
= rLine
.split("=");
262 toolsDefIdentifier
= (result
[1]).trim();
263 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
264 result
= rLine
.split("=");
265 toolsDefFields
= ((result
[0]).trim()).split("_");
266 if (toolsDefTargetNames
== null) {
267 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
268 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim())) {
269 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
271 if (toolsDefTagNames
== null) {
272 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().toUpperCase().trim() + " ";
273 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim())) {
274 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim() + " ";
276 if (toolsDefArchNames
== null) {
277 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
278 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim())) {
279 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
281 if ((toolFamilies
== null) && (rLine
.trim().contains("FAMILY"))) {
282 toolFamilies
= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
283 } else if ((rLine
.trim().contains("FAMILY"))
284 && (!toolFamilies
.contains((toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim()))) {
285 toolFamilies
+= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
287 if ((toolCommandCodes
== null)) {
288 toolCommandCodes
= (toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim() + " ";
289 } else if ((!toolCommandCodes
.contains((toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim()))) {
290 toolCommandCodes
+= (toolsDefFields
[toolsDefCmdCodeArgumentField
].toUpperCase().trim()) + " ";
293 toolDefinitionContents
.add(rLine
.trim().replaceAll(" ", ""));
297 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
298 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
300 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
303 } catch (IOException e
) {
304 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());