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