]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/toolchain/ToolChainId.java
992bd2f753571646dad0fb42d15ce55181b69dc0
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / toolchain / ToolChainId.java
1 /** @file
2
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
9
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.
12
13 **/
14
15 package org.tianocore.frameworkwizard.toolchain;
16
17 import java.io.*;
18 import java.io.File;
19 import java.lang.Integer;
20 import java.util.ArrayList;
21
22 import javax.swing.JOptionPane;
23
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;
28
29 public class ToolChainId {
30 //
31 // Define class members
32 //
33
34 private final boolean Debug = false;
35
36 private String toolDefinitionFile = null;
37
38 private final int toolDefFieldCount = 5;
39
40 private String toolsDefIdentifier = null;
41
42 private String toolsDefTargetNames = null;
43
44 private final int toolsDefTargetNameField = 0;
45
46 private String toolsDefTagNames = null;
47
48 private final int toolsDefTagNameField = 1;
49
50 private String toolsDefArchNames = null;
51
52 private final int toolsDefArchNameField = 2;
53
54 private final int toolsDefToolArgumentField = 4;
55
56 private String toolCommandCodes = null;
57
58 private final int toolsDefCmdCodeArgumentField = 3;
59
60
61 private String activePlatform = null;
62
63 private String targetArchs = null;
64
65 private String tagNames = null;
66
67 private String buildTargets = null;
68
69 private String toolFamilies = null;
70
71 private ArrayList<String> toolDefinitionContents = new ArrayList<String>(50);
72
73 private static boolean threadEnabled = false;
74
75 private static int maxThreadCount = 0;
76
77 private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools"
78 + System.getProperty("file.separator") + "Conf";
79
80 private String strTargetFile = toolsDir + DataType.FILE_SEPARATOR + "target.txt";
81
82 private String defaultToolsConf = toolsDir + DataType.FILE_SEPARATOR + "tools_def.txt";
83
84 public void init() {
85 readTargetTxtFile();
86 readToolDefinitionFile();
87 }
88
89 public ToolChainId() {
90 super();
91 init();
92 }
93
94 public String getToolDefinitionFile() {
95 return toolDefinitionFile;
96 }
97
98 public String getActivePlatform() {
99 return activePlatform;
100 }
101
102 public String getBuildTargets() {
103 return buildTargets;
104 }
105
106 public String getTagNames() {
107 return tagNames;
108 }
109
110 public String getTargetArchitectures() {
111 return targetArchs;
112 }
113
114 public boolean getThreadEnabled() {
115 return threadEnabled;
116 }
117
118 public int getMaxThreadCount() {
119 return maxThreadCount;
120 }
121
122 public String getToolFamilies() {
123 return toolFamilies;
124 }
125
126 public String getToolDefinitionIdentifier() {
127 return toolsDefIdentifier;
128 }
129
130 public ArrayList<String> getToolDefinitionStatements() {
131 return toolDefinitionContents;
132 }
133
134 public String getToolsDefTagNames() {
135 return toolsDefTagNames;
136 }
137
138 public String getToolsDefTargetNames() {
139 return toolsDefTargetNames;
140 }
141
142 public String getToolsDefCommandCodes() {
143 return toolCommandCodes;
144 }
145
146 private void readTargetTxtFile() {
147 File tFile = new File(strTargetFile);
148
149 if (tFile.exists()) {
150 try {
151 FileReader fileReader = new FileReader(strTargetFile);
152 BufferedReader reader = new BufferedReader(fileReader);
153 String rLine = null;
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();
160 }
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(",", " ");
167 } else {
168 inLine = rLine.trim().split("=");
169 buildTargets = inLine[1].trim();
170 }
171 }
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(",", " ");
177 } else {
178 inLine = rLine.trim().split("=");
179 targetArchs = inLine[1].trim();
180 }
181 }
182 if (rLine.startsWith("TOOL_CHAIN_CONF")) {
183 // Only one file is permitted
184 inLine = rLine.trim().split("=");
185 toolDefinitionFile = inLine[1].trim();
186 }
187
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(",", " ");
193 } else {
194 inLine = rLine.trim().split("=");
195 tagNames = inLine[1].trim();
196 }
197 }
198
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;
204 } else {
205 threadEnabled = false;
206 }
207 }
208
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());
213 }
214 }
215 reader.close();
216 } catch (IOException e) {
217 Log.log(this.strTargetFile + " Read Error ", e.getMessage());
218 e.printStackTrace();
219 }
220 } else {
221 JOptionPane.showMessageDialog(null, "<html>" + "Tool Preferences file: <br>" + strTargetFile
222 + "<br>does not exist!</html>");
223 }
224 }
225
226 private void readToolDefinitionFile() {
227
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>"
238 + defaultToolsConf);
239 toolsConfFile = defaultToolsConf;
240 }
241 } else {
242 toolsConfFile = defaultToolsConf;
243 }
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()) {
249 try {
250 FileReader fileReader = new FileReader(toolDefFile);
251 BufferedReader reader = new BufferedReader(fileReader);
252 String rLine = null;
253 String result[];
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() + " ";
265 }
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() + " ";
270 }
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() + " ";
275 }
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() + " ";
281 }
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()) + " ";
286 }
287
288 toolDefinitionContents.add(rLine.trim().replaceAll(" ", ""));
289 }
290 }
291 reader.close();
292 if (!toolsDefTargetNames.matches("[A-Z]+")) {
293 toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim();
294 if (Debug)
295 System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames
296 + "'");
297 }
298 } catch (IOException e) {
299 Log.log(toolsConfFile + " Read Error ", e.getMessage());
300 e.printStackTrace();
301 }
302 }
303 }
304
305 }