]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/GenBuild/org/tianocore/build/global/GlobalData.java
rename ACPI, PCI, END and LPC to DP_ACPI, DP_PCI, DP_END and DP_LPC, for ACPI, PCI...
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / global / GlobalData.java
CommitLineData
878ddf1f 1/** @file\r
ff225cbb 2 GlobalData class.\r
3\r
878ddf1f 4 GlobalData provide initializing, instoring, querying and update global data.\r
5 It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
ff225cbb 6 PCD and so on.\r
7\r
878ddf1f 8Copyright (c) 2006, Intel Corporation\r
9All rights reserved. This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16**/\r
17package org.tianocore.build.global;\r
18\r
73b4e31a 19import java.io.File;\r
892b0e7a 20import java.io.IOException;\r
73b4e31a 21import java.util.HashMap;\r
22import java.util.HashSet;\r
23import java.util.Iterator;\r
24import java.util.List;\r
25import java.util.Map;\r
26import java.util.Set;\r
73b4e31a 27\r
892b0e7a 28import org.apache.xmlbeans.XmlException;\r
a29c47e0 29import org.apache.xmlbeans.XmlObject;\r
ff225cbb 30\r
b0a80562 31import org.tianocore.common.definitions.ToolDefinitions;\r
ff225cbb 32import org.tianocore.common.exception.EdkException;\r
33import org.tianocore.common.logger.EdkLog;\r
34import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
a29c47e0 35import org.tianocore.DbPathAndFilename;\r
36import org.tianocore.FrameworkDatabaseDocument;\r
37import org.tianocore.ModuleSurfaceAreaDocument;\r
38import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r
a29c47e0 39import org.tianocore.build.id.FpdModuleIdentification;\r
40import org.tianocore.build.id.ModuleIdentification;\r
41import org.tianocore.build.id.PackageIdentification;\r
42import org.tianocore.build.id.PlatformIdentification;\r
a29c47e0 43import org.tianocore.build.toolchain.ToolChainConfig;\r
44import org.tianocore.build.toolchain.ToolChainElement;\r
45import org.tianocore.build.toolchain.ToolChainInfo;\r
46import org.tianocore.build.toolchain.ToolChainKey;\r
47import org.tianocore.build.toolchain.ToolChainMap;\r
a29c47e0 48\r
878ddf1f 49/**\r
50 GlobalData provide initializing, instoring, querying and update global data.\r
51 It is a bridge to intercommunicate between multiple component, such as AutoGen,\r
ff225cbb 52 PCD and so on.\r
53\r
54 <p>Note that all global information are initialized incrementally. All data will\r
a29c47e0 55 parse and record only of necessary during build time. </p>\r
ff225cbb 56\r
878ddf1f 57 @since GenBuild 1.0\r
58**/\r
59public class GlobalData {\r
878ddf1f 60 ///\r
61 /// Record current WORKSPACE Directory\r
62 ///\r
63 private static String workspaceDir = "";\r
ff225cbb 64\r
878ddf1f 65 ///\r
a29c47e0 66 /// Be used to ensure Global data will be initialized only once.\r
878ddf1f 67 ///\r
a29c47e0 68 private static boolean globalFlag = false;\r
ff225cbb 69\r
878ddf1f 70 ///\r
a29c47e0 71 /// Framework Database information: package list and platform list\r
878ddf1f 72 ///\r
ff225cbb 73 private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();\r
878ddf1f 74\r
a29c47e0 75 private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r
878ddf1f 76\r
77 ///\r
a29c47e0 78 /// Every detail SPD informations: Module list, Library class definition,\r
79 /// Package header file, GUID/PPI/Protocol definitions\r
878ddf1f 80 ///\r
a29c47e0 81 private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();\r
878ddf1f 82\r
83 ///\r
a29c47e0 84 /// Build informations are divided into three parts:\r
85 /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA\r
878ddf1f 86 ///\r
a29c47e0 87 private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();\r
878ddf1f 88\r
a29c47e0 89 private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
878ddf1f 90\r
19bf6b15 91 private static Map<String, XmlObject> fpdBuildOptionsMap = new HashMap<String, XmlObject>();\r
92 \r
a29c47e0 93 private static XmlObject fpdBuildOptions;\r
878ddf1f 94\r
a29c47e0 95 private static XmlObject fpdDynamicPcds;\r
ff225cbb 96\r
878ddf1f 97 ///\r
a29c47e0 98 /// Parsed modules list\r
878ddf1f 99 ///\r
a29c47e0 100 private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
ff225cbb 101\r
878ddf1f 102 ///\r
a29c47e0 103 /// built modules list with ARCH, TARGET, TOOLCHAIN\r
878ddf1f 104 ///\r
a29c47e0 105 private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r
ff225cbb 106\r
878ddf1f 107 ///\r
a29c47e0 108 /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r
878ddf1f 109 ///\r
8b7bd455 110 private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r
878ddf1f 111\r
112 ///\r
a29c47e0 113 /// build target + tool chain family/tag name + arch + command types + command options\r
878ddf1f 114 ///\r
a29c47e0 115 ///\r
116 /// Tool Chain Data\r
117 /// toolsDef - build tool program information\r
118 /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r
119 /// moduleSaBuildOption - build options for a specific module\r
ff225cbb 120 ///\r
a29c47e0 121 private static ToolChainConfig toolsDef;\r
878ddf1f 122\r
a29c47e0 123 private static ToolChainInfo toolChainInfo;\r
124 private static ToolChainInfo toolChainEnvInfo;\r
125 private static ToolChainInfo toolChainPlatformInfo;\r
878ddf1f 126\r
a29c47e0 127 private static ToolChainMap platformToolChainOption;\r
128 private static ToolChainMap platformToolChainFamilyOption;\r
878ddf1f 129\r
a29c47e0 130 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
131 private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r
878ddf1f 132\r
b69bb9ba 133 private static Map<ModuleIdentification, ToolChainMap> msaBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();\r
134 private static Map<ModuleIdentification, ToolChainMap> msaFamilyBuildOption = new HashMap<ModuleIdentification, ToolChainMap>();\r
135\r
136// private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r
878ddf1f 137 /**\r
138 Parse framework database (DB) and all SPD files listed in DB to initialize\r
139 the environment for next build. This method will only be executed only once\r
ff225cbb 140 in the whole build process.\r
141\r
878ddf1f 142 @param workspaceDatabaseFile the file name of framework database\r
143 @param workspaceDir current workspace directory path\r
144 @throws BuildException\r
a29c47e0 145 Framework Dababase or SPD or MSA file is not valid\r
878ddf1f 146 **/\r
892b0e7a 147 public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException {\r
a29c47e0 148 //\r
149 // ensure this method will be revoked only once\r
150 //\r
878ddf1f 151 if (globalFlag) {\r
152 return;\r
153 }\r
154 globalFlag = true;\r
73b4e31a 155\r
ff225cbb 156 //\r
a29c47e0 157 // Backup workspace directory. It will be used by other method\r
158 //\r
159 GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r
ff225cbb 160\r
a29c47e0 161 //\r
162 // Parse tools definition file\r
163 //\r
164 //\r
165 // If ToolChain has been set up before, do nothing.\r
166 // CONF dir + tools definition file name\r
167 //\r
de4bb9f6 168 File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r
2eb7d78d 169 EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "].");\r
892b0e7a 170 toolsDef = new ToolChainConfig(toolsDefFile);\r
171\r
a29c47e0 172 //\r
173 // Parse Framework Database\r
174 //\r
878ddf1f 175 File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r
176 try {\r
177 FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r
a29c47e0 178 //\r
179 // validate FrameworkDatabaseFile\r
180 //\r
82516887 181 if (!db.validate()) {\r
892b0e7a 182 throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r
878ddf1f 183 }\r
a29c47e0 184 //\r
185 // Get package list\r
186 //\r
187 if (db.getFrameworkDatabase().getPackageList() != null ) {\r
188 List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r
189 Iterator<DbPathAndFilename> iter = packages.iterator();\r
190 while (iter.hasNext()) {\r
83fba802 191 String fileName = iter.next().getStringValue().trim();\r
a29c47e0 192 Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r
193 packageList.add(spd.getPackageId());\r
892b0e7a 194 //\r
195 // Report warning if existing two packages with same GUID and Version\r
196 //\r
197 if (spdTable.containsKey(spd.getPackageId())) {\r
198 //\r
199 // BUGBUG\r
200 //\r
201 EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath());\r
202 }\r
a29c47e0 203 spdTable.put(spd.getPackageId(), spd);\r
250258de 204 }\r
205 }\r
206\r
a29c47e0 207 //\r
208 // Get platform list\r
209 //\r
210 if (db.getFrameworkDatabase().getPlatformList() != null) {\r
211 List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r
212 Iterator<DbPathAndFilename> iter = platforms.iterator();\r
213 while (iter.hasNext()) {\r
83fba802 214 String fileName = iter.next().getStringValue().trim();\r
a29c47e0 215 File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r
82516887 216 if ( !fpdFile.exists() ) {\r
892b0e7a 217 throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r
250258de 218 }\r
a29c47e0 219 XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r
220 //\r
221 // Verify FPD file, if is invalid, throw Exception\r
222 //\r
82516887 223 if (!fpdDoc.validate()) {\r
892b0e7a 224 throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r
a29c47e0 225 }\r
226 //\r
227 // We can change Map to XmlObject\r
228 //\r
a29c47e0 229 Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r
230 fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r
83fba802 231 SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r
232 PlatformIdentification platformId = saq.getFpdHeader();\r
a29c47e0 233 platformId.setFpdFile(fpdFile);\r
892b0e7a 234 //\r
235 // Report warning if existing two platfrom with same GUID and Version\r
236 //\r
237 if (platformList.contains(platformId)) {\r
238 //\r
239 // BUGBUG\r
240 //\r
241 EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath());\r
242 }\r
a29c47e0 243 platformList.add(platformId);\r
878ddf1f 244 }\r
878ddf1f 245 }\r
892b0e7a 246 } catch(IOException ex) {\r
247 EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r
248 edkException.setStackTrace(ex.getStackTrace());\r
249 throw edkException;\r
250 } catch(XmlException ex) {\r
251 EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r
252 edkException.setStackTrace(ex.getStackTrace());\r
253 throw edkException;\r
878ddf1f 254 }\r
255 }\r
ff225cbb 256\r
878ddf1f 257 /**\r
ff225cbb 258 Get the current WORKSPACE Directory.\r
259\r
a29c47e0 260 @return current workspace directory\r
878ddf1f 261 **/\r
a29c47e0 262 public synchronized static String getWorkspacePath() {\r
263 return workspaceDir;\r
878ddf1f 264 }\r
265\r
878ddf1f 266\r
267 /**\r
a29c47e0 268 Get the MSA file name with absolute path\r
269 */\r
892b0e7a 270 public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {\r
a29c47e0 271 File msaFile = null;\r
272 //\r
ff225cbb 273 // TBD. Do only when package is null.\r
a29c47e0 274 //\r
275 Iterator iter = packageList.iterator();\r
276 while (iter.hasNext()) {\r
277 PackageIdentification packageId = (PackageIdentification)iter.next();\r
278 Spd spd = spdTable.get(packageId);\r
279 msaFile = spd.getModuleFile(moduleId);\r
280 if (msaFile != null ) {\r
281 break ;\r
282 }\r
283 }\r
284 if (msaFile == null){\r
892b0e7a 285 throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
82516887 286 } else {\r
a29c47e0 287 return msaFile;\r
288 }\r
878ddf1f 289 }\r
290\r
892b0e7a 291 public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {\r
a29c47e0 292 //\r
293 // If package already defined in module\r
294 //\r
295 if (moduleId.getPackage() != null) {\r
296 return moduleId.getPackage();\r
297 }\r
ff225cbb 298\r
a29c47e0 299 PackageIdentification packageId = null;\r
300 Iterator iter = packageList.iterator();\r
301 while (iter.hasNext()) {\r
302 packageId = (PackageIdentification)iter.next();\r
303 moduleId.setPackage(packageId);\r
304 Spd spd = spdTable.get(packageId);\r
89e1408f 305 File tempMsaFile = null;\r
306 if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) {\r
307 if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) {\r
308 break ;\r
309 }\r
310 tempMsaFile = null;\r
a29c47e0 311 }\r
312 }\r
313 if (packageId == null){\r
892b0e7a 314 throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r
82516887 315 } else {\r
a29c47e0 316 return packageId;\r
317 }\r
318 }\r
ff225cbb 319\r
878ddf1f 320 /**\r
a29c47e0 321 Difference between build and parse: ToolChain and Target\r
878ddf1f 322 **/\r
a29c47e0 323 public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r
324 return builtModules.contains(moduleId);\r
878ddf1f 325 }\r
ff225cbb 326\r
a29c47e0 327 public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r
328 builtModules.add(fpdModuleId);\r
878ddf1f 329 }\r
330\r
ff225cbb 331\r
892b0e7a 332 public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{\r
a29c47e0 333 Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r
334 Set keySet = doc.keySet();\r
335 Iterator iter = keySet.iterator();\r
336 while (iter.hasNext()){\r
337 String key = (String)iter.next();\r
338 XmlObject item = cloneXmlObject(doc.get(key), true);\r
339 result.put(key, item);\r
340 }\r
341 fpdModuleSA.put(fpdModuleId, result);\r
878ddf1f 342 }\r
57cc2ee7 343\r
344 public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {\r
345 return fpdModuleSA.containsKey(fpdModuleId);\r
346 }\r
347\r
878ddf1f 348 /**\r
82516887 349 Query module surface area information.\r
ff225cbb 350\r
351 <p>Note that surface area parsing is incremental. That means the method will\r
82516887 352 only parse the MSA files if necessary. </p>\r
353 \r
354 @param fpdModuleId Module ID with arch\r
355 @return ModuleSA info and MSA info for fpdModuleId\r
356 @throws BuildException Can't find MSA\r
878ddf1f 357 **/\r
892b0e7a 358 public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{\r
a29c47e0 359 if (parsedModules.containsKey(fpdModuleId)) {\r
360 return parsedModules.get(fpdModuleId);\r
361 }\r
362 Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r
363 ModuleIdentification moduleId = fpdModuleId.getModule();\r
878ddf1f 364 //\r
a29c47e0 365 // First part: get the MSA files info\r
878ddf1f 366 //\r
136adffc 367 doc.putAll(getNativeMsa(moduleId));\r
ff225cbb 368\r
a29c47e0 369 //\r
370 // Second part: put build options\r
371 //\r
372 doc.put("BuildOptions", fpdBuildOptions);\r
ff225cbb 373\r
a29c47e0 374 //\r
375 // Third part: get Module info from FPD, such as Library instances, PCDs\r
376 //\r
377 if (fpdModuleSA.containsKey(fpdModuleId)){\r
378 //\r
379 // merge module info in FPD to final Doc\r
380 // For Library Module, do nothing here\r
381 //\r
382 doc.putAll(fpdModuleSA.get(fpdModuleId));\r
878ddf1f 383 }\r
a29c47e0 384 parsedModules.put(fpdModuleId, doc);\r
385 return doc;\r
878ddf1f 386 }\r
387\r
892b0e7a 388 public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{\r
a29c47e0 389 FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r
390 return getDoc(fpdModuleId);\r
391 }\r
892b0e7a 392 \r
878ddf1f 393 /**\r
ff225cbb 394 Query the native MSA information with module base name.\r
395\r
396 <p>Note that MSA parsing is incremental. That means the method will\r
878ddf1f 397 only to parse the MSA files when never parsed before. </p>\r
ff225cbb 398\r
878ddf1f 399 @param moduleName the base name of the module\r
400 @return the native MSA information\r
401 @throws BuildException\r
402 MSA file is not valid\r
403 **/\r
892b0e7a 404 public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {\r
a29c47e0 405 if (nativeMsa.containsKey(moduleId)) {\r
406 return nativeMsa.get(moduleId);\r
407 }\r
408 File msaFile = getMsaFile(moduleId);\r
409 Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r
410 nativeMsa.put(moduleId, msaMap);\r
411 return msaMap;\r
412 }\r
ff225cbb 413\r
892b0e7a 414 public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {\r
82516887 415 if (!msaFile.exists()) {\r
892b0e7a 416 throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r
a29c47e0 417 }\r
418 try {\r
419 ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r
420 //\r
421 // Validate File if they accord with XML Schema\r
422 //\r
82516887 423 if ( !doc.validate()){\r
892b0e7a 424 throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r
a29c47e0 425 }\r
426 //\r
427 // parse MSA file\r
428 //\r
429 ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r
430 Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r
431 msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r
432 msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r
433 msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r
434 msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r
435 msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r
436 msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r
437 msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r
438 msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r
439 msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r
136adffc 440 msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r
b69bb9ba 441 msaMap.put("ModuleBuildOptions", cloneXmlObject(msa.getModuleBuildOptions(), true));\r
a29c47e0 442 return msaMap;\r
892b0e7a 443 } catch(IOException ex) {\r
444 EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r
445 edkException.setStackTrace(ex.getStackTrace());\r
446 throw edkException;\r
447 } catch(XmlException ex) {\r
448 EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r
449 edkException.setStackTrace(ex.getStackTrace());\r
450 throw edkException;\r
a29c47e0 451 }\r
452 }\r
ff225cbb 453\r
19bf6b15 454 public static Map<String, XmlObject> getFpdBuildOptionsMap() {\r
455 return fpdBuildOptionsMap;\r
878ddf1f 456 }\r
ff225cbb 457\r
892b0e7a 458 public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {\r
a29c47e0 459 GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r
19bf6b15 460 fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);\r
a29c47e0 461 }\r
462\r
463 public static XmlObject getFpdDynamicPcds() {\r
464 return fpdDynamicPcds;\r
465 }\r
466\r
467 public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r
468 GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r
469 }\r
470\r
a29c47e0 471 public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r
472 Spd spd = spdTable.get(packageId);\r
473 if (spd == null ) {\r
474 Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r
475 return dummy;\r
82516887 476 } else {\r
a29c47e0 477 return spd.getModules();\r
878ddf1f 478 }\r
878ddf1f 479 }\r
480\r
481 /**\r
a29c47e0 482 * The header file path is relative to workspace dir\r
483 */\r
484 public static String[] getLibraryClassHeaderFiles(\r
892b0e7a 485 PackageIdentification[] packages, String name) throws EdkException{\r
a29c47e0 486 if (packages == null) {\r
487 // throw Exception or not????\r
488 return new String[0];\r
489 }\r
490 String[] result = null;\r
491 for (int i = 0; i < packages.length; i++) {\r
492 Spd spd = spdTable.get(packages[i]);\r
493 //\r
494 // If find one package defined the library class\r
495 //\r
496 if ((result = spd.getLibClassIncluder(name)) != null) {\r
497 return result;\r
498 }\r
499 }\r
500 //\r
501 // If can't find library class declaration in every package\r
502 //\r
892b0e7a 503 throw new EdkException("Can not find library class [" + name\r
391dbbb1 504 + "] declaration in any SPD package!");\r
878ddf1f 505 }\r
506\r
507 /**\r
a29c47e0 508 * The header file path is relative to workspace dir\r
878ddf1f 509 */\r
a29c47e0 510 public static String getPackageHeaderFiles(PackageIdentification packages,\r
892b0e7a 511 String moduleType) {\r
a29c47e0 512 if (packages == null) {\r
513 return new String("");\r
514 }\r
515 Spd spd = spdTable.get(packages);\r
516 //\r
517 // If can't find package header file, skip it\r
518 //\r
519 String temp = null;\r
520 if (spd != null) {\r
521 if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r
522 return temp;\r
523 } else {\r
524 temp = "";\r
525 return temp;\r
878ddf1f 526 }\r
a29c47e0 527 } else {\r
528 return null;\r
878ddf1f 529 }\r
878ddf1f 530 }\r
531\r
a29c47e0 532 /**\r
533 * return two values: {cName, GuidValue}\r
534 */\r
892b0e7a 535 public static String[] getGuid(List<PackageIdentification> packages, String name) {\r
a29c47e0 536 if (packages == null) {\r
537 // throw Exception or not????\r
538 return new String[0];\r
539 }\r
540 String[] result = null;\r
136adffc 541 Iterator item = packages.iterator();\r
542 while (item.hasNext()){\r
543 Spd spd = spdTable.get(item.next());\r
a29c47e0 544 //\r
545 // If find one package defined the GUID\r
546 //\r
547 if ((result = spd.getGuid(name)) != null) {\r
548 return result;\r
878ddf1f 549 }\r
550 }\r
136adffc 551\r
a29c47e0 552 return null;\r
878ddf1f 553 }\r
554\r
555 /**\r
a29c47e0 556 * return two values: {cName, GuidValue}\r
878ddf1f 557 */\r
136adffc 558 public static String[] getPpiGuid(List<PackageIdentification> packages,\r
892b0e7a 559 String name) {\r
a29c47e0 560 if (packages == null) {\r
561 return new String[0];\r
562 }\r
563 String[] result = null;\r
136adffc 564 Iterator item = packages.iterator();\r
565 while (item.hasNext()){\r
566 Spd spd = spdTable.get(item.next());\r
a29c47e0 567 //\r
568 // If find one package defined the Ppi GUID\r
569 //\r
570 if ((result = spd.getPpi(name)) != null) {\r
571 return result;\r
878ddf1f 572 }\r
573 }\r
a29c47e0 574 return null;\r
878ddf1f 575 }\r
576\r
a29c47e0 577 /**\r
578 * return two values: {cName, GuidValue}\r
579 */\r
136adffc 580 public static String[] getProtocolGuid(List<PackageIdentification> packages,\r
892b0e7a 581 String name) {\r
a29c47e0 582 if (packages == null) {\r
583 return new String[0];\r
584 }\r
585 String[] result = null;\r
136adffc 586 Iterator item = packages.iterator();\r
587 while (item.hasNext()){\r
588 Spd spd = spdTable.get(item.next());\r
a29c47e0 589 //\r
590 // If find one package defined the protocol GUID\r
591 //\r
136adffc 592 if ((result = spd.getProtocol(name))!= null){\r
a29c47e0 593 return result;\r
594 }\r
595 }\r
596 return null;\r
878ddf1f 597\r
a29c47e0 598 }\r
ff225cbb 599\r
892b0e7a 600 public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException {\r
a29c47e0 601 Iterator iter = platformList.iterator();\r
602 while(iter.hasNext()){\r
603 PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
604 if (platformId.getName().equalsIgnoreCase(name)) {\r
a29c47e0 605 return platformId;\r
878ddf1f 606 }\r
a29c47e0 607 }\r
892b0e7a 608 throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r
de4bb9f6 609 }\r
ff225cbb 610\r
892b0e7a 611 public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException {\r
de4bb9f6 612 File file = new File(workspaceDir + File.separatorChar + filename);\r
613 Iterator iter = platformList.iterator();\r
614 while(iter.hasNext()){\r
615 PlatformIdentification platformId = (PlatformIdentification)iter.next();\r
616 if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r
617 return platformId;\r
618 }\r
619 }\r
892b0e7a 620 throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r
a29c47e0 621 }\r
ff225cbb 622\r
892b0e7a 623 public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException {\r
a29c47e0 624 Iterator iter = packageList.iterator();\r
625 while(iter.hasNext()){\r
626 PackageIdentification packageItem = (PackageIdentification)iter.next();\r
627 if (packageItem.equals(packageId)) {\r
628 packageId.setName(packageItem.getName());\r
629 packageId.setSpdFile(packageItem.getSpdFile());\r
630 return packageId;\r
878ddf1f 631 }\r
632 }\r
892b0e7a 633 throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r
a29c47e0 634 }\r
ff225cbb 635\r
892b0e7a 636 public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException {\r
a29c47e0 637 PackageIdentification packageId = getPackageForModule(moduleId);\r
a29c47e0 638 moduleId.setPackage(packageId);\r
639 Spd spd = spdTable.get(packageId);\r
640 if (spd == null) {\r
892b0e7a 641 throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r
a29c47e0 642 }\r
643 Set<ModuleIdentification> modules = spd.getModules();\r
644 Iterator<ModuleIdentification> iter = modules.iterator();\r
645 while (iter.hasNext()) {\r
646 ModuleIdentification item = iter.next();\r
647 if (item.equals(moduleId)) {\r
648 moduleId.setName(item.getName());\r
649 moduleId.setModuleType(item.getModuleType());\r
650 moduleId.setMsaFile(item.getMsaFile());\r
651 return moduleId;\r
652 }\r
653 }\r
892b0e7a 654 throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r
a29c47e0 655 }\r
ff225cbb 656\r
a29c47e0 657 public synchronized static Set<PackageIdentification> getPackageList(){\r
658 return packageList;\r
659 }\r
82516887 660\r
661 /**\r
662 BUGBUG: It is a walk around method. If do not clone, can't query info with\r
663 XPath correctly. \r
664 \r
665 @param object XmlObject\r
666 @param deep flag for deep clone\r
667 @return XmlObject after clone\r
668 @throws BuildException parse original XmlObject error. \r
669 **/\r
892b0e7a 670 private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException {\r
a29c47e0 671 if ( object == null) {\r
672 return null;\r
673 }\r
674 XmlObject result = null;\r
675 try {\r
676 result = XmlObject.Factory.parse(object.getDomNode()\r
677 .cloneNode(deep));\r
892b0e7a 678 } catch (XmlException ex) {\r
679 EdkException edkException = new EdkException(ex.getMessage());\r
680 edkException.setStackTrace(ex.getStackTrace());\r
681 throw edkException;\r
a29c47e0 682 }\r
683 return result;\r
878ddf1f 684 }\r
685\r
4b5f5549 686 ///\r
687 /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r
688 ///\r
1744b047 689 public synchronized static ToolChainInfo getToolChainInfo() {\r
a29c47e0 690 if (toolChainInfo == null) {\r
691 toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r
692 if (toolChainPlatformInfo != null) {\r
693 toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r
878ddf1f 694 }\r
a29c47e0 695 toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r
696 toolChainInfo.normalize();\r
2eb7d78d 697 EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: ");\r
698 EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + "");\r
878ddf1f 699 }\r
a29c47e0 700 return toolChainInfo;\r
701 }\r
702\r
a29c47e0 703 public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r
704 platformToolChainFamilyOption = map;\r
878ddf1f 705 }\r
706\r
a29c47e0 707 public static void setPlatformToolChainOption(ToolChainMap map) {\r
708 platformToolChainOption = map;\r
709 }\r
878ddf1f 710\r
a29c47e0 711 public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r
712 ToolChainMap toolChainOption) {\r
713 moduleToolChainOption.put(fpdModuleId, toolChainOption);\r
878ddf1f 714 }\r
715\r
a29c47e0 716 public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r
717 ToolChainMap toolChainOption) {\r
718 moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r
878ddf1f 719 }\r
b69bb9ba 720 \r
721 public static void addMsaBuildOption(ModuleIdentification moduleId,\r
722 ToolChainMap toolChainOption) {\r
723 msaBuildOption.put(moduleId, toolChainOption);\r
724 }\r
725 \r
726 public static void addMsaFamilyBuildOption(ModuleIdentification moduleId,\r
727 ToolChainMap toolChainOption) {\r
728 msaFamilyBuildOption.put(moduleId, toolChainOption);\r
729 }\r
730 \r
c773bec0 731 public static boolean isCommandSet(String target, String toolchain, String arch) {\r
732 String[] commands = getToolChainInfo().getCommands();\r
733\r
734 for (int i = 0; i < commands.length; ++i) {\r
b0a80562 735 String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolDefinitions.TOOLS_DEF_ATTRIBUTE_NAME});\r
a10c0400 736 if (cmdName != null && cmdName.length() != 0) {\r
c773bec0 737 return true;\r
738 }\r
739 }\r
740\r
741 return false;\r
742 }\r
743\r
b69bb9ba 744 /**\r
745 Except FLAGS, all attribute are from TOOLS_DEF file. \r
746 \r
747 For FLAGS, information from four places, they are: \r
748 <pre>\r
749 1. tools_def.txt\r
750 2. MSA &lt;BuildOptions&gt;/&lt;Options&gt;\r
751 3. FPD &lt;BuildOptions&gt;/&lt;Options&gt;\r
752 4. FPD &lt;FrameworkModules&gt;/&lt;ModuleSaBuildOptions&gt;/&lt;Options&gt;\r
753 </pre>\r
754 \r
755 @param commandDescription Key: TARGET, TAGNAME, ARCH, COMMANDTYPE, ATTRIBUTE\r
756 @param fpdModuleId Module Identification with Arch\r
757 @return The corresponding String\r
758 @throws EdkException If build option definition error\r
759 **/\r
2f2c367a 760 public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r
a29c47e0 761 ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r
ff225cbb 762 ToolChainMap toolChainConfig = toolsDef.getConfig();\r
a29c47e0 763 String setting = null;\r
764\r
8c84e1b1 765 //\r
766 // Default in tools_def.txt\r
767 // \r
0923e8b3 768 setting = toolChainConfig.get(toolChainKey);\r
769 if (setting == null) {\r
8c84e1b1 770 setting = "";\r
0923e8b3 771 }\r
b0a80562 772 if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS)) {\r
a29c47e0 773 return setting;\r
878ddf1f 774 }\r
878ddf1f 775\r
a29c47e0 776 //\r
b69bb9ba 777 // Tool's option can be in .fpd and/or .msa file\r
8c84e1b1 778 //\r
779 String optionString;\r
780 ToolChainMap option = null;\r
781 ToolChainKey toolChainFamilyKey = new ToolChainKey(commandDescription);\r
0923e8b3 782\r
b0a80562 783 toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FAMILY, ToolChainElement.ATTRIBUTE.value);\r
8c84e1b1 784 String family = toolChainConfig.get(toolChainFamilyKey);\r
785 toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r
b0a80562 786 toolChainFamilyKey.setKey(ToolDefinitions.TOOLS_DEF_ATTRIBUTE_FLAGS, ToolChainElement.ATTRIBUTE.value);\r
0923e8b3 787\r
b69bb9ba 788 //\r
789 // MSA's tool chain family option\r
790 //\r
791 option = msaFamilyBuildOption.get(fpdModuleId.getModule());\r
792 if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) {\r
793 setting += (" " + optionString);\r
794 }\r
795 \r
796 //\r
797 // MSA's tool chain option\r
798 //\r
799 option = msaBuildOption.get(fpdModuleId.getModule());\r
800 if (option != null && (optionString = option.get(toolChainKey)) != null) {\r
801 setting += (" " + optionString);\r
802 }\r
803 \r
0923e8b3 804 //\r
8c84e1b1 805 // Platform's tool chain family option\r
0923e8b3 806 //\r
8c84e1b1 807 optionString = platformToolChainFamilyOption.get(toolChainFamilyKey);\r
808 if (optionString != null) {\r
809 setting += (" " + optionString);\r
878ddf1f 810 }\r
878ddf1f 811\r
a29c47e0 812 //\r
8c84e1b1 813 // Platform's tool chain tag option\r
a29c47e0 814 //\r
8c84e1b1 815 optionString = platformToolChainOption.get(toolChainKey);\r
816 if (optionString != null) {\r
b69bb9ba 817 setting += (" " + optionString);\r
8c84e1b1 818 }\r
a29c47e0 819\r
8c84e1b1 820 //\r
821 // Module's tool chain family option\r
822 //\r
823 option = moduleToolChainFamilyOption.get(fpdModuleId);\r
824 if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) {\r
b69bb9ba 825 setting += (" " + optionString);\r
a29c47e0 826 }\r
827\r
8c84e1b1 828 //\r
829 // Module's tool chain tag option\r
830 //\r
831 option = moduleToolChainOption.get(fpdModuleId);\r
832 if (option != null && (optionString = option.get(toolChainKey)) != null) {\r
b69bb9ba 833 setting += (" " + optionString);\r
a29c47e0 834 }\r
835\r
836 return setting;\r
837 }\r
ff225cbb 838\r
a29c47e0 839 public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r
840 toolChainEnvInfo = envInfo;\r
841 }\r
842 public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r
843 toolChainPlatformInfo = platformInfo;\r
878ddf1f 844 }\r
a29c47e0 845\r
846 //\r
847 // for PCD\r
848 //\r
136adffc 849 public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r
850 return pcdDbManager;\r
851 }\r
a29c47e0 852\r
853 //\r
136adffc 854 // For PCD get tokenSpaceGUid\r
a29c47e0 855 //\r
20c5c53f 856 public synchronized static String getGuidInfoFromCname(String cName){\r
857 String cNameGuid = null;\r
136adffc 858 String guid = null;\r
859 Set set = spdTable.keySet();\r
860 Iterator iter = set.iterator();\r
548ce97a 861\r
862 if (iter == null) {\r
863 return null;\r
864 }\r
865\r
136adffc 866 while (iter.hasNext()){\r
867 Spd spd = (Spd) spdTable.get(iter.next());\r
868 guid = spd.getGuidFromCname(cName);\r
869 if (guid != null){\r
20c5c53f 870 cNameGuid = guid;\r
136adffc 871 break;\r
872 }\r
873 }\r
874 return cNameGuid;\r
875 }\r
a29c47e0 876\r
877 //\r
878 // For PCD\r
879 //\r
ff225cbb 880 public synchronized static Map<FpdModuleIdentification, XmlObject>\r
eece174a 881 getFpdModuleSaXmlObject(String xmlObjectName) {\r
136adffc 882 Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r
883 Iterator item = fpdModuleSASet.iterator();\r
ff225cbb 884\r
136adffc 885\r
886 Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r
887 Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r
888 FpdModuleIdentification moduleId;\r
889 while (item.hasNext()) {\r
ff225cbb 890\r
136adffc 891 moduleId = (FpdModuleIdentification) item.next();\r
892 SANode = fpdModuleSA.get(moduleId);\r
893 try{\r
894 if (SANode.get(xmlObjectName)!= null){\r
895 SAPcdBuildDef.put(moduleId,\r
eece174a 896 (XmlObject) SANode.get(xmlObjectName));\r
136adffc 897\r
898 }\r
136adffc 899 } catch (Exception e){\r
900 EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r
901 }\r
eece174a 902 }\r
136adffc 903 return SAPcdBuildDef;\r
904 }\r
eece174a 905\r
906 public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {\r
907 Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");\r
908\r
909 return pcdBuildDef;\r
910 }\r
878ddf1f 911}\r
a29c47e0 912\r