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