]>
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 |
a29c47e0 | 318 | \r |
878ddf1f | 319 | /**\r |
320 | Query overrided module surface area information. If current is Package\r | |
321 | or Platform build, also include the information from FPD file. \r | |
322 | \r | |
323 | <p>Note that surface area parsing is incremental. That means the method will \r | |
a29c47e0 | 324 | only parse the MSA and MBD files if necessary. </p>\r |
878ddf1f | 325 | \r |
326 | @param moduleName the base name of the module\r | |
327 | @return the overrided module surface area information\r | |
328 | @throws BuildException\r | |
329 | MSA or MBD is not valid\r | |
330 | **/\r | |
a29c47e0 | 331 | public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {\r |
332 | if (parsedModules.containsKey(fpdModuleId)) {\r | |
333 | return parsedModules.get(fpdModuleId);\r | |
334 | }\r | |
335 | Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r | |
336 | ModuleIdentification moduleId = fpdModuleId.getModule();\r | |
878ddf1f | 337 | //\r |
a29c47e0 | 338 | // First part: get the MSA files info\r |
878ddf1f | 339 | //\r |
136adffc | 340 | doc.putAll(getNativeMsa(moduleId));\r |
a29c47e0 | 341 | \r |
342 | //\r | |
343 | // Second part: put build options\r | |
344 | //\r | |
345 | doc.put("BuildOptions", fpdBuildOptions);\r | |
346 | \r | |
347 | //\r | |
348 | // Third part: get Module info from FPD, such as Library instances, PCDs\r | |
349 | //\r | |
350 | if (fpdModuleSA.containsKey(fpdModuleId)){\r | |
351 | //\r | |
352 | // merge module info in FPD to final Doc\r | |
353 | // For Library Module, do nothing here\r | |
354 | //\r | |
355 | doc.putAll(fpdModuleSA.get(fpdModuleId));\r | |
878ddf1f | 356 | }\r |
a29c47e0 | 357 | parsedModules.put(fpdModuleId, doc);\r |
358 | return doc;\r | |
878ddf1f | 359 | }\r |
360 | \r | |
a29c47e0 | 361 | public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {\r |
362 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r | |
363 | return getDoc(fpdModuleId);\r | |
364 | }\r | |
878ddf1f | 365 | /**\r |
366 | Query the native MSA information with module base name. \r | |
367 | \r | |
368 | <p>Note that MSA parsing is incremental. That means the method will \r | |
369 | only to parse the MSA files when never parsed before. </p>\r | |
370 | \r | |
371 | @param moduleName the base name of the module\r | |
372 | @return the native MSA information\r | |
373 | @throws BuildException\r | |
374 | MSA file is not valid\r | |
375 | **/\r | |
a29c47e0 | 376 | public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {\r |
377 | if (nativeMsa.containsKey(moduleId)) {\r | |
378 | return nativeMsa.get(moduleId);\r | |
379 | }\r | |
380 | File msaFile = getMsaFile(moduleId);\r | |
381 | Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r | |
382 | nativeMsa.put(moduleId, msaMap);\r | |
383 | return msaMap;\r | |
384 | }\r | |
385 | \r | |
386 | public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r | |
387 | if (! msaFile.exists()) {\r | |
388 | throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");\r | |
389 | }\r | |
390 | try {\r | |
391 | ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r | |
392 | //\r | |
393 | // Validate File if they accord with XML Schema\r | |
394 | //\r | |
395 | if ( ! doc.validate()){\r | |
396 | throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");\r | |
397 | }\r | |
398 | //\r | |
399 | // parse MSA file\r | |
400 | //\r | |
401 | ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r | |
402 | Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r | |
403 | msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r | |
404 | msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r | |
405 | msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r | |
406 | msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r | |
407 | msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r | |
408 | msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r | |
409 | msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r | |
410 | msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r | |
411 | msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r | |
136adffc | 412 | msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r |
a29c47e0 | 413 | return msaMap;\r |
414 | }\r | |
415 | catch (Exception ex){\r | |
416 | throw new BuildException(ex.getMessage());\r | |
417 | }\r | |
418 | }\r | |
419 | \r | |
420 | public static Map<String, XmlObject> getFpdBuildOptions() {\r | |
421 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r | |
422 | map.put("BuildOptions", fpdBuildOptions);\r | |
878ddf1f | 423 | return map;\r |
424 | }\r | |
425 | \r | |
a29c47e0 | 426 | public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r |
427 | GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r | |
428 | }\r | |
429 | \r | |
430 | public static XmlObject getFpdDynamicPcds() {\r | |
431 | return fpdDynamicPcds;\r | |
432 | }\r | |
433 | \r | |
434 | public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r | |
435 | GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r | |
436 | }\r | |
437 | \r | |
438 | //////////////////////////////////////////////\r | |
439 | //////////////////////////////////////////////\r | |
878ddf1f | 440 | \r |
a29c47e0 | 441 | public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r |
442 | Spd spd = spdTable.get(packageId);\r | |
443 | if (spd == null ) {\r | |
444 | Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r | |
445 | return dummy;\r | |
878ddf1f | 446 | }\r |
a29c47e0 | 447 | else {\r |
448 | return spd.getModules();\r | |
878ddf1f | 449 | }\r |
878ddf1f | 450 | }\r |
451 | \r | |
452 | /**\r | |
a29c47e0 | 453 | * The header file path is relative to workspace dir\r |
454 | */\r | |
455 | public static String[] getLibraryClassHeaderFiles(\r | |
456 | PackageIdentification[] packages, String name)\r | |
457 | throws BuildException {\r | |
458 | if (packages == null) {\r | |
459 | // throw Exception or not????\r | |
460 | return new String[0];\r | |
461 | }\r | |
462 | String[] result = null;\r | |
463 | for (int i = 0; i < packages.length; i++) {\r | |
464 | Spd spd = spdTable.get(packages[i]);\r | |
465 | //\r | |
466 | // If find one package defined the library class\r | |
467 | //\r | |
468 | if ((result = spd.getLibClassIncluder(name)) != null) {\r | |
469 | return result;\r | |
470 | }\r | |
471 | }\r | |
472 | //\r | |
473 | // If can't find library class declaration in every package\r | |
474 | //\r | |
475 | throw new BuildException("Can not find library class [" + name\r | |
476 | + "] declaration in every packages. ");\r | |
878ddf1f | 477 | }\r |
478 | \r | |
479 | /**\r | |
a29c47e0 | 480 | * The header file path is relative to workspace dir\r |
878ddf1f | 481 | */\r |
a29c47e0 | 482 | public static String getPackageHeaderFiles(PackageIdentification packages,\r |
483 | String moduleType) throws BuildException {\r | |
484 | if (packages == null) {\r | |
485 | return new String("");\r | |
486 | }\r | |
487 | Spd spd = spdTable.get(packages);\r | |
488 | //\r | |
489 | // If can't find package header file, skip it\r | |
490 | //\r | |
491 | String temp = null;\r | |
492 | if (spd != null) {\r | |
493 | if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r | |
494 | return temp;\r | |
495 | } else {\r | |
496 | temp = "";\r | |
497 | return temp;\r | |
878ddf1f | 498 | }\r |
a29c47e0 | 499 | } else {\r |
500 | return null;\r | |
878ddf1f | 501 | }\r |
878ddf1f | 502 | }\r |
503 | \r | |
a29c47e0 | 504 | /**\r |
505 | * return two values: {cName, GuidValue}\r | |
506 | */\r | |
136adffc | 507 | public static String[] getGuid(List<PackageIdentification> packages, String name)\r |
a29c47e0 | 508 | throws BuildException {\r |
509 | if (packages == null) {\r | |
510 | // throw Exception or not????\r | |
511 | return new String[0];\r | |
512 | }\r | |
513 | String[] result = null;\r | |
136adffc | 514 | Iterator item = packages.iterator();\r |
515 | while (item.hasNext()){\r | |
516 | Spd spd = spdTable.get(item.next());\r | |
a29c47e0 | 517 | //\r |
518 | // If find one package defined the GUID\r | |
519 | //\r | |
520 | if ((result = spd.getGuid(name)) != null) {\r | |
521 | return result;\r | |
878ddf1f | 522 | }\r |
523 | }\r | |
136adffc | 524 | \r |
a29c47e0 | 525 | return null;\r |
878ddf1f | 526 | }\r |
527 | \r | |
528 | /**\r | |
a29c47e0 | 529 | * return two values: {cName, GuidValue}\r |
878ddf1f | 530 | */\r |
136adffc | 531 | public static String[] getPpiGuid(List<PackageIdentification> packages,\r |
a29c47e0 | 532 | String name) throws BuildException {\r |
533 | if (packages == null) {\r | |
534 | return new String[0];\r | |
535 | }\r | |
536 | String[] result = null;\r | |
136adffc | 537 | Iterator item = packages.iterator();\r |
538 | while (item.hasNext()){\r | |
539 | Spd spd = spdTable.get(item.next());\r | |
a29c47e0 | 540 | //\r |
541 | // If find one package defined the Ppi GUID\r | |
542 | //\r | |
543 | if ((result = spd.getPpi(name)) != null) {\r | |
544 | return result;\r | |
878ddf1f | 545 | }\r |
546 | }\r | |
a29c47e0 | 547 | return null;\r |
548 | \r | |
878ddf1f | 549 | }\r |
550 | \r | |
a29c47e0 | 551 | /**\r |
552 | * return two values: {cName, GuidValue}\r | |
553 | */\r | |
136adffc | 554 | public static String[] getProtocolGuid(List<PackageIdentification> packages,\r |
a29c47e0 | 555 | String name) throws BuildException {\r |
556 | if (packages == null) {\r | |
557 | return new String[0];\r | |
558 | }\r | |
559 | String[] result = null;\r | |
136adffc | 560 | Iterator item = packages.iterator();\r |
561 | while (item.hasNext()){\r | |
562 | Spd spd = spdTable.get(item.next());\r | |
a29c47e0 | 563 | //\r |
564 | // If find one package defined the protocol GUID\r | |
565 | //\r | |
136adffc | 566 | if ((result = spd.getProtocol(name))!= null){\r |
a29c47e0 | 567 | return result;\r |
568 | }\r | |
569 | }\r | |
570 | return null;\r | |
878ddf1f | 571 | \r |
a29c47e0 | 572 | }\r |
573 | \r | |
de4bb9f6 | 574 | public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r |
a29c47e0 | 575 | Iterator iter = platformList.iterator();\r |
576 | while(iter.hasNext()){\r | |
577 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r | |
578 | if (platformId.getName().equalsIgnoreCase(name)) {\r | |
a29c47e0 | 579 | return platformId;\r |
878ddf1f | 580 | }\r |
a29c47e0 | 581 | }\r |
de4bb9f6 | 582 | throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");\r |
583 | }\r | |
584 | \r | |
585 | public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r | |
586 | File file = new File(workspaceDir + File.separatorChar + filename);\r | |
587 | Iterator iter = platformList.iterator();\r | |
588 | while(iter.hasNext()){\r | |
589 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r | |
590 | if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r | |
591 | return platformId;\r | |
592 | }\r | |
593 | }\r | |
594 | throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");\r | |
a29c47e0 | 595 | }\r |
596 | \r | |
597 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r | |
598 | Iterator iter = packageList.iterator();\r | |
599 | while(iter.hasNext()){\r | |
600 | PackageIdentification packageItem = (PackageIdentification)iter.next();\r | |
601 | if (packageItem.equals(packageId)) {\r | |
602 | packageId.setName(packageItem.getName());\r | |
603 | packageId.setSpdFile(packageItem.getSpdFile());\r | |
604 | return packageId;\r | |
878ddf1f | 605 | }\r |
606 | }\r | |
a29c47e0 | 607 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r |
608 | }\r | |
609 | \r | |
610 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r | |
611 | // System.out.println("1");\r | |
612 | // System.out.println("##" + moduleId.getGuid());\r | |
613 | PackageIdentification packageId = getPackageForModule(moduleId);\r | |
614 | // System.out.println("" + packageId.getGuid());\r | |
615 | moduleId.setPackage(packageId);\r | |
616 | Spd spd = spdTable.get(packageId);\r | |
617 | if (spd == null) {\r | |
618 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r | |
619 | }\r | |
620 | Set<ModuleIdentification> modules = spd.getModules();\r | |
621 | Iterator<ModuleIdentification> iter = modules.iterator();\r | |
622 | while (iter.hasNext()) {\r | |
623 | ModuleIdentification item = iter.next();\r | |
624 | if (item.equals(moduleId)) {\r | |
625 | moduleId.setName(item.getName());\r | |
626 | moduleId.setModuleType(item.getModuleType());\r | |
627 | moduleId.setMsaFile(item.getMsaFile());\r | |
628 | return moduleId;\r | |
629 | }\r | |
630 | }\r | |
631 | throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");\r | |
632 | }\r | |
633 | \r | |
634 | public synchronized static Set<PackageIdentification> getPackageList(){\r | |
635 | return packageList;\r | |
636 | }\r | |
637 | ///// remove!!\r | |
638 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r | |
639 | if ( object == null) {\r | |
640 | return null;\r | |
641 | }\r | |
642 | XmlObject result = null;\r | |
643 | try {\r | |
644 | result = XmlObject.Factory.parse(object.getDomNode()\r | |
645 | .cloneNode(deep));\r | |
646 | } catch (Exception ex) {\r | |
647 | throw new BuildException(ex.getMessage());\r | |
648 | }\r | |
649 | return result;\r | |
878ddf1f | 650 | }\r |
651 | \r | |
a29c47e0 | 652 | ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r |
878ddf1f | 653 | \r |
a29c47e0 | 654 | public static ToolChainInfo getToolChainInfo() {\r |
655 | // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r | |
656 | if (toolChainInfo == null) {\r | |
657 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r | |
658 | if (toolChainPlatformInfo != null) {\r | |
659 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r | |
878ddf1f | 660 | }\r |
a29c47e0 | 661 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r |
662 | toolChainInfo.normalize();\r | |
663 | GlobalData.log.info(toolChainInfo + "");\r | |
878ddf1f | 664 | }\r |
a29c47e0 | 665 | return toolChainInfo;\r |
666 | }\r | |
667 | \r | |
668 | \r | |
878ddf1f | 669 | \r |
a29c47e0 | 670 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r |
671 | platformToolChainFamilyOption = map;\r | |
878ddf1f | 672 | }\r |
673 | \r | |
a29c47e0 | 674 | public static void setPlatformToolChainOption(ToolChainMap map) {\r |
675 | platformToolChainOption = map;\r | |
676 | }\r | |
878ddf1f | 677 | \r |
a29c47e0 | 678 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r |
679 | ToolChainMap toolChainOption) {\r | |
680 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r | |
878ddf1f | 681 | }\r |
682 | \r | |
a29c47e0 | 683 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r |
684 | ToolChainMap toolChainOption) {\r | |
685 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r | |
878ddf1f | 686 | }\r |
687 | \r | |
c773bec0 | 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 | |
a10c0400 | 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 | |
c773bec0 | 694 | return true;\r |
695 | }\r | |
696 | }\r | |
697 | \r | |
698 | return false;\r | |
699 | }\r | |
700 | \r | |
a29c47e0 | 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 | |
878ddf1f | 712 | }\r |
878ddf1f | 713 | \r |
a29c47e0 | 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 | |
878ddf1f | 735 | }\r |
878ddf1f | 736 | \r |
a29c47e0 | 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 | |
878ddf1f | 768 | }\r |
a29c47e0 | 769 | \r |
770 | //\r | |
771 | // for PCD\r | |
772 | //\r | |
136adffc | 773 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
774 | return pcdDbManager;\r | |
775 | }\r | |
a29c47e0 | 776 | \r |
777 | //\r | |
136adffc | 778 | // For PCD get tokenSpaceGUid\r |
a29c47e0 | 779 | //\r |
136adffc | 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 | |
548ce97a | 785 | \r |
786 | if (iter == null) {\r | |
787 | return null;\r | |
788 | }\r | |
789 | \r | |
136adffc | 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 | |
548ce97a | 794 | cNameGuid = new String[2];\r |
795 | cNameGuid[0] = cName;\r | |
796 | cNameGuid[1] = guid;\r | |
136adffc | 797 | break;\r |
798 | }\r | |
799 | }\r | |
800 | return cNameGuid;\r | |
801 | }\r | |
a29c47e0 | 802 | \r |
803 | //\r | |
804 | // For PCD\r | |
805 | //\r | |
136adffc | 806 | public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r |
807 | String xmlObjectName) {\r | |
808 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r | |
809 | Iterator item = fpdModuleSASet.iterator();\r | |
810 | \r | |
811 | \r | |
812 | Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r | |
813 | Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r | |
814 | FpdModuleIdentification moduleId;\r | |
815 | while (item.hasNext()) {\r | |
816 | \r | |
817 | moduleId = (FpdModuleIdentification) item.next();\r | |
818 | SANode = fpdModuleSA.get(moduleId);\r | |
819 | try{\r | |
820 | if (SANode.get(xmlObjectName)!= null){\r | |
821 | SAPcdBuildDef.put(moduleId,\r | |
822 | (XmlObject) SANode\r | |
823 | .get(xmlObjectName));\r | |
824 | \r | |
825 | }\r | |
826 | \r | |
827 | \r | |
828 | } catch (Exception e){\r | |
829 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r | |
830 | }\r | |
831 | }\r | |
832 | return SAPcdBuildDef;\r | |
833 | }\r | |
878ddf1f | 834 | }\r |
a29c47e0 | 835 | \r |