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