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