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