]>
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) { | |
161 | if ((rLine.startsWith("ACTIVE_PLATFORM")) && (activePlatform == null)) { | |
162 | // Only one active platform is permitted! | |
163 | inLine = rLine.trim().split("="); | |
164 | activePlatform = inLine[1].trim(); | |
165 | } | |
166 | if ((rLine.startsWith("TARGET" + " ")) || (rLine.startsWith("TARGET" + "\t")) | |
167 | || (rLine.startsWith("TARGET="))) { | |
168 | // Handle multiple Target Names | |
169 | if (rLine.contains(",")) { | |
170 | inLine = rLine.trim().split("="); | |
171 | buildTargets = inLine[1].trim().replaceAll(",", " "); | |
172 | } else { | |
173 | inLine = rLine.trim().split("="); | |
174 | buildTargets = inLine[1].trim(); | |
175 | } | |
176 | } | |
177 | if (rLine.startsWith("TARGET_ARCH")) { | |
178 | // Handle multiple Target Architectures | |
179 | if (rLine.contains(",")) { | |
180 | inLine = rLine.trim().split("="); | |
181 | targetArchs = inLine[1].trim().replaceAll(",", " "); | |
182 | } else { | |
183 | inLine = rLine.trim().split("="); | |
184 | targetArchs = inLine[1].trim(); | |
185 | } | |
186 | } | |
187 | if (rLine.startsWith("TOOL_CHAIN_CONF")) { | |
188 | // Only one file is permitted | |
189 | inLine = rLine.trim().split("="); | |
190 | toolDefinitionFile = inLine[1].trim(); | |
191 | } | |
192 | ||
193 | if (rLine.startsWith("TOOL_CHAIN_TAG")) { | |
194 | // Handle multiple Tool TagNames | |
195 | if (rLine.contains(",")) { | |
196 | inLine = rLine.trim().split("="); | |
197 | tagNames = inLine[1].trim().replaceAll(",", " "); | |
198 | } else { | |
199 | inLine = rLine.trim().split("="); | |
200 | tagNames = inLine[1].trim(); | |
201 | } | |
202 | } | |
203 | ||
204 | if (rLine.startsWith("MULTIPLE_THREAD")) { | |
205 | // Handle Thread Enable flag | |
206 | if ((rLine.trim().toLowerCase().contains("enabled")) | |
207 | || (rLine.trim().toLowerCase().contains("true"))) { | |
208 | threadEnabled = true; | |
209 | } else { | |
210 | threadEnabled = false; | |
211 | } | |
212 | } | |
213 | ||
214 | if (rLine.startsWith("MAX_CONCURRENT_THREAD_NUMBER")) { | |
215 | // Handle Thread Enable flag | |
216 | inLine = rLine.trim().split("="); | |
217 | maxThreadCount = Integer.valueOf(inLine[1].trim()); | |
218 | } | |
219 | } | |
220 | reader.close(); | |
221 | } catch (IOException e) { | |
222 | Log.log(this.strTargetFile + " Read Error ", e.getMessage()); | |
223 | e.printStackTrace(); | |
224 | } | |
225 | } else { | |
82484861 | 226 | JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "<html>" + "Tool Preferences file: <br>" + strTargetFile |
52ee46a6 | 227 | + "<br>does not exist!</html>"); |
228 | } | |
229 | } | |
230 | ||
231 | private void readToolDefinitionFile() { | |
232 | ||
233 | // Parse the tool definition file looking for targets and architectures | |
234 | String toolsConfFile = null; | |
235 | if (toolDefinitionFile != null) { | |
236 | String resString = (Tools.convertPathToCurrentOsType(toolDefinitionFile)).trim(); | |
237 | toolsConfFile = Workspace.getCurrentWorkspace() + System.getProperty("file.separator") + resString.trim(); | |
238 | File toolsDefFile = new File(toolsConfFile); | |
239 | if (!toolsDefFile.exists()) { | |
82484861 | 240 | JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), "<html>" + "Tool Definition file, " + toolDefinitionFile |
52ee46a6 | 241 | + "<br>specified in the target.txt file does not exist!" |
242 | + "<br>Using the default Tool Definition File:<br>" | |
243 | + defaultToolsConf); | |
244 | toolsConfFile = defaultToolsConf; | |
245 | } | |
246 | } else { | |
247 | toolsConfFile = defaultToolsConf; | |
248 | } | |
249 | String[] toolsDefFields = new String[toolDefFieldCount]; | |
250 | for (int i = 0; i < toolDefFieldCount; i++) | |
251 | toolsDefFields[i] = null; | |
252 | File toolDefFile = new File(toolsConfFile); | |
253 | if (toolDefFile.exists()) { | |
254 | try { | |
255 | FileReader fileReader = new FileReader(toolDefFile); | |
256 | BufferedReader reader = new BufferedReader(fileReader); | |
257 | String rLine = null; | |
258 | String result[]; | |
259 | while ((rLine = reader.readLine()) != null) { | |
260 | if ((rLine.startsWith("IDENTIFIER")) && (toolsDefIdentifier == null)) { | |
261 | result = rLine.split("="); | |
262 | toolsDefIdentifier = (result[1]).trim(); | |
263 | } else if ((!rLine.startsWith("#")) && (rLine.contains("="))) { | |
264 | result = rLine.split("="); | |
265 | toolsDefFields = ((result[0]).trim()).split("_"); | |
266 | if (toolsDefTargetNames == null) { | |
267 | toolsDefTargetNames = (toolsDefFields[toolsDefTargetNameField]).toUpperCase().trim() + " "; | |
268 | } else if (!toolsDefTargetNames.contains((toolsDefFields[toolsDefTargetNameField]).toUpperCase().trim())) { | |
269 | toolsDefTargetNames += (toolsDefFields[toolsDefTargetNameField]).toUpperCase().trim() + " "; | |
270 | } | |
271 | if (toolsDefTagNames == null) { | |
272 | toolsDefTagNames = (toolsDefFields[toolsDefTagNameField]).toUpperCase().toUpperCase().trim() + " "; | |
273 | } else if (!toolsDefTagNames.contains((toolsDefFields[toolsDefTagNameField]).toUpperCase().trim())) { | |
274 | toolsDefTagNames += (toolsDefFields[toolsDefTagNameField]).toUpperCase().trim() + " "; | |
275 | } | |
276 | if (toolsDefArchNames == null) { | |
277 | toolsDefArchNames = (toolsDefFields[toolsDefArchNameField]).toUpperCase().trim() + " "; | |
278 | } else if (!toolsDefArchNames.contains((toolsDefFields[toolsDefArchNameField]).toUpperCase().trim())) { | |
279 | toolsDefArchNames += (toolsDefFields[toolsDefArchNameField]).toUpperCase().trim() + " "; | |
280 | } | |
281 | if ((toolFamilies == null) && (rLine.trim().contains("FAMILY"))) { | |
282 | toolFamilies = (toolsDefFields[toolsDefToolArgumentField]).toUpperCase().trim() + " "; | |
283 | } else if ((rLine.trim().contains("FAMILY")) | |
284 | && (!toolFamilies.contains((toolsDefFields[toolsDefToolArgumentField]).toUpperCase().trim()))) { | |
285 | toolFamilies += (toolsDefFields[toolsDefToolArgumentField]).toUpperCase().trim() + " "; | |
286 | } | |
287 | if ((toolCommandCodes == null)) { | |
288 | toolCommandCodes = (toolsDefFields[toolsDefCmdCodeArgumentField]).toUpperCase().trim() + " "; | |
289 | } else if ((!toolCommandCodes.contains((toolsDefFields[toolsDefCmdCodeArgumentField]).toUpperCase().trim()))) { | |
290 | toolCommandCodes += (toolsDefFields[toolsDefCmdCodeArgumentField].toUpperCase().trim()) + " "; | |
291 | } | |
292 | ||
293 | toolDefinitionContents.add(rLine.trim().replaceAll(" ", "")); | |
294 | } | |
295 | } | |
296 | reader.close(); | |
297 | if (!toolsDefTargetNames.matches("[A-Z]+")) { | |
298 | toolsDefTargetNames = toolsDefTargetNames.replace("* ", "").trim(); | |
299 | if (Debug) | |
300 | System.out.println("tools_def file does not define build targets: '" + toolsDefTargetNames | |
301 | + "'"); | |
302 | } | |
303 | } catch (IOException e) { | |
304 | Log.log(toolsConfFile + " Read Error ", e.getMessage()); | |
305 | e.printStackTrace(); | |
306 | } | |
307 | } | |
308 | } | |
309 | ||
310 | } |