]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
Change to new XML Schema.
[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.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
25 import org.tianocore.build.exception.EdkException;
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.toolchain.ToolChainAttribute;
31 import org.tianocore.build.toolchain.ToolChainConfig;
32 import org.tianocore.build.toolchain.ToolChainElement;
33 import org.tianocore.build.toolchain.ToolChainInfo;
34 import org.tianocore.build.toolchain.ToolChainKey;
35 import org.tianocore.build.toolchain.ToolChainMap;
36 //import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
37 //import org.tianocore.logger.EdkLog;
38
39 import java.io.File;
40 import java.util.HashMap;
41 import java.util.HashSet;
42 import java.util.Iterator;
43 import java.util.List;
44 import java.util.Map;
45 import java.util.Set;
46 import java.util.logging.Logger;
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 MemoryDatabasseManager pcdDbManager = new MemoryDatabaseManager();
134
135
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 String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";
169 File toolsDefFile = new File(confDir + 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 e.printStackTrace();
234 throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());
235 }
236 }
237
238 /**
239 Get the current WORKSPACE Directory.
240
241 @return current workspace directory
242 **/
243 public synchronized static String getWorkspacePath() {
244 return workspaceDir;
245 }
246
247
248 /**
249 Get the MSA file name with absolute path
250 */
251 public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {
252 File msaFile = null;
253 //
254 // TBD. Do only when package is null.
255 //
256 Iterator iter = packageList.iterator();
257 while (iter.hasNext()) {
258 PackageIdentification packageId = (PackageIdentification)iter.next();
259 Spd spd = spdTable.get(packageId);
260 msaFile = spd.getModuleFile(moduleId);
261 if (msaFile != null ) {
262 break ;
263 }
264 }
265 if (msaFile == null){
266 throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");
267 }
268 else {
269 return msaFile;
270 }
271 }
272
273 public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {
274 //
275 // If package already defined in module
276 //
277 if (moduleId.getPackage() != null) {
278 return moduleId.getPackage();
279 }
280
281 PackageIdentification packageId = null;
282 Iterator iter = packageList.iterator();
283 while (iter.hasNext()) {
284 packageId = (PackageIdentification)iter.next();
285 moduleId.setPackage(packageId);
286 Spd spd = spdTable.get(packageId);
287 if (spd.getModuleFile(moduleId) != null ) {
288 break ;
289 }
290 }
291 if (packageId == null){
292 throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");
293 }
294 else {
295 return packageId;
296 }
297 }
298
299 /**
300 Difference between build and parse: ToolChain and Target
301 **/
302 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {
303 return builtModules.contains(moduleId);
304 }
305
306 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {
307 builtModules.add(fpdModuleId);
308 }
309
310
311 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {
312 Map<String, XmlObject> result = new HashMap<String, XmlObject>();
313 Set keySet = doc.keySet();
314 Iterator iter = keySet.iterator();
315 while (iter.hasNext()){
316 String key = (String)iter.next();
317 XmlObject item = cloneXmlObject(doc.get(key), true);
318 result.put(key, item);
319 }
320 fpdModuleSA.put(fpdModuleId, result);
321 }
322
323 /**
324 Query overrided module surface area information. If current is Package
325 or Platform build, also include the information from FPD file.
326
327 <p>Note that surface area parsing is incremental. That means the method will
328 only parse the MSA and MBD files if necessary. </p>
329
330 @param moduleName the base name of the module
331 @return the overrided module surface area information
332 @throws BuildException
333 MSA or MBD is not valid
334 **/
335 public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {
336 if (parsedModules.containsKey(fpdModuleId)) {
337 return parsedModules.get(fpdModuleId);
338 }
339 Map<String, XmlObject> doc = new HashMap<String, XmlObject>();
340 ModuleIdentification moduleId = fpdModuleId.getModule();
341 //
342 // First part: get the MSA files info
343 //
344 doc = getNativeMsa(moduleId);
345
346 //
347 // Second part: put build options
348 //
349 doc.put("BuildOptions", fpdBuildOptions);
350
351 //
352 // Third part: get Module info from FPD, such as Library instances, PCDs
353 //
354 if (fpdModuleSA.containsKey(fpdModuleId)){
355 //
356 // merge module info in FPD to final Doc
357 // For Library Module, do nothing here
358 //
359 doc.putAll(fpdModuleSA.get(fpdModuleId));
360 }
361 parsedModules.put(fpdModuleId, doc);
362 return doc;
363 }
364
365 public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {
366 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
367 return getDoc(fpdModuleId);
368 }
369 /**
370 Query the native MSA information with module base name.
371
372 <p>Note that MSA parsing is incremental. That means the method will
373 only to parse the MSA files when never parsed before. </p>
374
375 @param moduleName the base name of the module
376 @return the native MSA information
377 @throws BuildException
378 MSA file is not valid
379 **/
380 public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {
381 if (nativeMsa.containsKey(moduleId)) {
382 return nativeMsa.get(moduleId);
383 }
384 File msaFile = getMsaFile(moduleId);
385 Map<String, XmlObject> msaMap = getNativeMsa(msaFile);
386 nativeMsa.put(moduleId, msaMap);
387 return msaMap;
388 }
389
390 public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {
391 if (! msaFile.exists()) {
392 throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");
393 }
394 try {
395 ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
396 //
397 // Validate File if they accord with XML Schema
398 //
399 if ( ! doc.validate()){
400 throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");
401 }
402 //
403 // parse MSA file
404 //
405 ModuleSurfaceArea msa= doc.getModuleSurfaceArea();
406 Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();
407 msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));
408 msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));
409 msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));
410 msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));
411 msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));
412 msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));
413 msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));
414 msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
415 msaMap.put("Externs", cloneXmlObject(msa.getExterns(), 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(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 for (int i = 0; i < packages.length; i++) {
518 Spd spd = spdTable.get(packages[i]);
519 //
520 // If find one package defined the GUID
521 //
522 if ((result = spd.getGuid(name)) != null) {
523 return result;
524 }
525 }
526 return null;
527 }
528
529 /**
530 * return two values: {cName, GuidValue}
531 */
532 public static String[] getPpiGuid(PackageIdentification[] packages,
533 String name) throws BuildException {
534 if (packages == null) {
535 return new String[0];
536 }
537 String[] result = null;
538 for (int i = 0; i < packages.length; i++) {
539 Spd spd = spdTable.get(packages[i]);
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(PackageIdentification[] packages,
555 String name) throws BuildException {
556 if (packages == null) {
557 return new String[0];
558 }
559 String[] result = null;
560 for (int i = 0; i < packages.length; i++) {
561 Spd spd = spdTable.get(packages[i]);
562 //
563 // If find one package defined the protocol GUID
564 //
565 if ((result = spd.getProtocol(name)) != null) {
566 return result;
567 }
568 }
569 return null;
570
571 }
572
573 /////////////////////////// Update!! Update!! Update!!
574 // public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
575 // return pcdDbManager;
576 // }
577 ///////////////////////////
578 public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {
579 Iterator iter = platformList.iterator();
580 while(iter.hasNext()){
581 PlatformIdentification platformId = (PlatformIdentification)iter.next();
582 if (platformId.getName().equalsIgnoreCase(name)) {
583 // GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());
584 return platformId;
585 }
586 }
587 throw new BuildException("Can't find platform [" + name + "] in current workspace. ");
588 }
589
590 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {
591 Iterator iter = packageList.iterator();
592 while(iter.hasNext()){
593 PackageIdentification packageItem = (PackageIdentification)iter.next();
594 if (packageItem.equals(packageId)) {
595 packageId.setName(packageItem.getName());
596 packageId.setSpdFile(packageItem.getSpdFile());
597 return packageId;
598 }
599 }
600 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
601 }
602
603 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {
604 // System.out.println("1");
605 // System.out.println("##" + moduleId.getGuid());
606 PackageIdentification packageId = getPackageForModule(moduleId);
607 // System.out.println("" + packageId.getGuid());
608 moduleId.setPackage(packageId);
609 Spd spd = spdTable.get(packageId);
610 if (spd == null) {
611 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
612 }
613 Set<ModuleIdentification> modules = spd.getModules();
614 Iterator<ModuleIdentification> iter = modules.iterator();
615 while (iter.hasNext()) {
616 ModuleIdentification item = iter.next();
617 if (item.equals(moduleId)) {
618 moduleId.setName(item.getName());
619 moduleId.setModuleType(item.getModuleType());
620 moduleId.setMsaFile(item.getMsaFile());
621 return moduleId;
622 }
623 }
624 throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");
625 }
626
627 public synchronized static Set<PackageIdentification> getPackageList(){
628 return packageList;
629 }
630 ///// remove!!
631 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {
632 if ( object == null) {
633 return null;
634 }
635 XmlObject result = null;
636 try {
637 result = XmlObject.Factory.parse(object.getDomNode()
638 .cloneNode(deep));
639 } catch (Exception ex) {
640 throw new BuildException(ex.getMessage());
641 }
642 return result;
643 }
644
645 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
646
647 public static ToolChainInfo getToolChainInfo() {
648 // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);
649 if (toolChainInfo == null) {
650 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
651 if (toolChainPlatformInfo != null) {
652 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
653 }
654 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
655 toolChainInfo.normalize();
656 GlobalData.log.info(toolChainInfo + "");
657 }
658 return toolChainInfo;
659 }
660
661
662
663 public static void setPlatformToolChainFamilyOption(ToolChainMap map) {
664 platformToolChainFamilyOption = map;
665 }
666
667 public static void setPlatformToolChainOption(ToolChainMap map) {
668 platformToolChainOption = map;
669 }
670
671 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,
672 ToolChainMap toolChainOption) {
673 moduleToolChainOption.put(fpdModuleId, toolChainOption);
674 }
675
676 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,
677 ToolChainMap toolChainOption) {
678 moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
679 }
680
681 public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
682 ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
683 ToolChainMap toolChainConfig = toolsDef.getConfig();
684 String setting = null;
685
686 if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {
687 setting = toolChainConfig.get(toolChainKey);
688 if (setting == null) {
689 setting = "";
690 }
691 return setting;
692 }
693
694 //
695 // get module specific options, if any
696 //
697 // tool tag first
698 ToolChainMap option = moduleToolChainOption.get(fpdModuleId);
699 ToolChainKey toolChainFamilyKey = null;
700
701 if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {
702 //
703 // then tool chain family
704 //
705 toolChainFamilyKey = new ToolChainKey(commandDescription);
706 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
707 String family = toolChainConfig.get(toolChainFamilyKey);
708 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
709 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
710
711 option = moduleToolChainFamilyOption.get(fpdModuleId);
712 if (option != null) {
713 setting = option.get(toolChainFamilyKey);
714 }
715 }
716
717 //
718 // get platform options, if any
719 //
720 if (setting == null) {
721 // tool tag first
722 if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {
723 // then tool chain family
724 if (toolChainFamilyKey == null) {
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
732 setting = platformToolChainFamilyOption.get(toolChainFamilyKey);
733 }
734 }
735
736 if (setting == null) {
737 setting = "";
738 }
739
740 return setting;
741 }
742
743 public static void setToolChainEnvInfo(ToolChainInfo envInfo) {
744 toolChainEnvInfo = envInfo;
745 }
746 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {
747 toolChainPlatformInfo = platformInfo;
748 }
749
750 //
751 // for PCD
752 //
753 // public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
754 // return pcdDbManager;
755 // }
756
757 //
758 // For PCD
759 //
760 /**
761 *
762 * @param guidName
763 * @return
764 */
765 // public synchronized static String[] getGuidInfoGuid(String guidName) {
766 // String[] cNameGuid = null;
767 // Set set = spdTable.keySet();
768 // Iterator iter = set.iterator();
769 //
770 // while (iter.hasNext()) {
771 // Spd spd = (Spd) spdTable.get(iter.next());
772 // cNameGuid = spd.getGuidNameArray(guidName);
773 // if (cNameGuid != null) {
774 // break;
775 // }
776 // }
777 // return cNameGuid;
778 // }
779
780 //
781 // For PCD
782 //
783 // public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(
784 // String xmlObjectName) {
785 // Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();
786 // Iterator item = fpdModuleSASet.iterator();
787 //
788 // Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();
789 // Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();
790 // FpdModuleIdentification moduleId;
791 // while (item.hasNext()) {
792 // moduleId = (FpdModuleIdentification) item.next();
793 // SANode = fpdModuleSA.get(item.next());
794 // SAPcdBuildDef.put(moduleId,
795 // (PcdBuildDefinitionDocument.PcdBuildDefinition) SANode
796 // .get(xmlObjectName));
797 // }
798 // return SAPcdBuildDef;
799 // }
800 }
801