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