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 private void readTargetTxtFile() {
147 File tFile
= new File(strTargetFile
);
149 if (tFile
.exists()) {
151 FileReader fileReader
= new FileReader(strTargetFile
);
152 BufferedReader reader
= new BufferedReader(fileReader
);
154 String inLine
[] = new String
[2];
155 while ((rLine
= reader
.readLine()) != null) {
156 if ((rLine
.startsWith("ACTIVE_PLATFORM")) && (activePlatform
== null)) {
157 // Only one active platform is permitted!
158 inLine
= rLine
.trim().split("=");
159 activePlatform
= inLine
[1].trim();
161 if ((rLine
.startsWith("TARGET" + " ")) || (rLine
.startsWith("TARGET" + "\t"))
162 || (rLine
.startsWith("TARGET="))) {
163 // Handle multiple Target Names
164 if (rLine
.contains(",")) {
165 inLine
= rLine
.trim().split("=");
166 buildTargets
= inLine
[1].trim().replaceAll(",", " ");
168 inLine
= rLine
.trim().split("=");
169 buildTargets
= inLine
[1].trim();
172 if (rLine
.startsWith("TARGET_ARCH")) {
173 // Handle multiple Target Architectures
174 if (rLine
.contains(",")) {
175 inLine
= rLine
.trim().split("=");
176 targetArchs
= inLine
[1].trim().replaceAll(",", " ");
178 inLine
= rLine
.trim().split("=");
179 targetArchs
= inLine
[1].trim();
182 if (rLine
.startsWith("TOOL_CHAIN_CONF")) {
183 // Only one file is permitted
184 inLine
= rLine
.trim().split("=");
185 toolDefinitionFile
= inLine
[1].trim();
188 if (rLine
.startsWith("TOOL_CHAIN_TAG")) {
189 // Handle multiple Tool TagNames
190 if (rLine
.contains(",")) {
191 inLine
= rLine
.trim().split("=");
192 tagNames
= inLine
[1].trim().replaceAll(",", " ");
194 inLine
= rLine
.trim().split("=");
195 tagNames
= inLine
[1].trim();
199 if (rLine
.startsWith("MULTIPLE_THREAD")) {
200 // Handle Thread Enable flag
201 if ((rLine
.trim().toLowerCase().contains("enabled"))
202 || (rLine
.trim().toLowerCase().contains("true"))) {
203 threadEnabled
= true;
205 threadEnabled
= false;
209 if (rLine
.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) {
210 // Handle Thread Enable flag
211 inLine
= rLine
.trim().split("=");
212 maxThreadCount
= Integer
.valueOf(inLine
[1].trim());
216 } catch (IOException e
) {
217 Log
.log(this.strTargetFile
+ " Read Error ", e
.getMessage());
221 JOptionPane
.showMessageDialog(null, "<html>" + "Tool Preferences file: <br>" + strTargetFile
222 + "<br>does not exist!</html>");
226 private void readToolDefinitionFile() {
228 // Parse the tool definition file looking for targets and architectures
229 String toolsConfFile
= null;
230 if (toolDefinitionFile
!= null) {
231 String resString
= (Tools
.convertPathToCurrentOsType(toolDefinitionFile
)).trim();
232 toolsConfFile
= Workspace
.getCurrentWorkspace() + System
.getProperty("file.separator") + resString
.trim();
233 File toolsDefFile
= new File(toolsConfFile
);
234 if (!toolsDefFile
.exists()) {
235 JOptionPane
.showMessageDialog(null, "<html>" + "Tool Definition file, " + toolDefinitionFile
236 + "<br>specified in the target.txt file does not exist!"
237 + "<br>Using the default Tool Definition File:<br>"
239 toolsConfFile
= defaultToolsConf
;
242 toolsConfFile
= defaultToolsConf
;
244 String
[] toolsDefFields
= new String
[toolDefFieldCount
];
245 for (int i
= 0; i
< toolDefFieldCount
; i
++)
246 toolsDefFields
[i
] = null;
247 File toolDefFile
= new File(toolsConfFile
);
248 if (toolDefFile
.exists()) {
250 FileReader fileReader
= new FileReader(toolDefFile
);
251 BufferedReader reader
= new BufferedReader(fileReader
);
254 while ((rLine
= reader
.readLine()) != null) {
255 if ((rLine
.startsWith("IDENTIFIER")) && (toolsDefIdentifier
== null)) {
256 result
= rLine
.split("=");
257 toolsDefIdentifier
= (result
[1]).trim();
258 } else if ((!rLine
.startsWith("#")) && (rLine
.contains("="))) {
259 result
= rLine
.split("=");
260 toolsDefFields
= ((result
[0]).trim()).split("_");
261 if (toolsDefTargetNames
== null) {
262 toolsDefTargetNames
= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
263 } else if (!toolsDefTargetNames
.contains((toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim())) {
264 toolsDefTargetNames
+= (toolsDefFields
[toolsDefTargetNameField
]).toUpperCase().trim() + " ";
266 if (toolsDefTagNames
== null) {
267 toolsDefTagNames
= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().toUpperCase().trim() + " ";
268 } else if (!toolsDefTagNames
.contains((toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim())) {
269 toolsDefTagNames
+= (toolsDefFields
[toolsDefTagNameField
]).toUpperCase().trim() + " ";
271 if (toolsDefArchNames
== null) {
272 toolsDefArchNames
= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
273 } else if (!toolsDefArchNames
.contains((toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim())) {
274 toolsDefArchNames
+= (toolsDefFields
[toolsDefArchNameField
]).toUpperCase().trim() + " ";
276 if ((toolFamilies
== null) && (rLine
.trim().contains("FAMILY"))) {
277 toolFamilies
= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
278 } else if ((rLine
.trim().contains("FAMILY"))
279 && (!toolFamilies
.contains((toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim()))) {
280 toolFamilies
+= (toolsDefFields
[toolsDefToolArgumentField
]).toUpperCase().trim() + " ";
282 if ((toolCommandCodes
== null)) {
283 toolCommandCodes
= (toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim() + " ";
284 } else if ((!toolCommandCodes
.contains((toolsDefFields
[toolsDefCmdCodeArgumentField
]).toUpperCase().trim()))) {
285 toolCommandCodes
+= (toolsDefFields
[toolsDefCmdCodeArgumentField
].toUpperCase().trim()) + " ";
288 toolDefinitionContents
.add(rLine
.trim().replaceAll(" ", ""));
292 if (!toolsDefTargetNames
.matches("[A-Z]+")) {
293 toolsDefTargetNames
= toolsDefTargetNames
.replace("* ", "").trim();
295 System
.out
.println("tools_def file does not define build targets: '" + toolsDefTargetNames
298 } catch (IOException e
) {
299 Log
.log(toolsConfFile
+ " Read Error ", e
.getMessage());