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 rLine
= rLine
.trim();
162 if ((rLine
.startsWith("ACTIVE_PLATFORM")) && (activePlatform
== null)) {
163 // Only one active platform is permitted!
164 inLine
= rLine
.split("=");
165 if (inLine
.length
> 1) {
166 activePlatform
= inLine
[1].trim();
169 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
170 || (rLine
.startsWith("TARGET="))) {
171 // Handle multiple Target Names
172 if (rLine
.contains(",")) {
173 inLine
= rLine
.split("=");
174 if (inLine
.length
> 1) {
175 buildTargets
= inLine
[1].trim().replaceAll(",", " ");
178 inLine
= rLine
.trim().split("=");
179 if (inLine
.length
> 1) {
180 buildTargets
= inLine
[1].trim();
184 if (rLine
.startsWith("TARGET_ARCH")) {
185 // Handle multiple Target Architectures
186 if (rLine
.contains(",")) {
187 inLine
= rLine
.split("=");
188 if (inLine
.length
> 1) {
189 targetArchs
= inLine
[1].trim().replaceAll(",", " ");
192 inLine
= rLine
.split("=");
193 if (inLine
.length
> 1) {
194 targetArchs
= inLine
[1].trim();
198 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
199 // Only one file is permitted
200 inLine
= rLine
.split("=");
201 if (inLine
.length
> 1) {
202 toolDefinitionFile
= inLine
[1].trim();
206 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
207 // Handle multiple Tool TagNames
208 if (rLine
.contains(",")) {
209 inLine
= rLine
.split("=");
210 if (inLine
.length
> 1) {
211 tagNames
= inLine
[1].trim().replaceAll(",", " ");
214 inLine
= rLine
.split("=");
215 if (inLine
.length
> 1) {
216 tagNames
= inLine
[1].trim();
221 if (rLine
.startsWith("MULTIPLE_THREAD")) {
222 // Handle Thread Enable flag
223 if ((rLine
.toLowerCase().contains("enabled"))
224 || (rLine
.toLowerCase().contains("true"))) {
225 threadEnabled
= true;
227 threadEnabled
= false;
231 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
232 // Handle Thread Enable flag
233 inLine
= rLine
.split("=");
234 if (inLine
.length
> 1) {
235 maxThreadCount
= Integer
.valueOf(inLine
[1].trim());
240 } catch (IOException e
) {
241 Log
.log(this.strTargetFile
+ " Read Error ", e
.getMessage());
245 JOptionPane
.showMessageDialog(FrameworkWizardUI
.getInstance(), "<html>" + "Tool Preferences file: <br>" + strTargetFile
246 + "<br>does not exist!</html>");
250 private void readToolDefinitionFile() {
252 // Parse the tool definition file looking for targets and architectures
253 String toolsConfFile
= null;
254 if (toolDefinitionFile
!= null) {
255 String resString
= (Tools
.convertPathToCurrentOsType(toolDefinitionFile
)).trim();
256 toolsConfFile
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + resString
.trim();
257 File toolsDefFile
= new File(toolsConfFile
);
258 if (!toolsDefFile
.exists()) {
259 JOptionPane
.showMessageDialog(FrameworkWizardUI
.getInstance(), "<html>" + "Tool Definition file, " + toolDefinitionFile
260 + "<br>specified in the target.txt file does not exist!"
261 + "<br>Using the default Tool Definition File:<br>"
263 toolsConfFile
= defaultToolsConf
;
266 toolsConfFile
= defaultToolsConf
;
268 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
269 for (int i
= 0; i
< toolDefFieldCount
; i
++)
270 toolsDefFields
[i
] = null;
271 File toolDefFile
= new File(toolsConfFile
);
272 if (toolDefFile
.exists()) {
274 FileReader fileReader
= new FileReader(toolDefFile
);
275 BufferedReader reader
= new BufferedReader(fileReader
);
278 while ((rLine
= reader
.readLine()) != null) {
279 if ((rLine
.startsWith("IDENTIFIER")) && (toolsDefIdentifier
== null)) {
280 result
= rLine
.split("=");
281 toolsDefIdentifier
= (result
[1]).trim();
282 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
283 result
= rLine
.split("=");
284 toolsDefFields
= ((result
[0]).trim()).split("_");
285 if (toolsDefTargetNames
== null) {
286 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
287 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim())) {
288 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
290 if (toolsDefTagNames
== null) {
291 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().toUpperCase().trim() + " ";
292 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim())) {
293 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim() + " ";
295 if (toolsDefArchNames
== null) {
296 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
297 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim())) {
298 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
300 if ((toolFamilies
== null) && (rLine
.trim().contains("FAMILY"))) {
301 toolFamilies
= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
302 } else if ((rLine
.trim().contains("FAMILY"))
303 && (!toolFamilies
.contains((toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim()))) {
304 toolFamilies
+= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
306 if ((toolCommandCodes
== null)) {
307 toolCommandCodes
= (toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim() + " ";
308 } else if ((!toolCommandCodes
.contains((toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim()))) {
309 toolCommandCodes
+= (toolsDefFields
[toolsDefCmdCodeArgumentField
].toUpperCase().trim()) + " ";
312 toolDefinitionContents
.add(rLine
.trim().replaceAll(" ", ""));
316 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
317 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
319 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
322 } catch (IOException e
) {
323 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());