Move ant-related code from ParserFpd function to enable single module debug for PCD...
[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
7629edbc 150\r
151 getProject().setProperty("PLATFORM", platformId.getName());\r
152 getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r
153 getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r
154\r
136adffc 155 //\r
156 // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
157 //\r
158 try {\r
136adffc 159 CollectPCDAction ca = new CollectPCDAction();\r
160 ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);\r
136adffc 161 } catch (Exception e){\r
162 throw new BuildException(e.getMessage());\r
163 }\r
164 \r
a29c47e0 165 //\r
166 // Prepare BUILD_DIR\r
878ddf1f 167 //\r
a29c47e0 168 isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r
169 \r
878ddf1f 170 //\r
a29c47e0 171 // Generate FDF (Flash Definition File) file\r
172 //\r
173\r
174 //\r
175 // For every Target and ToolChain\r
176 //\r
177 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
178 for (int i = 0; i < targetList.length; i++){\r
179 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
180 for(int j = 0; j < toolchainList.length; j++){\r
181 //\r
182 // Prepare FV_DIR\r
183 //\r
184 String ffsCommonDir = getProject().getProperty("BUILD_DIR") + File.separatorChar \r
185 + targetList[i] + File.separatorChar \r
186 + toolchainList[j];\r
187 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
188 fvDir.mkdirs();\r
189 getProject().setProperty("FV_DIR", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
190 \r
191 //\r
192 // Gen Fv.inf files\r
193 //\r
194 genFvInfFiles(ffsCommonDir);\r
195 }\r
196 }\r
197\r
878ddf1f 198 //\r
199 // Gen build.xml\r
200 //\r
a29c47e0 201 PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, sequences, isUnified);\r
202 fileGenerator.genBuildFile();\r
203 \r
204 //\r
205 // Ant call ${PLATFORM}_build.xml\r
878ddf1f 206 //\r
136adffc 207 \r
a29c47e0 208 Ant ant = new Ant();\r
209 ant.setProject(getProject());\r
210 ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");\r
211 ant.setTarget(type);\r
212 ant.setInheritAll(true);\r
213 ant.init();\r
214 ant.execute();\r
215 \r
216// GlobalData.log.info("Fpd build end. ");\r
878ddf1f 217 }\r
a29c47e0 218\r
878ddf1f 219 /**\r
220 Generate Fv.inf files. The Fv.inf file is composed with four \r
221 parts: Options, Attributes, Components and Files. The Fv.inf files \r
a29c47e0 222 will be under FV_DIR.\r
223 \r
878ddf1f 224 @throws BuildException\r
a29c47e0 225 File write FV.inf files error. \r
878ddf1f 226 **/\r
a29c47e0 227 private void genFvInfFiles(String ffsCommonDir) throws BuildException {\r
878ddf1f 228 String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
229 for (int i = 0; i < validFv.length; i++) {\r
878ddf1f 230 //\r
231 // Get all global variables from FPD and set them to properties\r
232 //\r
a29c47e0 233 String[][] globalVariables = SurfaceAreaQuery.getFpdGlobalVariable();\r
878ddf1f 234 for (int j = 0; j < globalVariables.length; j++) {\r
a29c47e0 235 getProject().setProperty(globalVariables[j][0], globalVariables[j][1]);\r
878ddf1f 236 }\r
237\r
a29c47e0 238 getProject().setProperty("FV_FILENAME", validFv[i].toUpperCase());\r
239 \r
240 File fvFile = new File(getProject().replaceProperties( getProject().getProperty("FV_DIR") + File.separatorChar + validFv[i].toUpperCase() + ".inf"));\r
878ddf1f 241 fvFile.getParentFile().mkdirs();\r
242\r
243 try {\r
244 FileWriter fw = new FileWriter(fvFile);\r
245 BufferedWriter bw = new BufferedWriter(fw);\r
a29c47e0 246 \r
878ddf1f 247 //\r
248 // Options\r
249 //\r
250 String[][] options = SurfaceAreaQuery.getFpdOptions(validFv[i]);\r
251 if (options.length > 0) {\r
252 bw.write("[options]");\r
253 bw.newLine();\r
254 for (int j = 0; j < options.length; j++) {\r
255 StringBuffer str = new StringBuffer(100);\r
256 str.append(options[j][0]);\r
257 while (str.length() < 40) {\r
258 str.append(' ');\r
259 }\r
260 str.append("= ");\r
261 str.append(options[j][1]);\r
262 bw.write(getProject().replaceProperties(str.toString()));\r
263 bw.newLine();\r
264 }\r
265 bw.newLine();\r
266 }\r
a29c47e0 267 \r
878ddf1f 268 //\r
269 // Attributes;\r
270 //\r
a29c47e0 271 String[][] attributes = SurfaceAreaQuery.getFpdAttributes(validFv[i]);\r
878ddf1f 272 if (attributes.length > 0) {\r
273 bw.write("[attributes]");\r
274 bw.newLine();\r
275 for (int j = 0; j < attributes.length; j++) {\r
276 StringBuffer str = new StringBuffer(100);\r
277 str.append(attributes[j][0]);\r
278 while (str.length() < 40) {\r
279 str.append(' ');\r
280 }\r
281 str.append("= ");\r
282 str.append(attributes[j][1]);\r
a29c47e0 283 bw.write(getProject().replaceProperties(str.toString()));\r
878ddf1f 284 bw.newLine();\r
285 }\r
286 bw.newLine();\r
287 }\r
a29c47e0 288 \r
878ddf1f 289 //\r
290 // Components\r
291 //\r
a29c47e0 292 String[][] components = SurfaceAreaQuery.getFpdComponents(validFv[i]);\r
878ddf1f 293 if (components.length > 0) {\r
294 bw.write("[components]");\r
295 bw.newLine();\r
296 for (int j = 0; j < components.length; j++) {\r
297 StringBuffer str = new StringBuffer(100);\r
298 str.append(components[j][0]);\r
299 while (str.length() < 40) {\r
300 str.append(' ');\r
301 }\r
302 str.append("= ");\r
303 str.append(components[j][1]);\r
a29c47e0 304 bw.write(getProject().replaceProperties(str.toString()));\r
878ddf1f 305 bw.newLine();\r
306 }\r
307 bw.newLine();\r
308 }\r
a29c47e0 309 \r
878ddf1f 310 //\r
311 // Files\r
312 //\r
313 Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i].toUpperCase());\r
314 if (filesSet != null) {\r
a29c47e0 315 FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);\r
878ddf1f 316 bw.write("[files]");\r
317 bw.newLine();\r
318 for (int j = 0; j < files.length; j++) {\r
a29c47e0 319 String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r
320 bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r
878ddf1f 321 bw.newLine();\r
322 }\r
323 }\r
324 bw.flush();\r
325 bw.close();\r
326 fw.close();\r
327 } catch (Exception e) {\r
a29c47e0 328 e.printStackTrace();\r
329 throw new BuildException("Generate FV file [" + fvFile.getPath() + "] failed. \n" + e.getMessage());\r
878ddf1f 330 }\r
331 }\r
332 }\r
a29c47e0 333 /**\r
334 This method is used for Single Module Build.\r
335 \r
336 \r
337 @throws BuildException\r
338 FPD file is not valid. \r
339 **/\r
340 public void parseFpdFile(File fpdFile) throws BuildException {\r
341 this.fpdFile = fpdFile;\r
342 parseFpdFile();\r
343 }\r
878ddf1f 344\r
345 /**\r
346 Parse FPD file. \r
a29c47e0 347 \r
878ddf1f 348 @throws BuildException\r
a29c47e0 349 FPD file is not valid. \r
350 **/\r
878ddf1f 351 private void parseFpdFile() throws BuildException {\r
352 try {\r
a29c47e0 353 XmlObject doc = XmlObject.Factory.parse(fpdFile);\r
354 \r
355 if (!doc.validate()) {\r
356 throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] is invalid.");\r
878ddf1f 357 }\r
a29c47e0 358 \r
359 Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
360 map.put("PlatformSurfaceArea", doc);\r
878ddf1f 361 SurfaceAreaQuery.setDoc(map);\r
a29c47e0 362 \r
363 //\r
364 // Initialize\r
365 //\r
366 platformId = SurfaceAreaQuery.getFpdHeader();\r
367 platformId.setFpdFile(fpdFile);\r
a29c47e0 368\r
369 //\r
370 // Build mode. User-defined output dir. \r
371 //\r
372 String buildMode = SurfaceAreaQuery.getFpdIntermediateDirectories();\r
373 String userDefinedOutputDir = SurfaceAreaQuery.getFpdOutputDirectory();\r
374\r
375 OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r
376\r
377 //\r
378 // TBD. Deal PCD and BuildOption related Info\r
379 //\r
380 GlobalData.setFpdBuildOptions(SurfaceAreaQuery.getFpdBuildOptions());\r
381 \r
382 GlobalData.setToolChainPlatformInfo(SurfaceAreaQuery.getFpdToolChainInfo());\r
383 \r
878ddf1f 384 //\r
385 // Parse all list modules SA\r
386 //\r
387 parseModuleSAFiles();\r
a29c47e0 388\r
389 //\r
390 // TBD. Deal PCD and BuildOption related Info\r
391 //\r
392 parseToolChainFamilyOptions();\r
393 parseToolChainOptions();\r
394\r
878ddf1f 395 SurfaceAreaQuery.setDoc(map);\r
396 } catch (Exception e) {\r
a29c47e0 397 e.printStackTrace();\r
398 throw new BuildException("Load FPD file [" + fpdFile.getPath() + "] error. \n" + e.getMessage());\r
878ddf1f 399 }\r
400 }\r
401\r
a29c47e0 402\r
403 \r
878ddf1f 404 /**\r
405 Parse all modules listed in FPD file. \r
406 **/\r
a29c47e0 407 private void parseModuleSAFiles() throws EdkException{\r
408 Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = SurfaceAreaQuery.getFpdModules();\r
136adffc 409\r
878ddf1f 410 //\r
411 // For every Module lists in FPD file.\r
412 //\r
a29c47e0 413 Set<FpdModuleIdentification> keys = moduleSAs.keySet();\r
414 Iterator iter = keys.iterator();\r
415 while (iter.hasNext()) {\r
416 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
417 \r
878ddf1f 418 //\r
a29c47e0 419 // Judge if Module is existed? \r
420 // TBD\r
421 \r
422 GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r
423\r
878ddf1f 424 //\r
a29c47e0 425 // Put fpdModuleId to the corresponding FV\r
878ddf1f 426 //\r
a29c47e0 427 SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
428 String fvBinding = SurfaceAreaQuery.getModuleFvBindingKeyword();\r
429 SurfaceAreaQuery.pop();\r
430\r
431 fpdModuleId.setFvBinding(fvBinding);\r
432 String fvSequence = fpdModuleId.getSequence();\r
433 updateFvs(fvSequence, fvBinding, fpdModuleId);\r
434 \r
878ddf1f 435 //\r
a29c47e0 436 // Prepare for out put file name\r
878ddf1f 437 //\r
a29c47e0 438 ModuleIdentification moduleId = fpdModuleId.getModule();\r
439 SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
440 String baseName = SurfaceAreaQuery.getModuleOutputFileBasename();\r
441 SurfaceAreaQuery.pop();\r
442 if (baseName == null) {\r
443 baseName = moduleId.getName();\r
878ddf1f 444 }\r
a29c47e0 445 outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar \r
446 + moduleId.getGuid() + "-" + baseName \r
447 + getSuffix(moduleId.getModuleType()));\r
448\r
449 //\r
450 // parse module build options, if any\r
451 // \r
452 SurfaceAreaQuery.push(GlobalData.getDoc(fpdModuleId));\r
453 GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r
454 GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r
455 SurfaceAreaQuery.pop();\r
878ddf1f 456 }\r
457 }\r
458\r
a29c47e0 459 private ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
460 String[][] options = SurfaceAreaQuery.getModuleBuildOptions(toolChainFamilyFlag);\r
461 if (options == null || options.length == 0) {\r
462 return null;\r
878ddf1f 463 }\r
a29c47e0 464 return parseOptions(options);\r
878ddf1f 465 }\r
878ddf1f 466 \r
a29c47e0 467 private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r
468 String[][] options = SurfaceAreaQuery.getPlatformBuildOptions(toolChainFamilyFlag);\r
469 if (options == null || options.length == 0) {\r
470 return null;\r
878ddf1f 471 }\r
a29c47e0 472 return parseOptions(options);\r
878ddf1f 473 }\r
474\r
a29c47e0 475 private ToolChainMap parseOptions(String[][] options) throws EdkException {\r
476 ToolChainMap map = new ToolChainMap();\r
477 int flagIndex = ToolChainElement.ATTRIBUTE.value;\r
478\r
479 for (int i = 0; i < options.length; ++i) {\r
480 String flagString = options[i][flagIndex];\r
481 if (flagString == null) {\r
482 flagString = "";\r
483 }\r
484 options[i][flagIndex] = ToolChainAttribute.FLAGS + "";\r
485 map.put(options[i], flagString.trim());\r
486 }\r
487\r
878ddf1f 488 return map;\r
489 }\r
a29c47e0 490 \r
491 private void parseToolChainFamilyOptions() throws EdkException {\r
492 GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));\r
493 }\r
494\r
495 private void parseToolChainOptions() throws EdkException {\r
496 GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));\r
497 }\r
878ddf1f 498\r
499 /**\r
a29c47e0 500 Add the current module to corresponding FV. \r
501 \r
502 @param fvName current FV name\r
503 @param moduleName current module identification\r
878ddf1f 504 **/\r
a29c47e0 505 private void updateFvs(String fvSequence, String fvName, FpdModuleIdentification fpdModuleId) {\r
506 String upcaseFvName = fvName.toUpperCase();\r
507 String[] fvNameArray = upcaseFvName.split("[, \t]+");\r
508 for (int i = 0; i < fvNameArray.length; i++) {\r
878ddf1f 509 //\r
a29c47e0 510 // Put module to corresponding fvName\r
878ddf1f 511 //\r
a29c47e0 512 if (fvs.containsKey(fvNameArray[i])) {\r
513 Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r
514 set.add(fpdModuleId);\r
878ddf1f 515 }\r
516 else {\r
a29c47e0 517 Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
518 set.add(fpdModuleId);\r
519 fvs.put(fvNameArray[i], set);\r
878ddf1f 520 }\r
a29c47e0 521 \r
878ddf1f 522 //\r
a29c47e0 523 // Put fvName to corresponding fvSequence\r
878ddf1f 524 //\r
a29c47e0 525 if (sequences.containsKey(fvSequence)) {\r
526 Set<String> set = sequences.get(fvSequence);\r
527 set.add(fvNameArray[i]);\r
878ddf1f 528 }\r
529 else {\r
a29c47e0 530 Set<String> set = new LinkedHashSet<String>();\r
531 set.add(fvNameArray[i]);\r
532 sequences.put(fvSequence, set);\r
878ddf1f 533 }\r
878ddf1f 534 }\r
535 }\r
536\r
537 /**\r
a29c47e0 538 Get the suffix based on module type. Current relationship are listed: \r
878ddf1f 539 \r
a29c47e0 540 <pre>\r
541 <b>ModuleType</b> <b>Suffix</b>\r
542 BASE .FFS\r
543 SEC .SEC\r
544 PEI_CORE .PEI\r
545 PEIM .PEI\r
546 DXE_CORE .DXE\r
547 DXE_DRIVER .DXE\r
548 DXE_RUNTIME_DRIVER .DXE\r
549 DXE_SAL_DRIVER .DXE\r
550 DXE_SMM_DRIVER .DXE\r
551 TOOL .FFS\r
552 UEFI_DRIVER .DXE\r
553 UEFI_APPLICATION .APP\r
554 USER_DEFINED .FFS\r
555 </pre>\r
556 \r
557 @param moduleType module type\r
558 @return\r
559 @throws BuildException\r
560 If module type is null\r
878ddf1f 561 **/\r
a29c47e0 562 public static String getSuffix(String moduleType) throws BuildException {\r
563 if (moduleType == null) {\r
564 throw new BuildException("Module type is not specified.");\r
565 }\r
878ddf1f 566\r
a29c47e0 567 String[][] suffix = { { "BASE", ".FFS"},\r
568 { "SEC", ".SEC" }, { "PEI_CORE", ".PEI" }, \r
569 { "PEIM", ".PEI" }, { "DXE_CORE", ".DXE" },\r
570 { "DXE_DRIVER", ".DXE" }, { "DXE_RUNTIME_DRIVER", ".DXE" }, \r
571 { "DXE_SAL_DRIVER", ".DXE" }, { "DXE_SMM_DRIVER", ".DXE" }, \r
572 { "TOOL", ".FFS" }, { "UEFI_DRIVER", ".DXE" },\r
573 { "UEFI_APPLICATION", ".APP" }, { "USER_DEFINED", ".FFS" } };\r
574 \r
575 for (int i = 0; i < suffix.length; i++) {\r
576 if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r
577 return suffix[i][1];\r
578 }\r
579 }\r
580 //\r
581 // Default is '.FFS'\r
582 //\r
583 return ".FFS";\r
878ddf1f 584 }\r
878ddf1f 585 /**\r
a29c47e0 586 Add a property. \r
587 \r
588 @param p property\r
589 **/\r
590 public void addProperty(Property p) {\r
591 properties.addElement(p);\r
878ddf1f 592 }\r
593\r
a29c47e0 594 public void setPlatformName(String platformName) {\r
595 this.platformName = platformName;\r
878ddf1f 596 }\r
597\r
a29c47e0 598 public void setFpdFile(File fpdFile) {\r
599 this.fpdFile = fpdFile;\r
878ddf1f 600 }\r
601\r
a29c47e0 602 public void setType(String type) {\r
603 this.type = type;\r
878ddf1f 604 }\r
a29c47e0 605 \r
606\r
878ddf1f 607}\r