]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java
3a5d1dd9a086ec730719744142484309a3fb2a1b
[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
31 import org.tianocore.common.exception.EdkException;
32 import org.tianocore.common.logger.EdkLog;
33 import org.tianocore.pcd.entity.MemoryDatabaseManager;
34 import org.tianocore.DbPathAndFilename;
35 import org.tianocore.FrameworkDatabaseDocument;
36 import org.tianocore.ModuleSurfaceAreaDocument;
37 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
38 import org.tianocore.build.id.FpdModuleIdentification;
39 import org.tianocore.build.id.ModuleIdentification;
40 import org.tianocore.build.id.PackageIdentification;
41 import org.tianocore.build.id.PlatformIdentification;
42 import org.tianocore.build.toolchain.ToolChainAttribute;
43 import org.tianocore.build.toolchain.ToolChainConfig;
44 import org.tianocore.build.toolchain.ToolChainElement;
45 import org.tianocore.build.toolchain.ToolChainInfo;
46 import org.tianocore.build.toolchain.ToolChainKey;
47 import org.tianocore.build.toolchain.ToolChainMap;
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 /**
135 Parse framework database (DB) and all SPD files listed in DB to initialize
136 the environment for next build. This method will only be executed only once
137 in the whole build process.
138
139 @param workspaceDatabaseFile the file name of framework database
140 @param workspaceDir current workspace directory path
141 @throws BuildException
142 Framework Dababase or SPD or MSA file is not valid
143 **/
144 public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException {
145 //
146 // ensure this method will be revoked only once
147 //
148 if (globalFlag) {
149 return;
150 }
151 globalFlag = true;
152
153 //
154 // Backup workspace directory. It will be used by other method
155 //
156 GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");
157
158 //
159 // Parse tools definition file
160 //
161 //
162 // If ToolChain has been set up before, do nothing.
163 // CONF dir + tools definition file name
164 //
165 File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
166 System.out.println("Using tool definiton file [" + toolsDefFile.getPath() + "].");
167 try {
168 toolsDef = new ToolChainConfig(toolsDefFile);
169 } catch (Exception e) {
170 throw new BuildException(e.getMessage());
171 }
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() + "] format 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() + "] format 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 throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage());
234 }
235 }
236
237 /**
238 Get the current WORKSPACE Directory.
239
240 @return current workspace directory
241 **/
242 public synchronized static String getWorkspacePath() {
243 return workspaceDir;
244 }
245
246
247 /**
248 Get the MSA file name with absolute path
249 */
250 public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {
251 File msaFile = null;
252 //
253 // TBD. Do only when package is null.
254 //
255 Iterator iter = packageList.iterator();
256 while (iter.hasNext()) {
257 PackageIdentification packageId = (PackageIdentification)iter.next();
258 Spd spd = spdTable.get(packageId);
259 msaFile = spd.getModuleFile(moduleId);
260 if (msaFile != null ) {
261 break ;
262 }
263 }
264 if (msaFile == null){
265 throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
266 } else {
267 return msaFile;
268 }
269 }
270
271 public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {
272 //
273 // If package already defined in module
274 //
275 if (moduleId.getPackage() != null) {
276 return moduleId.getPackage();
277 }
278
279 PackageIdentification packageId = null;
280 Iterator iter = packageList.iterator();
281 while (iter.hasNext()) {
282 packageId = (PackageIdentification)iter.next();
283 moduleId.setPackage(packageId);
284 Spd spd = spdTable.get(packageId);
285 if (spd.getModuleFile(moduleId) != null ) {
286 break ;
287 }
288 }
289 if (packageId == null){
290 throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");
291 } else {
292 return packageId;
293 }
294 }
295
296 /**
297 Difference between build and parse: ToolChain and Target
298 **/
299 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {
300 return builtModules.contains(moduleId);
301 }
302
303 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {
304 builtModules.add(fpdModuleId);
305 }
306
307
308 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {
309 Map<String, XmlObject> result = new HashMap<String, XmlObject>();
310 Set keySet = doc.keySet();
311 Iterator iter = keySet.iterator();
312 while (iter.hasNext()){
313 String key = (String)iter.next();
314 XmlObject item = cloneXmlObject(doc.get(key), true);
315 result.put(key, item);
316 }
317 fpdModuleSA.put(fpdModuleId, result);
318 }
319
320 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {
321 return fpdModuleSA.containsKey(fpdModuleId);
322 }
323
324 /**
325 Query module surface area information.
326
327 <p>Note that surface area parsing is incremental. That means the method will
328 only parse the MSA files if necessary. </p>
329
330 @param fpdModuleId Module ID with arch
331 @return ModuleSA info and MSA info for fpdModuleId
332 @throws BuildException Can't find MSA
333 **/
334 public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {
335 if (parsedModules.containsKey(fpdModuleId)) {
336 return parsedModules.get(fpdModuleId);
337 }
338 Map<String, XmlObject> doc = new HashMap<String, XmlObject>();
339 ModuleIdentification moduleId = fpdModuleId.getModule();
340 //
341 // First part: get the MSA files info
342 //
343 doc.putAll(getNativeMsa(moduleId));
344
345 //
346 // Second part: put build options
347 //
348 doc.put("BuildOptions", fpdBuildOptions);
349
350 //
351 // Third part: get Module info from FPD, such as Library instances, PCDs
352 //
353 if (fpdModuleSA.containsKey(fpdModuleId)){
354 //
355 // merge module info in FPD to final Doc
356 // For Library Module, do nothing here
357 //
358 doc.putAll(fpdModuleSA.get(fpdModuleId));
359 }
360 parsedModules.put(fpdModuleId, doc);
361 return doc;
362 }
363
364 public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {
365 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
366 return getDoc(fpdModuleId);
367 }
368 /**
369 Query the native MSA information with module base name.
370
371 <p>Note that MSA parsing is incremental. That means the method will
372 only to parse the MSA files when never parsed before. </p>
373
374 @param moduleName the base name of the module
375 @return the native MSA information
376 @throws BuildException
377 MSA file is not valid
378 **/
379 public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {
380 if (nativeMsa.containsKey(moduleId)) {
381 return nativeMsa.get(moduleId);
382 }
383 File msaFile = getMsaFile(moduleId);
384 Map<String, XmlObject> msaMap = getNativeMsa(msaFile);
385 nativeMsa.put(moduleId, msaMap);
386 return msaMap;
387 }
388
389 public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {
390 if (!msaFile.exists()) {
391 throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");
392 }
393 try {
394 ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
395 //
396 // Validate File if they accord with XML Schema
397 //
398 if ( !doc.validate()){
399 throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");
400 }
401 //
402 // parse MSA file
403 //
404 ModuleSurfaceArea msa= doc.getModuleSurfaceArea();
405 Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();
406 msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));
407 msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));
408 msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));
409 msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));
410 msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));
411 msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));
412 msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));
413 msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));
414 msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
415 msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), 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 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 } else {
447 return spd.getModules();
448 }
449 }
450
451 /**
452 * The header file path is relative to workspace dir
453 */
454 public static String[] getLibraryClassHeaderFiles(
455 PackageIdentification[] packages, String name)
456 throws BuildException {
457 if (packages == null) {
458 // throw Exception or not????
459 return new String[0];
460 }
461 String[] result = null;
462 for (int i = 0; i < packages.length; i++) {
463 Spd spd = spdTable.get(packages[i]);
464 //
465 // If find one package defined the library class
466 //
467 if ((result = spd.getLibClassIncluder(name)) != null) {
468 return result;
469 }
470 }
471 //
472 // If can't find library class declaration in every package
473 //
474 throw new BuildException("Can not find library class [" + name
475 + "] declaration in any SPD package!");
476 }
477
478 /**
479 * The header file path is relative to workspace dir
480 */
481 public static String getPackageHeaderFiles(PackageIdentification packages,
482 String moduleType) throws BuildException {
483 if (packages == null) {
484 return new String("");
485 }
486 Spd spd = spdTable.get(packages);
487 //
488 // If can't find package header file, skip it
489 //
490 String temp = null;
491 if (spd != null) {
492 if ((temp = spd.getPackageIncluder(moduleType)) != null) {
493 return temp;
494 } else {
495 temp = "";
496 return temp;
497 }
498 } else {
499 return null;
500 }
501 }
502
503 /**
504 * return two values: {cName, GuidValue}
505 */
506 public static String[] getGuid(List<PackageIdentification> packages, String name)
507 throws BuildException {
508 if (packages == null) {
509 // throw Exception or not????
510 return new String[0];
511 }
512 String[] result = null;
513 Iterator item = packages.iterator();
514 while (item.hasNext()){
515 Spd spd = spdTable.get(item.next());
516 //
517 // If find one package defined the GUID
518 //
519 if ((result = spd.getGuid(name)) != null) {
520 return result;
521 }
522 }
523
524 return null;
525 }
526
527 /**
528 * return two values: {cName, GuidValue}
529 */
530 public static String[] getPpiGuid(List<PackageIdentification> packages,
531 String name) throws BuildException {
532 if (packages == null) {
533 return new String[0];
534 }
535 String[] result = null;
536 Iterator item = packages.iterator();
537 while (item.hasNext()){
538 Spd spd = spdTable.get(item.next());
539 //
540 // If find one package defined the Ppi GUID
541 //
542 if ((result = spd.getPpi(name)) != null) {
543 return result;
544 }
545 }
546 return null;
547
548 }
549
550 /**
551 * return two values: {cName, GuidValue}
552 */
553 public static String[] getProtocolGuid(List<PackageIdentification> packages,
554 String name) throws BuildException {
555 if (packages == null) {
556 return new String[0];
557 }
558 String[] result = null;
559 Iterator item = packages.iterator();
560 while (item.hasNext()){
561 Spd spd = spdTable.get(item.next());
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 public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {
574 Iterator iter = platformList.iterator();
575 while(iter.hasNext()){
576 PlatformIdentification platformId = (PlatformIdentification)iter.next();
577 if (platformId.getName().equalsIgnoreCase(name)) {
578 return platformId;
579 }
580 }
581 throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");
582 }
583
584 public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {
585 File file = new File(workspaceDir + File.separatorChar + filename);
586 Iterator iter = platformList.iterator();
587 while(iter.hasNext()){
588 PlatformIdentification platformId = (PlatformIdentification)iter.next();
589 if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {
590 return platformId;
591 }
592 }
593 throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");
594 }
595
596 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {
597 Iterator iter = packageList.iterator();
598 while(iter.hasNext()){
599 PackageIdentification packageItem = (PackageIdentification)iter.next();
600 if (packageItem.equals(packageId)) {
601 packageId.setName(packageItem.getName());
602 packageId.setSpdFile(packageItem.getSpdFile());
603 return packageId;
604 }
605 }
606 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " in the current workspace!");
607 }
608
609 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {
610 PackageIdentification packageId = getPackageForModule(moduleId);
611 moduleId.setPackage(packageId);
612 Spd spd = spdTable.get(packageId);
613 if (spd == null) {
614 throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " in the current workspace!");
615 }
616 Set<ModuleIdentification> modules = spd.getModules();
617 Iterator<ModuleIdentification> iter = modules.iterator();
618 while (iter.hasNext()) {
619 ModuleIdentification item = iter.next();
620 if (item.equals(moduleId)) {
621 moduleId.setName(item.getName());
622 moduleId.setModuleType(item.getModuleType());
623 moduleId.setMsaFile(item.getMsaFile());
624 return moduleId;
625 }
626 }
627 throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in package, " + packageId + ", in the current workspace!");
628 }
629
630 public synchronized static Set<PackageIdentification> getPackageList(){
631 return packageList;
632 }
633
634 /**
635 BUGBUG: It is a walk around method. If do not clone, can't query info with
636 XPath correctly.
637
638 @param object XmlObject
639 @param deep flag for deep clone
640 @return XmlObject after clone
641 @throws BuildException parse original XmlObject error.
642 **/
643 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {
644 if ( object == null) {
645 return null;
646 }
647 XmlObject result = null;
648 try {
649 result = XmlObject.Factory.parse(object.getDomNode()
650 .cloneNode(deep));
651 } catch (Exception ex) {
652 throw new BuildException(ex.getMessage());
653 }
654 return result;
655 }
656
657 ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory
658
659 public static ToolChainInfo getToolChainInfo() {
660 // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);
661 if (toolChainInfo == null) {
662 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);
663 if (toolChainPlatformInfo != null) {
664 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);
665 }
666 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());
667 toolChainInfo.normalize();
668 GlobalData.log.info(toolChainInfo + "");
669 }
670 return toolChainInfo;
671 }
672
673
674
675 public static void setPlatformToolChainFamilyOption(ToolChainMap map) {
676 platformToolChainFamilyOption = map;
677 }
678
679 public static void setPlatformToolChainOption(ToolChainMap map) {
680 platformToolChainOption = map;
681 }
682
683 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,
684 ToolChainMap toolChainOption) {
685 moduleToolChainOption.put(fpdModuleId, toolChainOption);
686 }
687
688 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,
689 ToolChainMap toolChainOption) {
690 moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);
691 }
692
693 public static boolean isCommandSet(String target, String toolchain, String arch) {
694 String[] commands = getToolChainInfo().getCommands();
695
696 for (int i = 0; i < commands.length; ++i) {
697 String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});
698 if (cmdName != null && cmdName.length() != 0) {
699 return true;
700 }
701 }
702
703 return false;
704 }
705
706 public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {
707 ToolChainKey toolChainKey = new ToolChainKey(commandDescription);
708 ToolChainMap toolChainConfig = toolsDef.getConfig();
709 String setting = null;
710
711 if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {
712 setting = toolChainConfig.get(toolChainKey);
713 if (setting == null) {
714 setting = "";
715 }
716 return setting;
717 }
718
719 //
720 // get module specific options, if any
721 //
722 // tool tag first
723 ToolChainMap option = moduleToolChainOption.get(fpdModuleId);
724 ToolChainKey toolChainFamilyKey = null;
725
726 if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {
727 //
728 // then tool chain family
729 //
730 toolChainFamilyKey = new ToolChainKey(commandDescription);
731 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
732 String family = toolChainConfig.get(toolChainFamilyKey);
733 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
734 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
735
736 option = moduleToolChainFamilyOption.get(fpdModuleId);
737 if (option != null) {
738 setting = option.get(toolChainFamilyKey);
739 }
740 }
741
742 //
743 // get platform options, if any
744 //
745 if (setting == null) {
746 // tool tag first
747 if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {
748 // then tool chain family
749 if (toolChainFamilyKey == null) {
750 toolChainFamilyKey = new ToolChainKey(commandDescription);
751 toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);
752 String family = toolChainConfig.get(toolChainFamilyKey);
753 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);
754 toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);
755 }
756
757 setting = platformToolChainFamilyOption.get(toolChainFamilyKey);
758 }
759 }
760
761 if (setting == null) {
762 setting = "";
763 }
764
765 return setting;
766 }
767
768 public static void setToolChainEnvInfo(ToolChainInfo envInfo) {
769 toolChainEnvInfo = envInfo;
770 }
771 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {
772 toolChainPlatformInfo = platformInfo;
773 }
774
775 //
776 // for PCD
777 //
778 public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {
779 return pcdDbManager;
780 }
781
782 //
783 // For PCD get tokenSpaceGUid
784 //
785 public synchronized static String getGuidInfoFromCname(String cName){
786 String cNameGuid = null;
787 String guid = null;
788 Set set = spdTable.keySet();
789 Iterator iter = set.iterator();
790
791 if (iter == null) {
792 return null;
793 }
794
795 while (iter.hasNext()){
796 Spd spd = (Spd) spdTable.get(iter.next());
797 guid = spd.getGuidFromCname(cName);
798 if (guid != null){
799 cNameGuid = guid;
800 break;
801 }
802 }
803 return cNameGuid;
804 }
805
806 //
807 // For PCD
808 //
809 public synchronized static Map<FpdModuleIdentification, XmlObject>
810 getFpdModuleSaXmlObject(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.get(xmlObjectName));
826
827 }
828 } catch (Exception e){
829 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());
830 }
831 }
832 return SAPcdBuildDef;
833 }
834
835 public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {
836 Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");
837
838 return pcdBuildDef;
839 }
840 }
841