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