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