]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | GlobalData class.\r | |
3 | \r | |
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 | |
6 | PCD and so on.\r | |
7 | \r | |
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 | |
19 | import java.io.File;\r | |
20 | import java.io.IOException;\r | |
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 | |
27 | \r | |
28 | import org.apache.xmlbeans.XmlException;\r | |
29 | import org.apache.xmlbeans.XmlObject;\r | |
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 | |
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 | |
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 | |
48 | \r | |
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 | |
52 | PCD and so on.\r | |
53 | \r | |
54 | <p>Note that all global information are initialized incrementally. All data will\r | |
55 | parse and record only of necessary during build time. </p>\r | |
56 | \r | |
57 | @since GenBuild 1.0\r | |
58 | **/\r | |
59 | public class GlobalData {\r | |
60 | ///\r | |
61 | /// Record current WORKSPACE Directory\r | |
62 | ///\r | |
63 | private static String workspaceDir = "";\r | |
64 | \r | |
65 | ///\r | |
66 | /// Be used to ensure Global data will be initialized only once.\r | |
67 | ///\r | |
68 | private static boolean globalFlag = false;\r | |
69 | \r | |
70 | ///\r | |
71 | /// Framework Database information: package list and platform list\r | |
72 | ///\r | |
73 | private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>();\r | |
74 | \r | |
75 | private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r | |
76 | \r | |
77 | ///\r | |
78 | /// Every detail SPD informations: Module list, Library class definition,\r | |
79 | /// Package header file, GUID/PPI/Protocol definitions\r | |
80 | ///\r | |
81 | private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();\r | |
82 | \r | |
83 | ///\r | |
84 | /// Build informations are divided into three parts:\r | |
85 | /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA\r | |
86 | ///\r | |
87 | private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();\r | |
88 | \r | |
89 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r | |
90 | \r | |
91 | private static Map<String, XmlObject> fpdBuildOptionsMap = new HashMap<String, XmlObject>();\r | |
92 | \r | |
93 | private static XmlObject fpdBuildOptions;\r | |
94 | \r | |
95 | private static XmlObject fpdDynamicPcds;\r | |
96 | \r | |
97 | ///\r | |
98 | /// Parsed modules list\r | |
99 | ///\r | |
100 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r | |
101 | \r | |
102 | ///\r | |
103 | /// built modules list with ARCH, TARGET, TOOLCHAIN\r | |
104 | ///\r | |
105 | private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r | |
106 | \r | |
107 | ///\r | |
108 | /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r | |
109 | ///\r | |
110 | private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r | |
111 | \r | |
112 | ///\r | |
113 | /// build target + tool chain family/tag name + arch + command types + command options\r | |
114 | ///\r | |
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 | |
120 | ///\r | |
121 | private static ToolChainConfig toolsDef;\r | |
122 | \r | |
123 | private static ToolChainInfo toolChainInfo;\r | |
124 | private static ToolChainInfo toolChainEnvInfo;\r | |
125 | private static ToolChainInfo toolChainPlatformInfo;\r | |
126 | \r | |
127 | private static ToolChainMap platformToolChainOption;\r | |
128 | private static ToolChainMap platformToolChainFamilyOption;\r | |
129 | \r | |
130 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r | |
131 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r | |
132 | \r | |
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 | |
136 | in the whole build process.\r | |
137 | \r | |
138 | @param workspaceDatabaseFile the file name of framework database\r | |
139 | @param workspaceDir current workspace directory path\r | |
140 | @throws BuildException\r | |
141 | Framework Dababase or SPD or MSA file is not valid\r | |
142 | **/\r | |
143 | public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException {\r | |
144 | //\r | |
145 | // ensure this method will be revoked only once\r | |
146 | //\r | |
147 | if (globalFlag) {\r | |
148 | return;\r | |
149 | }\r | |
150 | globalFlag = true;\r | |
151 | \r | |
152 | //\r | |
153 | // Backup workspace directory. It will be used by other method\r | |
154 | //\r | |
155 | GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r | |
156 | \r | |
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 | |
164 | File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r | |
165 | EdkLog.log("Init", "Using tool definition file [" + toolsDefFile.getPath() + "].");\r | |
166 | toolsDef = new ToolChainConfig(toolsDefFile);\r | |
167 | \r | |
168 | \r | |
169 | //\r | |
170 | // Parse Framework Database\r | |
171 | //\r | |
172 | File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r | |
173 | try {\r | |
174 | FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r | |
175 | //\r | |
176 | // validate FrameworkDatabaseFile\r | |
177 | //\r | |
178 | if (!db.validate()) {\r | |
179 | throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r | |
180 | }\r | |
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 | |
188 | String fileName = iter.next().getStringValue().trim();\r | |
189 | Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r | |
190 | packageList.add(spd.getPackageId());\r | |
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 | |
200 | spdTable.put(spd.getPackageId(), spd);\r | |
201 | }\r | |
202 | }\r | |
203 | \r | |
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 | |
211 | String fileName = iter.next().getStringValue().trim();\r | |
212 | File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r | |
213 | if ( !fpdFile.exists() ) {\r | |
214 | throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r | |
215 | }\r | |
216 | XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r | |
217 | //\r | |
218 | // Verify FPD file, if is invalid, throw Exception\r | |
219 | //\r | |
220 | if (!fpdDoc.validate()) {\r | |
221 | throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r | |
222 | }\r | |
223 | //\r | |
224 | // We can change Map to XmlObject\r | |
225 | //\r | |
226 | Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r | |
227 | fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r | |
228 | SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r | |
229 | PlatformIdentification platformId = saq.getFpdHeader();\r | |
230 | platformId.setFpdFile(fpdFile);\r | |
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 | |
240 | platformList.add(platformId);\r | |
241 | }\r | |
242 | }\r | |
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 | |
251 | }\r | |
252 | }\r | |
253 | \r | |
254 | /**\r | |
255 | Get the current WORKSPACE Directory.\r | |
256 | \r | |
257 | @return current workspace directory\r | |
258 | **/\r | |
259 | public synchronized static String getWorkspacePath() {\r | |
260 | return workspaceDir;\r | |
261 | }\r | |
262 | \r | |
263 | \r | |
264 | /**\r | |
265 | Get the MSA file name with absolute path\r | |
266 | */\r | |
267 | public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {\r | |
268 | File msaFile = null;\r | |
269 | //\r | |
270 | // TBD. Do only when package is null.\r | |
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 | |
282 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r | |
283 | } else {\r | |
284 | return msaFile;\r | |
285 | }\r | |
286 | }\r | |
287 | \r | |
288 | public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {\r | |
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 | |
295 | \r | |
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 | |
307 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r | |
308 | } else {\r | |
309 | return packageId;\r | |
310 | }\r | |
311 | }\r | |
312 | \r | |
313 | /**\r | |
314 | Difference between build and parse: ToolChain and Target\r | |
315 | **/\r | |
316 | public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r | |
317 | return builtModules.contains(moduleId);\r | |
318 | }\r | |
319 | \r | |
320 | public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r | |
321 | builtModules.add(fpdModuleId);\r | |
322 | }\r | |
323 | \r | |
324 | \r | |
325 | public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{\r | |
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 | |
335 | }\r | |
336 | \r | |
337 | public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {\r | |
338 | return fpdModuleSA.containsKey(fpdModuleId);\r | |
339 | }\r | |
340 | \r | |
341 | /**\r | |
342 | Query module surface area information.\r | |
343 | \r | |
344 | <p>Note that surface area parsing is incremental. That means the method will\r | |
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 | |
350 | **/\r | |
351 | public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{\r | |
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 | |
357 | //\r | |
358 | // First part: get the MSA files info\r | |
359 | //\r | |
360 | doc.putAll(getNativeMsa(moduleId));\r | |
361 | \r | |
362 | //\r | |
363 | // Second part: put build options\r | |
364 | //\r | |
365 | doc.put("BuildOptions", fpdBuildOptions);\r | |
366 | \r | |
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 | |
376 | }\r | |
377 | parsedModules.put(fpdModuleId, doc);\r | |
378 | return doc;\r | |
379 | }\r | |
380 | \r | |
381 | public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{\r | |
382 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r | |
383 | return getDoc(fpdModuleId);\r | |
384 | }\r | |
385 | \r | |
386 | /**\r | |
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 | |
390 | only to parse the MSA files when never parsed before. </p>\r | |
391 | \r | |
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 | |
397 | public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {\r | |
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 | |
406 | \r | |
407 | public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {\r | |
408 | if (!msaFile.exists()) {\r | |
409 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r | |
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 | |
416 | if ( !doc.validate()){\r | |
417 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r | |
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 | |
433 | msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r | |
434 | return msaMap;\r | |
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 | |
443 | }\r | |
444 | }\r | |
445 | \r | |
446 | public static Map<String, XmlObject> getFpdBuildOptionsMap() {\r | |
447 | return fpdBuildOptionsMap;\r | |
448 | }\r | |
449 | \r | |
450 | public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {\r | |
451 | GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r | |
452 | fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);\r | |
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 | |
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 | |
468 | } else {\r | |
469 | return spd.getModules();\r | |
470 | }\r | |
471 | }\r | |
472 | \r | |
473 | /**\r | |
474 | * The header file path is relative to workspace dir\r | |
475 | */\r | |
476 | public static String[] getLibraryClassHeaderFiles(\r | |
477 | PackageIdentification[] packages, String name) throws EdkException{\r | |
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 | |
495 | throw new EdkException("Can not find library class [" + name\r | |
496 | + "] declaration in any SPD package!");\r | |
497 | }\r | |
498 | \r | |
499 | /**\r | |
500 | * The header file path is relative to workspace dir\r | |
501 | */\r | |
502 | public static String getPackageHeaderFiles(PackageIdentification packages,\r | |
503 | String moduleType) {\r | |
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 | |
518 | }\r | |
519 | } else {\r | |
520 | return null;\r | |
521 | }\r | |
522 | }\r | |
523 | \r | |
524 | /**\r | |
525 | * return two values: {cName, GuidValue}\r | |
526 | */\r | |
527 | public static String[] getGuid(List<PackageIdentification> packages, String name) {\r | |
528 | if (packages == null) {\r | |
529 | // throw Exception or not????\r | |
530 | return new String[0];\r | |
531 | }\r | |
532 | String[] result = null;\r | |
533 | Iterator item = packages.iterator();\r | |
534 | while (item.hasNext()){\r | |
535 | Spd spd = spdTable.get(item.next());\r | |
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 | |
541 | }\r | |
542 | }\r | |
543 | \r | |
544 | return null;\r | |
545 | }\r | |
546 | \r | |
547 | /**\r | |
548 | * return two values: {cName, GuidValue}\r | |
549 | */\r | |
550 | public static String[] getPpiGuid(List<PackageIdentification> packages,\r | |
551 | String name) {\r | |
552 | if (packages == null) {\r | |
553 | return new String[0];\r | |
554 | }\r | |
555 | String[] result = null;\r | |
556 | Iterator item = packages.iterator();\r | |
557 | while (item.hasNext()){\r | |
558 | Spd spd = spdTable.get(item.next());\r | |
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 | |
564 | }\r | |
565 | }\r | |
566 | return null;\r | |
567 | }\r | |
568 | \r | |
569 | /**\r | |
570 | * return two values: {cName, GuidValue}\r | |
571 | */\r | |
572 | public static String[] getProtocolGuid(List<PackageIdentification> packages,\r | |
573 | String name) {\r | |
574 | if (packages == null) {\r | |
575 | return new String[0];\r | |
576 | }\r | |
577 | String[] result = null;\r | |
578 | Iterator item = packages.iterator();\r | |
579 | while (item.hasNext()){\r | |
580 | Spd spd = spdTable.get(item.next());\r | |
581 | //\r | |
582 | // If find one package defined the protocol GUID\r | |
583 | //\r | |
584 | if ((result = spd.getProtocol(name))!= null){\r | |
585 | return result;\r | |
586 | }\r | |
587 | }\r | |
588 | return null;\r | |
589 | \r | |
590 | }\r | |
591 | \r | |
592 | public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException {\r | |
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 | |
597 | return platformId;\r | |
598 | }\r | |
599 | }\r | |
600 | throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r | |
601 | }\r | |
602 | \r | |
603 | public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException {\r | |
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 | |
612 | throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r | |
613 | }\r | |
614 | \r | |
615 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException {\r | |
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 | |
623 | }\r | |
624 | }\r | |
625 | throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r | |
626 | }\r | |
627 | \r | |
628 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException {\r | |
629 | PackageIdentification packageId = getPackageForModule(moduleId);\r | |
630 | moduleId.setPackage(packageId);\r | |
631 | Spd spd = spdTable.get(packageId);\r | |
632 | if (spd == null) {\r | |
633 | throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r | |
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 | |
646 | throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r | |
647 | }\r | |
648 | \r | |
649 | public synchronized static Set<PackageIdentification> getPackageList(){\r | |
650 | return packageList;\r | |
651 | }\r | |
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 | |
662 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException {\r | |
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 | |
670 | } catch (XmlException ex) {\r | |
671 | EdkException edkException = new EdkException(ex.getMessage());\r | |
672 | edkException.setStackTrace(ex.getStackTrace());\r | |
673 | throw edkException;\r | |
674 | }\r | |
675 | return result;\r | |
676 | }\r | |
677 | \r | |
678 | ///\r | |
679 | /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r | |
680 | ///\r | |
681 | public static ToolChainInfo getToolChainInfo() {\r | |
682 | if (toolChainInfo == null) {\r | |
683 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r | |
684 | if (toolChainPlatformInfo != null) {\r | |
685 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r | |
686 | }\r | |
687 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r | |
688 | toolChainInfo.normalize();\r | |
689 | EdkLog.log("Init", "Current build tool chain information summary: ");\r | |
690 | EdkLog.log("Init", toolChainInfo + "");\r | |
691 | }\r | |
692 | return toolChainInfo;\r | |
693 | }\r | |
694 | \r | |
695 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r | |
696 | platformToolChainFamilyOption = map;\r | |
697 | }\r | |
698 | \r | |
699 | public static void setPlatformToolChainOption(ToolChainMap map) {\r | |
700 | platformToolChainOption = map;\r | |
701 | }\r | |
702 | \r | |
703 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r | |
704 | ToolChainMap toolChainOption) {\r | |
705 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r | |
706 | }\r | |
707 | \r | |
708 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r | |
709 | ToolChainMap toolChainOption) {\r | |
710 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r | |
711 | }\r | |
712 | \r | |
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 | |
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 | |
719 | return true;\r | |
720 | }\r | |
721 | }\r | |
722 | \r | |
723 | return false;\r | |
724 | }\r | |
725 | \r | |
726 | public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r | |
727 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r | |
728 | ToolChainMap toolChainConfig = toolsDef.getConfig();\r | |
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 | |
737 | }\r | |
738 | \r | |
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 | |
757 | if (option != null) {\r | |
758 | setting = option.get(toolChainFamilyKey);\r | |
759 | }\r | |
760 | }\r | |
761 | \r | |
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 | |
787 | \r | |
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 | |
793 | }\r | |
794 | \r | |
795 | //\r | |
796 | // for PCD\r | |
797 | //\r | |
798 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r | |
799 | return pcdDbManager;\r | |
800 | }\r | |
801 | \r | |
802 | //\r | |
803 | // For PCD get tokenSpaceGUid\r | |
804 | //\r | |
805 | public synchronized static String getGuidInfoFromCname(String cName){\r | |
806 | String cNameGuid = null;\r | |
807 | String guid = null;\r | |
808 | Set set = spdTable.keySet();\r | |
809 | Iterator iter = set.iterator();\r | |
810 | \r | |
811 | if (iter == null) {\r | |
812 | return null;\r | |
813 | }\r | |
814 | \r | |
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 | |
819 | cNameGuid = guid;\r | |
820 | break;\r | |
821 | }\r | |
822 | }\r | |
823 | return cNameGuid;\r | |
824 | }\r | |
825 | \r | |
826 | //\r | |
827 | // For PCD\r | |
828 | //\r | |
829 | public synchronized static Map<FpdModuleIdentification, XmlObject>\r | |
830 | getFpdModuleSaXmlObject(String xmlObjectName) {\r | |
831 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r | |
832 | Iterator item = fpdModuleSASet.iterator();\r | |
833 | \r | |
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 | |
839 | \r | |
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 | |
845 | (XmlObject) SANode.get(xmlObjectName));\r | |
846 | \r | |
847 | }\r | |
848 | } catch (Exception e){\r | |
849 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r | |
850 | }\r | |
851 | }\r | |
852 | return SAPcdBuildDef;\r | |
853 | }\r | |
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 | |
860 | }\r | |
861 | \r |