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
.common
.DataType
;
25 import org
.tianocore
.frameworkwizard
.common
.Tools
;
26 import org
.tianocore
.frameworkwizard
.common
.Log
;
27 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
29 public class ToolChainId
{
31 // Define class members
34 private final boolean Debug
= false;
36 private String toolDefinitionFile
= null;
38 private final int toolDefFieldCount
= 5;
40 private String toolsDefIdentifier
= null;
42 private String toolsDefTargetNames
= null;
44 private final int toolsDefTargetNameField
= 0;
46 private String toolsDefTagNames
= null;
48 private final int toolsDefTagNameField
= 1;
50 private String toolsDefArchNames
= null;
52 private final int toolsDefArchNameField
= 2;
54 private final int toolsDefToolArgumentField
= 4;
56 private String toolCommandCodes
= null;
58 private final int toolsDefCmdCodeArgumentField
= 3;
61 private String activePlatform
= null;
63 private String targetArchs
= null;
65 private String tagNames
= null;
67 private String buildTargets
= null;
69 private String toolFamilies
= null;
71 private ArrayList
<String
> toolDefinitionContents
= new ArrayList
<String
>(50);
73 private static boolean threadEnabled
= false;
75 private static int maxThreadCount
= 0;
77 private String toolsDir
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + "Tools"
78 + System
.getProperty("file.separator") + "Conf";
80 private String strTargetFile
= toolsDir
+ DataType
.FILE_SEPARATOR
+ "target.txt";
82 private String defaultToolsConf
= toolsDir
+ DataType
.FILE_SEPARATOR
+ "tools_def.txt";
86 readToolDefinitionFile();
89 public ToolChainId() {
94 public String
getToolDefinitionFile() {
95 return toolDefinitionFile
;
98 public String
getActivePlatform() {
99 return activePlatform
;
102 public String
getBuildTargets() {
106 public String
getTagNames() {
110 public String
getTargetArchitectures() {
114 public boolean getThreadEnabled() {
115 return threadEnabled
;
118 public int getMaxThreadCount() {
119 return maxThreadCount
;
122 public String
getToolFamilies() {
126 public String
getToolDefinitionIdentifier() {
127 return toolsDefIdentifier
;
130 public ArrayList
<String
> getToolDefinitionStatements() {
131 return toolDefinitionContents
;
134 public String
getToolsDefTagNames() {
135 return toolsDefTagNames
;
138 public String
getToolsDefTargetNames() {
139 return toolsDefTargetNames
;
142 public String
getToolsDefCommandCodes() {
143 return toolCommandCodes
;
146 public String
getToolsDefArchNames() {
147 return toolsDefArchNames
;
150 private void readTargetTxtFile() {
151 File tFile
= new File(strTargetFile
);
153 if (tFile
.exists()) {
155 FileReader fileReader
= new FileReader(strTargetFile
);
156 BufferedReader reader
= new BufferedReader(fileReader
);
158 String inLine
[] = new String
[2];
159 while ((rLine
= reader
.readLine()) != null) {
160 if ((rLine
.startsWith("ACTIVE_PLATFORM")) && (activePlatform
== null)) {
161 // Only one active platform is permitted!
162 inLine
= rLine
.trim().split("=");
163 activePlatform
= inLine
[1].trim();
165 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
166 || (rLine
.startsWith("TARGET="))) {
167 // Handle multiple Target Names
168 if (rLine
.contains(",")) {
169 inLine
= rLine
.trim().split("=");
170 buildTargets
= inLine
[1].trim().replaceAll(",", " ");
172 inLine
= rLine
.trim().split("=");
173 buildTargets
= inLine
[1].trim();
176 if (rLine
.startsWith("TARGET_ARCH")) {
177 // Handle multiple Target Architectures
178 if (rLine
.contains(",")) {
179 inLine
= rLine
.trim().split("=");
180 targetArchs
= inLine
[1].trim().replaceAll(",", " ");
182 inLine
= rLine
.trim().split("=");
183 targetArchs
= inLine
[1].trim();
186 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
187 // Only one file is permitted
188 inLine
= rLine
.trim().split("=");
189 toolDefinitionFile
= inLine
[1].trim();
192 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
193 // Handle multiple Tool TagNames
194 if (rLine
.contains(",")) {
195 inLine
= rLine
.trim().split("=");
196 tagNames
= inLine
[1].trim().replaceAll(",", " ");
198 inLine
= rLine
.trim().split("=");
199 tagNames
= inLine
[1].trim();
203 if (rLine
.startsWith("MULTIPLE_THREAD")) {
204 // Handle Thread Enable flag
205 if ((rLine
.trim().toLowerCase().contains("enabled"))
206 || (rLine
.trim().toLowerCase().contains("true"))) {
207 threadEnabled
= true;
209 threadEnabled
= false;
213 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
214 // Handle Thread Enable flag
215 inLine
= rLine
.trim().split("=");
216 maxThreadCount
= Integer
.valueOf(inLine
[1].trim());
220 } catch (IOException e
) {
221 Log
.log(this.strTargetFile
+ " Read Error ", e
.getMessage());
225 JOptionPane
.showMessageDialog(null, "<html>" + "Tool Preferences file: <br>" + strTargetFile
226 + "<br>does not exist!</html>");
230 private void readToolDefinitionFile() {
232 // Parse the tool definition file looking for targets and architectures
233 String toolsConfFile
= null;
234 if (toolDefinitionFile
!= null) {
235 String resString
= (Tools
.convertPathToCurrentOsType(toolDefinitionFile
)).trim();
236 toolsConfFile
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + resString
.trim();
237 File toolsDefFile
= new File(toolsConfFile
);
238 if (!toolsDefFile
.exists()) {
239 JOptionPane
.showMessageDialog(null, "<html>" + "Tool Definition file, " + toolDefinitionFile
240 + "<br>specified in the target.txt file does not exist!"
241 + "<br>Using the default Tool Definition File:<br>"
243 toolsConfFile
= defaultToolsConf
;
246 toolsConfFile
= defaultToolsConf
;
248 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
249 for (int i
= 0; i
< toolDefFieldCount
; i
++)
250 toolsDefFields
[i
] = null;
251 File toolDefFile
= new File(toolsConfFile
);
252 if (toolDefFile
.exists()) {
254 FileReader fileReader
= new FileReader(toolDefFile
);
255 BufferedReader reader
= new BufferedReader(fileReader
);
258 while ((rLine
= reader
.readLine()) != null) {
259 if ((rLine
.startsWith("IDENTIFIER")) && (toolsDefIdentifier
== null)) {
260 result
= rLine
.split("=");
261 toolsDefIdentifier
= (result
[1]).trim();
262 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
263 result
= rLine
.split("=");
264 toolsDefFields
= ((result
[0]).trim()).split("_");
265 if (toolsDefTargetNames
== null) {
266 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
267 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim())) {
268 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
270 if (toolsDefTagNames
== null) {
271 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().toUpperCase().trim() + " ";
272 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim())) {
273 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim() + " ";
275 if (toolsDefArchNames
== null) {
276 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
277 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim())) {
278 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
280 if ((toolFamilies
== null) && (rLine
.trim().contains("FAMILY"))) {
281 toolFamilies
= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
282 } else if ((rLine
.trim().contains("FAMILY"))
283 && (!toolFamilies
.contains((toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim()))) {
284 toolFamilies
+= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
286 if ((toolCommandCodes
== null)) {
287 toolCommandCodes
= (toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim() + " ";
288 } else if ((!toolCommandCodes
.contains((toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim()))) {
289 toolCommandCodes
+= (toolsDefFields
[toolsDefCmdCodeArgumentField
].toUpperCase().trim()) + " ";
292 toolDefinitionContents
.add(rLine
.trim().replaceAll(" ", ""));
296 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
297 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
299 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
302 } catch (IOException e
) {
303 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());