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