]>
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 | |
89e1408f | 21 | import java.io.IOException;\r |
878ddf1f | 22 | import java.util.HashMap;\r |
23 | import java.util.Iterator;\r | |
24 | import java.util.LinkedHashMap;\r | |
25 | import java.util.LinkedHashSet;\r | |
26 | import java.util.Map;\r | |
27 | import java.util.Set;\r | |
28 | import java.util.Vector;\r | |
878ddf1f | 29 | \r |
30 | import org.apache.tools.ant.BuildException;\r | |
31 | import org.apache.tools.ant.Task;\r | |
a29c47e0 | 32 | import org.apache.tools.ant.taskdefs.Ant;\r |
878ddf1f | 33 | import org.apache.tools.ant.taskdefs.Property;\r |
89e1408f | 34 | import org.apache.xmlbeans.XmlException;\r |
878ddf1f | 35 | import org.apache.xmlbeans.XmlObject;\r |
878ddf1f | 36 | \r |
4a6a5026 | 37 | import org.tianocore.common.definitions.EdkDefinitions;\r |
ff225cbb | 38 | import org.tianocore.common.exception.EdkException;\r |
39 | import org.tianocore.pcd.action.ActionMessage;\r | |
aca6c736 | 40 | import org.tianocore.build.FrameworkBuildTask;\r |
878ddf1f | 41 | import org.tianocore.build.global.GlobalData;\r |
42 | import org.tianocore.build.global.OutputManager;\r | |
878ddf1f | 43 | import org.tianocore.build.global.SurfaceAreaQuery;\r |
a29c47e0 | 44 | import org.tianocore.build.id.FpdModuleIdentification;\r |
45 | import org.tianocore.build.id.ModuleIdentification;\r | |
46 | import org.tianocore.build.id.PlatformIdentification;\r | |
af98370e | 47 | import org.tianocore.build.pcd.action.PlatformPcdPreprocessActionForBuilding;\r |
a29c47e0 | 48 | import org.tianocore.build.toolchain.ToolChainAttribute;\r |
49 | import org.tianocore.build.toolchain.ToolChainElement;\r | |
50 | import 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 | |
71 | public 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 |
878ddf1f | 196 | fvFile.getParentFile().mkdirs();\r |
197 | \r | |
198 | try {\r | |
199 | FileWriter fw = new FileWriter(fvFile);\r | |
200 | BufferedWriter bw = new BufferedWriter(fw);\r | |
ff225cbb | 201 | \r |
878ddf1f | 202 | //\r |
203 | // Options\r | |
204 | //\r | |
83fba802 | 205 | String[][] options = saq.getFpdOptions(validFv[i]);\r |
878ddf1f | 206 | if (options.length > 0) {\r |
207 | bw.write("[options]");\r | |
208 | bw.newLine();\r | |
209 | for (int j = 0; j < options.length; j++) {\r | |
210 | StringBuffer str = new StringBuffer(100);\r | |
211 | str.append(options[j][0]);\r | |
212 | while (str.length() < 40) {\r | |
213 | str.append(' ');\r | |
214 | }\r | |
215 | str.append("= ");\r | |
216 | str.append(options[j][1]);\r | |
217 | bw.write(getProject().replaceProperties(str.toString()));\r | |
218 | bw.newLine();\r | |
219 | }\r | |
220 | bw.newLine();\r | |
221 | }\r | |
ff225cbb | 222 | \r |
878ddf1f | 223 | //\r |
224 | // Attributes;\r | |
225 | //\r | |
83fba802 | 226 | String[][] attributes = saq.getFpdAttributes(validFv[i]);\r |
878ddf1f | 227 | if (attributes.length > 0) {\r |
228 | bw.write("[attributes]");\r | |
229 | bw.newLine();\r | |
230 | for (int j = 0; j < attributes.length; j++) {\r | |
231 | StringBuffer str = new StringBuffer(100);\r | |
232 | str.append(attributes[j][0]);\r | |
233 | while (str.length() < 40) {\r | |
234 | str.append(' ');\r | |
235 | }\r | |
236 | str.append("= ");\r | |
237 | str.append(attributes[j][1]);\r | |
a29c47e0 | 238 | bw.write(getProject().replaceProperties(str.toString()));\r |
878ddf1f | 239 | bw.newLine();\r |
240 | }\r | |
241 | bw.newLine();\r | |
242 | }\r | |
ff225cbb | 243 | \r |
878ddf1f | 244 | //\r |
245 | // Components\r | |
246 | //\r | |
83fba802 | 247 | String[][] components = saq.getFpdComponents(validFv[i]);\r |
878ddf1f | 248 | if (components.length > 0) {\r |
249 | bw.write("[components]");\r | |
250 | bw.newLine();\r | |
251 | for (int j = 0; j < components.length; j++) {\r | |
252 | StringBuffer str = new StringBuffer(100);\r | |
253 | str.append(components[j][0]);\r | |
254 | while (str.length() < 40) {\r | |
255 | str.append(' ');\r | |
256 | }\r | |
257 | str.append("= ");\r | |
258 | str.append(components[j][1]);\r | |
a29c47e0 | 259 | bw.write(getProject().replaceProperties(str.toString()));\r |
878ddf1f | 260 | bw.newLine();\r |
261 | }\r | |
262 | bw.newLine();\r | |
263 | }\r | |
ff225cbb | 264 | \r |
878ddf1f | 265 | //\r |
266 | // Files\r | |
267 | //\r | |
57cc2ee7 | 268 | Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i]);\r |
878ddf1f | 269 | if (filesSet != null) {\r |
a29c47e0 | 270 | FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet.size()]);\r |
878ddf1f | 271 | bw.write("[files]");\r |
272 | bw.newLine();\r | |
273 | for (int j = 0; j < files.length; j++) {\r | |
a29c47e0 | 274 | String str = ffsCommonDir + File.separatorChar + outfiles.get(files[j]);\r |
275 | bw.write(getProject().replaceProperties("EFI_FILE_NAME = " + str));\r | |
878ddf1f | 276 | bw.newLine();\r |
277 | }\r | |
278 | }\r | |
279 | bw.flush();\r | |
280 | bw.close();\r | |
281 | fw.close();\r | |
89e1408f | 282 | } catch (IOException ex) {\r |
283 | BuildException buildException = new BuildException("Generation of the FV file [" + fvFile.getPath() + "] failed!\n" + ex.getMessage());\r | |
284 | buildException.setStackTrace(ex.getStackTrace());\r | |
285 | throw buildException;\r | |
878ddf1f | 286 | }\r |
287 | }\r | |
288 | }\r | |
a29c47e0 | 289 | /**\r |
290 | This method is used for Single Module Build.\r | |
ff225cbb | 291 | \r |
292 | \r | |
a29c47e0 | 293 | @throws BuildException\r |
ff225cbb | 294 | FPD file is not valid.\r |
a29c47e0 | 295 | **/\r |
89e1408f | 296 | public void parseFpdFile(File fpdFile) throws BuildException, EdkException {\r |
a29c47e0 | 297 | this.fpdFile = fpdFile;\r |
5acb4b67 | 298 | parseFpdFile();\r |
2a9060e2 | 299 | \r |
300 | //\r | |
301 | // Call Platform_build.xml prebuild firstly in stand-alone build\r | |
302 | // Prepare BUILD_DIR\r | |
303 | //\r | |
304 | isUnified = OutputManager.getInstance().prepareBuildDir(getProject());\r | |
305 | \r | |
306 | String buildDir = getProject().getProperty("BUILD_DIR");\r | |
307 | //\r | |
308 | // For every Target and ToolChain\r | |
309 | //\r | |
310 | String[] targetList = GlobalData.getToolChainInfo().getTargets();\r | |
311 | for (int i = 0; i < targetList.length; i++) {\r | |
312 | String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r | |
313 | for(int j = 0; j < toolchainList.length; j++) {\r | |
314 | //\r | |
315 | // Prepare FV_DIR\r | |
316 | //\r | |
317 | String ffsCommonDir = buildDir + File.separatorChar\r | |
318 | + targetList[i] + "_"\r | |
319 | + toolchainList[j];\r | |
320 | File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r | |
321 | fvDir.mkdirs();\r | |
322 | }\r | |
323 | }\r | |
324 | \r | |
325 | String platformBuildFile = buildDir + File.separatorChar + platformId.getName() + "_build.xml";\r | |
326 | PlatformBuildFileGenerator fileGenerator = new PlatformBuildFileGenerator(getProject(), outfiles, fvs, isUnified, saq, platformBuildFile);\r | |
327 | fileGenerator.genBuildFile();\r | |
328 | \r | |
329 | Ant ant = new Ant();\r | |
330 | ant.setProject(getProject());\r | |
331 | ant.setAntfile(platformBuildFile);\r | |
332 | ant.setTarget("prebuild");\r | |
333 | ant.setInheritAll(true);\r | |
334 | ant.init();\r | |
335 | ant.execute();\r | |
a29c47e0 | 336 | }\r |
878ddf1f | 337 | \r |
338 | /**\r | |
ff225cbb | 339 | Parse FPD file.\r |
340 | \r | |
878ddf1f | 341 | @throws BuildException\r |
ff225cbb | 342 | FPD file is not valid.\r |
a29c47e0 | 343 | **/\r |
19bf6b15 | 344 | void parseFpdFile() throws BuildException {\r |
878ddf1f | 345 | try {\r |
a29c47e0 | 346 | XmlObject doc = XmlObject.Factory.parse(fpdFile);\r |
ff225cbb | 347 | \r |
a29c47e0 | 348 | if (!doc.validate()) {\r |
391dbbb1 | 349 | throw new BuildException("Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r |
878ddf1f | 350 | }\r |
ff225cbb | 351 | \r |
a29c47e0 | 352 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r |
353 | map.put("PlatformSurfaceArea", doc);\r | |
83fba802 | 354 | saq = new SurfaceAreaQuery(map);\r |
8031d48d | 355 | \r |
a29c47e0 | 356 | //\r |
357 | // Initialize\r | |
358 | //\r | |
83fba802 | 359 | platformId = saq.getFpdHeader();\r |
a29c47e0 | 360 | platformId.setFpdFile(fpdFile);\r |
de4bb9f6 | 361 | getProject().setProperty("PLATFORM", platformId.getName());\r |
362 | getProject().setProperty("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r | |
363 | getProject().setProperty("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
364 | getProject().setProperty("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
aca6c736 | 365 | \r |
366 | if( !FrameworkBuildTask.multithread) {\r | |
367 | FrameworkBuildTask.originalProperties.put("PLATFORM", platformId.getName());\r | |
368 | FrameworkBuildTask.originalProperties.put("PLATFORM_FILE", platformId.getRelativeFpdFile().replaceAll("(\\\\)", "/"));\r | |
369 | FrameworkBuildTask.originalProperties.put("PLATFORM_DIR", platformId.getFpdFile().getParent().replaceAll("(\\\\)", "/"));\r | |
370 | FrameworkBuildTask.originalProperties.put("PLATFORM_RELATIVE_DIR", platformId.getPlatformRelativeDir().replaceAll("(\\\\)", "/"));\r | |
371 | }\r | |
a29c47e0 | 372 | \r |
373 | //\r | |
ff225cbb | 374 | // Build mode. User-defined output dir.\r |
a29c47e0 | 375 | //\r |
83fba802 | 376 | String buildMode = saq.getFpdIntermediateDirectories();\r |
377 | String userDefinedOutputDir = saq.getFpdOutputDirectory();\r | |
a29c47e0 | 378 | \r |
379 | OutputManager.getInstance().setup(userDefinedOutputDir, buildMode);\r | |
380 | \r | |
381 | //\r | |
382 | // TBD. Deal PCD and BuildOption related Info\r | |
383 | //\r | |
83fba802 | 384 | GlobalData.setFpdBuildOptions(saq.getFpdBuildOptions());\r |
ff225cbb | 385 | \r |
83fba802 | 386 | GlobalData.setToolChainPlatformInfo(saq.getFpdToolChainInfo());\r |
ff225cbb | 387 | \r |
878ddf1f | 388 | //\r |
389 | // Parse all list modules SA\r | |
390 | //\r | |
07193171 | 391 | parseModuleSAFiles();\r |
a29c47e0 | 392 | \r |
393 | //\r | |
394 | // TBD. Deal PCD and BuildOption related Info\r | |
395 | //\r | |
396 | parseToolChainFamilyOptions();\r | |
397 | parseToolChainOptions();\r | |
398 | \r | |
83fba802 | 399 | saq.push(map);\r |
ff225cbb | 400 | \r |
de4bb9f6 | 401 | //\r |
402 | // Pcd Collection. Call CollectPCDAction to collect pcd info.\r | |
403 | //\r | |
8b7bd455 | 404 | PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r |
405 | ca.perform(platformId.getFpdFile().getPath(), ActionMessage.NULL_MESSAGE_LEVEL);\r | |
89e1408f | 406 | } catch (IOException ex) {\r |
407 | BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r | |
408 | buildException.setStackTrace(ex.getStackTrace());\r | |
409 | throw buildException;\r | |
410 | } catch (XmlException ex) {\r | |
411 | BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r | |
412 | buildException.setStackTrace(ex.getStackTrace());\r | |
413 | throw buildException;\r | |
414 | } catch (EdkException ex) {\r | |
415 | BuildException buildException = new BuildException("Parsing of the FPD file [" + fpdFile.getPath() + "] failed!\n" + ex.getMessage());\r | |
416 | buildException.setStackTrace(ex.getStackTrace());\r | |
417 | throw buildException;\r | |
878ddf1f | 418 | }\r |
419 | }\r | |
420 | \r | |
421 | /**\r | |
ff225cbb | 422 | Parse all modules listed in FPD file.\r |
878ddf1f | 423 | **/\r |
19bf6b15 | 424 | void parseModuleSAFiles() throws EdkException{\r |
83fba802 | 425 | Map<FpdModuleIdentification, Map<String, XmlObject>> moduleSAs = saq.getFpdModules();\r |
136adffc | 426 | \r |
878ddf1f | 427 | //\r |
428 | // For every Module lists in FPD file.\r | |
429 | //\r | |
a29c47e0 | 430 | Set<FpdModuleIdentification> keys = moduleSAs.keySet();\r |
431 | Iterator iter = keys.iterator();\r | |
432 | while (iter.hasNext()) {\r | |
433 | FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r | |
ff225cbb | 434 | \r |
878ddf1f | 435 | //\r |
ff225cbb | 436 | // Judge if Module is existed?\r |
a29c47e0 | 437 | // TBD\r |
a29c47e0 | 438 | GlobalData.registerFpdModuleSA(fpdModuleId, moduleSAs.get(fpdModuleId));\r |
439 | \r | |
878ddf1f | 440 | //\r |
a29c47e0 | 441 | // Put fpdModuleId to the corresponding FV\r |
878ddf1f | 442 | //\r |
83fba802 | 443 | saq.push(GlobalData.getDoc(fpdModuleId));\r |
444 | String fvBinding = saq.getModuleFvBindingKeyword();\r | |
a29c47e0 | 445 | \r |
446 | fpdModuleId.setFvBinding(fvBinding);\r | |
01413f0c | 447 | updateFvs(fvBinding, fpdModuleId);\r |
ff225cbb | 448 | \r |
878ddf1f | 449 | //\r |
a29c47e0 | 450 | // Prepare for out put file name\r |
878ddf1f | 451 | //\r |
a29c47e0 | 452 | ModuleIdentification moduleId = fpdModuleId.getModule();\r |
82516887 | 453 | \r |
83fba802 | 454 | String baseName = saq.getModuleOutputFileBasename();\r |
82516887 | 455 | \r |
a29c47e0 | 456 | if (baseName == null) {\r |
457 | baseName = moduleId.getName();\r | |
878ddf1f | 458 | }\r |
ff225cbb | 459 | outfiles.put(fpdModuleId, fpdModuleId.getArch() + File.separatorChar\r |
460 | + moduleId.getGuid() + "-" + baseName\r | |
a29c47e0 | 461 | + getSuffix(moduleId.getModuleType()));\r |
462 | \r | |
463 | //\r | |
464 | // parse module build options, if any\r | |
ff225cbb | 465 | //\r |
a29c47e0 | 466 | GlobalData.addModuleToolChainOption(fpdModuleId, parseModuleBuildOptions(false));\r |
467 | GlobalData.addModuleToolChainFamilyOption(fpdModuleId, parseModuleBuildOptions(true));\r | |
83fba802 | 468 | saq.pop();\r |
878ddf1f | 469 | }\r |
470 | }\r | |
471 | \r | |
19bf6b15 | 472 | ToolChainMap parseModuleBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r |
83fba802 | 473 | String[][] options = saq.getModuleBuildOptions(toolChainFamilyFlag);\r |
a29c47e0 | 474 | if (options == null || options.length == 0) {\r |
80eb97ff | 475 | return new ToolChainMap();\r |
878ddf1f | 476 | }\r |
a29c47e0 | 477 | return parseOptions(options);\r |
878ddf1f | 478 | }\r |
ff225cbb | 479 | \r |
a29c47e0 | 480 | private ToolChainMap parsePlatformBuildOptions(boolean toolChainFamilyFlag) throws EdkException {\r |
83fba802 | 481 | String[][] options = saq.getPlatformBuildOptions(toolChainFamilyFlag);\r |
a29c47e0 | 482 | if (options == null || options.length == 0) {\r |
80eb97ff | 483 | return new ToolChainMap();\r |
878ddf1f | 484 | }\r |
a29c47e0 | 485 | return parseOptions(options);\r |
878ddf1f | 486 | }\r |
487 | \r | |
a29c47e0 | 488 | private ToolChainMap parseOptions(String[][] options) throws EdkException {\r |
489 | ToolChainMap map = new ToolChainMap();\r | |
490 | int flagIndex = ToolChainElement.ATTRIBUTE.value;\r | |
491 | \r | |
492 | for (int i = 0; i < options.length; ++i) {\r | |
493 | String flagString = options[i][flagIndex];\r | |
494 | if (flagString == null) {\r | |
495 | flagString = "";\r | |
496 | }\r | |
497 | options[i][flagIndex] = ToolChainAttribute.FLAGS + "";\r | |
498 | map.put(options[i], flagString.trim());\r | |
499 | }\r | |
500 | \r | |
878ddf1f | 501 | return map;\r |
502 | }\r | |
ff225cbb | 503 | \r |
a29c47e0 | 504 | private void parseToolChainFamilyOptions() throws EdkException {\r |
505 | GlobalData.setPlatformToolChainFamilyOption(parsePlatformBuildOptions(true));\r | |
506 | }\r | |
507 | \r | |
508 | private void parseToolChainOptions() throws EdkException {\r | |
509 | GlobalData.setPlatformToolChainOption(parsePlatformBuildOptions(false));\r | |
510 | }\r | |
878ddf1f | 511 | \r |
512 | /**\r | |
ff225cbb | 513 | Add the current module to corresponding FV.\r |
514 | \r | |
a29c47e0 | 515 | @param fvName current FV name\r |
516 | @param moduleName current module identification\r | |
878ddf1f | 517 | **/\r |
19bf6b15 | 518 | void updateFvs(String fvName, FpdModuleIdentification fpdModuleId) {\r |
fa2da5b1 | 519 | if (fvName == null || fvName.trim().length() == 0) {\r |
520 | fvName = "NULL";\r | |
521 | }\r | |
57cc2ee7 | 522 | String[] fvNameArray = fvName.split("[, \t]+");\r |
a29c47e0 | 523 | for (int i = 0; i < fvNameArray.length; i++) {\r |
878ddf1f | 524 | //\r |
a29c47e0 | 525 | // Put module to corresponding fvName\r |
878ddf1f | 526 | //\r |
a29c47e0 | 527 | if (fvs.containsKey(fvNameArray[i])) {\r |
528 | Set<FpdModuleIdentification> set = fvs.get(fvNameArray[i]);\r | |
529 | set.add(fpdModuleId);\r | |
82516887 | 530 | } else {\r |
a29c47e0 | 531 | Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r |
532 | set.add(fpdModuleId);\r | |
533 | fvs.put(fvNameArray[i], set);\r | |
878ddf1f | 534 | }\r |
878ddf1f | 535 | }\r |
536 | }\r | |
537 | \r | |
538 | /**\r | |
ff225cbb | 539 | Get the suffix based on module type. Current relationship are listed:\r |
540 | \r | |
a29c47e0 | 541 | <pre>\r |
542 | <b>ModuleType</b> <b>Suffix</b>\r | |
543 | BASE .FFS\r | |
544 | SEC .SEC\r | |
545 | PEI_CORE .PEI\r | |
546 | PEIM .PEI\r | |
547 | DXE_CORE .DXE\r | |
548 | DXE_DRIVER .DXE\r | |
549 | DXE_RUNTIME_DRIVER .DXE\r | |
550 | DXE_SAL_DRIVER .DXE\r | |
551 | DXE_SMM_DRIVER .DXE\r | |
552 | TOOL .FFS\r | |
553 | UEFI_DRIVER .DXE\r | |
554 | UEFI_APPLICATION .APP\r | |
555 | USER_DEFINED .FFS\r | |
556 | </pre>\r | |
ff225cbb | 557 | \r |
a29c47e0 | 558 | @param moduleType module type\r |
559 | @return\r | |
560 | @throws BuildException\r | |
561 | If module type is null\r | |
878ddf1f | 562 | **/\r |
a29c47e0 | 563 | public static String getSuffix(String moduleType) throws BuildException {\r |
564 | if (moduleType == null) {\r | |
565 | throw new BuildException("Module type is not specified.");\r | |
566 | }\r | |
878ddf1f | 567 | \r |
4a6a5026 | 568 | String[][] suffix = EdkDefinitions.ModuleTypeExtensions;\r |
ff225cbb | 569 | \r |
a29c47e0 | 570 | for (int i = 0; i < suffix.length; i++) {\r |
571 | if (suffix[i][0].equalsIgnoreCase(moduleType)) {\r | |
572 | return suffix[i][1];\r | |
573 | }\r | |
574 | }\r | |
575 | //\r | |
576 | // Default is '.FFS'\r | |
577 | //\r | |
578 | return ".FFS";\r | |
878ddf1f | 579 | }\r |
878ddf1f | 580 | /**\r |
ff225cbb | 581 | Add a property.\r |
582 | \r | |
a29c47e0 | 583 | @param p property\r |
584 | **/\r | |
585 | public void addProperty(Property p) {\r | |
586 | properties.addElement(p);\r | |
878ddf1f | 587 | }\r |
588 | \r | |
a29c47e0 | 589 | public void setFpdFile(File fpdFile) {\r |
590 | this.fpdFile = fpdFile;\r | |
878ddf1f | 591 | }\r |
592 | \r | |
a29c47e0 | 593 | public void setType(String type) {\r |
594 | this.type = type;\r | |
878ddf1f | 595 | }\r |
3790e93c | 596 | \r |
597 | public String getAllArchForModule(ModuleIdentification moduleId) {\r | |
598 | String archs = "";\r | |
599 | Iterator<FpdModuleIdentification> iter = outfiles.keySet().iterator();\r | |
600 | while (iter.hasNext()) {\r | |
601 | FpdModuleIdentification fpdModuleId = iter.next();\r | |
602 | \r | |
603 | if (fpdModuleId.getModule().equals(moduleId)) {\r | |
604 | archs += fpdModuleId.getArch() + " ";\r | |
605 | }\r | |
606 | }\r | |
607 | \r | |
608 | return archs;\r | |
609 | }\r | |
878ddf1f | 610 | }\r |