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