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