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