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