]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Adding new Logger instead of Ant's.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
1 /** @file
2 GlobalData class.
3
4 GlobalData provide initializing, instoring, querying and update global data.
5 It is a bridge to intercommunicate between multiple component, such as AutoGen,
6 PCD and so on.
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 **/
17 package org.tianocore.build.global;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.apache.xmlbeans.XmlException;
29 import org.apache.xmlbeans.XmlObject;
30
31 import org.tianocore.common.exception.EdkException;
32 import org.tianocore.common.logger.EdkLog;
33 import org.tianocore.pcd.entity.MemoryDatabaseManager;
34 import org.tianocore.DbPathAndFilename;
35 import org.tianocore.FrameworkDatabaseDocument;
36 import org.tianocore.ModuleSurfaceAreaDocument;
37 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
38 import org.tianocore.build.id.FpdModuleIdentification;
39 import org.tianocore.build.id.ModuleIdentification;
40 import org.tianocore.build.id.PackageIdentification;
41 import org.tianocore.build.id.PlatformIdentification;
42 import org.tianocore.build.toolchain.ToolChainAttribute;
43 import org.tianocore.build.toolchain.ToolChainConfig;
44 import org.tianocore.build.toolchain.ToolChainElement;
45 import org.tianocore.build.toolchain.ToolChainInfo;
46 import org.tianocore.build.toolchain.ToolChainKey;
47 import org.tianocore.build.toolchain.ToolChainMap;
48
49 /**
50 GlobalData provide initializing, instoring, querying and update global data.
51 It is a bridge to intercommunicate between multiple component, such as AutoGen,
52 PCD and so on.
53
54 <p>Note that all global information are initialized incrementally. All data will
55 parse and record only of necessary during build time. </p>
56
57 @since GenBuild 1.0
58 **/
59 public class GlobalData {
60 ///
61 /// Record current WORKSPACE Directory
62 ///
63 private static String workspaceDir = "";
64
65 ///
66 /// Be used to ensure Global data will be initialized only once.
67 ///
68 private static boolean globalFlag = false;
69
70 ///
71 /// Framework Database information: package list and platform list
72 ///
73 private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();
74
75 private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();
76
77 ///
78 /// Every detail SPD informations: Module list, Library class definition,
79 /// Package header file, GUID/PPI/Protocol definitions
80 ///
81 private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();
82
83 ///
84 /// Build informations are divided into three parts:
85 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
86 ///
87 private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();
88
89 private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
90
91 private static Map<String, XmlObject> fpdBuildOptionsMap = new HashMap<String, XmlObject>();
92
93 private static XmlObject fpdBuildOptions;
94
95 private static XmlObject fpdDynamicPcds;
96
97 ///
98 /// Parsed modules list
99 ///
100 private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
101
102 ///
103 /// built modules list with ARCH, TARGET, TOOLCHAIN
104 ///
105 private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();
106
107 ///
108 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
109 ///
110 private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
111
112 ///
113 /// build target + tool chain family/tag name + arch + command types + command options
114 ///
115 ///
116 /// Tool Chain Data
117 /// toolsDef - build tool program information
118 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
119 /// moduleSaBuildOption - build options for a specific module
120 ///
121 private static ToolChainConfig toolsDef;
122
123 private static ToolChainInfo toolChainInfo;
124 private static ToolChainInfo toolChainEnvInfo;
125 private static ToolChainInfo toolChainPlatformInfo;
126
127 private static ToolChainMap platformToolChainOption;
128 private static ToolChainMap platformToolChainFamilyOption;
129
130 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
131 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
132
133 /**
134 Parse framework database (DB) and all SPD files listed in DB to initialize
135 the environment for next build. This method will only be executed only once
136 in the whole build process.
137
138 @param workspaceDatabaseFile the file name of framework database
139 @param workspaceDir current workspace directory path
140 @throws BuildException
141 Framework Dababase or SPD or MSA file is not valid
142 **/
143 public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException {
144 //
145 // ensure this method will be revoked only once
146 //
147 if (globalFlag) {
148 return;
149 }
150 globalFlag = true;
151
152 //
153 // Backup workspace directory. It will be used by other method
154 //
155 GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");
156
157 //
158 // Parse tools definition file
159 //
160 //
161 // If ToolChain has been set up before, do nothing.
162 // CONF dir + tools definition file name
163 //
164 File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
165 EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "].");
166 toolsDef = new ToolChainConfig(toolsDefFile);
167
168
169 //
170 // Parse Framework Database
171 //
172 File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
173 try {
174 FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
175 //
176 // validate FrameworkDatabaseFile
177 //
178 if (!db.validate()) {
179 throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");
180 }
181 //
182 // Get package list
183 //
184 if (db.getFrameworkDatabase().getPackageList() != null ) {
185 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();
186 Iterator<DbPathAndFilename> iter = packages.iterator();
187 while (iter.hasNext()) {
188 String fileName = iter.next().getStringValue().trim();
189 Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));
190 packageList.add(spd.getPackageId());
191 //
192 // Report warning if existing two packages with same GUID and Version
193 //
194 if (spdTable.containsKey(spd.getPackageId())) {
195 //
196 // BUGBUG
197 //
198 EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath());
199 }
200 spdTable.put(spd.getPackageId(), spd);
201 }
202 }
203
204 //
205 // Get platform list
206 //
207 if (db.getFrameworkDatabase().getPlatformList() != null) {
208 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();
209 Iterator<DbPathAndFilename> iter = platforms.iterator();
210 while (iter.hasNext()) {
211 String fileName = iter.next().getStringValue().trim();
212 File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
213 if ( !fpdFile.exists() ) {
214 throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");
215 }
216 XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
217 //
218 // Verify FPD file, if is invalid, throw Exception
219 //
220 if (!fpdDoc.validate()) {
221 throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");
222 }
223 //
224 // We can change Map to XmlObject
225 //
226 Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();
227 fpdDocMap.put("PlatformSurfaceArea", fpdDoc);
228 SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);
229 PlatformIdentification platformId = saq.getFpdHeader();
230 platformId.setFpdFile(fpdFile);
231 //
232 // Report warning if existing two platfrom with same GUID and Version
233 //
234 if (platformList.contains(platformId)) {
235 //
236 // BUGBUG
237 //
238 EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath());
239 }
240 platformList.add(platformId);
241 }
242 }
243 } catch(IOException ex) {
244 EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());
245 edkException.setStackTrace(ex.getStackTrace());
246 throw edkException;
247 } catch(XmlException ex) {
248 EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());
249 edkException.setStackTrace(ex.getStackTrace());
250 throw edkException;
251 }
252 }
253
254 /**
255 Get the current WORKSPACE Directory.
256
257 @return current workspace directory
258 **/
259 public synchronized static String getWorkspacePath() {
260 return workspaceDir;
261 }
262
263
264 /**
265 Get the MSA file name with absolute path
266 */
267 public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {
268 File msaFile = null;
269 //
270 // TBD. Do only when package is null.
271 //
272 Iterator iter = packageList.iterator();
273 while (iter.hasNext()) {
274 PackageIdentification packageId = (PackageIdentification)iter.next();
275 Spd spd = spdTable.get(packageId);
276 msaFile = spd.getModuleFile(moduleId);
277 if (msaFile != null ) {
278 break ;
279 }
280 }
281 if (msaFile == null){
282 throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
283 } else {
284 return msaFile;
285 }
286 }
287
288 public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {
289 //
290 // If package already defined in module
291 //
292 if (moduleId.getPackage() != null) {
293 return moduleId.getPackage();
294 }
295
296 PackageIdentification packageId = null;
297 Iterator iter = packageList.iterator();
298 while (iter.hasNext()) {
299 packageId = (PackageIdentification)iter.next();
300 moduleId.setPackage(packageId);
301 Spd spd = spdTable.get(packageId);
302 if (spd.getModuleFile(moduleId) != null ) {
303 break ;
304 }
305 }
306 if (packageId == null){
307 throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
308 } else {
309 return packageId;
310 }
311 }
312
313 /**
314 Difference between build and parse: ToolChain and Target
315 **/
316 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {
317 return builtModules.contains(moduleId);
318 }
319
320 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {
321 builtModules.add(fpdModuleId);
322 }
323
324
325 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{
326 Map<String, XmlObject> result = new HashMap<String, XmlObject>();
327 Set keySet = doc.keySet();
328 Iterator iter = keySet.iterator();
329 while (iter.hasNext()){
330 String key = (String)iter.next();
331 XmlObject item = cloneXmlObject(doc.get(key), true);
332 result.put(key, item);
333 }
334 fpdModuleSA.put(fpdModuleId, result);
335 }
336
337 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {
338 return fpdModuleSA.containsKey(fpdModuleId);
339 }
340
341 /**
342 Query module surface area information.
343
344 <p>Note that surface area parsing is incremental. That means the method will
345 only parse the MSA files if necessary. </p>
346
347 @param fpdModuleId Module ID with arch
348 @return ModuleSA info and MSA info for fpdModuleId
349 @throws BuildException Can't find MSA
350 **/
351 public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{
352 if (parsedModules.containsKey(fpdModuleId)) {
353 return parsedModules.get(fpdModuleId);
354 }
355 Map<String, XmlObject> doc = new HashMap<String, XmlObject>();
356 ModuleIdentification moduleId = fpdModuleId.getModule();
357 //
358 // First part: get the MSA files info
359 //
360 doc.putAll(getNativeMsa(moduleId));
361
362 //
363 // Second part: put build options
364 //
365 doc.put("BuildOptions", fpdBuildOptions);
366
367 //
368 // Third part: get Module info from FPD, such as Library instances, PCDs
369 //
370 if (fpdModuleSA.containsKey(fpdModuleId)){
371 //
372 // merge module info in FPD to final Doc
373 // For Library Module, do nothing here
374 //
375 doc.putAll(fpdModuleSA.get(fpdModuleId));
376 }
377 parsedModules.put(fpdModuleId, doc);
378 return doc;
379 }
380
381 public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{
382 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
383 return getDoc(fpdModuleId);
384 }
385
386 /**
387 Query the native MSA information with module base name.
388
389 <p>Note that MSA parsing is incremental. That means the method will
390 only to parse the MSA files when never parsed before. </p>
391
392 @param moduleName the base name of the module
393 @return the native MSA information
394 @throws BuildException
395 MSA file is not valid
396 **/
397 public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {
398 if (nativeMsa.containsKey(moduleId)) {
399 return nativeMsa.get(moduleId);
400 }
401 File msaFile = getMsaFile(moduleId);
402 Map<String, XmlObject> msaMap = getNativeMsa(msaFile);
403 nativeMsa.put(moduleId, msaMap);
404 return msaMap;
405 }
406
407 public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {
408 if (!msaFile.exists()) {
409 throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");
410 }
411 try {
412 ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
413 //
414 // Validate File if they accord with XML Schema
415 //
416 if ( !doc.validate()){
417 throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");
418 }
419 //
420 // parse MSA file
421 //
422 ModuleSurfaceArea msa= doc.getModuleSurfaceArea();
423 Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();
424 msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));
425 msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));
426 msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));
427 msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));
428 msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));
429 msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));
430 msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));
431 msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
432 msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
433 msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
434 return msaMap;
435 } catch(IOException ex) {
436 EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());
437 edkException.setStackTrace(ex.getStackTrace());
438 throw edkException;
439 } catch(XmlException ex) {
440 EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());
441 edkException.setStackTrace(ex.getStackTrace());
442 throw edkException;
443 }
444 }
445
446 public static Map<String, XmlObject> getFpdBuildOptionsMap() {
447 return fpdBuildOptionsMap;
448 }
449
450 public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {
451 GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);
452 fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);
453 }
454
455 public static XmlObject getFpdDynamicPcds() {
456 return fpdDynamicPcds;
457 }
458
459 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {
460 GlobalData.fpdDynamicPcds = fpdDynamicPcds;
461 }
462
463 public static Set<ModuleIdentification> getModules(PackageIdentification packageId){
464 Spd spd = spdTable.get(packageId);
465 if (spd == null ) {
466 Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();
467 return dummy;
468 } else {
469 return spd.getModules();
470 }
471 }
472
473 /**
474 * The header file path is relative to workspace dir
475 */
476 public static String[] getLibraryClassHeaderFiles(
477 PackageIdentification[] packages, String name) throws EdkException{
478 if (packages == null) {
479 // throw Exception or not????
480 return new String[0];
481 }
482 String[] result = null;
483 for (int i = 0; i < packages.length; i++) {
484 Spd spd = spdTable.get(packages[i]);
485 //
486 // If find one package defined the library class
487 //
488 if ((result = spd.getLibClassIncluder(name)) != null) {
489 return result;
490 }
491 }
492 //
493 // If can't find library class declaration in every package
494 //
495 throw new EdkException("Can not find library class [" + name
496 + "] declaration in any SPD package!");
497 }
498
499 /**
500 * The header file path is relative to workspace dir
501 */
502 public static String getPackageHeaderFiles(PackageIdentification packages,
503 String moduleType) {
504 if (packages == null) {
505 return new String("");
506 }
507 Spd spd = spdTable.get(packages);
508 //
509 // If can't find package header file, skip it
510 //
511 String temp = null;
512 if (spd != null) {
513 if ((temp = spd.getPackageIncluder(moduleType)) != null) {
514 return temp;
515 } else {
516 temp = "";
517 return temp;
518 }
519 } else {
520 return null;
521 }
522 }
523
524 /**
525 * return two values: {cName, GuidValue}
526 */
527 public static String[] getGuid(List<PackageIdentification> packages, String name) {
528 if (packages == null) {
529 // throw Exception or not????
530 return new String[0];
531 }
532 String[] result = null;
533 Iterator item = packages.iterator();
534 while (item.hasNext()){
535 Spd spd = spdTable.get(item.next());
536 //
537 // If find one package defined the GUID
538 //
539 if ((result = spd.getGuid(name)) != null) {
540 return result;
541 }
542 }
543
544 return null;
545 }
546
547 /**
548 * return two values: {cName, GuidValue}
549 */
550 public static String[] getPpiGuid(List<PackageIdentification> packages,
551 String name) {
552 if (packages == null) {
553 return new String[0];
554 }
555 String[] result = null;
556 Iterator item = packages.iterator();
557 while (item.hasNext()){
558 Spd spd = spdTable.get(item.next());
559 //
560 // If find one package defined the Ppi GUID
561 //
562 if ((result = spd.getPpi(name)) != null) {
563 return result;
564 }
565 }
566 return null;
567 }
568
569 /**
570 * return two values: {cName, GuidValue}
571 */
572 public static String[] getProtocolGuid(List<PackageIdentification> packages,
573 String name) {
574 if (packages == null) {
575 return new String[0];
576 }
577 String[] result = null;
578 Iterator item = packages.iterator();
579 while (item.hasNext()){
580 Spd spd = spdTable.get(item.next());
581 //
582 // If find one package defined the protocol GUID
583 //
584 if ((result = spd.getProtocol(name))!= null){
585 return result;
586 }
587 }
588 return null;
589
590 }
591
592 public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException {
593 Iterator iter = platformList.iterator();
594 while(iter.hasNext()){
595 PlatformIdentification platformId = (PlatformIdentification)iter.next();
596 if (platformId.getName().equalsIgnoreCase(name)) {
597 return platformId;
598 }
599 }
600 throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!");
601 }
602
603 public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException {
604 File file = new File(workspaceDir + File.separatorChar + filename);
605 Iterator iter = platformList.iterator();
606 while(iter.hasNext()){
607 PlatformIdentification platformId = (PlatformIdentification)iter.next();
608 if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
609 return platformId;
610 }
611 }
612 throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");
613 }
614
615 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException {
616 Iterator iter = packageList.iterator();
617 while(iter.hasNext()){
618 PackageIdentification packageItem = (PackageIdentification)iter.next();
619 if (packageItem.equals(packageId)) {
620 packageId.setName(packageItem.getName());
621 packageId.setSpdFile(packageItem.getSpdFile());
622 return packageId;
623 }
624 }
625 throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");
626 }
627
628 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException {
629 PackageIdentification packageId = getPackageForModule(moduleId);
630 moduleId.setPackage(packageId);
631 Spd spd = spdTable.get(packageId);
632 if (spd == null) {
633 throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");
634 }
635 Set<ModuleIdentification> modules = spd.getModules();
636 Iterator<ModuleIdentification> iter = modules.iterator();
637 while (iter.hasNext()) {
638 ModuleIdentification item = iter.next();
639 if (item.equals(moduleId)) {
640 moduleId.setName(item.getName());
641 moduleId.setModuleType(item.getModuleType());
642 moduleId.setMsaFile(item.getMsaFile());
643 return moduleId;
644 }
645 }
646 throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");
647 }
648
649 public synchronized static Set<PackageIdentification> getPackageList(){
650 return packageList;
651 }
652
653 /**
654 BUGBUG: It is a walk around method. If do not clone, can't query info with
655 XPath correctly.
656
657 @param object XmlObject
658 @param deep flag for deep clone
659 @return XmlObject after clone
660 @throws BuildException parse original XmlObject error.
661 **/
662 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException {
663 if ( object == null) {
664 return null;
665 }
666 XmlObject result = null;
667 try {
668 result = XmlObject.Factory.parse(object.getDomNode()
669 .cloneNode(deep));
670 } catch (XmlException ex) {
671 EdkException edkException = new EdkException(ex.getMessage());
672 edkException.setStackTrace(ex.getStackTrace());
673 throw edkException;
674 }
675 return result;
676 }
677
678 ///
679 /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
680 ///
681 public static ToolChainInfo getToolChainInfo() {
682 if (toolChainInfo == null) {
683 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
684 if (toolChainPlatformInfo != null) {
685 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
686 }
687 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
688 toolChainInfo.normalize();
689 EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: ");
690 EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + "");
691 }
692 return toolChainInfo;
693 }
694
695 public static void setPlatformToolChainFamilyOption(ToolChainMap map) {
696 platformToolChainFamilyOption = map;
697 }
698
699 public static void setPlatformToolChainOption(ToolChainMap map) {
700 platformToolChainOption = map;
701 }
702
703 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,
704 ToolChainMap toolChainOption) {
705 moduleToolChainOption.put(fpdModuleId, toolChainOption);
706 }
707
708 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,
709 ToolChainMap toolChainOption) {
710 moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
711 }
712
713 public static boolean isCommandSet(String target, String toolchain, String arch) {
714 String[] commands = getToolChainInfo().getCommands();
715
716 for (int i = 0; i < commands.length; ++i) {
717 String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});
718 if (cmdName != null && cmdName.length() != 0) {
719 return true;
720 }
721 }
722
723 return false;
724 }
725
726 public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
727 ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
728 ToolChainMap toolChainConfig = toolsDef.getConfig();
729 String setting = null;
730
731 if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {
732 setting = toolChainConfig.get(toolChainKey);
733 if (setting == null) {
734 setting = "";
735 }
736 return setting;
737 }
738
739 //
740 // get module specific options, if any
741 //
742 // tool tag first
743 ToolChainMap option = moduleToolChainOption.get(fpdModuleId);
744 ToolChainKey toolChainFamilyKey = null;
745
746 if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {
747 //
748 // then tool chain family
749 //
750 toolChainFamilyKey = new ToolChainKey(commandDescription);
751 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
752 String family = toolChainConfig.get(toolChainFamilyKey);
753 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
754 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
755
756 option = moduleToolChainFamilyOption.get(fpdModuleId);
757 if (option != null) {
758 setting = option.get(toolChainFamilyKey);
759 }
760 }
761
762 //
763 // get platform options, if any
764 //
765 if (setting == null) {
766 // tool tag first
767 if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {
768 // then tool chain family
769 if (toolChainFamilyKey == null) {
770 toolChainFamilyKey = new ToolChainKey(commandDescription);
771 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
772 String family = toolChainConfig.get(toolChainFamilyKey);
773 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
774 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
775 }
776
777 setting = platformToolChainFamilyOption.get(toolChainFamilyKey);
778 }
779 }
780
781 if (setting == null) {
782 setting = "";
783 }
784
785 return setting;
786 }
787
788 public static void setToolChainEnvInfo(ToolChainInfo envInfo) {
789 toolChainEnvInfo = envInfo;
790 }
791 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {
792 toolChainPlatformInfo = platformInfo;
793 }
794
795 //
796 // for PCD
797 //
798 public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
799 return pcdDbManager;
800 }
801
802 //
803 // For PCD get tokenSpaceGUid
804 //
805 public synchronized static String getGuidInfoFromCname(String cName){
806 String cNameGuid = null;
807 String guid = null;
808 Set set = spdTable.keySet();
809 Iterator iter = set.iterator();
810
811 if (iter == null) {
812 return null;
813 }
814
815 while (iter.hasNext()){
816 Spd spd = (Spd) spdTable.get(iter.next());
817 guid = spd.getGuidFromCname(cName);
818 if (guid != null){
819 cNameGuid = guid;
820 break;
821 }
822 }
823 return cNameGuid;
824 }
825
826 //
827 // For PCD
828 //
829 public synchronized static Map<FpdModuleIdentification, XmlObject>
830 getFpdModuleSaXmlObject(String xmlObjectName) {
831 Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();
832 Iterator item = fpdModuleSASet.iterator();
833
834
835 Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();
836 Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();
837 FpdModuleIdentification moduleId;
838 while (item.hasNext()) {
839
840 moduleId = (FpdModuleIdentification) item.next();
841 SANode = fpdModuleSA.get(moduleId);
842 try{
843 if (SANode.get(xmlObjectName)!= null){
844 SAPcdBuildDef.put(moduleId,
845 (XmlObject) SANode.get(xmlObjectName));
846
847 }
848 } catch (Exception e){
849 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());
850 }
851 }
852 return SAPcdBuildDef;
853 }
854
855 public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {
856 Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");
857
858 return pcdBuildDef;
859 }
860 }
861