]>
Commit | Line | Data |
---|---|---|
52ee46a6 | 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 | ||
82484861 | 24 | import org.tianocore.frameworkwizard.FrameworkWizardUI; |
52ee46a6 | 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; | |
29 | ||
30 | public class ToolChainId { | |
31 | // | |
32 | // Define class members | |
33 | // | |
34 | ||
35 | private final boolean Debug = false; | |
36 | ||
37 | private String toolDefinitionFile = null; | |
38 | ||
39 | private final int toolDefFieldCount = 5; | |
40 | ||
41 | private String toolsDefIdentifier = null; | |
42 | ||
43 | private String toolsDefTargetNames = null; | |
44 | ||
45 | private final int toolsDefTargetNameField = 0; | |
46 | ||
47 | private String toolsDefTagNames = null; | |
48 | ||
49 | private final int toolsDefTagNameField = 1; | |
50 | ||
51 | private String toolsDefArchNames = null; | |
52 | ||
53 | private final int toolsDefArchNameField = 2; | |
54 | ||
55 | private final int toolsDefToolArgumentField = 4; | |
56 | ||
57 | private String toolCommandCodes = null; | |
58 | ||
59 | private final int toolsDefCmdCodeArgumentField = 3; | |
60 | ||
61 | ||
62 | private String activePlatform = null; | |
63 | ||
64 | private String targetArchs = null; | |
65 | ||
66 | private String tagNames = null; | |
67 | ||
68 | private String buildTargets = null; | |
69 | ||
70 | private String toolFamilies = null; | |
71 | ||
72 | private ArrayList<String> toolDefinitionContents = new ArrayList<String>(50); | |
73 | ||
74 | private static boolean threadEnabled = false; | |
75 | ||
76 | private static int maxThreadCount = 0; | |
77 | ||
78 | private String toolsDir = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + "Tools" | |
79 | + System.getProperty("file.separator") + "Conf"; | |
80 | ||
81 | private String strTargetFile = toolsDir + DataType.FILE_SEPARATOR + "target.txt"; | |
82 | ||
83 | private String defaultToolsConf = toolsDir + DataType.FILE_SEPARATOR + "tools_def.txt"; | |
84 | ||
85 | public void init() { | |
86 | readTargetTxtFile(); | |
87 | readToolDefinitionFile(); | |
88 | } | |
89 | ||
90 | public ToolChainId() { | |
91 | super(); | |
92 | init(); | |
93 | } | |
94 | ||
95 | public String getToolDefinitionFile() { | |
96 | return toolDefinitionFile; | |
97 | } | |
98 | ||
99 | public String getActivePlatform() { | |
100 | return activePlatform; | |
101 | } | |
102 | ||
103 | public String getBuildTargets() { | |
104 | return buildTargets; | |
105 | } | |
106 | ||
107 | public String getTagNames() { | |
108 | return tagNames; | |
109 | } | |
110 | ||
111 | public String getTargetArchitectures() { | |
112 | return targetArchs; | |
113 | } | |
114 | ||
115 | public boolean getThreadEnabled() { | |
116 | return threadEnabled; | |
117 | } | |
118 | ||
119 | public int getMaxThreadCount() { | |
120 | return maxThreadCount; | |
121 | } | |
122 | ||
123 | public String getToolFamilies() { | |
124 | return toolFamilies; | |
125 | } | |
126 | ||
127 | public String getToolDefinitionIdentifier() { | |
128 | return toolsDefIdentifier; | |
129 | } | |
130 | ||
131 | public ArrayList<String> getToolDefinitionStatements() { | |
132 | return toolDefinitionContents; | |
133 | } | |
134 | ||
135 | public String getToolsDefTagNames() { | |
136 | return toolsDefTagNames; | |
137 | } | |
138 | ||
139 | public String getToolsDefTargetNames() { | |
140 | return toolsDefTargetNames; | |
141 | } | |
142 | ||
143 | public String getToolsDefCommandCodes() { | |
144 | return toolCommandCodes; | |
145 | } | |
146 | ||
b8d0bba0 | 147 | public String getToolsDefArchNames() { |
148 | return toolsDefArchNames; | |
149 | } | |
150 | ||
52ee46a6 | 151 | private void readTargetTxtFile() { |
152 | File tFile = new File(strTargetFile); | |
153 | ||
154 | if (tFile.exists()) { | |
155 | try { | |
156 | FileReader fileReader = new FileReader(strTargetFile); | |
157 | BufferedReader reader = new BufferedReader(fileReader); | |
158 | String rLine = null; | |
159 | String inLine[] = new String[2]; | |
160 | while ((rLine = reader.readLine()) != null) { | |
c0db4cdc | 161 | rLine = rLine.trim(); |
52ee46a6 | 162 | if ((rLine.startsWith("ACTIVE_PLATFORM")) && (activePlatform == null)) { |
163 | // Only one active platform is permitted! | |
c0db4cdc | 164 | inLine = rLine.split("="); |
165 | if (inLine.length > 1) { | |
166 | activePlatform = inLine[1].trim(); | |
167 | } | |
52ee46a6 | 168 | } |
169 | if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t")) | |
170 | || (rLine.startsWith("TARGET="))) { | |
171 | // Handle multiple Target Names | |
172 | if (rLine.contains(",")) { | |
c0db4cdc | 173 | inLine = rLine.split("="); |
174 | if (inLine.length > 1) { | |
175 | buildTargets = inLine[1].trim().replaceAll(",", " "); | |
176 | } | |
52ee46a6 | 177 | } else { |
178 | inLine = rLine.trim().split("="); | |
c0db4cdc | 179 | if (inLine.length > 1) { |
180 | buildTargets = inLine[1].trim(); | |
181 | } | |
52ee46a6 | 182 | } |
183 | } | |
184 | if (rLine.startsWith("TARGET_ARCH")) { | |
185 | // Handle multiple Target Architectures | |
186 | if (rLine.contains(",")) { | |
c0db4cdc | 187 | inLine = rLine.split("="); |
188 | if (inLine.length > 1) { | |
189 | targetArchs = inLine[1].trim().replaceAll(",", " "); | |
190 | } | |
52ee46a6 | 191 | } else { |
c0db4cdc | 192 | inLine = rLine.split("="); |
193 | if (inLine.length > 1) { | |
194 | targetArchs = inLine[1].trim(); | |
195 | } | |
52ee46a6 | 196 | } |
197 | } | |
198 | if (rLine.startsWith("TOOL_CHAIN_CONF")) { | |
199 | // Only one file is permitted | |
c0db4cdc | 200 | inLine = rLine.split("="); |
201 | if (inLine.length > 1) { | |
202 | toolDefinitionFile = inLine[1].trim(); | |
203 | } | |
52ee46a6 | 204 | } |
205 | ||
206 | if (rLine.startsWith("TOOL_CHAIN_TAG")) { | |
207 | // Handle multiple Tool TagNames | |
208 | if (rLine.contains(",")) { | |
c0db4cdc | 209 | inLine = rLine.split("="); |
210 | if (inLine.length > 1) { | |
211 | tagNames = inLine[1].trim().replaceAll(",", " "); | |
212 | } | |
52ee46a6 | 213 | } else { |
c0db4cdc | 214 | inLine = rLine.split("="); |
215 | if (inLine.length > 1) { | |
216 | tagNames = inLine[1].trim(); | |
217 | } | |
52ee46a6 | 218 | } |
219 | } | |
220 | ||
221 | if (rLine.startsWith("MULTIPLE_THREAD")) { | |
222 | // Handle Thread Enable flag | |
c0db4cdc | 223 | if ((rLine.toLowerCase().contains("enabled")) |
224 | || (rLine.toLowerCase().contains("true"))) { | |
52ee46a6 | 225 | threadEnabled = true; |
226 | } else { | |
227 | threadEnabled = false; | |
228 | } | |
229 | } | |
230 | ||
231 | if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) { | |
232 | // Handle Thread Enable flag | |
c0db4cdc | 233 | inLine = rLine.split("="); |
234 | if (inLine.length > 1) { | |
235 | maxThreadCount = Integer.valueOf(inLine[1].trim()); | |
236 | } | |
52ee46a6 | 237 | } |
238 | } | |
239 | reader.close(); | |
240 | } catch (IOException e) { | |
241 | Log.log(this.strTargetFile + " Read Error ", e.getMessage()); | |
242 | e.printStackTrace(); | |
243 | } | |
244 | } else { | |
82484861 | 245 | JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "<html>" + "Tool Preferences file: <br>" + strTargetFile |
52ee46a6 | 246 | + "<br>does not exist!</html>"); |
247 | } | |
248 | } | |
249 | ||
250 | private void readToolDefinitionFile() { | |
251 | ||
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()) { | |
82484861 | 259 | JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "<html>" + "Tool Definition file, " + toolDefinitionFile |
52ee46a6 | 260 | + "<br>specified in the target.txt file does not exist!" |
261 | + "<br>Using the default Tool Definition File:<br>" | |
262 | + defaultToolsConf); | |
263 | toolsConfFile = defaultToolsConf; | |
264 | } | |
265 | } else { | |
266 | toolsConfFile = defaultToolsConf; | |
267 | } | |
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()) { | |
273 | try { | |
274 | FileReader fileReader = new FileReader(toolDefFile); | |
275 | BufferedReader reader = new BufferedReader(fileReader); | |
276 | String rLine = null; | |
277 | String result[]; | |
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() + " "; | |
289 | } | |
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() + " "; | |
294 | } | |
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() + " "; | |
299 | } | |
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() + " "; | |
305 | } | |
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()) + " "; | |
310 | } | |
311 | ||
312 | toolDefinitionContents.add(rLine.trim().replaceAll(" ", "")); | |
313 | } | |
314 | } | |
315 | reader.close(); | |
316 | if (!toolsDefTargetNames.matches("[A-Z]+")) { | |
317 | toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim(); | |
318 | if (Debug) | |
319 | System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames | |
320 | + "'"); | |
321 | } | |
322 | } catch (IOException e) { | |
323 | Log.log(toolsConfFile + " Read Error ", e.getMessage()); | |
324 | e.printStackTrace(); | |
325 | } | |
326 | } | |
327 | } | |
328 | ||
329 | } |