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