]>
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 | |
a29c47e0 | 168 | //\r |
169 | // Parse Framework Database\r | |
170 | //\r | |
878ddf1f | 171 | File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r |
172 | try {\r | |
173 | FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r | |
a29c47e0 | 174 | //\r |
175 | // validate FrameworkDatabaseFile\r | |
176 | //\r | |
82516887 | 177 | if (!db.validate()) {\r |
892b0e7a | 178 | throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r |
878ddf1f | 179 | }\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 | |
202 | \r | |
a29c47e0 | 203 | //\r |
204 | // Get platform list\r | |
205 | //\r | |
206 | if (db.getFrameworkDatabase().getPlatformList() != null) {\r | |
207 | List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r | |
208 | Iterator<DbPathAndFilename> iter = platforms.iterator();\r | |
209 | while (iter.hasNext()) {\r | |
83fba802 | 210 | String fileName = iter.next().getStringValue().trim();\r |
a29c47e0 | 211 | File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r |
82516887 | 212 | if ( !fpdFile.exists() ) {\r |
892b0e7a | 213 | throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r |
250258de | 214 | }\r |
a29c47e0 | 215 | XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r |
216 | //\r | |
217 | // Verify FPD file, if is invalid, throw Exception\r | |
218 | //\r | |
82516887 | 219 | if (!fpdDoc.validate()) {\r |
892b0e7a | 220 | throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r |
a29c47e0 | 221 | }\r |
222 | //\r | |
223 | // We can change Map to XmlObject\r | |
224 | //\r | |
a29c47e0 | 225 | Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r |
226 | fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r | |
83fba802 | 227 | SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r |
228 | PlatformIdentification platformId = saq.getFpdHeader();\r | |
a29c47e0 | 229 | platformId.setFpdFile(fpdFile);\r |
892b0e7a | 230 | //\r |
231 | // Report warning if existing two platfrom with same GUID and Version\r | |
232 | //\r | |
233 | if (platformList.contains(platformId)) {\r | |
234 | //\r | |
235 | // BUGBUG\r | |
236 | //\r | |
237 | EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath());\r | |
238 | }\r | |
a29c47e0 | 239 | platformList.add(platformId);\r |
878ddf1f | 240 | }\r |
878ddf1f | 241 | }\r |
892b0e7a | 242 | } catch(IOException ex) {\r |
243 | EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r | |
244 | edkException.setStackTrace(ex.getStackTrace());\r | |
245 | throw edkException;\r | |
246 | } catch(XmlException ex) {\r | |
247 | EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r | |
248 | edkException.setStackTrace(ex.getStackTrace());\r | |
249 | throw edkException;\r | |
878ddf1f | 250 | }\r |
251 | }\r | |
ff225cbb | 252 | \r |
878ddf1f | 253 | /**\r |
ff225cbb | 254 | Get the current WORKSPACE Directory.\r |
255 | \r | |
a29c47e0 | 256 | @return current workspace directory\r |
878ddf1f | 257 | **/\r |
a29c47e0 | 258 | public synchronized static String getWorkspacePath() {\r |
259 | return workspaceDir;\r | |
878ddf1f | 260 | }\r |
261 | \r | |
878ddf1f | 262 | \r |
263 | /**\r | |
a29c47e0 | 264 | Get the MSA file name with absolute path\r |
265 | */\r | |
892b0e7a | 266 | public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 | 267 | File msaFile = null;\r |
268 | //\r | |
ff225cbb | 269 | // TBD. Do only when package is null.\r |
a29c47e0 | 270 | //\r |
271 | Iterator iter = packageList.iterator();\r | |
272 | while (iter.hasNext()) {\r | |
273 | PackageIdentification packageId = (PackageIdentification)iter.next();\r | |
274 | Spd spd = spdTable.get(packageId);\r | |
275 | msaFile = spd.getModuleFile(moduleId);\r | |
276 | if (msaFile != null ) {\r | |
277 | break ;\r | |
278 | }\r | |
279 | }\r | |
280 | if (msaFile == null){\r | |
892b0e7a | 281 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r |
82516887 | 282 | } else {\r |
a29c47e0 | 283 | return msaFile;\r |
284 | }\r | |
878ddf1f | 285 | }\r |
286 | \r | |
892b0e7a | 287 | public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 | 288 | //\r |
289 | // If package already defined in module\r | |
290 | //\r | |
291 | if (moduleId.getPackage() != null) {\r | |
292 | return moduleId.getPackage();\r | |
293 | }\r | |
ff225cbb | 294 | \r |
a29c47e0 | 295 | PackageIdentification packageId = null;\r |
296 | Iterator iter = packageList.iterator();\r | |
297 | while (iter.hasNext()) {\r | |
298 | packageId = (PackageIdentification)iter.next();\r | |
299 | moduleId.setPackage(packageId);\r | |
300 | Spd spd = spdTable.get(packageId);\r | |
89e1408f | 301 | File tempMsaFile = null;\r |
302 | if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) {\r | |
303 | if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) {\r | |
304 | break ;\r | |
305 | }\r | |
306 | tempMsaFile = null;\r | |
a29c47e0 | 307 | }\r |
308 | }\r | |
309 | if (packageId == null){\r | |
892b0e7a | 310 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r |
82516887 | 311 | } else {\r |
a29c47e0 | 312 | return packageId;\r |
313 | }\r | |
314 | }\r | |
ff225cbb | 315 | \r |
878ddf1f | 316 | /**\r |
a29c47e0 | 317 | Difference between build and parse: ToolChain and Target\r |
878ddf1f | 318 | **/\r |
a29c47e0 | 319 | public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r |
320 | return builtModules.contains(moduleId);\r | |
878ddf1f | 321 | }\r |
ff225cbb | 322 | \r |
a29c47e0 | 323 | public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r |
324 | builtModules.add(fpdModuleId);\r | |
878ddf1f | 325 | }\r |
326 | \r | |
ff225cbb | 327 | \r |
892b0e7a | 328 | public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{\r |
a29c47e0 | 329 | Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r |
330 | Set keySet = doc.keySet();\r | |
331 | Iterator iter = keySet.iterator();\r | |
332 | while (iter.hasNext()){\r | |
333 | String key = (String)iter.next();\r | |
334 | XmlObject item = cloneXmlObject(doc.get(key), true);\r | |
335 | result.put(key, item);\r | |
336 | }\r | |
337 | fpdModuleSA.put(fpdModuleId, result);\r | |
878ddf1f | 338 | }\r |
57cc2ee7 | 339 | \r |
340 | public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {\r | |
341 | return fpdModuleSA.containsKey(fpdModuleId);\r | |
342 | }\r | |
343 | \r | |
878ddf1f | 344 | /**\r |
82516887 | 345 | Query module surface area information.\r |
ff225cbb | 346 | \r |
347 | <p>Note that surface area parsing is incremental. That means the method will\r | |
82516887 | 348 | only parse the MSA files if necessary. </p>\r |
349 | \r | |
350 | @param fpdModuleId Module ID with arch\r | |
351 | @return ModuleSA info and MSA info for fpdModuleId\r | |
352 | @throws BuildException Can't find MSA\r | |
878ddf1f | 353 | **/\r |
892b0e7a | 354 | public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{\r |
a29c47e0 | 355 | if (parsedModules.containsKey(fpdModuleId)) {\r |
356 | return parsedModules.get(fpdModuleId);\r | |
357 | }\r | |
358 | Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r | |
359 | ModuleIdentification moduleId = fpdModuleId.getModule();\r | |
878ddf1f | 360 | //\r |
a29c47e0 | 361 | // First part: get the MSA files info\r |
878ddf1f | 362 | //\r |
136adffc | 363 | doc.putAll(getNativeMsa(moduleId));\r |
ff225cbb | 364 | \r |
a29c47e0 | 365 | //\r |
366 | // Second part: put build options\r | |
367 | //\r | |
368 | doc.put("BuildOptions", fpdBuildOptions);\r | |
ff225cbb | 369 | \r |
a29c47e0 | 370 | //\r |
371 | // Third part: get Module info from FPD, such as Library instances, PCDs\r | |
372 | //\r | |
373 | if (fpdModuleSA.containsKey(fpdModuleId)){\r | |
374 | //\r | |
375 | // merge module info in FPD to final Doc\r | |
376 | // For Library Module, do nothing here\r | |
377 | //\r | |
378 | doc.putAll(fpdModuleSA.get(fpdModuleId));\r | |
878ddf1f | 379 | }\r |
a29c47e0 | 380 | parsedModules.put(fpdModuleId, doc);\r |
381 | return doc;\r | |
878ddf1f | 382 | }\r |
383 | \r | |
892b0e7a | 384 | public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{\r |
a29c47e0 | 385 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r |
386 | return getDoc(fpdModuleId);\r | |
387 | }\r | |
892b0e7a | 388 | \r |
878ddf1f | 389 | /**\r |
ff225cbb | 390 | Query the native MSA information with module base name.\r |
391 | \r | |
392 | <p>Note that MSA parsing is incremental. That means the method will\r | |
878ddf1f | 393 | only to parse the MSA files when never parsed before. </p>\r |
ff225cbb | 394 | \r |
878ddf1f | 395 | @param moduleName the base name of the module\r |
396 | @return the native MSA information\r | |
397 | @throws BuildException\r | |
398 | MSA file is not valid\r | |
399 | **/\r | |
892b0e7a | 400 | public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 | 401 | if (nativeMsa.containsKey(moduleId)) {\r |
402 | return nativeMsa.get(moduleId);\r | |
403 | }\r | |
404 | File msaFile = getMsaFile(moduleId);\r | |
405 | Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r | |
406 | nativeMsa.put(moduleId, msaMap);\r | |
407 | return msaMap;\r | |
408 | }\r | |
ff225cbb | 409 | \r |
892b0e7a | 410 | public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {\r |
82516887 | 411 | if (!msaFile.exists()) {\r |
892b0e7a | 412 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r |
a29c47e0 | 413 | }\r |
414 | try {\r | |
415 | ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r | |
416 | //\r | |
417 | // Validate File if they accord with XML Schema\r | |
418 | //\r | |
82516887 | 419 | if ( !doc.validate()){\r |
892b0e7a | 420 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r |
a29c47e0 | 421 | }\r |
422 | //\r | |
423 | // parse MSA file\r | |
424 | //\r | |
425 | ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r | |
426 | Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r | |
427 | msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r | |
428 | msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r | |
429 | msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r | |
430 | msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r | |
431 | msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r | |
432 | msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r | |
433 | msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r | |
434 | msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r | |
435 | msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r | |
136adffc | 436 | msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r |
a29c47e0 | 437 | return msaMap;\r |
892b0e7a | 438 | } catch(IOException ex) {\r |
439 | EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r | |
440 | edkException.setStackTrace(ex.getStackTrace());\r | |
441 | throw edkException;\r | |
442 | } catch(XmlException ex) {\r | |
443 | EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r | |
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 | |
a29c47e0 | 684 | public 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 |
715 | \r | |
c773bec0 | 716 | public static boolean isCommandSet(String target, String toolchain, String arch) {\r |
717 | String[] commands = getToolChainInfo().getCommands();\r | |
718 | \r | |
719 | for (int i = 0; i < commands.length; ++i) {\r | |
a10c0400 | 720 | String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});\r |
721 | if (cmdName != null && cmdName.length() != 0) {\r | |
c773bec0 | 722 | return true;\r |
723 | }\r | |
724 | }\r | |
725 | \r | |
726 | return false;\r | |
727 | }\r | |
728 | \r | |
a29c47e0 | 729 | public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
730 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r | |
ff225cbb | 731 | ToolChainMap toolChainConfig = toolsDef.getConfig();\r |
a29c47e0 | 732 | String setting = null;\r |
733 | \r | |
734 | if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r | |
735 | setting = toolChainConfig.get(toolChainKey);\r | |
736 | if (setting == null) {\r | |
737 | setting = "";\r | |
738 | }\r | |
739 | return setting;\r | |
878ddf1f | 740 | }\r |
878ddf1f | 741 | \r |
a29c47e0 | 742 | //\r |
743 | // get module specific options, if any\r | |
744 | //\r | |
745 | // tool tag first\r | |
746 | ToolChainMap option = moduleToolChainOption.get(fpdModuleId);\r | |
747 | ToolChainKey toolChainFamilyKey = null;\r | |
748 | \r | |
749 | if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {\r | |
750 | //\r | |
751 | // then tool chain family\r | |
752 | //\r | |
753 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r | |
754 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
755 | String family = toolChainConfig.get(toolChainFamilyKey);\r | |
756 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r | |
757 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
758 | \r | |
759 | option = moduleToolChainFamilyOption.get(fpdModuleId);\r | |
ff225cbb | 760 | if (option != null) {\r |
a29c47e0 | 761 | setting = option.get(toolChainFamilyKey);\r |
762 | }\r | |
878ddf1f | 763 | }\r |
878ddf1f | 764 | \r |
a29c47e0 | 765 | //\r |
766 | // get platform options, if any\r | |
767 | //\r | |
768 | if (setting == null) {\r | |
769 | // tool tag first\r | |
770 | if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {\r | |
771 | // then tool chain family\r | |
772 | if (toolChainFamilyKey == null) {\r | |
773 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r | |
774 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
775 | String family = toolChainConfig.get(toolChainFamilyKey);\r | |
776 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r | |
777 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
778 | }\r | |
779 | \r | |
780 | setting = platformToolChainFamilyOption.get(toolChainFamilyKey);\r | |
781 | }\r | |
782 | }\r | |
783 | \r | |
784 | if (setting == null) {\r | |
785 | setting = "";\r | |
786 | }\r | |
787 | \r | |
788 | return setting;\r | |
789 | }\r | |
ff225cbb | 790 | \r |
a29c47e0 | 791 | public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r |
792 | toolChainEnvInfo = envInfo;\r | |
793 | }\r | |
794 | public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r | |
795 | toolChainPlatformInfo = platformInfo;\r | |
878ddf1f | 796 | }\r |
a29c47e0 | 797 | \r |
798 | //\r | |
799 | // for PCD\r | |
800 | //\r | |
136adffc | 801 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
802 | return pcdDbManager;\r | |
803 | }\r | |
a29c47e0 | 804 | \r |
805 | //\r | |
136adffc | 806 | // For PCD get tokenSpaceGUid\r |
a29c47e0 | 807 | //\r |
20c5c53f | 808 | public synchronized static String getGuidInfoFromCname(String cName){\r |
809 | String cNameGuid = null;\r | |
136adffc | 810 | String guid = null;\r |
811 | Set set = spdTable.keySet();\r | |
812 | Iterator iter = set.iterator();\r | |
548ce97a | 813 | \r |
814 | if (iter == null) {\r | |
815 | return null;\r | |
816 | }\r | |
817 | \r | |
136adffc | 818 | while (iter.hasNext()){\r |
819 | Spd spd = (Spd) spdTable.get(iter.next());\r | |
820 | guid = spd.getGuidFromCname(cName);\r | |
821 | if (guid != null){\r | |
20c5c53f | 822 | cNameGuid = guid;\r |
136adffc | 823 | break;\r |
824 | }\r | |
825 | }\r | |
826 | return cNameGuid;\r | |
827 | }\r | |
a29c47e0 | 828 | \r |
829 | //\r | |
830 | // For PCD\r | |
831 | //\r | |
ff225cbb | 832 | public synchronized static Map<FpdModuleIdentification, XmlObject>\r |
eece174a | 833 | getFpdModuleSaXmlObject(String xmlObjectName) {\r |
136adffc | 834 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r |
835 | Iterator item = fpdModuleSASet.iterator();\r | |
ff225cbb | 836 | \r |
136adffc | 837 | \r |
838 | Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r | |
839 | Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r | |
840 | FpdModuleIdentification moduleId;\r | |
841 | while (item.hasNext()) {\r | |
ff225cbb | 842 | \r |
136adffc | 843 | moduleId = (FpdModuleIdentification) item.next();\r |
844 | SANode = fpdModuleSA.get(moduleId);\r | |
845 | try{\r | |
846 | if (SANode.get(xmlObjectName)!= null){\r | |
847 | SAPcdBuildDef.put(moduleId,\r | |
eece174a | 848 | (XmlObject) SANode.get(xmlObjectName));\r |
136adffc | 849 | \r |
850 | }\r | |
136adffc | 851 | } catch (Exception e){\r |
852 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r | |
853 | }\r | |
eece174a | 854 | }\r |
136adffc | 855 | return SAPcdBuildDef;\r |
856 | }\r | |
eece174a | 857 | \r |
858 | public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {\r | |
859 | Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");\r | |
860 | \r | |
861 | return pcdBuildDef;\r | |
862 | }\r | |
878ddf1f | 863 | }\r |
a29c47e0 | 864 | \r |