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