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