]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
75c637ffe1dea8f74edf1fb1dddf33c16e358674
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GlobalData.java
1 /** @file
2 GlobalData class.
3
4 GlobalData provide initializing, instoring, querying and update global data.
5 It is a bridge to intercommunicate between multiple component, such as AutoGen,
6 PCD and so on.
7
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 **/
17 package org.tianocore.build.global;
18
19 import org.apache.tools.ant.BuildException;
20 import org.apache.xmlbeans.XmlObject;
21 import org.tianocore.DbPathAndFilename;
22 import org.tianocore.FrameworkDatabaseDocument;
23 import org.tianocore.ModuleSurfaceAreaDocument;
24 import org.tianocore.PcdBuildDefinitionDocument;
25 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
26 import org.tianocore.build.id.FpdModuleIdentification;
27 import org.tianocore.build.id.ModuleIdentification;
28 import org.tianocore.build.id.PackageIdentification;
29 import org.tianocore.build.id.PlatformIdentification;
30 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
31 import org.tianocore.build.toolchain.ToolChainAttribute;
32 import org.tianocore.build.toolchain.ToolChainConfig;
33 import org.tianocore.build.toolchain.ToolChainElement;
34 import org.tianocore.build.toolchain.ToolChainInfo;
35 import org.tianocore.build.toolchain.ToolChainKey;
36 import org.tianocore.build.toolchain.ToolChainMap;
37 import org.tianocore.exception.EdkException;
38 import org.tianocore.logger.EdkLog;
39
40 import java.io.File;
41 import java.util.HashMap;
42 import java.util.HashSet;
43 import java.util.Iterator;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.Set;
47 import java.util.logging.Logger;
48
49 /**
50 GlobalData provide initializing, instoring, querying and update global data.
51 It is a bridge to intercommunicate between multiple component, such as AutoGen,
52 PCD and so on.
53
54 <p>Note that all global information are initialized incrementally. All data will
55 parse and record only of necessary during build time. </p>
56
57 @since GenBuild 1.0
58 **/
59 public class GlobalData {
60
61 public static Logger log = Logger.getAnonymousLogger();
62
63 ///
64 /// Record current WORKSPACE Directory
65 ///
66 private static String workspaceDir = "";
67
68 ///
69 /// Be used to ensure Global data will be initialized only once.
70 ///
71 private static boolean globalFlag = false;
72
73 ///
74 /// Framework Database information: package list and platform list
75 ///
76 private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();
77
78 private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();
79
80 ///
81 /// Every detail SPD informations: Module list, Library class definition,
82 /// Package header file, GUID/PPI/Protocol definitions
83 ///
84 private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();
85
86 ///
87 /// Build informations are divided into three parts:
88 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA
89 ///
90 private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();
91
92 private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
93
94 private static XmlObject fpdBuildOptions;
95
96 private static XmlObject fpdDynamicPcds;
97
98 ///
99 /// Parsed modules list
100 ///
101 private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();
102
103 ///
104 /// built modules list with ARCH, TARGET, TOOLCHAIN
105 ///
106 private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();
107
108 ///
109 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.
110 ///
111 // private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
112
113 ///
114 /// build target + tool chain family/tag name + arch + command types + command options
115 ///
116 ///
117 /// Tool Chain Data
118 /// toolsDef - build tool program information
119 /// fpdBuildOption - all modules's build options for tool tag or tool chain families
120 /// moduleSaBuildOption - build options for a specific module
121 ///
122 private static ToolChainConfig toolsDef;
123
124 private static ToolChainInfo toolChainInfo;
125 private static ToolChainInfo toolChainEnvInfo;
126 private static ToolChainInfo toolChainPlatformInfo;
127
128 private static ToolChainMap platformToolChainOption;
129 private static ToolChainMap platformToolChainFamilyOption;
130
131 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
132 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();
133
134 private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();
135
136
137
138 /**
139 Parse framework database (DB) and all SPD files listed in DB to initialize
140 the environment for next build. This method will only be executed only once
141 in the whole build process.
142
143 @param workspaceDatabaseFile the file name of framework database
144 @param workspaceDir current workspace directory path
145 @throws BuildException
146 Framework Dababase or SPD or MSA file is not valid
147 **/
148 public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException {
149 //
150 // ensure this method will be revoked only once
151 //
152 if (globalFlag) {
153 return;
154 }
155 globalFlag = true;
156
157 //
158 // Backup workspace directory. It will be used by other method
159 //
160 GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");
161
162 //
163 // Parse tools definition file
164 //
165 //
166 // If ToolChain has been set up before, do nothing.
167 // CONF dir + tools definition file name
168 //
169 File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
170 System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");
171 toolsDef = new ToolChainConfig(toolsDefFile);
172
173 //
174 // Parse Framework Database
175 //
176 File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);
177 try {
178 FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);
179 //
180 // validate FrameworkDatabaseFile
181 //
182 if (! db.validate()) {
183 throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");
184 }
185 //
186 // Get package list
187 //
188 if (db.getFrameworkDatabase().getPackageList() != null ) {
189 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();
190 Iterator<DbPathAndFilename> iter = packages.iterator();
191 while (iter.hasNext()) {
192 String fileName = iter.next().getStringValue();
193 Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));
194 packageList.add(spd.getPackageId());
195 spdTable.put(spd.getPackageId(), spd);
196 }
197 }
198
199 //
200 // Get platform list
201 //
202 if (db.getFrameworkDatabase().getPlatformList() != null) {
203 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();
204 Iterator<DbPathAndFilename> iter = platforms.iterator();
205 while (iter.hasNext()) {
206 String fileName = iter.next().getStringValue();
207 File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
208 if ( ! fpdFile.exists() ) {
209 throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");
210 }
211 XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
212 //
213 // Verify FPD file, if is invalid, throw Exception
214 //
215 if (! fpdDoc.validate()) {
216 throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. ");
217 }
218 //
219 // We can change Map to XmlObject
220 //
221 //
222 // TBD check SPD or FPD is existed in FS
223 //
224 Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();
225 fpdDocMap.put("PlatformSurfaceArea", fpdDoc);
226 SurfaceAreaQuery.setDoc(fpdDocMap);
227 PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();
228 platformId.setFpdFile(fpdFile);
229 platformList.add(platformId);
230 }
231 }
232 } catch (Exception e) {
233 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.putAll(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 msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
417 return msaMap;
418 }
419 catch (Exception ex){
420 throw new BuildException(ex.getMessage());
421 }
422 }
423
424 public static Map<String, XmlObject> getFpdBuildOptions() {
425 Map<String, XmlObject> map = new HashMap<String, XmlObject>();
426 map.put("BuildOptions", fpdBuildOptions);
427 return map;
428 }
429
430 public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {
431 GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);
432 }
433
434 public static XmlObject getFpdDynamicPcds() {
435 return fpdDynamicPcds;
436 }
437
438 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {
439 GlobalData.fpdDynamicPcds = fpdDynamicPcds;
440 }
441
442 //////////////////////////////////////////////
443 //////////////////////////////////////////////
444
445 public static Set<ModuleIdentification> getModules(PackageIdentification packageId){
446 Spd spd = spdTable.get(packageId);
447 if (spd == null ) {
448 Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();
449 return dummy;
450 }
451 else {
452 return spd.getModules();
453 }
454 }
455
456 /**
457 * The header file path is relative to workspace dir
458 */
459 public static String[] getLibraryClassHeaderFiles(
460 PackageIdentification[] packages, String name)
461 throws BuildException {
462 if (packages == null) {
463 // throw Exception or not????
464 return new String[0];
465 }
466 String[] result = null;
467 for (int i = 0; i < packages.length; i++) {
468 Spd spd = spdTable.get(packages[i]);
469 //
470 // If find one package defined the library class
471 //
472 if ((result = spd.getLibClassIncluder(name)) != null) {
473 return result;
474 }
475 }
476 //
477 // If can't find library class declaration in every package
478 //
479 throw new BuildException("Can not find library class [" + name
480 + "] declaration in every packages. ");
481 }
482
483 /**
484 * The header file path is relative to workspace dir
485 */
486 public static String getPackageHeaderFiles(PackageIdentification packages,
487 String moduleType) throws BuildException {
488 if (packages == null) {
489 return new String("");
490 }
491 Spd spd = spdTable.get(packages);
492 //
493 // If can't find package header file, skip it
494 //
495 String temp = null;
496 if (spd != null) {
497 if ((temp = spd.getPackageIncluder(moduleType)) != null) {
498 return temp;
499 } else {
500 temp = "";
501 return temp;
502 }
503 } else {
504 return null;
505 }
506 }
507
508 /**
509 * return two values: {cName, GuidValue}
510 */
511 public static String[] getGuid(List<PackageIdentification> packages, String name)
512 throws BuildException {
513 if (packages == null) {
514 // throw Exception or not????
515 return new String[0];
516 }
517 String[] result = null;
518 Iterator item = packages.iterator();
519 while (item.hasNext()){
520 Spd spd = spdTable.get(item.next());
521 //
522 // If find one package defined the GUID
523 //
524 if ((result = spd.getGuid(name)) != null) {
525 return result;
526 }
527 }
528
529 return null;
530 }
531
532 /**
533 * return two values: {cName, GuidValue}
534 */
535 public static String[] getPpiGuid(List<PackageIdentification> packages,
536 String name) throws BuildException {
537 if (packages == null) {
538 return new String[0];
539 }
540 String[] result = null;
541 Iterator item = packages.iterator();
542 while (item.hasNext()){
543 Spd spd = spdTable.get(item.next());
544 //
545 // If find one package defined the Ppi GUID
546 //
547 if ((result = spd.getPpi(name)) != null) {
548 return result;
549 }
550 }
551 return null;
552
553 }
554
555 /**
556 * return two values: {cName, GuidValue}
557 */
558 public static String[] getProtocolGuid(List<PackageIdentification> packages,
559 String name) throws BuildException {
560 if (packages == null) {
561 return new String[0];
562 }
563 String[] result = null;
564 Iterator item = packages.iterator();
565 while (item.hasNext()){
566 Spd spd = spdTable.get(item.next());
567 //
568 // If find one package defined the protocol GUID
569 //
570 if ((result = spd.getProtocol(name))!= null){
571 return result;
572 }
573 }
574 return null;
575
576 }
577
578 public synchronized static PlatformIdentification getPlatformByName(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 return platformId;
584 }
585 }
586 throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");
587 }
588
589 public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {
590 File file = new File(workspaceDir + File.separatorChar + filename);
591 Iterator iter = platformList.iterator();
592 while(iter.hasNext()){
593 PlatformIdentification platformId = (PlatformIdentification)iter.next();
594 if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
595 return platformId;
596 }
597 }
598 throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");
599 }
600
601 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {
602 Iterator iter = packageList.iterator();
603 while(iter.hasNext()){
604 PackageIdentification packageItem = (PackageIdentification)iter.next();
605 if (packageItem.equals(packageId)) {
606 packageId.setName(packageItem.getName());
607 packageId.setSpdFile(packageItem.getSpdFile());
608 return packageId;
609 }
610 }
611 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
612 }
613
614 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {
615 // System.out.println("1");
616 // System.out.println("##" + moduleId.getGuid());
617 PackageIdentification packageId = getPackageForModule(moduleId);
618 // System.out.println("" + packageId.getGuid());
619 moduleId.setPackage(packageId);
620 Spd spd = spdTable.get(packageId);
621 if (spd == null) {
622 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");
623 }
624 Set<ModuleIdentification> modules = spd.getModules();
625 Iterator<ModuleIdentification> iter = modules.iterator();
626 while (iter.hasNext()) {
627 ModuleIdentification item = iter.next();
628 if (item.equals(moduleId)) {
629 moduleId.setName(item.getName());
630 moduleId.setModuleType(item.getModuleType());
631 moduleId.setMsaFile(item.getMsaFile());
632 return moduleId;
633 }
634 }
635 throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");
636 }
637
638 public synchronized static Set<PackageIdentification> getPackageList(){
639 return packageList;
640 }
641 ///// remove!!
642 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {
643 if ( object == null) {
644 return null;
645 }
646 XmlObject result = null;
647 try {
648 result = XmlObject.Factory.parse(object.getDomNode()
649 .cloneNode(deep));
650 } catch (Exception ex) {
651 throw new BuildException(ex.getMessage());
652 }
653 return result;
654 }
655
656 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
657
658 public static ToolChainInfo getToolChainInfo() {
659 // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);
660 if (toolChainInfo == null) {
661 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
662 if (toolChainPlatformInfo != null) {
663 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
664 }
665 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
666 toolChainInfo.normalize();
667 GlobalData.log.info(toolChainInfo + "");
668 }
669 return toolChainInfo;
670 }
671
672
673
674 public static void setPlatformToolChainFamilyOption(ToolChainMap map) {
675 platformToolChainFamilyOption = map;
676 }
677
678 public static void setPlatformToolChainOption(ToolChainMap map) {
679 platformToolChainOption = map;
680 }
681
682 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,
683 ToolChainMap toolChainOption) {
684 moduleToolChainOption.put(fpdModuleId, toolChainOption);
685 }
686
687 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,
688 ToolChainMap toolChainOption) {
689 moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
690 }
691
692 public static boolean isCommandSet(String target, String toolchain, String arch) {
693 String[] commands = getToolChainInfo().getCommands();
694
695 for (int i = 0; i < commands.length; ++i) {
696 if (toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()}) != null) {
697 return true;
698 }
699 }
700
701 return false;
702 }
703
704 public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
705 ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
706 ToolChainMap toolChainConfig = toolsDef.getConfig();
707 String setting = null;
708
709 if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {
710 setting = toolChainConfig.get(toolChainKey);
711 if (setting == null) {
712 setting = "";
713 }
714 return setting;
715 }
716
717 //
718 // get module specific options, if any
719 //
720 // tool tag first
721 ToolChainMap option = moduleToolChainOption.get(fpdModuleId);
722 ToolChainKey toolChainFamilyKey = null;
723
724 if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {
725 //
726 // then tool chain family
727 //
728 toolChainFamilyKey = new ToolChainKey(commandDescription);
729 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
730 String family = toolChainConfig.get(toolChainFamilyKey);
731 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
732 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
733
734 option = moduleToolChainFamilyOption.get(fpdModuleId);
735 if (option != null) {
736 setting = option.get(toolChainFamilyKey);
737 }
738 }
739
740 //
741 // get platform options, if any
742 //
743 if (setting == null) {
744 // tool tag first
745 if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {
746 // then tool chain family
747 if (toolChainFamilyKey == null) {
748 toolChainFamilyKey = new ToolChainKey(commandDescription);
749 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
750 String family = toolChainConfig.get(toolChainFamilyKey);
751 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
752 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
753 }
754
755 setting = platformToolChainFamilyOption.get(toolChainFamilyKey);
756 }
757 }
758
759 if (setting == null) {
760 setting = "";
761 }
762
763 return setting;
764 }
765
766 public static void setToolChainEnvInfo(ToolChainInfo envInfo) {
767 toolChainEnvInfo = envInfo;
768 }
769 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {
770 toolChainPlatformInfo = platformInfo;
771 }
772
773 //
774 // for PCD
775 //
776 public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
777 return pcdDbManager;
778 }
779
780 //
781 // For PCD get tokenSpaceGUid
782 //
783 public synchronized static String[] getGuidInfoFromCname(String cName){
784 String cNameGuid[] = null;
785 String guid = null;
786 Set set = spdTable.keySet();
787 Iterator iter = set.iterator();
788
789 if (iter == null) {
790 return null;
791 }
792
793 while (iter.hasNext()){
794 Spd spd = (Spd) spdTable.get(iter.next());
795 guid = spd.getGuidFromCname(cName);
796 if (guid != null){
797 cNameGuid = new String[2];
798 cNameGuid[0] = cName;
799 cNameGuid[1] = guid;
800 break;
801 }
802 }
803 return cNameGuid;
804 }
805
806 //
807 // For PCD
808 //
809 public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(
810 String xmlObjectName) {
811 Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();
812 Iterator item = fpdModuleSASet.iterator();
813
814
815 Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();
816 Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();
817 FpdModuleIdentification moduleId;
818 while (item.hasNext()) {
819
820 moduleId = (FpdModuleIdentification) item.next();
821 SANode = fpdModuleSA.get(moduleId);
822 try{
823 if (SANode.get(xmlObjectName)!= null){
824 SAPcdBuildDef.put(moduleId,
825 (XmlObject) SANode
826 .get(xmlObjectName));
827
828 }
829
830
831 } catch (Exception e){
832 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());
833 }
834 }
835 return SAPcdBuildDef;
836 }
837 }
838