]>
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 |
a29c47e0 | 90 | private static XmlObject fpdBuildOptions;\r |
878ddf1f | 91 | \r |
a29c47e0 | 92 | private static XmlObject fpdDynamicPcds;\r |
ff225cbb | 93 | \r |
878ddf1f | 94 | ///\r |
a29c47e0 | 95 | /// Parsed modules list\r |
878ddf1f | 96 | ///\r |
a29c47e0 | 97 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r |
ff225cbb | 98 | \r |
878ddf1f | 99 | ///\r |
a29c47e0 | 100 | /// built modules list with ARCH, TARGET, TOOLCHAIN\r |
878ddf1f | 101 | ///\r |
a29c47e0 | 102 | private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r |
ff225cbb | 103 | \r |
878ddf1f | 104 | ///\r |
a29c47e0 | 105 | /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r |
878ddf1f | 106 | ///\r |
8b7bd455 | 107 | private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r |
878ddf1f | 108 | \r |
109 | ///\r | |
a29c47e0 | 110 | /// build target + tool chain family/tag name + arch + command types + command options\r |
878ddf1f | 111 | ///\r |
a29c47e0 | 112 | ///\r |
113 | /// Tool Chain Data\r | |
114 | /// toolsDef - build tool program information\r | |
115 | /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r | |
116 | /// moduleSaBuildOption - build options for a specific module\r | |
ff225cbb | 117 | ///\r |
a29c47e0 | 118 | private static ToolChainConfig toolsDef;\r |
878ddf1f | 119 | \r |
a29c47e0 | 120 | private static ToolChainInfo toolChainInfo;\r |
121 | private static ToolChainInfo toolChainEnvInfo;\r | |
122 | private static ToolChainInfo toolChainPlatformInfo;\r | |
878ddf1f | 123 | \r |
a29c47e0 | 124 | private static ToolChainMap platformToolChainOption;\r |
125 | private static ToolChainMap platformToolChainFamilyOption;\r | |
878ddf1f | 126 | \r |
a29c47e0 | 127 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r |
128 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r | |
878ddf1f | 129 | \r |
878ddf1f | 130 | /**\r |
131 | Parse framework database (DB) and all SPD files listed in DB to initialize\r | |
132 | the environment for next build. This method will only be executed only once\r | |
ff225cbb | 133 | in the whole build process.\r |
134 | \r | |
878ddf1f | 135 | @param workspaceDatabaseFile the file name of framework database\r |
136 | @param workspaceDir current workspace directory path\r | |
137 | @throws BuildException\r | |
a29c47e0 | 138 | Framework Dababase or SPD or MSA file is not valid\r |
878ddf1f | 139 | **/\r |
73b4e31a | 140 | public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException {\r |
a29c47e0 | 141 | //\r |
142 | // ensure this method will be revoked only once\r | |
143 | //\r | |
878ddf1f | 144 | if (globalFlag) {\r |
145 | return;\r | |
146 | }\r | |
147 | globalFlag = true;\r | |
73b4e31a | 148 | \r |
ff225cbb | 149 | //\r |
a29c47e0 | 150 | // Backup workspace directory. It will be used by other method\r |
151 | //\r | |
152 | GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r | |
ff225cbb | 153 | \r |
a29c47e0 | 154 | //\r |
155 | // Parse tools definition file\r | |
156 | //\r | |
157 | //\r | |
158 | // If ToolChain has been set up before, do nothing.\r | |
159 | // CONF dir + tools definition file name\r | |
160 | //\r | |
de4bb9f6 | 161 | File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r |
391dbbb1 | 162 | System.out.println("Using tool definiton file [" + toolsDefFile.getPath() + "].");\r |
d2059d05 | 163 | try {\r |
164 | toolsDef = new ToolChainConfig(toolsDefFile);\r | |
165 | } catch (Exception e) {\r | |
166 | throw new BuildException(e.getMessage());\r | |
167 | }\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 | |
83fba802 | 188 | String fileName = iter.next().getStringValue().trim();\r |
a29c47e0 | 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 | |
83fba802 | 202 | String fileName = iter.next().getStringValue().trim();\r |
a29c47e0 | 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 | |
83fba802 | 222 | SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r |
223 | PlatformIdentification platformId = saq.getFpdHeader();\r | |
a29c47e0 | 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 | |
e485bb4b | 415 | throw new BuildException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage() );\r |
a29c47e0 | 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 |
878ddf1f | 543 | }\r |
544 | \r | |
a29c47e0 | 545 | /**\r |
546 | * return two values: {cName, GuidValue}\r | |
547 | */\r | |
136adffc | 548 | public static String[] getProtocolGuid(List<PackageIdentification> packages,\r |
a29c47e0 | 549 | String name) throws BuildException {\r |
550 | if (packages == null) {\r | |
551 | return new String[0];\r | |
552 | }\r | |
553 | String[] result = null;\r | |
136adffc | 554 | Iterator item = packages.iterator();\r |
555 | while (item.hasNext()){\r | |
556 | Spd spd = spdTable.get(item.next());\r | |
a29c47e0 | 557 | //\r |
558 | // If find one package defined the protocol GUID\r | |
559 | //\r | |
136adffc | 560 | if ((result = spd.getProtocol(name))!= null){\r |
a29c47e0 | 561 | return result;\r |
562 | }\r | |
563 | }\r | |
564 | return null;\r | |
878ddf1f | 565 | \r |
a29c47e0 | 566 | }\r |
ff225cbb | 567 | \r |
de4bb9f6 | 568 | public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r |
a29c47e0 | 569 | Iterator iter = platformList.iterator();\r |
570 | while(iter.hasNext()){\r | |
571 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r | |
572 | if (platformId.getName().equalsIgnoreCase(name)) {\r | |
a29c47e0 | 573 | return platformId;\r |
878ddf1f | 574 | }\r |
a29c47e0 | 575 | }\r |
391dbbb1 | 576 | throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r |
de4bb9f6 | 577 | }\r |
ff225cbb | 578 | \r |
de4bb9f6 | 579 | public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r |
580 | File file = new File(workspaceDir + File.separatorChar + filename);\r | |
581 | Iterator iter = platformList.iterator();\r | |
582 | while(iter.hasNext()){\r | |
583 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r | |
584 | if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r | |
585 | return platformId;\r | |
586 | }\r | |
587 | }\r | |
391dbbb1 | 588 | throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r |
a29c47e0 | 589 | }\r |
ff225cbb | 590 | \r |
a29c47e0 | 591 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r |
592 | Iterator iter = packageList.iterator();\r | |
593 | while(iter.hasNext()){\r | |
594 | PackageIdentification packageItem = (PackageIdentification)iter.next();\r | |
595 | if (packageItem.equals(packageId)) {\r | |
596 | packageId.setName(packageItem.getName());\r | |
597 | packageId.setSpdFile(packageItem.getSpdFile());\r | |
598 | return packageId;\r | |
878ddf1f | 599 | }\r |
600 | }\r | |
e485bb4b | 601 | throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r |
a29c47e0 | 602 | }\r |
ff225cbb | 603 | \r |
a29c47e0 | 604 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r |
a29c47e0 | 605 | PackageIdentification packageId = getPackageForModule(moduleId);\r |
a29c47e0 | 606 | moduleId.setPackage(packageId);\r |
607 | Spd spd = spdTable.get(packageId);\r | |
608 | if (spd == null) {\r | |
e485bb4b | 609 | throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r |
a29c47e0 | 610 | }\r |
611 | Set<ModuleIdentification> modules = spd.getModules();\r | |
612 | Iterator<ModuleIdentification> iter = modules.iterator();\r | |
613 | while (iter.hasNext()) {\r | |
614 | ModuleIdentification item = iter.next();\r | |
615 | if (item.equals(moduleId)) {\r | |
616 | moduleId.setName(item.getName());\r | |
617 | moduleId.setModuleType(item.getModuleType());\r | |
618 | moduleId.setMsaFile(item.getMsaFile());\r | |
619 | return moduleId;\r | |
620 | }\r | |
621 | }\r | |
e485bb4b | 622 | throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r |
a29c47e0 | 623 | }\r |
ff225cbb | 624 | \r |
a29c47e0 | 625 | public synchronized static Set<PackageIdentification> getPackageList(){\r |
626 | return packageList;\r | |
627 | }\r | |
82516887 | 628 | \r |
629 | /**\r | |
630 | BUGBUG: It is a walk around method. If do not clone, can't query info with\r | |
631 | XPath correctly. \r | |
632 | \r | |
633 | @param object XmlObject\r | |
634 | @param deep flag for deep clone\r | |
635 | @return XmlObject after clone\r | |
636 | @throws BuildException parse original XmlObject error. \r | |
637 | **/\r | |
a29c47e0 | 638 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r |
639 | if ( object == null) {\r | |
640 | return null;\r | |
641 | }\r | |
642 | XmlObject result = null;\r | |
643 | try {\r | |
644 | result = XmlObject.Factory.parse(object.getDomNode()\r | |
645 | .cloneNode(deep));\r | |
646 | } catch (Exception ex) {\r | |
647 | throw new BuildException(ex.getMessage());\r | |
648 | }\r | |
649 | return result;\r | |
878ddf1f | 650 | }\r |
651 | \r | |
4b5f5549 | 652 | ///\r |
653 | /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r | |
654 | ///\r | |
a29c47e0 | 655 | public static ToolChainInfo getToolChainInfo() {\r |
a29c47e0 | 656 | if (toolChainInfo == null) {\r |
657 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r | |
658 | if (toolChainPlatformInfo != null) {\r | |
659 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r | |
878ddf1f | 660 | }\r |
a29c47e0 | 661 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r |
662 | toolChainInfo.normalize();\r | |
4b5f5549 | 663 | System.out.println("Current build tool chain information summary: ");\r |
664 | System.out.println(toolChainInfo + "");\r | |
878ddf1f | 665 | }\r |
a29c47e0 | 666 | return toolChainInfo;\r |
667 | }\r | |
668 | \r | |
a29c47e0 | 669 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r |
670 | platformToolChainFamilyOption = map;\r | |
878ddf1f | 671 | }\r |
672 | \r | |
a29c47e0 | 673 | public static void setPlatformToolChainOption(ToolChainMap map) {\r |
674 | platformToolChainOption = map;\r | |
675 | }\r | |
878ddf1f | 676 | \r |
a29c47e0 | 677 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r |
678 | ToolChainMap toolChainOption) {\r | |
679 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r | |
878ddf1f | 680 | }\r |
681 | \r | |
a29c47e0 | 682 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r |
683 | ToolChainMap toolChainOption) {\r | |
684 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r | |
878ddf1f | 685 | }\r |
686 | \r | |
c773bec0 | 687 | public static boolean isCommandSet(String target, String toolchain, String arch) {\r |
688 | String[] commands = getToolChainInfo().getCommands();\r | |
689 | \r | |
690 | for (int i = 0; i < commands.length; ++i) {\r | |
a10c0400 | 691 | String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});\r |
692 | if (cmdName != null && cmdName.length() != 0) {\r | |
c773bec0 | 693 | return true;\r |
694 | }\r | |
695 | }\r | |
696 | \r | |
697 | return false;\r | |
698 | }\r | |
699 | \r | |
a29c47e0 | 700 | public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
701 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r | |
ff225cbb | 702 | ToolChainMap toolChainConfig = toolsDef.getConfig();\r |
a29c47e0 | 703 | String setting = null;\r |
704 | \r | |
705 | if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r | |
706 | setting = toolChainConfig.get(toolChainKey);\r | |
707 | if (setting == null) {\r | |
708 | setting = "";\r | |
709 | }\r | |
710 | return setting;\r | |
878ddf1f | 711 | }\r |
878ddf1f | 712 | \r |
a29c47e0 | 713 | //\r |
714 | // get module specific options, if any\r | |
715 | //\r | |
716 | // tool tag first\r | |
717 | ToolChainMap option = moduleToolChainOption.get(fpdModuleId);\r | |
718 | ToolChainKey toolChainFamilyKey = null;\r | |
719 | \r | |
720 | if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {\r | |
721 | //\r | |
722 | // then tool chain family\r | |
723 | //\r | |
724 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r | |
725 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
726 | String family = toolChainConfig.get(toolChainFamilyKey);\r | |
727 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r | |
728 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
729 | \r | |
730 | option = moduleToolChainFamilyOption.get(fpdModuleId);\r | |
ff225cbb | 731 | if (option != null) {\r |
a29c47e0 | 732 | setting = option.get(toolChainFamilyKey);\r |
733 | }\r | |
878ddf1f | 734 | }\r |
878ddf1f | 735 | \r |
a29c47e0 | 736 | //\r |
737 | // get platform options, if any\r | |
738 | //\r | |
739 | if (setting == null) {\r | |
740 | // tool tag first\r | |
741 | if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {\r | |
742 | // then tool chain family\r | |
743 | if (toolChainFamilyKey == null) {\r | |
744 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r | |
745 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
746 | String family = toolChainConfig.get(toolChainFamilyKey);\r | |
747 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r | |
748 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r | |
749 | }\r | |
750 | \r | |
751 | setting = platformToolChainFamilyOption.get(toolChainFamilyKey);\r | |
752 | }\r | |
753 | }\r | |
754 | \r | |
755 | if (setting == null) {\r | |
756 | setting = "";\r | |
757 | }\r | |
758 | \r | |
759 | return setting;\r | |
760 | }\r | |
ff225cbb | 761 | \r |
a29c47e0 | 762 | public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r |
763 | toolChainEnvInfo = envInfo;\r | |
764 | }\r | |
765 | public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r | |
766 | toolChainPlatformInfo = platformInfo;\r | |
878ddf1f | 767 | }\r |
a29c47e0 | 768 | \r |
769 | //\r | |
770 | // for PCD\r | |
771 | //\r | |
136adffc | 772 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
773 | return pcdDbManager;\r | |
774 | }\r | |
a29c47e0 | 775 | \r |
776 | //\r | |
136adffc | 777 | // For PCD get tokenSpaceGUid\r |
a29c47e0 | 778 | //\r |
20c5c53f | 779 | public synchronized static String getGuidInfoFromCname(String cName){\r |
780 | String cNameGuid = null;\r | |
136adffc | 781 | String guid = null;\r |
782 | Set set = spdTable.keySet();\r | |
783 | Iterator iter = set.iterator();\r | |
548ce97a | 784 | \r |
785 | if (iter == null) {\r | |
786 | return null;\r | |
787 | }\r | |
788 | \r | |
136adffc | 789 | while (iter.hasNext()){\r |
790 | Spd spd = (Spd) spdTable.get(iter.next());\r | |
791 | guid = spd.getGuidFromCname(cName);\r | |
792 | if (guid != null){\r | |
20c5c53f | 793 | cNameGuid = guid;\r |
136adffc | 794 | break;\r |
795 | }\r | |
796 | }\r | |
797 | return cNameGuid;\r | |
798 | }\r | |
a29c47e0 | 799 | \r |
800 | //\r | |
801 | // For PCD\r | |
802 | //\r | |
ff225cbb | 803 | public synchronized static Map<FpdModuleIdentification, XmlObject>\r |
eece174a | 804 | getFpdModuleSaXmlObject(String xmlObjectName) {\r |
136adffc | 805 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r |
806 | Iterator item = fpdModuleSASet.iterator();\r | |
ff225cbb | 807 | \r |
136adffc | 808 | \r |
809 | Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r | |
810 | Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r | |
811 | FpdModuleIdentification moduleId;\r | |
812 | while (item.hasNext()) {\r | |
ff225cbb | 813 | \r |
136adffc | 814 | moduleId = (FpdModuleIdentification) item.next();\r |
815 | SANode = fpdModuleSA.get(moduleId);\r | |
816 | try{\r | |
817 | if (SANode.get(xmlObjectName)!= null){\r | |
818 | SAPcdBuildDef.put(moduleId,\r | |
eece174a | 819 | (XmlObject) SANode.get(xmlObjectName));\r |
136adffc | 820 | \r |
821 | }\r | |
136adffc | 822 | } catch (Exception e){\r |
823 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r | |
824 | }\r | |
eece174a | 825 | }\r |
136adffc | 826 | return SAPcdBuildDef;\r |
827 | }\r | |
eece174a | 828 | \r |
829 | public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {\r | |
830 | Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");\r | |
831 | \r | |
832 | return pcdBuildDef;\r | |
833 | }\r | |
878ddf1f | 834 | }\r |
a29c47e0 | 835 | \r |