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