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