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