]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
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 | |
28 | \r | |
29 | import javax.xml.parsers.DocumentBuilder;\r | |
30 | import javax.xml.parsers.DocumentBuilderFactory;\r | |
31 | import javax.xml.transform.OutputKeys;\r | |
32 | import javax.xml.transform.Result;\r | |
33 | import javax.xml.transform.Source;\r | |
34 | import javax.xml.transform.Transformer;\r | |
35 | import javax.xml.transform.TransformerFactory;\r | |
36 | import javax.xml.transform.dom.DOMSource;\r | |
37 | import javax.xml.transform.stream.StreamResult;\r | |
38 | \r | |
39 | import org.apache.tools.ant.BuildException;\r | |
40 | import org.apache.tools.ant.Task;\r | |
41 | import org.apache.tools.ant.taskdefs.Property;\r | |
42 | import org.apache.xmlbeans.XmlObject;\r | |
43 | import org.w3c.dom.Comment;\r | |
44 | import org.w3c.dom.Document;\r | |
45 | import org.w3c.dom.Element;\r | |
46 | \r | |
47 | import org.tianocore.build.global.GlobalData;\r | |
48 | import org.tianocore.build.global.OutputManager;\r | |
49 | import org.tianocore.build.global.OverrideProcess;\r | |
50 | import org.tianocore.build.global.SurfaceAreaQuery;\r | |
51 | import org.tianocore.build.pcd.action.CollectPCDAction;\r | |
52 | import org.tianocore.build.pcd.action.ActionMessage;\r | |
53 | import org.tianocore.BuildOptionsDocument;\r | |
54 | import org.tianocore.FrameworkPlatformDescriptionDocument;\r | |
55 | import 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 | <FPDParser fpdfilename="Build\Nt32.fpd" />\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 | |
73 | public 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 | |
355 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r | |
356 | //\r | |
357 | // Whether the Module SA has parsed before or not\r | |
358 | //\r | |
359 | if (!GlobalData.isModuleParsed(baseName)) {\r | |
360 | OverrideProcess op = new OverrideProcess();\r | |
361 | //\r | |
362 | // using overriding rules\r | |
363 | // Here we can also put platform Build override\r | |
364 | //\r | |
365 | map = op.override(mbdMap, msaMap);\r | |
366 | Map<String, XmlObject> overrideMap = op.override(\r | |
367 | getPlatformOverrideInfo(moduleSAs[i]),\r | |
368 | OverrideProcess.deal(map));\r | |
369 | GlobalData.registerModule(baseName, overrideMap);\r | |
370 | } else {\r | |
371 | map = GlobalData.getDoc(baseName);\r | |
372 | }\r | |
373 | SurfaceAreaQuery.setDoc(map);\r | |
374 | String guid = SurfaceAreaQuery.getModuleGuid();\r | |
375 | String componentType = SurfaceAreaQuery.getComponentType();\r | |
376 | FpdModuleIdentification moduleId = new FpdModuleIdentification(baseName, guid, arch);\r | |
377 | updateFvs(fvBinding, moduleId);\r | |
378 | outfiles.put(moduleId, "${PLATFORM_DIR}" + File.separatorChar + "Build" + File.separatorChar \r | |
379 | + "${TARGET}" + File.separatorChar + arch\r | |
380 | + File.separatorChar + guid + "-" + baseName\r | |
381 | + getSuffix(componentType));\r | |
382 | }\r | |
383 | }\r | |
384 | \r | |
385 | /**\r | |
386 | Add the current module to corresponding FV. \r | |
387 | \r | |
388 | @param fvName current FV name\r | |
389 | @param moduleName current module identification\r | |
390 | **/\r | |
391 | private void updateFvs(String fvName, FpdModuleIdentification moduleName) {\r | |
392 | String upcaseFvName = fvName.toUpperCase();\r | |
393 | if (fvs.containsKey(upcaseFvName)) {\r | |
394 | Set<FpdModuleIdentification> set = fvs.get(upcaseFvName);\r | |
395 | set.add(moduleName);\r | |
396 | } else {\r | |
397 | Set<FpdModuleIdentification> set = new LinkedHashSet<FpdModuleIdentification>();\r | |
398 | set.add(moduleName);\r | |
399 | fvs.put(upcaseFvName, set);\r | |
400 | }\r | |
401 | }\r | |
402 | \r | |
403 | /**\r | |
404 | Get the suffix based on component type. Current relationship are listed: \r | |
405 | \r | |
406 | <pre>\r | |
407 | <b>ComponentType</b> <b>Suffix</b>\r | |
408 | APPLICATION .APP\r | |
409 | SEC .SEC\r | |
410 | PEI_CORE .PEI\r | |
411 | PE32_PEIM .PEI\r | |
412 | RELOCATABLE_PEIM .PEI\r | |
413 | PIC_PEIM .PEI\r | |
414 | COMBINED_PEIM_DRIVER .PEI\r | |
415 | TE_PEIM .PEI\r | |
416 | LOGO .FFS\r | |
417 | others .DXE\r | |
418 | </pre>\r | |
419 | \r | |
420 | @param componentType component type\r | |
421 | @return\r | |
422 | @throws BuildException\r | |
423 | If component type is null\r | |
424 | **/\r | |
425 | public static String getSuffix(String componentType) throws BuildException{\r | |
426 | if (componentType == null) {\r | |
427 | throw new BuildException("Component type is not specified.");\r | |
428 | }\r | |
429 | String str = ".DXE";\r | |
430 | if (componentType.equalsIgnoreCase("APPLICATION")) {\r | |
431 | str = ".APP";\r | |
432 | } else if (componentType.equalsIgnoreCase("SEC")) {\r | |
433 | str = ".SEC";\r | |
434 | } else if (componentType.equalsIgnoreCase("PEI_CORE")) {\r | |
435 | str = ".PEI";\r | |
436 | } else if (componentType.equalsIgnoreCase("PE32_PEIM")) {\r | |
437 | str = ".PEI";\r | |
438 | } else if (componentType.equalsIgnoreCase("RELOCATABLE_PEIM")) {\r | |
439 | str = ".PEI";\r | |
440 | } else if (componentType.equalsIgnoreCase("PIC_PEIM")) {\r | |
441 | str = ".PEI";\r | |
442 | } else if (componentType.equalsIgnoreCase("COMBINED_PEIM_DRIVER")) {\r | |
443 | str = ".PEI";\r | |
444 | } else if (componentType.equalsIgnoreCase("TE_PEIM")) {\r | |
445 | str = ".PEI";\r | |
446 | } else if (componentType.equalsIgnoreCase("LOGO")) {\r | |
447 | str = ".FFS";\r | |
448 | }\r | |
449 | return str;\r | |
450 | }\r | |
451 | \r | |
452 | /**\r | |
453 | Parse module surface are info described in FPD file and put them into map. \r | |
454 | \r | |
455 | @param sa module surface area info descibed in FPD file\r | |
456 | @return map list with top level elements\r | |
457 | **/\r | |
458 | private Map<String, XmlObject> getPlatformOverrideInfo(\r | |
459 | ModuleSADocument.ModuleSA sa) {\r | |
460 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r | |
461 | map.put("SourceFiles", sa.getSourceFiles());\r | |
462 | map.put("Includes", sa.getIncludes());\r | |
463 | map.put("Libraries", sa.getLibraries());\r | |
464 | map.put("Protocols", sa.getProtocols());\r | |
465 | map.put("Events", sa.getEvents());\r | |
466 | map.put("Hobs", sa.getHobs());\r | |
467 | map.put("PPIs", sa.getPPIs());\r | |
468 | map.put("Variables", sa.getVariables());\r | |
469 | map.put("BootModes", sa.getBootModes());\r | |
470 | map.put("SystemTables", sa.getSystemTables());\r | |
471 | map.put("DataHubs", sa.getDataHubs());\r | |
472 | map.put("Formsets", sa.getFormsets());\r | |
473 | map.put("Guids", sa.getGuids());\r | |
474 | map.put("Externs", sa.getExterns());\r | |
475 | map.put("BuildOptions", platformBuildOptions);\r | |
476 | return map;\r | |
477 | }\r | |
478 | \r | |
479 | /**\r | |
480 | Generate build.out.xml file.\r | |
481 | \r | |
482 | @throws BuildException\r | |
483 | build.out.xml XML document create error\r | |
484 | **/\r | |
485 | private void genBuildFile() throws BuildException {\r | |
486 | DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r | |
487 | try {\r | |
488 | DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r | |
489 | Document document = dombuilder.newDocument();\r | |
490 | Comment rootComment = document.createComment(info);\r | |
491 | //\r | |
492 | // create root element and its attributes\r | |
493 | //\r | |
494 | Element root = document.createElement("project");\r | |
495 | root.setAttribute("name", getProject().getProperty("PLATFORM"));\r | |
496 | root.setAttribute("default", "main");\r | |
497 | root.setAttribute("basedir", ".");\r | |
498 | //\r | |
499 | // element for External ANT tasks\r | |
500 | //\r | |
501 | root.appendChild(document.createComment("Apply external ANT tasks"));\r | |
502 | Element ele = document.createElement("taskdef");\r | |
503 | ele.setAttribute("resource", "GenBuild.tasks");\r | |
504 | root.appendChild(ele);\r | |
505 | \r | |
506 | ele = document.createElement("taskdef");\r | |
507 | ele.setAttribute("resource", "frameworktasks.tasks");\r | |
508 | root.appendChild(ele);\r | |
509 | \r | |
510 | ele = document.createElement("property");\r | |
511 | ele.setAttribute("environment", "env");\r | |
512 | root.appendChild(ele);\r | |
513 | //\r | |
514 | // Default Target\r | |
515 | //\r | |
516 | root.appendChild(document.createComment("Default target"));\r | |
517 | ele = document.createElement("target");\r | |
518 | ele.setAttribute("name", "main");\r | |
519 | ele.setAttribute("depends", "modules, fvs");\r | |
520 | root.appendChild(ele);\r | |
521 | //\r | |
522 | // Modules Target\r | |
523 | //\r | |
524 | root.appendChild(document.createComment("Modules target"));\r | |
525 | ele = document.createElement("target");\r | |
526 | ele.setAttribute("name", "modules");\r | |
527 | \r | |
528 | Set set = outfiles.keySet();\r | |
529 | Iterator iter = set.iterator();\r | |
530 | while (iter.hasNext()) {\r | |
531 | FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r | |
532 | String baseName = moduleId.getBaseName();\r | |
533 | Element moduleEle = document.createElement("ant");\r | |
534 | moduleEle.setAttribute("antfile", GlobalData\r | |
535 | .getModulePath(baseName)\r | |
536 | + File.separatorChar + "build.xml");\r | |
537 | moduleEle.setAttribute("target", baseName);\r | |
538 | //\r | |
539 | // ARCH\r | |
540 | //\r | |
541 | Element property = document.createElement("property");\r | |
542 | property.setAttribute("name", "ARCH");\r | |
543 | property.setAttribute("value", moduleId.getArch());\r | |
544 | moduleEle.appendChild(property);\r | |
545 | //\r | |
546 | // PACKAGE_DIR\r | |
547 | //\r | |
548 | property = document.createElement("property");\r | |
549 | property.setAttribute("name", "PACKAGE_DIR");\r | |
550 | property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r | |
551 | + GlobalData.getPackagePathForModule(baseName));\r | |
552 | moduleEle.appendChild(property);\r | |
553 | //\r | |
554 | // PACKAGE\r | |
555 | //\r | |
556 | property = document.createElement("property");\r | |
557 | property.setAttribute("name", "PACKAGE");\r | |
558 | property.setAttribute("value", GlobalData\r | |
559 | .getPackageNameForModule(baseName));\r | |
560 | moduleEle.appendChild(property);\r | |
561 | ele.appendChild(moduleEle);\r | |
562 | }\r | |
563 | root.appendChild(ele);\r | |
564 | //\r | |
565 | // FVS Target\r | |
566 | //\r | |
567 | root.appendChild(document.createComment("FVs target"));\r | |
568 | ele = document.createElement("target");\r | |
569 | ele.setAttribute("name", "fvs");\r | |
570 | \r | |
571 | String[] validFv = SurfaceAreaQuery.getFpdValidImageNames();\r | |
572 | for (int i = 0; i < validFv.length; i++) {\r | |
573 | String inputFile = FV_OUTPUT_DIR + "" + File.separatorChar\r | |
574 | + validFv[i].toUpperCase() + ".inf";\r | |
575 | Element fvEle = document.createElement("genfvimage");\r | |
576 | fvEle.setAttribute("infFile", inputFile);\r | |
577 | ele.appendChild(fvEle);\r | |
578 | Element moveEle = document.createElement("move");\r | |
579 | moveEle.setAttribute("file", validFv[i].toUpperCase() + ".fv");\r | |
580 | moveEle.setAttribute("todir", FV_OUTPUT_DIR);\r | |
581 | ele.appendChild(moveEle);\r | |
582 | }\r | |
583 | root.appendChild(ele);\r | |
584 | \r | |
585 | boolean isUnified = false;\r | |
586 | BuildOptionsDocument.BuildOptions buildOptions = (BuildOptionsDocument.BuildOptions)platformBuildOptions;\r | |
587 | if (buildOptions.getOutputDirectory() != null){\r | |
588 | if (buildOptions.getOutputDirectory().getIntermediateDirectories() != null){\r | |
589 | if (buildOptions.getOutputDirectory().getIntermediateDirectories().toString().equalsIgnoreCase("UNIFIED")){\r | |
590 | isUnified = true;\r | |
591 | }\r | |
592 | }\r | |
593 | }\r | |
594 | //\r | |
595 | // Clean Target\r | |
596 | //\r | |
597 | root.appendChild(document.createComment("Clean target"));\r | |
598 | ele = document.createElement("target");\r | |
599 | ele.setAttribute("name", "clean");\r | |
600 | \r | |
601 | if (isUnified) {\r | |
602 | Element cleanEle = document.createElement("delete");\r | |
603 | cleanEle.setAttribute("includeemptydirs", "true");\r | |
604 | Element filesetEle = document.createElement("fileset");\r | |
605 | filesetEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r | |
606 | filesetEle.setAttribute("includes", "**/OUTPUT/**");\r | |
607 | cleanEle.appendChild(filesetEle);\r | |
608 | ele.appendChild(cleanEle);\r | |
609 | }\r | |
610 | else {\r | |
611 | set = outfiles.keySet();\r | |
612 | iter = set.iterator();\r | |
613 | while (iter.hasNext()) {\r | |
614 | FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r | |
615 | String baseName = moduleId.getBaseName();\r | |
616 | \r | |
617 | Element ifEle = document.createElement("if");\r | |
618 | Element availableEle = document.createElement("available");\r | |
619 | availableEle.setAttribute("file", GlobalData\r | |
620 | .getModulePath(baseName)\r | |
621 | + File.separatorChar + "build.xml");\r | |
622 | ifEle.appendChild(availableEle);\r | |
623 | Element elseEle = document.createElement("then");\r | |
624 | \r | |
625 | Element moduleEle = document.createElement("ant");\r | |
626 | moduleEle.setAttribute("antfile", GlobalData\r | |
627 | .getModulePath(baseName)\r | |
628 | + File.separatorChar + "build.xml");\r | |
629 | moduleEle.setAttribute("target", baseName + "_clean");\r | |
630 | //\r | |
631 | // ARCH\r | |
632 | //\r | |
633 | Element property = document.createElement("property");\r | |
634 | property.setAttribute("name", "ARCH");\r | |
635 | property.setAttribute("value", moduleId.getArch());\r | |
636 | moduleEle.appendChild(property);\r | |
637 | //\r | |
638 | // PACKAGE_DIR\r | |
639 | //\r | |
640 | property = document.createElement("property");\r | |
641 | property.setAttribute("name", "PACKAGE_DIR");\r | |
642 | property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r | |
643 | + GlobalData.getPackagePathForModule(baseName));\r | |
644 | moduleEle.appendChild(property);\r | |
645 | //\r | |
646 | // PACKAGE\r | |
647 | //\r | |
648 | property = document.createElement("property");\r | |
649 | property.setAttribute("name", "PACKAGE");\r | |
650 | property.setAttribute("value", GlobalData\r | |
651 | .getPackageNameForModule(baseName));\r | |
652 | moduleEle.appendChild(property);\r | |
653 | elseEle.appendChild(moduleEle);\r | |
654 | ifEle.appendChild(elseEle);\r | |
655 | ele.appendChild(ifEle);\r | |
656 | }\r | |
657 | }\r | |
658 | root.appendChild(ele);\r | |
659 | //\r | |
660 | // Deep Clean Target\r | |
661 | //\r | |
662 | root.appendChild(document.createComment("Clean All target"));\r | |
663 | ele = document.createElement("target");\r | |
664 | ele.setAttribute("name", "cleanall");\r | |
665 | \r | |
666 | if (isUnified) {\r | |
667 | Element cleanAllEle = document.createElement("delete");\r | |
668 | cleanAllEle.setAttribute("dir", getProject().getProperty("PLATFORM_DIR") + File.separatorChar + "Build" + File.separatorChar + "${TARGET}");\r | |
669 | ele.appendChild(cleanAllEle);\r | |
670 | }\r | |
671 | else {\r | |
672 | set = outfiles.keySet();\r | |
673 | iter = set.iterator();\r | |
674 | while (iter.hasNext()) {\r | |
675 | FpdModuleIdentification moduleId = (FpdModuleIdentification) iter.next();\r | |
676 | String baseName = moduleId.getBaseName();\r | |
677 | \r | |
678 | Element ifEle = document.createElement("if");\r | |
679 | Element availableEle = document.createElement("available");\r | |
680 | availableEle.setAttribute("file", GlobalData\r | |
681 | .getModulePath(baseName)\r | |
682 | + File.separatorChar + "build.xml");\r | |
683 | ifEle.appendChild(availableEle);\r | |
684 | Element elseEle = document.createElement("then");\r | |
685 | \r | |
686 | Element moduleEle = document.createElement("ant");\r | |
687 | moduleEle.setAttribute("antfile", GlobalData\r | |
688 | .getModulePath(baseName)\r | |
689 | + File.separatorChar + "build.xml");\r | |
690 | moduleEle.setAttribute("target", baseName + "_cleanall");\r | |
691 | //\r | |
692 | // ARCH\r | |
693 | //\r | |
694 | Element property = document.createElement("property");\r | |
695 | property.setAttribute("name", "ARCH");\r | |
696 | property.setAttribute("value", moduleId.getArch());\r | |
697 | moduleEle.appendChild(property);\r | |
698 | //\r | |
699 | // PACKAGE_DIR\r | |
700 | //\r | |
701 | property = document.createElement("property");\r | |
702 | property.setAttribute("name", "PACKAGE_DIR");\r | |
703 | property.setAttribute("value", "${WORKSPACE_DIR}" + File.separatorChar\r | |
704 | + GlobalData.getPackagePathForModule(baseName));\r | |
705 | moduleEle.appendChild(property);\r | |
706 | //\r | |
707 | // PACKAGE\r | |
708 | //\r | |
709 | property = document.createElement("property");\r | |
710 | property.setAttribute("name", "PACKAGE");\r | |
711 | property.setAttribute("value", GlobalData\r | |
712 | .getPackageNameForModule(baseName));\r | |
713 | moduleEle.appendChild(property);\r | |
714 | elseEle.appendChild(moduleEle);\r | |
715 | ifEle.appendChild(elseEle);\r | |
716 | ele.appendChild(ifEle);\r | |
717 | }\r | |
718 | }\r | |
719 | root.appendChild(ele);\r | |
720 | \r | |
721 | document.appendChild(rootComment);\r | |
722 | document.appendChild(root);\r | |
723 | //\r | |
724 | // Prepare the DOM document for writing\r | |
725 | //\r | |
726 | Source source = new DOMSource(document);\r | |
727 | //\r | |
728 | // Prepare the output file\r | |
729 | //\r | |
730 | File file = new File(getProject().getProperty("PLATFORM_DIR")\r | |
731 | + File.separatorChar + "build.out.xml");\r | |
732 | //\r | |
733 | // generate all directory path\r | |
734 | //\r | |
735 | (new File(file.getParent())).mkdirs();\r | |
736 | Result result = new StreamResult(file);\r | |
737 | //\r | |
738 | // Write the DOM document to the file\r | |
739 | //\r | |
740 | Transformer xformer = TransformerFactory.newInstance()\r | |
741 | .newTransformer();\r | |
742 | xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r | |
743 | xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r | |
744 | xformer.transform(source, result);\r | |
745 | } catch (Exception ex) {\r | |
746 | throw new BuildException("Generate build.out.xml failed. \n" + ex.getMessage());\r | |
747 | }\r | |
748 | }\r | |
749 | \r | |
750 | /**\r | |
751 | Add a property. \r | |
752 | \r | |
753 | @param p property\r | |
754 | **/\r | |
755 | public void addProperty(Property p) {\r | |
756 | properties.addElement(p);\r | |
757 | }\r | |
758 | \r | |
759 | /**\r | |
760 | Get FPD file name.\r | |
761 | \r | |
762 | @return FPD file name.\r | |
763 | **/\r | |
764 | public File getFpdFilename() {\r | |
765 | return fpdFilename;\r | |
766 | }\r | |
767 | \r | |
768 | /**\r | |
769 | Set FPD file name.\r | |
770 | \r | |
771 | @param fpdFilename FPD file name\r | |
772 | **/\r | |
773 | public void setFpdFilename(File fpdFilename) {\r | |
774 | this.fpdFilename = fpdFilename;\r | |
775 | }\r | |
776 | \r | |
777 | public File getGuiddatabase() {\r | |
778 | return guiddatabase;\r | |
779 | }\r | |
780 | \r | |
781 | public void setGuiddatabase(File guiddatabase) {\r | |
782 | this.guiddatabase = guiddatabase;\r | |
783 | }\r | |
784 | \r | |
785 | public void collectPCDInformation() {\r | |
7db4ab70 | 786 | String exceptionString = null;\r |
787 | CollectPCDAction collectAction = new CollectPCDAction ();\r | |
788 | //\r | |
789 | // Collect all PCD information from FPD to MSA, and get help information from SPD.\r | |
790 | // These all information will be stored into memory database for future usage such \r | |
791 | // as autogen.\r | |
792 | //\r | |
793 | try {\r | |
794 | collectAction.perform (getProject().getProperty("WORKSPACE_DIR"),\r | |
795 | fpdFilename.getPath(),\r | |
796 | ActionMessage.MAX_MESSAGE_LEVEL\r | |
797 | );\r | |
798 | } catch (Exception exp) {\r | |
799 | exceptionString = exp.getMessage();\r | |
800 | if (exceptionString == null) {\r | |
801 | 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 | |
802 | }\r | |
803 | throw new BuildException (String.format("Fail to do PCD preprocess from FPD file: %s", exceptionString));\r | |
804 | }\r | |
878ddf1f | 805 | }\r |
806 | }\r |