]>
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 | ||
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 | ||
b8d0bba0 | 146 | public String getToolsDefArchNames() { |
147 | return toolsDefArchNames; | |
148 | } | |
149 | ||
52ee46a6 | 150 | private void readTargetTxtFile() { |
151 | File tFile = new File(strTargetFile); | |
152 | ||
153 | if (tFile.exists()) { | |
154 | try { | |
155 | FileReader fileReader = new FileReader(strTargetFile); | |
156 | BufferedReader reader = new BufferedReader(fileReader); | |
157 | String rLine = null; | |
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(); | |
164 | } | |
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(",", " "); | |
171 | } else { | |
172 | inLine = rLine.trim().split("="); | |
173 | buildTargets = inLine[1].trim(); | |
174 | } | |
175 | } | |
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(",", " "); | |
181 | } else { | |
182 | inLine = rLine.trim().split("="); | |
183 | targetArchs = inLine[1].trim(); | |
184 | } | |
185 | } | |
186 | if (rLine.startsWith("TOOL_CHAIN_CONF")) { | |
187 | // Only one file is permitted | |
188 | inLine = rLine.trim().split("="); | |
189 | toolDefinitionFile = inLine[1].trim(); | |
190 | } | |
191 | ||
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(",", " "); | |
197 | } else { | |
198 | inLine = rLine.trim().split("="); | |
199 | tagNames = inLine[1].trim(); | |
200 | } | |
201 | } | |
202 | ||
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; | |
208 | } else { | |
209 | threadEnabled = false; | |
210 | } | |
211 | } | |
212 | ||
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()); | |
217 | } | |
218 | } | |
219 | reader.close(); | |
220 | } catch (IOException e) { | |
221 | Log.log(this.strTargetFile + " Read Error ", e.getMessage()); | |
222 | e.printStackTrace(); | |
223 | } | |
224 | } else { | |
225 | JOptionPane.showMessageDialog(null, "<html>" + "Tool Preferences file: <br>" + strTargetFile | |
226 | + "<br>does not exist!</html>"); | |
227 | } | |
228 | } | |
229 | ||
230 | private void readToolDefinitionFile() { | |
231 | ||
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>" | |
242 | + defaultToolsConf); | |
243 | toolsConfFile = defaultToolsConf; | |
244 | } | |
245 | } else { | |
246 | toolsConfFile = defaultToolsConf; | |
247 | } | |
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()) { | |
253 | try { | |
254 | FileReader fileReader = new FileReader(toolDefFile); | |
255 | BufferedReader reader = new BufferedReader(fileReader); | |
256 | String rLine = null; | |
257 | String result[]; | |
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() + " "; | |
269 | } | |
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() + " "; | |
274 | } | |
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() + " "; | |
279 | } | |
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() + " "; | |
285 | } | |
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()) + " "; | |
290 | } | |
291 | ||
292 | toolDefinitionContents.add(rLine.trim().replaceAll(" ", "")); | |
293 | } | |
294 | } | |
295 | reader.close(); | |
296 | if (!toolsDefTargetNames.matches("[A-Z]+")) { | |
297 | toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim(); | |
298 | if (Debug) | |
299 | System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames | |
300 | + "'"); | |
301 | } | |
302 | } catch (IOException e) { | |
303 | Log.log(toolsConfFile + " Read Error ", e.getMessage()); | |
304 | e.printStackTrace(); | |
305 | } | |
306 | } | |
307 | } | |
308 | ||
309 | } |