]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Remove BugBug in comments and adjust function header according to code style doc.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
1 /** @file
2 GlobalData class.
3
4 GlobalData provide initializing, instoring, querying and update global data.
5 It is a bridge to intercommunicate between multiple component, such as AutoGen,
6 PCD and so on.
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 **/
17 package org.tianocore.build.global;
18
19 import java.io.File;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.logging.Logger;
27
28 import org.apache.tools.ant.BuildException;
29 import org.apache.xmlbeans.XmlObject;
30 import org.tianocore.DbPathAndFilename;
31 import org.tianocore.FrameworkDatabaseDocument;
32 import org.tianocore.ModuleSurfaceAreaDocument;
33 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
34 import org.tianocore.build.id.FpdModuleIdentification;
35 import org.tianocore.build.id.ModuleIdentification;
36 import org.tianocore.build.id.PackageIdentification;
37 import org.tianocore.build.id.PlatformIdentification;
38 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
39 import org.tianocore.build.toolchain.ToolChainAttribute;
40 import org.tianocore.build.toolchain.ToolChainConfig;
41 import org.tianocore.build.toolchain.ToolChainElement;
42 import org.tianocore.build.toolchain.ToolChainInfo;
43 import org.tianocore.build.toolchain.ToolChainKey;
44 import org.tianocore.build.toolchain.ToolChainMap;
45 import org.tianocore.exception.EdkException;
46 import org.tianocore.logger.EdkLog;
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 public static Logger log = Logger.getAnonymousLogger();
61
62 ///
63 /// Record current WORKSPACE Directory
64 ///
65 private static String workspaceDir = "";
66
67 ///
68 /// Be used to ensure Global data will be initialized only once.
69 ///
70 private static boolean globalFlag = false;
71
72 ///
73 /// Framework Database information: package list and platform list
74 ///
75 private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();
76
77 private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();
78
79 ///
80 /// Every detail SPD informations: Module list, Library class definition,
81 /// Package header file, GUID/PPI/Protocol definitions
82 ///
83 private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();
84
85 ///
86 /// Build informations are divided into three parts:
87 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
88 ///
89 private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();
90
91 private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
92
93 private static XmlObject fpdBuildOptions;
94
95 private static XmlObject fpdDynamicPcds;
96
97 ///
98 /// Parsed modules list
99 ///
100 private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
101
102 ///
103 /// built modules list with ARCH, TARGET, TOOLCHAIN
104 ///
105 private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();
106
107 ///
108 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
109 ///
110 // private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
111
112 ///
113 /// build target + tool chain family/tag name + arch + command types + command options
114 ///
115 ///
116 /// Tool Chain Data
117 /// toolsDef - build tool program information
118 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
119 /// moduleSaBuildOption - build options for a specific module
120 ///
121 private static ToolChainConfig toolsDef;
122
123 private static ToolChainInfo toolChainInfo;
124 private static ToolChainInfo toolChainEnvInfo;
125 private static ToolChainInfo toolChainPlatformInfo;
126
127 private static ToolChainMap platformToolChainOption;
128 private static ToolChainMap platformToolChainFamilyOption;
129
130 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
131 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
132
133 private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
134
135 /**
136 Parse framework database (DB) and all SPD files listed in DB to initialize
137 the environment for next build. This method will only be executed only once
138 in the whole build process.
139
140 @param workspaceDatabaseFile the file name of framework database
141 @param workspaceDir current workspace directory path
142 @throws BuildException
143 Framework Dababase or SPD or MSA file is not valid
144 **/
145 public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException {
146 //
147 // ensure this method will be revoked only once
148 //
149 if (globalFlag) {
150 return;
151 }
152 globalFlag = true;
153
154 //
155 // Backup workspace directory. It will be used by other method
156 //
157 GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");
158
159 //
160 // Parse tools definition file
161 //
162 //
163 // If ToolChain has been set up before, do nothing.
164 // CONF dir + tools definition file name
165 //
166 File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
167 System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");
168 toolsDef = new ToolChainConfig(toolsDefFile);
169
170 //
171 // Parse Framework Database
172 //
173 File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
174 try {
175 FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
176 //
177 // validate FrameworkDatabaseFile
178 //
179 if (! db.validate()) {
180 throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");
181 }
182 //
183 // Get package list
184 //
185 if (db.getFrameworkDatabase().getPackageList() != null ) {
186 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();
187 Iterator<DbPathAndFilename> iter = packages.iterator();
188 while (iter.hasNext()) {
189 String fileName = iter.next().getStringValue();
190 Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));
191 packageList.add(spd.getPackageId());
192 spdTable.put(spd.getPackageId(), spd);
193 }
194 }
195
196 //
197 // Get platform list
198 //
199 if (db.getFrameworkDatabase().getPlatformList() != null) {
200 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();
201 Iterator<DbPathAndFilename> iter = platforms.iterator();
202 while (iter.hasNext()) {
203 String fileName = iter.next().getStringValue();
204 File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
205 if ( ! fpdFile.exists() ) {
206 throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");
207 }
208 XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
209 //
210 // Verify FPD file, if is invalid, throw Exception
211 //
212 if (! fpdDoc.validate()) {
213 throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. ");
214 }
215 //
216 // We can change Map to XmlObject
217 //
218 //
219 // TBD check SPD or FPD is existed in FS
220 //
221 Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();
222 fpdDocMap.put("PlatformSurfaceArea", fpdDoc);
223 SurfaceAreaQuery.setDoc(fpdDocMap);
224 PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();
225 platformId.setFpdFile(fpdFile);
226 platformList.add(platformId);
227 }
228 }
229 } catch (Exception e) {
230 throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());
231 }
232 }
233
234 /**
235 Get the current WORKSPACE Directory.
236
237 @return current workspace directory
238 **/
239 public synchronized static String getWorkspacePath() {
240 return workspaceDir;
241 }
242
243
244 /**
245 Get the MSA file name with absolute path
246 */
247 public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {
248 File msaFile = null;
249 //
250 // TBD. Do only when package is null.
251 //
252 Iterator iter = packageList.iterator();
253 while (iter.hasNext()) {
254 PackageIdentification packageId = (PackageIdentification)iter.next();
255 Spd spd = spdTable.get(packageId);
256 msaFile = spd.getModuleFile(moduleId);
257 if (msaFile != null ) {
258 break ;
259 }
260 }
261 if (msaFile == null){
262 throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");
263 }
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 all packages. ");
289 }
290 else {
291 return packageId;
292 }
293 }
294
295 /**
296 Difference between build and parse: ToolChain and Target
297 **/
298 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {
299 return builtModules.contains(moduleId);
300 }
301
302 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {
303 builtModules.add(fpdModuleId);
304 }
305
306
307 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {
308 Map<String, XmlObject> result = new HashMap<String, XmlObject>();
309 Set keySet = doc.keySet();
310 Iterator iter = keySet.iterator();
311 while (iter.hasNext()){
312 String key = (String)iter.next();
313 XmlObject item = cloneXmlObject(doc.get(key), true);
314 result.put(key, item);
315 }
316 fpdModuleSA.put(fpdModuleId, result);
317 }
318
319 /**
320 Query overrided module surface area information. If current is Package
321 or Platform build, also include the information from FPD file.
322
323 <p>Note that surface area parsing is incremental. That means the method will
324 only parse the MSA and MBD files if necessary. </p>
325
326 @param moduleName the base name of the module
327 @return the overrided module surface area information
328 @throws BuildException
329 MSA or MBD is not valid
330 **/
331 public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {
332 if (parsedModules.containsKey(fpdModuleId)) {
333 return parsedModules.get(fpdModuleId);
334 }
335 Map<String, XmlObject> doc = new HashMap<String, XmlObject>();
336 ModuleIdentification moduleId = fpdModuleId.getModule();
337 //
338 // First part: get the MSA files info
339 //
340 doc.putAll(getNativeMsa(moduleId));
341
342 //
343 // Second part: put build options
344 //
345 doc.put("BuildOptions", fpdBuildOptions);
346
347 //
348 // Third part: get Module info from FPD, such as Library instances, PCDs
349 //
350 if (fpdModuleSA.containsKey(fpdModuleId)){
351 //
352 // merge module info in FPD to final Doc
353 // For Library Module, do nothing here
354 //
355 doc.putAll(fpdModuleSA.get(fpdModuleId));
356 }
357 parsedModules.put(fpdModuleId, doc);
358 return doc;
359 }
360
361 public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {
362 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
363 return getDoc(fpdModuleId);
364 }
365 /**
366 Query the native MSA information with module base name.
367
368 <p>Note that MSA parsing is incremental. That means the method will
369 only to parse the MSA files when never parsed before. </p>
370
371 @param moduleName the base name of the module
372 @return the native MSA information
373 @throws BuildException
374 MSA file is not valid
375 **/
376 public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {
377 if (nativeMsa.containsKey(moduleId)) {
378 return nativeMsa.get(moduleId);
379 }
380 File msaFile = getMsaFile(moduleId);
381 Map<String, XmlObject> msaMap = getNativeMsa(msaFile);
382 nativeMsa.put(moduleId, msaMap);
383 return msaMap;
384 }
385
386 public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {
387 if (! msaFile.exists()) {
388 throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");
389 }
390 try {
391 ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
392 //
393 // Validate File if they accord with XML Schema
394 //
395 if ( ! doc.validate()){
396 throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");
397 }
398 //
399 // parse MSA file
400 //
401 ModuleSurfaceArea msa= doc.getModuleSurfaceArea();
402 Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();
403 msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));
404 msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));
405 msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));
406 msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));
407 msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));
408 msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));
409 msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));
410 msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
411 msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
412 msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
413 return msaMap;
414 }
415 catch (Exception ex){
416 throw new BuildException(ex.getMessage());
417 }
418 }
419
420 public static Map<String, XmlObject> getFpdBuildOptions() {
421 Map<String, XmlObject> map = new HashMap<String, XmlObject>();
422 map.put("BuildOptions", fpdBuildOptions);
423 return map;
424 }
425
426 public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {
427 GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);
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 //////////////////////////////////////////////
439 //////////////////////////////////////////////
440
441 public static Set<ModuleIdentification> getModules(PackageIdentification packageId){
442 Spd spd = spdTable.get(packageId);
443 if (spd == null ) {
444 Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();
445 return dummy;
446 }
447 else {
448 return spd.getModules();
449 }
450 }
451
452 /**
453 * The header file path is relative to workspace dir
454 */
455 public static String[] getLibraryClassHeaderFiles(
456 PackageIdentification[] packages, String name)
457 throws BuildException {
458 if (packages == null) {
459 // throw Exception or not????
460 return new String[0];
461 }
462 String[] result = null;
463 for (int i = 0; i < packages.length; i++) {
464 Spd spd = spdTable.get(packages[i]);
465 //
466 // If find one package defined the library class
467 //
468 if ((result = spd.getLibClassIncluder(name)) != null) {
469 return result;
470 }
471 }
472 //
473 // If can't find library class declaration in every package
474 //
475 throw new BuildException("Can not find library class [" + name
476 + "] declaration in every packages. ");
477 }
478
479 /**
480 * The header file path is relative to workspace dir
481 */
482 public static String getPackageHeaderFiles(PackageIdentification packages,
483 String moduleType) throws BuildException {
484 if (packages == null) {
485 return new String("");
486 }
487 Spd spd = spdTable.get(packages);
488 //
489 // If can't find package header file, skip it
490 //
491 String temp = null;
492 if (spd != null) {
493 if ((temp = spd.getPackageIncluder(moduleType)) != null) {
494 return temp;
495 } else {
496 temp = "";
497 return temp;
498 }
499 } else {
500 return null;
501 }
502 }
503
504 /**
505 * return two values: {cName, GuidValue}
506 */
507 public static String[] getGuid(List<PackageIdentification> packages, String name)
508 throws BuildException {
509 if (packages == null) {
510 // throw Exception or not????
511 return new String[0];
512 }
513 String[] result = null;
514 Iterator item = packages.iterator();
515 while (item.hasNext()){
516 Spd spd = spdTable.get(item.next());
517 //
518 // If find one package defined the GUID
519 //
520 if ((result = spd.getGuid(name)) != null) {
521 return result;
522 }
523 }
524
525 return null;
526 }
527
528 /**
529 * return two values: {cName, GuidValue}
530 */
531 public static String[] getPpiGuid(List<PackageIdentification> packages,
532 String name) throws BuildException {
533 if (packages == null) {
534 return new String[0];
535 }
536 String[] result = null;
537 Iterator item = packages.iterator();
538 while (item.hasNext()){
539 Spd spd = spdTable.get(item.next());
540 //
541 // If find one package defined the Ppi GUID
542 //
543 if ((result = spd.getPpi(name)) != null) {
544 return result;
545 }
546 }
547 return null;
548
549 }
550
551 /**
552 * return two values: {cName, GuidValue}
553 */
554 public static String[] getProtocolGuid(List<PackageIdentification> packages,
555 String name) throws BuildException {
556 if (packages == null) {
557 return new String[0];
558 }
559 String[] result = null;
560 Iterator item = packages.iterator();
561 while (item.hasNext()){
562 Spd spd = spdTable.get(item.next());
563 //
564 // If find one package defined the protocol GUID
565 //
566 if ((result = spd.getProtocol(name))!= null){
567 return result;
568 }
569 }
570 return null;
571
572 }
573
574 public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {
575 Iterator iter = platformList.iterator();
576 while(iter.hasNext()){
577 PlatformIdentification platformId = (PlatformIdentification)iter.next();
578 if (platformId.getName().equalsIgnoreCase(name)) {
579 return platformId;
580 }
581 }
582 throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");
583 }
584
585 public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {
586 File file = new File(workspaceDir + File.separatorChar + filename);
587 Iterator iter = platformList.iterator();
588 while(iter.hasNext()){
589 PlatformIdentification platformId = (PlatformIdentification)iter.next();
590 if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
591 return platformId;
592 }
593 }
594 throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");
595 }
596
597 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {
598 Iterator iter = packageList.iterator();
599 while(iter.hasNext()){
600 PackageIdentification packageItem = (PackageIdentification)iter.next();
601 if (packageItem.equals(packageId)) {
602 packageId.setName(packageItem.getName());
603 packageId.setSpdFile(packageItem.getSpdFile());
604 return packageId;
605 }
606 }
607 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
608 }
609
610 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {
611 // System.out.println("1");
612 // System.out.println("##" + moduleId.getGuid());
613 PackageIdentification packageId = getPackageForModule(moduleId);
614 // System.out.println("" + packageId.getGuid());
615 moduleId.setPackage(packageId);
616 Spd spd = spdTable.get(packageId);
617 if (spd == null) {
618 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
619 }
620 Set<ModuleIdentification> modules = spd.getModules();
621 Iterator<ModuleIdentification> iter = modules.iterator();
622 while (iter.hasNext()) {
623 ModuleIdentification item = iter.next();
624 if (item.equals(moduleId)) {
625 moduleId.setName(item.getName());
626 moduleId.setModuleType(item.getModuleType());
627 moduleId.setMsaFile(item.getMsaFile());
628 return moduleId;
629 }
630 }
631 throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");
632 }
633
634 public synchronized static Set<PackageIdentification> getPackageList(){
635 return packageList;
636 }
637 ///// remove!!
638 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {
639 if ( object == null) {
640 return null;
641 }
642 XmlObject result = null;
643 try {
644 result = XmlObject.Factory.parse(object.getDomNode()
645 .cloneNode(deep));
646 } catch (Exception ex) {
647 throw new BuildException(ex.getMessage());
648 }
649 return result;
650 }
651
652 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
653
654 public static ToolChainInfo getToolChainInfo() {
655 // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);
656 if (toolChainInfo == null) {
657 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
658 if (toolChainPlatformInfo != null) {
659 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
660 }
661 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
662 toolChainInfo.normalize();
663 GlobalData.log.info(toolChainInfo + "");
664 }
665 return toolChainInfo;
666 }
667
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 = new String[2];
795 cNameGuid[0] = cName;
796 cNameGuid[1] = guid;
797 break;
798 }
799 }
800 return cNameGuid;
801 }
802
803 //
804 // For PCD
805 //
806 public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(
807 String xmlObjectName) {
808 Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();
809 Iterator item = fpdModuleSASet.iterator();
810
811
812 Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();
813 Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();
814 FpdModuleIdentification moduleId;
815 while (item.hasNext()) {
816
817 moduleId = (FpdModuleIdentification) item.next();
818 SANode = fpdModuleSA.get(moduleId);
819 try{
820 if (SANode.get(xmlObjectName)!= null){
821 SAPcdBuildDef.put(moduleId,
822 (XmlObject) SANode
823 .get(xmlObjectName));
824
825 }
826
827
828 } catch (Exception e){
829 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());
830 }
831 }
832 return SAPcdBuildDef;
833 }
834 }
835