]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
added the support for new schema and old schema at the same time
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / fpd / FpdParserTask.java
CommitLineData
878ddf1f 1/** @file\r
2 This file is ANT task FpdParserTask. \r
3 \r
4 FpdParserTask is used to parse FPD (Framework Platform Description) and generate\r
5 build.out.xml. It is for Package or Platform build use. \r
6 \r
7Copyright (c) 2006, Intel Corporation\r
8All rights reserved. This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15**/\r
16package org.tianocore.build.fpd;\r
17\r
18import java.io.BufferedWriter;\r
19import java.io.File;\r
20import java.io.FileWriter;\r
21import java.util.HashMap;\r
22import java.util.Iterator;\r
23import java.util.LinkedHashMap;\r
24import java.util.LinkedHashSet;\r
25import java.util.Map;\r
26import java.util.Set;\r
27import java.util.Vector;\r
28\r
29import javax.xml.parsers.DocumentBuilder;\r
30import javax.xml.parsers.DocumentBuilderFactory;\r
31import javax.xml.transform.OutputKeys;\r
32import javax.xml.transform.Result;\r
33import javax.xml.transform.Source;\r
34import javax.xml.transform.Transformer;\r
35import javax.xml.transform.TransformerFactory;\r
36import javax.xml.transform.dom.DOMSource;\r
37import javax.xml.transform.stream.StreamResult;\r
38\r
39import org.apache.tools.ant.BuildException;\r
40import org.apache.tools.ant.Task;\r
41import org.apache.tools.ant.taskdefs.Property;\r
42import org.apache.xmlbeans.XmlObject;\r
43import org.w3c.dom.Comment;\r
44import org.w3c.dom.Document;\r
45import org.w3c.dom.Element;\r
46\r
47import org.tianocore.build.global.GlobalData;\r
48import org.tianocore.build.global.OutputManager;\r
49import org.tianocore.build.global.OverrideProcess;\r
50import org.tianocore.build.global.SurfaceAreaQuery;\r
51import org.tianocore.build.pcd.action.CollectPCDAction;\r
52import org.tianocore.build.pcd.action.ActionMessage;\r
53import org.tianocore.BuildOptionsDocument;\r
54import org.tianocore.FrameworkPlatformDescriptionDocument;\r
55import org.tianocore.ModuleSADocument;\r
56\r
57\r
58/**\r
59 <code>FpdParserTask</code> is an ANT task. The main function is parsing FPD\r
60 XML file and generating its ANT build script for Platform or Package. \r
61 \r
62 <p>The usage is (take NT32 Platform for example):</p>\r
63 \r
64 <pre>\r
65 &lt;FPDParser fpdfilename="Build\Nt32.fpd" /&gt;\r
66 </pre>\r
67 \r
68 <p>The task will initialize all information through parsing Framework Database, \r
69 SPD, Tool chain configuration files. </p>\r
70 \r
71 @since GenBuild 1.0\r
72**/\r
73public class FpdParserTask extends Task {\r
74\r
75 ///\r
76 /// FV dir: ${PLATFORM_DIR}/Build/FV\r
77 ///\r
78 public static final String FV_OUTPUT_DIR = "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar + "FV";\r
79\r
80 private File fpdFilename;\r
81\r
82 private File guiddatabase;\r
83\r
84 ///\r
85 /// Keep platform buildoption information\r
86 ///\r
87 public static XmlObject platformBuildOptions = null;\r
88\r
89 ///\r
90 /// Mapping from modules identification to out put file name\r
91 ///\r
92 private Map<FpdModuleIdentification, String> outfiles = new LinkedHashMap<FpdModuleIdentification, String>();\r
93\r
94 ///\r
95 /// Mapping from FV name to its modules\r
96 ///\r
97 private Map<String, Set<FpdModuleIdentification> > fvs = new HashMap<String, Set<FpdModuleIdentification> >();\r
98\r
99 ///\r
100 /// Mapping from sequence number to its modules\r
101 ///\r
102 private Map<String, Set<FpdModuleIdentification> > sequences = new HashMap<String, Set<FpdModuleIdentification> >();\r
103\r
104 ///\r
105 /// FpdParserTask can specify some ANT properties. \r
106 ///\r
107 private Vector<Property> properties = new Vector<Property>();\r
108\r
109 private String info = "====================================================================\n"\r
110 + "DO NOT EDIT \n"\r
111 + "File auto-generated by build utility\n"\r
112 + "\n"\r
113 + "Abstract:\n"\r
114 + "Auto-generated ANT build file for building of EFI Modules/Platforms\n"\r
115 + "=====================================================================";\r
116\r
117 /**\r
118 Public construct method. It is necessary for ANT task.\r
119 **/\r
120 public FpdParserTask () {\r
121 }\r
122\r
123 /**\r
124 ANT task's entry method. The main steps is described as following: \r
125 \r
126 <ul>\r
127 <li>Initialize global information (Framework DB, SPD files and all MSA files \r
128 listed in SPD). This step will execute only once in whole build process;</li>\r
129 <li>Parse specified FPD file; </li>\r
130 <li>Generate FV.inf files; </li>\r
131 <li>Generate build.out.xml file for Flatform or Package build; </li>\r
132 <li>Collect PCD information. </li>\r
133 </ul>\r
134 \r
135 @throws BuildException\r
136 Surface area is not valid. \r
137 **/\r
138 public void execute() throws BuildException {\r
139 OutputManager.update(getProject());\r
140 //\r
141 // Parse DB and SPDs files. Initialize Global Data\r
142 //\r
143 GlobalData.initInfo("Tools" + File.separatorChar + "Conf" + File.separatorChar + "FrameworkDatabase.db", getProject()\r
144 .getProperty("WORKSPACE_DIR"));\r
145 //\r
146 // Parse FPD file\r
147 //\r
148 parseFpdFile();\r
149 //\r
150 // Gen Fv.inf files\r
151 //\r
152 genFvInfFiles();\r
153 //\r
154 // Gen build.xml\r
155 //\r
156 genBuildFile();\r
157 //\r
158 // Collect PCD information \r
159 // \r
160 collectPCDInformation (); \r
161 }\r
162 \r
163 /**\r
164 Generate Fv.inf files. The Fv.inf file is composed with four \r
165 parts: Options, Attributes, Components and Files. The Fv.inf files \r
166 will be under ${PLATFOMR_DIR}\Build\Fv.\r
167 \r
168 @throws BuildException\r
169 File write FV.inf files error. \r
170 **/\r
171 private void genFvInfFiles() throws BuildException{\r
172 String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
173 for (int i = 0; i < validFv.length; i++) {\r
174 getProject().setProperty("FV_FILENAME", validFv[i].toUpperCase());\r
175 //\r
176 // Get all global variables from FPD and set them to properties\r
177 //\r
178 String[][] globalVariables = SurfaceAreaQuery\r
179 .getFpdGlobalVariable();\r
180 for (int j = 0; j < globalVariables.length; j++) {\r
181 getProject().setProperty(globalVariables[j][0],\r
182 globalVariables[j][1]);\r
183 }\r
184\r
185 File fvFile = new File(getProject().replaceProperties(\r
186 FV_OUTPUT_DIR + File.separatorChar + validFv[i].toUpperCase()\r
187 + ".inf"));\r
188 fvFile.getParentFile().mkdirs();\r
189\r
190 try {\r
191 FileWriter fw = new FileWriter(fvFile);\r
192 BufferedWriter bw = new BufferedWriter(fw);\r
193 //\r
194 // Options\r
195 //\r
196 String[][] options = SurfaceAreaQuery.getFpdOptions(validFv[i]);\r
197 if (options.length > 0) {\r
198 bw.write("[options]");\r
199 bw.newLine();\r
200 for (int j = 0; j < options.length; j++) {\r
201 StringBuffer str = new StringBuffer(100);\r
202 str.append(options[j][0]);\r
203 while (str.length() < 40) {\r
204 str.append(' ');\r
205 }\r
206 str.append("= ");\r
207 str.append(options[j][1]);\r
208 bw.write(getProject().replaceProperties(str.toString()));\r
209 bw.newLine();\r
210 }\r
211 bw.newLine();\r
212 }\r
213 //\r
214 // Attributes;\r
215 //\r
216 String[][] attributes = SurfaceAreaQuery\r
217 .getFpdAttributes(validFv[i]);\r
218 if (attributes.length > 0) {\r
219 bw.write("[attributes]");\r
220 bw.newLine();\r
221 for (int j = 0; j < attributes.length; j++) {\r
222 StringBuffer str = new StringBuffer(100);\r
223 str.append(attributes[j][0]);\r
224 while (str.length() < 40) {\r
225 str.append(' ');\r
226 }\r
227 str.append("= ");\r
228 str.append(attributes[j][1]);\r
229 bw\r
230 .write(getProject().replaceProperties(\r
231 str.toString()));\r
232 bw.newLine();\r
233 }\r
234 bw.newLine();\r
235 }\r
236 //\r
237 // Components\r
238 //\r
239 String[][] components = SurfaceAreaQuery\r
240 .getFpdComponents(validFv[i]);\r
241 if (components.length > 0) {\r
242 bw.write("[components]");\r
243 bw.newLine();\r
244 for (int j = 0; j < components.length; j++) {\r
245 StringBuffer str = new StringBuffer(100);\r
246 str.append(components[j][0]);\r
247 while (str.length() < 40) {\r
248 str.append(' ');\r
249 }\r
250 str.append("= ");\r
251 str.append(components[j][1]);\r
252 bw\r
253 .write(getProject().replaceProperties(\r
254 str.toString()));\r
255 bw.newLine();\r
256 }\r
257 bw.newLine();\r
258 }\r
259 //\r
260 // Files\r
261 //\r
262 Set<FpdModuleIdentification> filesSet = fvs.get(validFv[i].toUpperCase());\r
263 if (filesSet != null) {\r
264 FpdModuleIdentification[] files = filesSet.toArray(new FpdModuleIdentification[filesSet\r
265 .size()]);\r
266 bw.write("[files]");\r
267 bw.newLine();\r
268 for (int j = 0; j < files.length; j++) {\r
269 String str = outfiles.get(files[j]);\r
270 bw.write(getProject().replaceProperties(\r
271 "EFI_FILE_NAME = " + str));\r
272 bw.newLine();\r
273 }\r
274 }\r
275 bw.flush();\r
276 bw.close();\r
277 fw.close();\r
278 } catch (Exception e) {\r
279 throw new BuildException("Generate Fv.inf file failed. \n" + e.getMessage());\r
280 }\r
281 }\r
282 }\r
283\r
284 /**\r
285 Parse FPD file. \r
286 \r
287 @throws BuildException\r
288 FPD file is not valid. \r
289 **/\r
290 private void parseFpdFile() throws BuildException {\r
291 try {\r
292 FrameworkPlatformDescriptionDocument doc = (FrameworkPlatformDescriptionDocument) XmlObject.Factory\r
293 .parse(fpdFilename);\r
294 if ( ! doc.validate() ){\r
295 throw new BuildException("FPD file is invalid.");\r
296 }\r
297 platformBuildOptions = doc.getFrameworkPlatformDescription()\r
298 .getBuildOptions();\r
299 HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
300 map.put("FrameworkPlatformDescription", doc);\r
301 SurfaceAreaQuery.setDoc(map);\r
302 //\r
303 // Parse all list modules SA\r
304 //\r
305 parseModuleSAFiles();\r
306 SurfaceAreaQuery.setDoc(map);\r
307 } catch (Exception e) {\r
308 throw new BuildException("Load FPD file [" + fpdFilename.getPath()\r
309 + "] error. \n" + e.getMessage());\r
310 }\r
311 }\r
312\r
313 /**\r
314 Parse all modules listed in FPD file. \r
315 **/\r
316 private void parseModuleSAFiles() {\r
317 ModuleSADocument.ModuleSA[] moduleSAs = SurfaceAreaQuery\r
318 .getFpdModules();\r
319 //\r
320 // For every Module lists in FPD file.\r
321 //\r
322 for (int i = 0; i < moduleSAs.length; i++) {\r
323 String defaultFv = "NULL";\r
324 String defaultArch = "IA32";\r
325 String baseName = moduleSAs[i].getModuleName();\r
326 if (baseName == null) {\r
327 System.out.println("Warning: Module Name is not specified.");\r
328 continue;\r
329 }\r
330 String fvBinding = moduleSAs[i].getFvBinding();\r
331 //\r
332 // If the module do not specify any FvBinding, use the default value.\r
333 // Else update the default FvBinding value to this value.\r
334 //\r
335 if (fvBinding == null) {\r
336 fvBinding = defaultFv;\r
337 }\r
338 else {\r
339 defaultFv = fvBinding;\r
340 }\r
341 String arch;\r
342 //\r
343 // If the module do not specify any Arch, use the default value.\r
344 // Else update the default Arch value to this value.\r
345 //\r
346 if (moduleSAs[i].getArch() == null ){\r
347 arch = defaultArch;\r
348 }\r
349 else {\r
350 arch = moduleSAs[i].getArch().toString();\r
351 defaultArch = arch;\r
352 }\r
353 Map<String, XmlObject> msaMap = GlobalData.getNativeMsa(baseName);\r
354 Map<String, XmlObject> mbdMap = GlobalData.getNativeMbd(baseName);\r
250258de 355 Map<String, XmlObject> fpdMap = new HashMap<String, XmlObject>();\r
878ddf1f 356 Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
357 //\r
358 // Whether the Module SA has parsed before or not\r
359 //\r
360 if (!GlobalData.isModuleParsed(baseName)) {\r
361 OverrideProcess op = new OverrideProcess();\r
362 //\r
363 // using overriding rules\r
364 // Here we can also put platform Build override\r
365 //\r
366 map = op.override(mbdMap, msaMap);\r
250258de 367 fpdMap = getPlatformOverrideInfo(moduleSAs[i]);\r
368 XmlObject buildOption = (XmlObject)fpdMap.get("BuildOptions");\r
369 buildOption = (XmlObject)fpdMap.get("PackageDependencies");\r
370 buildOption = (XmlObject)fpdMap.get("BuildOptions");\r
371 buildOption = op.override(buildOption, platformBuildOptions);\r
372 fpdMap.put("BuildOptions", ((BuildOptionsDocument)buildOption).getBuildOptions());\r
373 Map<String, XmlObject> overrideMap = op.override(fpdMap, OverrideProcess.deal(map));\r
878ddf1f 374 GlobalData.registerModule(baseName, overrideMap);\r
375 } else {\r
376 map = GlobalData.getDoc(baseName);\r
377 }\r
378 SurfaceAreaQuery.setDoc(map);\r
379 String guid = SurfaceAreaQuery.getModuleGuid();\r
380 String componentType = SurfaceAreaQuery.getComponentType();\r
381 FpdModuleIdentification moduleId = new FpdModuleIdentification(baseName, guid, arch);\r
382 updateFvs(fvBinding, moduleId);\r
383 outfiles.put(moduleId, "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar \r
384 + "${TARGET}" + File.separatorChar + arch\r
385 + File.separatorChar + guid + "-" + baseName\r
386 + getSuffix(componentType));\r
387 }\r
388 }\r
389\r
390 /**\r
391 Add the current module to corresponding FV. \r
392 \r
393 @param fvName current FV name\r
394 @param moduleName current module identification\r
395 **/\r
396 private void updateFvs(String fvName, FpdModuleIdentification moduleName) {\r
397 String upcaseFvName = fvName.toUpperCase();\r
398 if (fvs.containsKey(upcaseFvName)) {\r
399 Set<FpdModuleIdentification> set = fvs.get(upcaseFvName);\r
400 set.add(moduleName);\r
401 } else {\r
402 Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r
403 set.add(moduleName);\r
404 fvs.put(upcaseFvName, set);\r
405 }\r
406 }\r
407\r
408 /**\r
409 Get the suffix based on component type. Current relationship are listed: \r
410 \r
411 <pre>\r
412 <b>ComponentType</b> <b>Suffix</b>\r
413 APPLICATION .APP\r
414 SEC .SEC\r
415 PEI_CORE .PEI\r
416 PE32_PEIM .PEI\r
417 RELOCATABLE_PEIM .PEI\r
418 PIC_PEIM .PEI\r
419 COMBINED_PEIM_DRIVER .PEI\r
420 TE_PEIM .PEI\r
421 LOGO .FFS\r
422 others .DXE\r
423 </pre>\r
424 \r
425 @param componentType component type\r
426 @return\r
427 @throws BuildException\r
428 If component type is null\r
429 **/\r
430 public static String getSuffix(String componentType) throws BuildException{\r
431 if (componentType == null) {\r
432 throw new BuildException("Component type is not specified.");\r
433 }\r
434 String str = ".DXE";\r
435 if (componentType.equalsIgnoreCase("APPLICATION")) {\r
436 str = ".APP";\r
437 } else if (componentType.equalsIgnoreCase("SEC")) {\r
438 str = ".SEC";\r
439 } else if (componentType.equalsIgnoreCase("PEI_CORE")) {\r
440 str = ".PEI";\r
441 } else if (componentType.equalsIgnoreCase("PE32_PEIM")) {\r
442 str = ".PEI";\r
443 } else if (componentType.equalsIgnoreCase("RELOCATABLE_PEIM")) {\r
444 str = ".PEI";\r
445 } else if (componentType.equalsIgnoreCase("PIC_PEIM")) {\r
446 str = ".PEI";\r
447 } else if (componentType.equalsIgnoreCase("COMBINED_PEIM_DRIVER")) {\r
448 str = ".PEI";\r
449 } else if (componentType.equalsIgnoreCase("TE_PEIM")) {\r
450 str = ".PEI";\r
451 } else if (componentType.equalsIgnoreCase("LOGO")) {\r
452 str = ".FFS";\r
453 }\r
454 return str;\r
455 }\r
456\r
457 /**\r
458 Parse module surface are info described in FPD file and put them into map. \r
459 \r
460 @param sa module surface area info descibed in FPD file\r
461 @return map list with top level elements\r
462 **/\r
463 private Map<String, XmlObject> getPlatformOverrideInfo(\r
464 ModuleSADocument.ModuleSA sa) {\r
465 Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r
466 map.put("SourceFiles", sa.getSourceFiles());\r
467 map.put("Includes", sa.getIncludes());\r
250258de 468 map.put("PackageDependencies", null);\r
878ddf1f 469 map.put("Libraries", sa.getLibraries());\r
470 map.put("Protocols", sa.getProtocols());\r
471 map.put("Events", sa.getEvents());\r
472 map.put("Hobs", sa.getHobs());\r
473 map.put("PPIs", sa.getPPIs());\r
474 map.put("Variables", sa.getVariables());\r
475 map.put("BootModes", sa.getBootModes());\r
476 map.put("SystemTables", sa.getSystemTables());\r
477 map.put("DataHubs", sa.getDataHubs());\r
478 map.put("Formsets", sa.getFormsets());\r
479 map.put("Guids", sa.getGuids());\r
480 map.put("Externs", sa.getExterns());\r
250258de 481 map.put("BuildOptions", sa.getBuildOptions());//platformBuildOptions);\r
878ddf1f 482 return map;\r
483 }\r
484\r
485 /**\r
486 Generate build.out.xml file.\r
487 \r
488 @throws BuildException\r
489 build.out.xml XML document create error\r
490 **/\r
491 private void genBuildFile() throws BuildException {\r
492 DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
493 try {\r
494 DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
495 Document document = dombuilder.newDocument();\r
496 Comment rootComment = document.createComment(info);\r
497 //\r
498 // create root element and its attributes\r
499 //\r
500 Element root = document.createElement("project");\r
501 root.setAttribute("name", getProject().getProperty("PLATFORM"));\r
502 root.setAttribute("default", "main");\r
503 root.setAttribute("basedir", ".");\r
504 //\r
505 // element for External ANT tasks\r
506 //\r
507 root.appendChild(document.createComment("Apply external ANT tasks"));\r
508 Element ele = document.createElement("taskdef");\r
509 ele.setAttribute("resource", "GenBuild.tasks");\r
510 root.appendChild(ele);\r
511\r
512 ele = document.createElement("taskdef");\r
513 ele.setAttribute("resource", "frameworktasks.tasks");\r
514 root.appendChild(ele);\r
515\r
516 ele = document.createElement("property");\r
517 ele.setAttribute("environment", "env");\r
518 root.appendChild(ele);\r
519 //\r
520 // Default Target\r
521 //\r
522 root.appendChild(document.createComment("Default target"));\r
523 ele = document.createElement("target");\r
524 ele.setAttribute("name", "main");\r
525 ele.setAttribute("depends", "modules, fvs");\r
526 root.appendChild(ele);\r
527 //\r
528 // Modules Target\r
529 //\r
530 root.appendChild(document.createComment("Modules target"));\r
531 ele = document.createElement("target");\r
532 ele.setAttribute("name", "modules");\r
533\r
534 Set set = outfiles.keySet();\r
535 Iterator iter = set.iterator();\r
536 while (iter.hasNext()) {\r
537 FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
538 String baseName = moduleId.getBaseName();\r
539 Element moduleEle = document.createElement("ant");\r
540 moduleEle.setAttribute("antfile", GlobalData\r
541 .getModulePath(baseName)\r
542 + File.separatorChar + "build.xml");\r
543 moduleEle.setAttribute("target", baseName);\r
544 //\r
545 // ARCH\r
546 //\r
547 Element property = document.createElement("property");\r
548 property.setAttribute("name", "ARCH");\r
549 property.setAttribute("value", moduleId.getArch());\r
550 moduleEle.appendChild(property);\r
551 //\r
552 // PACKAGE_DIR\r
553 //\r
554 property = document.createElement("property");\r
555 property.setAttribute("name", "PACKAGE_DIR");\r
556 property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
557 + GlobalData.getPackagePathForModule(baseName));\r
558 moduleEle.appendChild(property);\r
559 //\r
560 // PACKAGE\r
561 //\r
562 property = document.createElement("property");\r
563 property.setAttribute("name", "PACKAGE");\r
564 property.setAttribute("value", GlobalData\r
565 .getPackageNameForModule(baseName));\r
566 moduleEle.appendChild(property);\r
567 ele.appendChild(moduleEle);\r
568 }\r
569 root.appendChild(ele);\r
570 //\r
571 // FVS Target\r
572 //\r
573 root.appendChild(document.createComment("FVs target"));\r
574 ele = document.createElement("target");\r
575 ele.setAttribute("name", "fvs");\r
576\r
577 String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r
578 for (int i = 0; i < validFv.length; i++) {\r
579 String inputFile = FV_OUTPUT_DIR + "" + File.separatorChar\r
580 + validFv[i].toUpperCase() + ".inf";\r
581 Element fvEle = document.createElement("genfvimage");\r
582 fvEle.setAttribute("infFile", inputFile);\r
583 ele.appendChild(fvEle);\r
584 Element moveEle = document.createElement("move");\r
585 moveEle.setAttribute("file", validFv[i].toUpperCase() + ".fv");\r
586 moveEle.setAttribute("todir", FV_OUTPUT_DIR);\r
587 ele.appendChild(moveEle);\r
588 }\r
589 root.appendChild(ele);\r
590 \r
591 boolean isUnified = false;\r
592 BuildOptionsDocument.BuildOptions buildOptions = (BuildOptionsDocument.BuildOptions)platformBuildOptions;\r
593 if (buildOptions.getOutputDirectory() != null){\r
594 if (buildOptions.getOutputDirectory().getIntermediateDirectories() != null){\r
595 if (buildOptions.getOutputDirectory().getIntermediateDirectories().toString().equalsIgnoreCase("UNIFIED")){\r
596 isUnified = true;\r
597 }\r
598 }\r
599 }\r
600 //\r
601 // Clean Target\r
602 //\r
603 root.appendChild(document.createComment("Clean target"));\r
604 ele = document.createElement("target");\r
605 ele.setAttribute("name", "clean");\r
606 \r
607 if (isUnified) {\r
608 Element cleanEle = document.createElement("delete");\r
609 cleanEle.setAttribute("includeemptydirs", "true");\r
610 Element filesetEle = document.createElement("fileset");\r
611 filesetEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
612 filesetEle.setAttribute("includes", "**/OUTPUT/**");\r
613 cleanEle.appendChild(filesetEle);\r
614 ele.appendChild(cleanEle);\r
615 }\r
616 else {\r
617 set = outfiles.keySet();\r
618 iter = set.iterator();\r
619 while (iter.hasNext()) {\r
620 FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
621 String baseName = moduleId.getBaseName();\r
622 \r
623 Element ifEle = document.createElement("if");\r
624 Element availableEle = document.createElement("available");\r
625 availableEle.setAttribute("file", GlobalData\r
626 .getModulePath(baseName)\r
627 + File.separatorChar + "build.xml");\r
628 ifEle.appendChild(availableEle);\r
629 Element elseEle = document.createElement("then");\r
630 \r
631 Element moduleEle = document.createElement("ant");\r
632 moduleEle.setAttribute("antfile", GlobalData\r
633 .getModulePath(baseName)\r
634 + File.separatorChar + "build.xml");\r
635 moduleEle.setAttribute("target", baseName + "_clean");\r
636 //\r
637 // ARCH\r
638 //\r
639 Element property = document.createElement("property");\r
640 property.setAttribute("name", "ARCH");\r
641 property.setAttribute("value", moduleId.getArch());\r
642 moduleEle.appendChild(property);\r
643 //\r
644 // PACKAGE_DIR\r
645 //\r
646 property = document.createElement("property");\r
647 property.setAttribute("name", "PACKAGE_DIR");\r
648 property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
649 + GlobalData.getPackagePathForModule(baseName));\r
650 moduleEle.appendChild(property);\r
651 //\r
652 // PACKAGE\r
653 //\r
654 property = document.createElement("property");\r
655 property.setAttribute("name", "PACKAGE");\r
656 property.setAttribute("value", GlobalData\r
657 .getPackageNameForModule(baseName));\r
658 moduleEle.appendChild(property);\r
659 elseEle.appendChild(moduleEle);\r
660 ifEle.appendChild(elseEle);\r
661 ele.appendChild(ifEle);\r
662 }\r
663 }\r
664 root.appendChild(ele);\r
665 //\r
666 // Deep Clean Target\r
667 //\r
668 root.appendChild(document.createComment("Clean All target"));\r
669 ele = document.createElement("target");\r
670 ele.setAttribute("name", "cleanall");\r
671\r
672 if (isUnified) {\r
673 Element cleanAllEle = document.createElement("delete");\r
674 cleanAllEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r
675 ele.appendChild(cleanAllEle);\r
676 }\r
677 else {\r
678 set = outfiles.keySet();\r
679 iter = set.iterator();\r
680 while (iter.hasNext()) {\r
681 FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r
682 String baseName = moduleId.getBaseName();\r
683 \r
684 Element ifEle = document.createElement("if");\r
685 Element availableEle = document.createElement("available");\r
686 availableEle.setAttribute("file", GlobalData\r
687 .getModulePath(baseName)\r
688 + File.separatorChar + "build.xml");\r
689 ifEle.appendChild(availableEle);\r
690 Element elseEle = document.createElement("then");\r
691 \r
692 Element moduleEle = document.createElement("ant");\r
693 moduleEle.setAttribute("antfile", GlobalData\r
694 .getModulePath(baseName)\r
695 + File.separatorChar + "build.xml");\r
696 moduleEle.setAttribute("target", baseName + "_cleanall");\r
697 //\r
698 // ARCH\r
699 //\r
700 Element property = document.createElement("property");\r
701 property.setAttribute("name", "ARCH");\r
702 property.setAttribute("value", moduleId.getArch());\r
703 moduleEle.appendChild(property);\r
704 //\r
705 // PACKAGE_DIR\r
706 //\r
707 property = document.createElement("property");\r
708 property.setAttribute("name", "PACKAGE_DIR");\r
709 property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r
710 + GlobalData.getPackagePathForModule(baseName));\r
711 moduleEle.appendChild(property);\r
712 //\r
713 // PACKAGE\r
714 //\r
715 property = document.createElement("property");\r
716 property.setAttribute("name", "PACKAGE");\r
717 property.setAttribute("value", GlobalData\r
718 .getPackageNameForModule(baseName));\r
719 moduleEle.appendChild(property);\r
720 elseEle.appendChild(moduleEle);\r
721 ifEle.appendChild(elseEle);\r
722 ele.appendChild(ifEle);\r
723 }\r
724 }\r
725 root.appendChild(ele);\r
726 \r
727 document.appendChild(rootComment);\r
728 document.appendChild(root);\r
729 //\r
730 // Prepare the DOM document for writing\r
731 //\r
732 Source source = new DOMSource(document);\r
733 //\r
734 // Prepare the output file\r
735 //\r
736 File file = new File(getProject().getProperty("PLATFORM_DIR")\r
737 + File.separatorChar + "build.out.xml");\r
738 //\r
739 // generate all directory path\r
740 //\r
741 (new File(file.getParent())).mkdirs();\r
742 Result result = new StreamResult(file);\r
743 //\r
744 // Write the DOM document to the file\r
745 //\r
746 Transformer xformer = TransformerFactory.newInstance()\r
747 .newTransformer();\r
748 xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
749 xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
750 xformer.transform(source, result);\r
751 } catch (Exception ex) {\r
752 throw new BuildException("Generate build.out.xml failed. \n" + ex.getMessage());\r
753 }\r
754 }\r
755\r
756 /**\r
757 Add a property. \r
758 \r
759 @param p property\r
760 **/\r
761 public void addProperty(Property p) {\r
762 properties.addElement(p);\r
763 }\r
764\r
765 /**\r
766 Get FPD file name.\r
767 \r
768 @return FPD file name.\r
769 **/\r
770 public File getFpdFilename() {\r
771 return fpdFilename;\r
772 }\r
773\r
774 /**\r
775 Set FPD file name.\r
776 \r
777 @param fpdFilename FPD file name\r
778 **/\r
779 public void setFpdFilename(File fpdFilename) {\r
780 this.fpdFilename = fpdFilename;\r
781 }\r
782\r
783 public File getGuiddatabase() {\r
784 return guiddatabase;\r
785 }\r
786\r
787 public void setGuiddatabase(File guiddatabase) {\r
788 this.guiddatabase = guiddatabase;\r
789 }\r
790\r
791 public void collectPCDInformation() {\r
7db4ab70 792 String exceptionString = null;\r
793 CollectPCDAction collectAction = new CollectPCDAction ();\r
794 //\r
795 // Collect all PCD information from FPD to MSA, and get help information from SPD.\r
796 // These all information will be stored into memory database for future usage such \r
797 // as autogen.\r
798 //\r
799 try {\r
800 collectAction.perform (getProject().getProperty("WORKSPACE_DIR"),\r
801 fpdFilename.getPath(),\r
802 ActionMessage.MAX_MESSAGE_LEVEL\r
803 );\r
804 } catch (Exception exp) {\r
805 exceptionString = exp.getMessage();\r
806 if (exceptionString == null) {\r
807 exceptionString = "[Internal Error]Pcd tools catch a internel errors, Please report this bug into TianoCore or send email to Wang, scott or Lu, ken!";\r
808 }\r
809 throw new BuildException (String.format("Fail to do PCD preprocess from FPD file: %s", exceptionString));\r
810 }\r
878ddf1f 811 }\r
812}\r