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