878ddf1f |
1 | /** @file\r |
ff225cbb |
2 | This file is ANT task FpdParserTask.\r |
3 | \r |
a29c47e0 |
4 | FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r |
ff225cbb |
5 | build.out.xml. It is for Package or Platform build use.\r |
6 | \r |
a29c47e0 |
7 | Copyright (c) 2006, Intel Corporation\r |
8 | All rights reserved. This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r |
10 | which accompanies this distribution. The full text of the license may be found at\r |
11 | http://opensource.org/licenses/bsd-license.php\r |
12 | \r |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
15 | **/\r |
878ddf1f |
16 | package org.tianocore.build.fpd;\r |
17 | \r |
18 | import java.io.BufferedWriter;\r |
19 | import java.io.File;\r |
20 | import java.io.FileWriter;\r |
21 | import java.util.HashMap;\r |
22 | import java.util.Iterator;\r |
23 | import java.util.LinkedHashMap;\r |
24 | import java.util.LinkedHashSet;\r |
25 | import java.util.Map;\r |
26 | import java.util.Set;\r |
27 | import java.util.Vector;\r |
878ddf1f |
28 | \r |
29 | import org.apache.tools.ant.BuildException;\r |
30 | import org.apache.tools.ant.Task;\r |
a29c47e0 |
31 | import org.apache.tools.ant.taskdefs.Ant;\r |
878ddf1f |
32 | import org.apache.tools.ant.taskdefs.Property;\r |
33 | import org.apache.xmlbeans.XmlObject;\r |
878ddf1f |
34 | \r |
4a6a5026 |
35 | import org.tianocore.common.definitions.EdkDefinitions;\r |
ff225cbb |
36 | import org.tianocore.common.exception.EdkException;\r |
37 | import org.tianocore.pcd.action.ActionMessage;\r |
878ddf1f |
38 | import org.tianocore.build.global.GlobalData;\r |
39 | import org.tianocore.build.global.OutputManager;\r |
878ddf1f |
40 | import org.tianocore.build.global.SurfaceAreaQuery;\r |
a29c47e0 |
41 | import org.tianocore.build.id.FpdModuleIdentification;\r |
42 | import org.tianocore.build.id.ModuleIdentification;\r |
43 | import org.tianocore.build.id.PlatformIdentification;\r |
af98370e |
44 | import org.tianocore.build.pcd.action.PlatformPcdPreprocessActionForBuilding;\r |
a29c47e0 |
45 | import org.tianocore.build.toolchain.ToolChainAttribute;\r |
46 | import org.tianocore.build.toolchain.ToolChainElement;\r |
47 | import org.tianocore.build.toolchain.ToolChainMap;\r |
878ddf1f |
48 | \r |
49 | /**\r |
a29c47e0 |
50 | <code>FpdParserTask</code> is an ANT task. The main function is parsing Framework\r |
ff225cbb |
51 | Platform Descritpion (FPD) XML file and generating its ANT build script for\r |
52 | corresponding platform.\r |
a29c47e0 |
53 | \r |
54 | <p>The task sets global properties PLATFORM, PLATFORM_DIR, PLATFORM_RELATIVE_DIR\r |
55 | and BUILD_DIR. </p>\r |
ff225cbb |
56 | \r |
a29c47e0 |
57 | <p>The task generates ${PLATFORM}_build.xml file which will be called by top level\r |
4b5f5549 |
58 | build.xml. The task also generate Fv.inf files (File is for Tool GenFvImage). </p>\r |
ff225cbb |
59 | \r |
a29c47e0 |
60 | <p>FpdParserTask task stores all FPD information to GlobalData. And parse\r |
61 | tools definition file to set up compiler options for different Target and\r |
62 | different ToolChainTag. </p>\r |
ff225cbb |
63 | \r |
a29c47e0 |
64 | <p>The method parseFpdFile is also prepared for single module build. </p>\r |
ff225cbb |
65 | \r |
a29c47e0 |
66 | <p>The usage is (take NT32 Platform for example):</p>\r |
67 | \r |
878ddf1f |
68 | <pre>\r |
a29c47e0 |
69 | <FPDParser platformName="Nt32" />\r |
878ddf1f |
70 | </pre>\r |
a29c47e0 |
71 | \r |
878ddf1f |
72 | @since GenBuild 1.0\r |
73 | **/\r |
74 | public class FpdParserTask extends Task {\r |
ff225cbb |
75 | \r |
a29c47e0 |
76 | private String platformName;\r |
878ddf1f |
77 | \r |
a29c47e0 |
78 | private File fpdFile = null;\r |
ff225cbb |
79 | \r |
a29c47e0 |
80 | private PlatformIdentification platformId;\r |
ff225cbb |
81 | \r |
a29c47e0 |
82 | private String type;\r |
ff225cbb |
83 | \r |
878ddf1f |
84 | ///\r |
85 | /// Mapping from modules identification to out put file name\r |
86 | ///\r |
87 | private Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r |
88 | \r |
89 | ///\r |
90 | /// Mapping from FV name to its modules\r |
91 | ///\r |
a29c47e0 |
92 | private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r |
878ddf1f |
93 | \r |
878ddf1f |
94 | ///\r |
ff225cbb |
95 | /// FpdParserTask can specify some ANT properties.\r |
878ddf1f |
96 | ///\r |
97 | private Vector<Property> properties = new Vector<Property>();\r |
ff225cbb |
98 | \r |
83fba802 |
99 | SurfaceAreaQuery saq = null;\r |
100 | \r |
a29c47e0 |
101 | private boolean isUnified = true;\r |
878ddf1f |
102 | \r |
878ddf1f |
103 | /**\r |
104 | Public construct method. It is necessary for ANT task.\r |
105 | **/\r |
a29c47e0 |
106 | public FpdParserTask() {\r |
878ddf1f |
107 | }\r |
108 | \r |
109 | /**\r |
ff225cbb |
110 | ANT task's entry method. The main steps is described as following:\r |
111 | \r |
a29c47e0 |
112 | <ul>\r |
ff225cbb |
113 | <li>Initialize global information (Framework DB, SPD files and all MSA files\r |
a29c47e0 |
114 | listed in SPD). This step will execute only once in whole build process;</li>\r |
115 | <li>Parse specified FPD file; </li>\r |
116 | <li>Generate FV.inf files; </li>\r |
117 | <li>Generate PlatformName_build.xml file for Flatform build; </li>\r |
118 | <li>Collect PCD information. </li>\r |
119 | </ul>\r |
ff225cbb |
120 | \r |
a29c47e0 |
121 | @throws BuildException\r |
ff225cbb |
122 | Surface area is not valid.\r |
878ddf1f |
123 | **/\r |
124 | public void execute() throws BuildException {\r |
82516887 |
125 | //\r |
126 | // If fpdFile is not specified, \r |
127 | // then try to get FPD file by platformName\r |
128 | //\r |
a29c47e0 |
129 | if ( fpdFile == null) {\r |
130 | if (platformName == null) {\r |
391dbbb1 |
131 | throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!");\r |
a29c47e0 |
132 | }\r |
de4bb9f6 |
133 | platformId = GlobalData.getPlatformByName(platformName);\r |
a29c47e0 |
134 | fpdFile = platformId.getFpdFile();\r |
135 | }\r |
ff225cbb |
136 | \r |
878ddf1f |
137 | //\r |
138 | // Parse FPD file\r |
139 | //\r |
140 | parseFpdFile();\r |
ff225cbb |
141 | \r |
a29c47e0 |
142 | //\r |
143 | // Prepare BUILD_DIR\r |
878ddf1f |
144 | //\r |
a29c47e0 |
145 | isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r |
ff225cbb |
146 | \r |
a29c47e0 |
147 | //\r |
148 | // For every Target and ToolChain\r |
149 | //\r |
150 | String[] targetList = GlobalData.getToolChainInfo().getTargets();\r |
82516887 |
151 | for (int i = 0; i < targetList.length; i++) {\r |
a29c47e0 |
152 | String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r |
82516887 |
153 | for(int j = 0; j < toolchainList.length; j++) {\r |
a29c47e0 |
154 | //\r |
155 | // Prepare FV_DIR\r |
156 | //\r |
ff225cbb |
157 | String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar\r |
6ae1510e |
158 | + targetList[i] + "_"\r |
a29c47e0 |
159 | + toolchainList[j];\r |
160 | File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r |
161 | fvDir.mkdirs();\r |
162 | getProject().setProperty("FV_DIR", fvDir.getPath().replaceAll("(\\\\)", "/"));\r |
ff225cbb |
163 | \r |
a29c47e0 |
164 | //\r |
165 | // Gen Fv.inf files\r |
166 | //\r |
167 | genFvInfFiles(ffsCommonDir);\r |
168 | }\r |
169 | }\r |
170 | \r |
878ddf1f |
171 | //\r |
172 | // Gen build.xml\r |
173 | //\r |
83fba802 |
174 | PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq);\r |
a29c47e0 |
175 | fileGenerator.genBuildFile();\r |
ff225cbb |
176 | \r |
a29c47e0 |
177 | //\r |
178 | // Ant call ${PLATFORM}_build.xml\r |
878ddf1f |
179 | //\r |
ff225cbb |
180 | \r |
a29c47e0 |
181 | Ant ant = new Ant();\r |
182 | ant.setProject(getProject());\r |
183 | ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r |
184 | ant.setTarget(type);\r |
185 | ant.setInheritAll(true);\r |
186 | ant.init();\r |
187 | ant.execute();\r |
878ddf1f |
188 | }\r |
a29c47e0 |
189 | \r |
878ddf1f |
190 | /**\r |
ff225cbb |
191 | Generate Fv.inf files. The Fv.inf file is composed with four\r |
192 | parts: Options, Attributes, Components and Files. The Fv.inf files\r |
a29c47e0 |
193 | will be under FV_DIR.\r |
ff225cbb |
194 | \r |
878ddf1f |
195 | @throws BuildException\r |
ff225cbb |
196 | File write FV.inf files error.\r |
878ddf1f |
197 | **/\r |
a29c47e0 |
198 | private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r |
83fba802 |
199 | String[] validFv = saq.getFpdValidImageNames();\r |
878ddf1f |
200 | for (int i = 0; i < validFv.length; i++) {\r |
878ddf1f |
201 | //\r |
202 | // Get all global variables from FPD and set them to properties\r |
203 | //\r |
83fba802 |
204 | String[][] globalVariables = saq.getFpdGlobalVariable();\r |
878ddf1f |
205 | for (int j = 0; j < globalVariables.length; j++) {\r |
a29c47e0 |
206 | getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r |
878ddf1f |
207 | }\r |
208 | \r |
57cc2ee7 |
209 | getProject().setProperty("FV_FILENAME", validFv[i]);\r |
ff225cbb |
210 | \r |
57cc2ee7 |
211 | File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i] + ".inf"));\r |
878ddf1f |
212 | fvFile.getParentFile().mkdirs();\r |
213 | \r |
214 | try {\r |
215 | FileWriter fw = new FileWriter(fvFile);\r |
216 | BufferedWriter bw = new BufferedWriter(fw);\r |
ff225cbb |
217 | \r |
878ddf1f |
218 | //\r |
219 | // Options\r |
220 | //\r |
83fba802 |
221 | String[][] options = saq.getFpdOptions(validFv[i]);\r |
878ddf1f |
222 | if (options.length > 0) {\r |
223 | bw.write("[options]");\r |
224 | bw.newLine();\r |
225 | for (int j = 0; j < options.length; j++) {\r |
226 | StringBuffer str = new StringBuffer(100);\r |
227 | str.append(options[j][0]);\r |
228 | while (str.length() < 40) {\r |
229 | str.append(' ');\r |
230 | }\r |
231 | str.append("= ");\r |
232 | str.append(options[j][1]);\r |
233 | bw.write(getProject().replaceProperties(str.toString()));\r |
234 | bw.newLine();\r |
235 | }\r |
236 | bw.newLine();\r |
237 | }\r |
ff225cbb |
238 | \r |
878ddf1f |
239 | //\r |
240 | // Attributes;\r |
241 | //\r |
83fba802 |
242 | String[][] attributes = saq.getFpdAttributes(validFv[i]);\r |
878ddf1f |
243 | if (attributes.length > 0) {\r |
244 | bw.write("[attributes]");\r |
245 | bw.newLine();\r |
246 | for (int j = 0; j < attributes.length; j++) {\r |
247 | StringBuffer str = new StringBuffer(100);\r |
248 | str.append(attributes[j][0]);\r |
249 | while (str.length() < 40) {\r |
250 | str.append(' ');\r |
251 | }\r |
252 | str.append("= ");\r |
253 | str.append(attributes[j][1]);\r |
a29c47e0 |
254 | bw.write(getProject().replaceProperties(str.toString()));\r |
878ddf1f |
255 | bw.newLine();\r |
256 | }\r |
257 | bw.newLine();\r |
258 | }\r |
ff225cbb |
259 | \r |
878ddf1f |
260 | //\r |
261 | // Components\r |
262 | //\r |
83fba802 |
263 | String[][] components = saq.getFpdComponents(validFv[i]);\r |
878ddf1f |
264 | if (components.length > 0) {\r |
265 | bw.write("[components]");\r |
266 | bw.newLine();\r |
267 | for (int j = 0; j < components.length; j++) {\r |
268 | StringBuffer str = new StringBuffer(100);\r |
269 | str.append(components[j][0]);\r |
270 | while (str.length() < 40) {\r |
271 | str.append(' ');\r |
272 | }\r |
273 | str.append("= ");\r |
274 | str.append(components[j][1]);\r |
a29c47e0 |
275 | bw.write(getProject().replaceProperties(str.toString()));\r |
878ddf1f |
276 | bw.newLine();\r |
277 | }\r |
278 | bw.newLine();\r |
279 | }\r |
ff225cbb |
280 | \r |
878ddf1f |
281 | //\r |
282 | // Files\r |
283 | //\r |
57cc2ee7 |
284 | Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i]);\r |
878ddf1f |
285 | if (filesSet != null) {\r |
a29c47e0 |
286 | FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);\r |
878ddf1f |
287 | bw.write("[files]");\r |
288 | bw.newLine();\r |
289 | for (int j = 0; j < files.length; j++) {\r |
a29c47e0 |
290 | String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r |
291 | bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r |
878ddf1f |
292 | bw.newLine();\r |
293 | }\r |
294 | }\r |
295 | bw.flush();\r |
296 | bw.close();\r |
297 | fw.close();\r |
298 | } catch (Exception e) {\r |
391dbbb1 |
299 | throw new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + e.getMessage());\r |
878ddf1f |
300 | }\r |
301 | }\r |
302 | }\r |
a29c47e0 |
303 | /**\r |
304 | This method is used for Single Module Build.\r |
ff225cbb |
305 | \r |
306 | \r |
a29c47e0 |
307 | @throws BuildException\r |
ff225cbb |
308 | FPD file is not valid.\r |
a29c47e0 |
309 | **/\r |
07193171 |
310 | public void parseFpdFile(File fpdFile) throws BuildException {\r |
a29c47e0 |
311 | this.fpdFile = fpdFile;\r |
a29c47e0 |
312 | }\r |
878ddf1f |
313 | \r |
314 | /**\r |
ff225cbb |
315 | Parse FPD file.\r |
316 | \r |
878ddf1f |
317 | @throws BuildException\r |
ff225cbb |
318 | FPD file is not valid.\r |
a29c47e0 |
319 | **/\r |
07193171 |
320 | private void parseFpdFile() throws BuildException {\r |
878ddf1f |
321 | try {\r |
a29c47e0 |
322 | XmlObject doc = XmlObject.Factory.parse(fpdFile);\r |
ff225cbb |
323 | \r |
a29c47e0 |
324 | if (!doc.validate()) {\r |
391dbbb1 |
325 | throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r |
878ddf1f |
326 | }\r |
ff225cbb |
327 | \r |
a29c47e0 |
328 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r |
329 | map.put("PlatformSurfaceArea", doc);\r |
83fba802 |
330 | saq = new SurfaceAreaQuery(map);\r |
8031d48d |
331 | \r |
a29c47e0 |
332 | //\r |
333 | // Initialize\r |
334 | //\r |
83fba802 |
335 | platformId = saq.getFpdHeader();\r |
a29c47e0 |
336 | platformId.setFpdFile(fpdFile);\r |
de4bb9f6 |
337 | getProject().setProperty("PLATFORM", platformId.getName());\r |
338 | getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r |
339 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r |
340 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r |
a29c47e0 |
341 | \r |
342 | //\r |
ff225cbb |
343 | // Build mode. User-defined output dir.\r |
a29c47e0 |
344 | //\r |
83fba802 |
345 | String buildMode = saq.getFpdIntermediateDirectories();\r |
346 | String userDefinedOutputDir = saq.getFpdOutputDirectory();\r |
a29c47e0 |
347 | \r |
348 | OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r |
349 | \r |
350 | //\r |
351 | // TBD. Deal PCD and BuildOption related Info\r |
352 | //\r |
83fba802 |
353 | GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions());\r |
ff225cbb |
354 | \r |
83fba802 |
355 | GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo());\r |
ff225cbb |
356 | \r |
878ddf1f |
357 | //\r |
358 | // Parse all list modules SA\r |
359 | //\r |
07193171 |
360 | parseModuleSAFiles();\r |
a29c47e0 |
361 | \r |
362 | //\r |
363 | // TBD. Deal PCD and BuildOption related Info\r |
364 | //\r |
365 | parseToolChainFamilyOptions();\r |
366 | parseToolChainOptions();\r |
367 | \r |
83fba802 |
368 | saq.push(map);\r |
ff225cbb |
369 | \r |
de4bb9f6 |
370 | //\r |
371 | // Pcd Collection. Call CollectPCDAction to collect pcd info.\r |
372 | //\r |
8b7bd455 |
373 | PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r |
374 | ca.perform(platformId.getFpdFile().getPath(), ActionMessage.NULL_MESSAGE_LEVEL);\r |
878ddf1f |
375 | } catch (Exception e) {\r |
391dbbb1 |
376 | throw new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + e.getMessage());\r |
878ddf1f |
377 | }\r |
378 | }\r |
379 | \r |
380 | /**\r |
ff225cbb |
381 | Parse all modules listed in FPD file.\r |
878ddf1f |
382 | **/\r |
07193171 |
383 | private void parseModuleSAFiles() throws EdkException{\r |
83fba802 |
384 | Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = saq.getFpdModules();\r |
136adffc |
385 | \r |
878ddf1f |
386 | //\r |
387 | // For every Module lists in FPD file.\r |
388 | //\r |
a29c47e0 |
389 | Set<FpdModuleIdentification> keys = moduleSAs.keySet();\r |
390 | Iterator iter = keys.iterator();\r |
391 | while (iter.hasNext()) {\r |
392 | FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r |
ff225cbb |
393 | \r |
878ddf1f |
394 | //\r |
ff225cbb |
395 | // Judge if Module is existed?\r |
a29c47e0 |
396 | // TBD\r |
a29c47e0 |
397 | GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r |
398 | \r |
878ddf1f |
399 | //\r |
a29c47e0 |
400 | // Put fpdModuleId to the corresponding FV\r |
878ddf1f |
401 | //\r |
83fba802 |
402 | saq.push(GlobalData.getDoc(fpdModuleId));\r |
403 | String fvBinding = saq.getModuleFvBindingKeyword();\r |
a29c47e0 |
404 | \r |
405 | fpdModuleId.setFvBinding(fvBinding);\r |
01413f0c |
406 | updateFvs(fvBinding, fpdModuleId);\r |
ff225cbb |
407 | \r |
878ddf1f |
408 | //\r |
a29c47e0 |
409 | // Prepare for out put file name\r |
878ddf1f |
410 | //\r |
a29c47e0 |
411 | ModuleIdentification moduleId = fpdModuleId.getModule();\r |
82516887 |
412 | \r |
83fba802 |
413 | String baseName = saq.getModuleOutputFileBasename();\r |
82516887 |
414 | \r |
a29c47e0 |
415 | if (baseName == null) {\r |
416 | baseName = moduleId.getName();\r |
878ddf1f |
417 | }\r |
ff225cbb |
418 | outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar\r |
419 | + moduleId.getGuid() + "-" + baseName\r |
a29c47e0 |
420 | + getSuffix(moduleId.getModuleType()));\r |
421 | \r |
422 | //\r |
423 | // parse module build options, if any\r |
ff225cbb |
424 | //\r |
a29c47e0 |
425 | GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r |
426 | GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r |
83fba802 |
427 | saq.pop();\r |
878ddf1f |
428 | }\r |
429 | }\r |
430 | \r |
a29c47e0 |
431 | private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r |
83fba802 |
432 | String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag);\r |
a29c47e0 |
433 | if (options == null || options.length == 0) {\r |
80eb97ff |
434 | return new ToolChainMap();\r |
878ddf1f |
435 | }\r |
a29c47e0 |
436 | return parseOptions(options);\r |
878ddf1f |
437 | }\r |
ff225cbb |
438 | \r |
a29c47e0 |
439 | private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r |
83fba802 |
440 | String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag);\r |
a29c47e0 |
441 | if (options == null || options.length == 0) {\r |
80eb97ff |
442 | return new ToolChainMap();\r |
878ddf1f |
443 | }\r |
a29c47e0 |
444 | return parseOptions(options);\r |
878ddf1f |
445 | }\r |
446 | \r |
a29c47e0 |
447 | private ToolChainMap parseOptions(String[][] options) throws EdkException {\r |
448 | ToolChainMap map = new ToolChainMap();\r |
449 | int flagIndex = ToolChainElement.ATTRIBUTE.value;\r |
450 | \r |
451 | for (int i = 0; i < options.length; ++i) {\r |
452 | String flagString = options[i][flagIndex];\r |
453 | if (flagString == null) {\r |
454 | flagString = "";\r |
455 | }\r |
456 | options[i][flagIndex] = ToolChainAttribute.FLAGS + "";\r |
457 | map.put(options[i], flagString.trim());\r |
458 | }\r |
459 | \r |
878ddf1f |
460 | return map;\r |
461 | }\r |
ff225cbb |
462 | \r |
a29c47e0 |
463 | private void parseToolChainFamilyOptions() throws EdkException {\r |
464 | GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));\r |
465 | }\r |
466 | \r |
467 | private void parseToolChainOptions() throws EdkException {\r |
468 | GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));\r |
469 | }\r |
878ddf1f |
470 | \r |
471 | /**\r |
ff225cbb |
472 | Add the current module to corresponding FV.\r |
473 | \r |
a29c47e0 |
474 | @param fvName current FV name\r |
475 | @param moduleName current module identification\r |
878ddf1f |
476 | **/\r |
01413f0c |
477 | private void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r |
fa2da5b1 |
478 | if (fvName == null || fvName.trim().length() == 0) {\r |
479 | fvName = "NULL";\r |
480 | }\r |
57cc2ee7 |
481 | String[] fvNameArray = fvName.split("[, \t]+");\r |
a29c47e0 |
482 | for (int i = 0; i < fvNameArray.length; i++) {\r |
878ddf1f |
483 | //\r |
a29c47e0 |
484 | // Put module to corresponding fvName\r |
878ddf1f |
485 | //\r |
a29c47e0 |
486 | if (fvs.containsKey(fvNameArray[i])) {\r |
487 | Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r |
488 | set.add(fpdModuleId);\r |
82516887 |
489 | } else {\r |
a29c47e0 |
490 | Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r |
491 | set.add(fpdModuleId);\r |
492 | fvs.put(fvNameArray[i], set);\r |
878ddf1f |
493 | }\r |
878ddf1f |
494 | }\r |
495 | }\r |
496 | \r |
497 | /**\r |
ff225cbb |
498 | Get the suffix based on module type. Current relationship are listed:\r |
499 | \r |
a29c47e0 |
500 | <pre>\r |
501 | <b>ModuleType</b> <b>Suffix</b>\r |
502 | BASE .FFS\r |
503 | SEC .SEC\r |
504 | PEI_CORE .PEI\r |
505 | PEIM .PEI\r |
506 | DXE_CORE .DXE\r |
507 | DXE_DRIVER .DXE\r |
508 | DXE_RUNTIME_DRIVER .DXE\r |
509 | DXE_SAL_DRIVER .DXE\r |
510 | DXE_SMM_DRIVER .DXE\r |
511 | TOOL .FFS\r |
512 | UEFI_DRIVER .DXE\r |
513 | UEFI_APPLICATION .APP\r |
514 | USER_DEFINED .FFS\r |
515 | </pre>\r |
ff225cbb |
516 | \r |
a29c47e0 |
517 | @param moduleType module type\r |
518 | @return\r |
519 | @throws BuildException\r |
520 | If module type is null\r |
878ddf1f |
521 | **/\r |
a29c47e0 |
522 | public static String getSuffix(String moduleType) throws BuildException {\r |
523 | if (moduleType == null) {\r |
524 | throw new BuildException("Module type is not specified.");\r |
525 | }\r |
878ddf1f |
526 | \r |
4a6a5026 |
527 | String[][] suffix = EdkDefinitions.ModuleTypeExtensions;\r |
ff225cbb |
528 | \r |
a29c47e0 |
529 | for (int i = 0; i < suffix.length; i++) {\r |
530 | if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r |
531 | return suffix[i][1];\r |
532 | }\r |
533 | }\r |
534 | //\r |
535 | // Default is '.FFS'\r |
536 | //\r |
537 | return ".FFS";\r |
878ddf1f |
538 | }\r |
878ddf1f |
539 | /**\r |
ff225cbb |
540 | Add a property.\r |
541 | \r |
a29c47e0 |
542 | @param p property\r |
543 | **/\r |
544 | public void addProperty(Property p) {\r |
545 | properties.addElement(p);\r |
878ddf1f |
546 | }\r |
547 | \r |
a29c47e0 |
548 | public void setPlatformName(String platformName) {\r |
549 | this.platformName = platformName;\r |
878ddf1f |
550 | }\r |
551 | \r |
a29c47e0 |
552 | public void setFpdFile(File fpdFile) {\r |
553 | this.fpdFile = fpdFile;\r |
878ddf1f |
554 | }\r |
555 | \r |
a29c47e0 |
556 | public void setType(String type) {\r |
557 | this.type = type;\r |
878ddf1f |
558 | }\r |
3790e93c |
559 | \r |
560 | public String getAllArchForModule(ModuleIdentification moduleId) {\r |
561 | String archs = "";\r |
562 | Iterator<FpdModuleIdentification> iter = outfiles.keySet().iterator();\r |
563 | while (iter.hasNext()) {\r |
564 | FpdModuleIdentification fpdModuleId = iter.next();\r |
565 | \r |
566 | if (fpdModuleId.getModule().equals(moduleId)) {\r |
567 | archs += fpdModuleId.getArch() + " ";\r |
568 | }\r |
569 | }\r |
570 | \r |
571 | return archs;\r |
572 | }\r |
878ddf1f |
573 | }\r |