878ddf1f |
1 | /** @file\r |
2 | GlobalData class. \r |
3 | \r |
4 | GlobalData provide initializing, instoring, querying and update global data.\r |
5 | It is a bridge to intercommunicate between multiple component, such as AutoGen,\r |
6 | PCD and so on. \r |
7 | \r |
8 | Copyright (c) 2006, Intel Corporation\r |
9 | All rights reserved. This program and the accompanying materials\r |
10 | are licensed and made available under the terms and conditions of the BSD License\r |
11 | which accompanies this distribution. The full text of the license may be found at\r |
12 | http://opensource.org/licenses/bsd-license.php\r |
13 | \r |
14 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
15 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
16 | **/\r |
17 | package org.tianocore.build.global;\r |
18 | \r |
a29c47e0 |
19 | import org.apache.tools.ant.BuildException;\r |
20 | import org.apache.xmlbeans.XmlObject;\r |
21 | import org.tianocore.DbPathAndFilename;\r |
22 | import org.tianocore.FrameworkDatabaseDocument;\r |
23 | import org.tianocore.ModuleSurfaceAreaDocument;\r |
24 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
25 | import org.tianocore.build.exception.EdkException;\r |
26 | import org.tianocore.build.id.FpdModuleIdentification;\r |
27 | import org.tianocore.build.id.ModuleIdentification;\r |
28 | import org.tianocore.build.id.PackageIdentification;\r |
29 | import org.tianocore.build.id.PlatformIdentification;\r |
30 | import org.tianocore.build.toolchain.ToolChainAttribute;\r |
31 | import org.tianocore.build.toolchain.ToolChainConfig;\r |
32 | import org.tianocore.build.toolchain.ToolChainElement;\r |
33 | import org.tianocore.build.toolchain.ToolChainInfo;\r |
34 | import org.tianocore.build.toolchain.ToolChainKey;\r |
35 | import org.tianocore.build.toolchain.ToolChainMap;\r |
36 | //import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r |
37 | //import org.tianocore.logger.EdkLog;\r |
38 | \r |
878ddf1f |
39 | import java.io.File;\r |
40 | import java.util.HashMap;\r |
41 | import java.util.HashSet;\r |
42 | import java.util.Iterator;\r |
43 | import java.util.List;\r |
44 | import java.util.Map;\r |
45 | import java.util.Set;\r |
a29c47e0 |
46 | import java.util.logging.Logger;\r |
878ddf1f |
47 | \r |
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 |
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 |
878ddf1f |
55 | \r |
56 | @since GenBuild 1.0\r |
57 | **/\r |
58 | public class GlobalData {\r |
59 | \r |
a29c47e0 |
60 | public static Logger log = Logger.getAnonymousLogger();\r |
61 | \r |
878ddf1f |
62 | ///\r |
63 | /// Record current WORKSPACE Directory\r |
64 | ///\r |
65 | private static String workspaceDir = "";\r |
a29c47e0 |
66 | \r |
878ddf1f |
67 | ///\r |
a29c47e0 |
68 | /// Be used to ensure Global data will be initialized only once.\r |
878ddf1f |
69 | ///\r |
a29c47e0 |
70 | private static boolean globalFlag = false;\r |
71 | \r |
878ddf1f |
72 | ///\r |
a29c47e0 |
73 | /// Framework Database information: package list and platform list\r |
878ddf1f |
74 | ///\r |
a29c47e0 |
75 | private static Set<PackageIdentification> packageList = new HashSet<PackageIdentification>(); \r |
878ddf1f |
76 | \r |
a29c47e0 |
77 | private static Set<PlatformIdentification> platformList = new HashSet<PlatformIdentification>();\r |
878ddf1f |
78 | \r |
79 | ///\r |
a29c47e0 |
80 | /// Every detail SPD informations: Module list, Library class definition,\r |
81 | /// Package header file, GUID/PPI/Protocol definitions\r |
878ddf1f |
82 | ///\r |
a29c47e0 |
83 | private static final Map<PackageIdentification, Spd> spdTable = new HashMap<PackageIdentification, Spd>();\r |
878ddf1f |
84 | \r |
85 | ///\r |
a29c47e0 |
86 | /// Build informations are divided into three parts:\r |
87 | /// 1. From MSA 2. From FPD 3. From FPD' ModuleSA\r |
878ddf1f |
88 | ///\r |
a29c47e0 |
89 | private static Map<ModuleIdentification, Map<String, XmlObject>> nativeMsa = new HashMap<ModuleIdentification, Map<String, XmlObject>>();\r |
878ddf1f |
90 | \r |
a29c47e0 |
91 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleSA= new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r |
878ddf1f |
92 | \r |
a29c47e0 |
93 | private static XmlObject fpdBuildOptions;\r |
878ddf1f |
94 | \r |
a29c47e0 |
95 | private static XmlObject fpdDynamicPcds;\r |
96 | \r |
878ddf1f |
97 | ///\r |
a29c47e0 |
98 | /// Parsed modules list\r |
878ddf1f |
99 | ///\r |
a29c47e0 |
100 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r |
101 | \r |
878ddf1f |
102 | ///\r |
a29c47e0 |
103 | /// built modules list with ARCH, TARGET, TOOLCHAIN\r |
878ddf1f |
104 | ///\r |
a29c47e0 |
105 | private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r |
106 | \r |
878ddf1f |
107 | ///\r |
a29c47e0 |
108 | /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r |
878ddf1f |
109 | ///\r |
a29c47e0 |
110 | // private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r |
878ddf1f |
111 | \r |
112 | ///\r |
a29c47e0 |
113 | /// build target + tool chain family/tag name + arch + command types + command options\r |
878ddf1f |
114 | ///\r |
a29c47e0 |
115 | ///\r |
116 | /// Tool Chain Data\r |
117 | /// toolsDef - build tool program information\r |
118 | /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r |
119 | /// moduleSaBuildOption - build options for a specific module\r |
120 | /// \r |
121 | private static ToolChainConfig toolsDef;\r |
878ddf1f |
122 | \r |
a29c47e0 |
123 | private static ToolChainInfo toolChainInfo;\r |
124 | private static ToolChainInfo toolChainEnvInfo;\r |
125 | private static ToolChainInfo toolChainPlatformInfo;\r |
878ddf1f |
126 | \r |
a29c47e0 |
127 | private static ToolChainMap platformToolChainOption;\r |
128 | private static ToolChainMap platformToolChainFamilyOption;\r |
878ddf1f |
129 | \r |
a29c47e0 |
130 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r |
131 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r |
878ddf1f |
132 | \r |
a29c47e0 |
133 | // private static final MemoryDatabasseManager pcdDbManager = new MemoryDatabaseManager();\r |
878ddf1f |
134 | \r |
878ddf1f |
135 | \r |
878ddf1f |
136 | \r |
137 | /**\r |
138 | Parse framework database (DB) and all SPD files listed in DB to initialize\r |
139 | the environment for next build. This method will only be executed only once\r |
140 | in the whole build process. \r |
a29c47e0 |
141 | \r |
878ddf1f |
142 | @param workspaceDatabaseFile the file name of framework database\r |
143 | @param workspaceDir current workspace directory path\r |
144 | @throws BuildException\r |
a29c47e0 |
145 | Framework Dababase or SPD or MSA file is not valid\r |
878ddf1f |
146 | **/\r |
a29c47e0 |
147 | public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException {\r |
148 | //\r |
149 | // ensure this method will be revoked only once\r |
150 | //\r |
878ddf1f |
151 | if (globalFlag) {\r |
152 | return;\r |
153 | }\r |
154 | globalFlag = true;\r |
a29c47e0 |
155 | \r |
156 | //\r |
157 | // Backup workspace directory. It will be used by other method\r |
158 | //\r |
159 | GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r |
160 | \r |
161 | //\r |
162 | // Parse tools definition file\r |
163 | //\r |
164 | //\r |
165 | // If ToolChain has been set up before, do nothing.\r |
166 | // CONF dir + tools definition file name\r |
167 | //\r |
168 | String confDir = GlobalData.workspaceDir + File.separatorChar + "Tools" + File.separatorChar + "Conf";\r |
169 | File toolsDefFile = new File(confDir + File.separatorChar + toolsDefFilename);\r |
170 | System.out.println("Using file [" + toolsDefFile.getPath() + "] as tools definition file. ");\r |
171 | toolsDef = new ToolChainConfig(toolsDefFile);\r |
172 | \r |
173 | //\r |
174 | // Parse Framework Database\r |
175 | //\r |
878ddf1f |
176 | File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r |
177 | try {\r |
178 | FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r |
a29c47e0 |
179 | //\r |
180 | // validate FrameworkDatabaseFile\r |
181 | //\r |
182 | if (! db.validate()) {\r |
183 | throw new BuildException("Framework Database file [" + dbFile.getPath() + "] is invalid.");\r |
878ddf1f |
184 | }\r |
a29c47e0 |
185 | //\r |
186 | // Get package list\r |
187 | //\r |
188 | if (db.getFrameworkDatabase().getPackageList() != null ) {\r |
189 | List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r |
190 | Iterator<DbPathAndFilename> iter = packages.iterator();\r |
191 | while (iter.hasNext()) {\r |
192 | String fileName = iter.next().getStringValue();\r |
193 | Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r |
194 | packageList.add(spd.getPackageId());\r |
195 | spdTable.put(spd.getPackageId(), spd);\r |
250258de |
196 | }\r |
197 | }\r |
198 | \r |
a29c47e0 |
199 | //\r |
200 | // Get platform list\r |
201 | //\r |
202 | if (db.getFrameworkDatabase().getPlatformList() != null) {\r |
203 | List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r |
204 | Iterator<DbPathAndFilename> iter = platforms.iterator();\r |
205 | while (iter.hasNext()) {\r |
206 | String fileName = iter.next().getStringValue();\r |
207 | File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r |
208 | if ( ! fpdFile.exists() ) {\r |
209 | throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r |
250258de |
210 | }\r |
a29c47e0 |
211 | XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r |
212 | //\r |
213 | // Verify FPD file, if is invalid, throw Exception\r |
214 | //\r |
215 | if (! fpdDoc.validate()) {\r |
216 | throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] is invalid. ");\r |
217 | }\r |
218 | //\r |
219 | // We can change Map to XmlObject\r |
220 | //\r |
221 | //\r |
222 | // TBD check SPD or FPD is existed in FS\r |
223 | //\r |
224 | Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r |
225 | fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r |
226 | SurfaceAreaQuery.setDoc(fpdDocMap);\r |
227 | PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader();\r |
228 | platformId.setFpdFile(fpdFile);\r |
229 | platformList.add(platformId);\r |
878ddf1f |
230 | }\r |
878ddf1f |
231 | }\r |
232 | } catch (Exception e) {\r |
a29c47e0 |
233 | e.printStackTrace();\r |
234 | throw new BuildException("Parse workspace Database [" + dbFile.getPath() + "] Error.\n" + e.getMessage());\r |
878ddf1f |
235 | }\r |
236 | }\r |
878ddf1f |
237 | \r |
878ddf1f |
238 | /**\r |
a29c47e0 |
239 | Get the current WORKSPACE Directory. \r |
878ddf1f |
240 | \r |
a29c47e0 |
241 | @return current workspace directory\r |
878ddf1f |
242 | **/\r |
a29c47e0 |
243 | public synchronized static String getWorkspacePath() {\r |
244 | return workspaceDir;\r |
878ddf1f |
245 | }\r |
246 | \r |
878ddf1f |
247 | \r |
248 | /**\r |
a29c47e0 |
249 | Get the MSA file name with absolute path\r |
250 | */\r |
251 | public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException {\r |
252 | File msaFile = null;\r |
253 | //\r |
254 | // TBD. Do only when package is null. \r |
255 | //\r |
256 | Iterator iter = packageList.iterator();\r |
257 | while (iter.hasNext()) {\r |
258 | PackageIdentification packageId = (PackageIdentification)iter.next();\r |
259 | Spd spd = spdTable.get(packageId);\r |
260 | msaFile = spd.getModuleFile(moduleId);\r |
261 | if (msaFile != null ) {\r |
262 | break ;\r |
263 | }\r |
264 | }\r |
265 | if (msaFile == null){\r |
266 | throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r |
267 | }\r |
268 | else {\r |
269 | return msaFile;\r |
270 | }\r |
878ddf1f |
271 | }\r |
272 | \r |
a29c47e0 |
273 | public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) {\r |
274 | //\r |
275 | // If package already defined in module\r |
276 | //\r |
277 | if (moduleId.getPackage() != null) {\r |
278 | return moduleId.getPackage();\r |
279 | }\r |
280 | \r |
281 | PackageIdentification packageId = null;\r |
282 | Iterator iter = packageList.iterator();\r |
283 | while (iter.hasNext()) {\r |
284 | packageId = (PackageIdentification)iter.next();\r |
285 | moduleId.setPackage(packageId);\r |
286 | Spd spd = spdTable.get(packageId);\r |
287 | if (spd.getModuleFile(moduleId) != null ) {\r |
288 | break ;\r |
289 | }\r |
290 | }\r |
291 | if (packageId == null){\r |
292 | throw new BuildException("Can't find Module [" + moduleId.getName() + "] in all packages. ");\r |
293 | }\r |
294 | else {\r |
295 | return packageId;\r |
296 | }\r |
297 | }\r |
298 | \r |
878ddf1f |
299 | /**\r |
a29c47e0 |
300 | Difference between build and parse: ToolChain and Target\r |
878ddf1f |
301 | **/\r |
a29c47e0 |
302 | public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r |
303 | return builtModules.contains(moduleId);\r |
878ddf1f |
304 | }\r |
878ddf1f |
305 | \r |
a29c47e0 |
306 | public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r |
307 | builtModules.add(fpdModuleId);\r |
878ddf1f |
308 | }\r |
309 | \r |
a29c47e0 |
310 | \r |
311 | public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) {\r |
312 | Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r |
313 | Set keySet = doc.keySet();\r |
314 | Iterator iter = keySet.iterator();\r |
315 | while (iter.hasNext()){\r |
316 | String key = (String)iter.next();\r |
317 | XmlObject item = cloneXmlObject(doc.get(key), true);\r |
318 | result.put(key, item);\r |
319 | }\r |
320 | fpdModuleSA.put(fpdModuleId, result);\r |
878ddf1f |
321 | }\r |
a29c47e0 |
322 | \r |
878ddf1f |
323 | /**\r |
324 | Query overrided module surface area information. If current is Package\r |
325 | or Platform build, also include the information from FPD file. \r |
326 | \r |
327 | <p>Note that surface area parsing is incremental. That means the method will \r |
a29c47e0 |
328 | only parse the MSA and MBD files if necessary. </p>\r |
878ddf1f |
329 | \r |
330 | @param moduleName the base name of the module\r |
331 | @return the overrided module surface area information\r |
332 | @throws BuildException\r |
333 | MSA or MBD is not valid\r |
334 | **/\r |
a29c47e0 |
335 | public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException {\r |
336 | if (parsedModules.containsKey(fpdModuleId)) {\r |
337 | return parsedModules.get(fpdModuleId);\r |
338 | }\r |
339 | Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r |
340 | ModuleIdentification moduleId = fpdModuleId.getModule();\r |
878ddf1f |
341 | //\r |
a29c47e0 |
342 | // First part: get the MSA files info\r |
878ddf1f |
343 | //\r |
a29c47e0 |
344 | doc = getNativeMsa(moduleId);\r |
345 | \r |
346 | //\r |
347 | // Second part: put build options\r |
348 | //\r |
349 | doc.put("BuildOptions", fpdBuildOptions);\r |
350 | \r |
351 | //\r |
352 | // Third part: get Module info from FPD, such as Library instances, PCDs\r |
353 | //\r |
354 | if (fpdModuleSA.containsKey(fpdModuleId)){\r |
355 | //\r |
356 | // merge module info in FPD to final Doc\r |
357 | // For Library Module, do nothing here\r |
358 | //\r |
359 | doc.putAll(fpdModuleSA.get(fpdModuleId));\r |
878ddf1f |
360 | }\r |
a29c47e0 |
361 | parsedModules.put(fpdModuleId, doc);\r |
362 | return doc;\r |
878ddf1f |
363 | }\r |
364 | \r |
a29c47e0 |
365 | public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException {\r |
366 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r |
367 | return getDoc(fpdModuleId);\r |
368 | }\r |
878ddf1f |
369 | /**\r |
370 | Query the native MSA information with module base name. \r |
371 | \r |
372 | <p>Note that MSA parsing is incremental. That means the method will \r |
373 | only to parse the MSA files when never parsed before. </p>\r |
374 | \r |
375 | @param moduleName the base name of the module\r |
376 | @return the native MSA information\r |
377 | @throws BuildException\r |
378 | MSA file is not valid\r |
379 | **/\r |
a29c47e0 |
380 | public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException {\r |
381 | if (nativeMsa.containsKey(moduleId)) {\r |
382 | return nativeMsa.get(moduleId);\r |
383 | }\r |
384 | File msaFile = getMsaFile(moduleId);\r |
385 | Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r |
386 | nativeMsa.put(moduleId, msaMap);\r |
387 | return msaMap;\r |
388 | }\r |
389 | \r |
390 | public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException {\r |
391 | if (! msaFile.exists()) {\r |
392 | throw new BuildException("Surface Area file [" + msaFile.getPath() + "] can't found.");\r |
393 | }\r |
394 | try {\r |
395 | ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r |
396 | //\r |
397 | // Validate File if they accord with XML Schema\r |
398 | //\r |
399 | if ( ! doc.validate()){\r |
400 | throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] is invalid.");\r |
401 | }\r |
402 | //\r |
403 | // parse MSA file\r |
404 | //\r |
405 | ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r |
406 | Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r |
407 | msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r |
408 | msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r |
409 | msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r |
410 | msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r |
411 | msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r |
412 | msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r |
413 | msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r |
414 | msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r |
415 | msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r |
416 | return msaMap;\r |
417 | }\r |
418 | catch (Exception ex){\r |
419 | throw new BuildException(ex.getMessage());\r |
420 | }\r |
421 | }\r |
422 | \r |
423 | public static Map<String, XmlObject> getFpdBuildOptions() {\r |
424 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r |
425 | map.put("BuildOptions", fpdBuildOptions);\r |
878ddf1f |
426 | return map;\r |
427 | }\r |
428 | \r |
a29c47e0 |
429 | public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r |
430 | GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r |
431 | }\r |
432 | \r |
433 | public static XmlObject getFpdDynamicPcds() {\r |
434 | return fpdDynamicPcds;\r |
435 | }\r |
436 | \r |
437 | public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r |
438 | GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r |
439 | }\r |
440 | \r |
441 | //////////////////////////////////////////////\r |
442 | //////////////////////////////////////////////\r |
878ddf1f |
443 | \r |
a29c47e0 |
444 | public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r |
445 | Spd spd = spdTable.get(packageId);\r |
446 | if (spd == null ) {\r |
447 | Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r |
448 | return dummy;\r |
878ddf1f |
449 | }\r |
a29c47e0 |
450 | else {\r |
451 | return spd.getModules();\r |
878ddf1f |
452 | }\r |
878ddf1f |
453 | }\r |
454 | \r |
455 | /**\r |
a29c47e0 |
456 | * The header file path is relative to workspace dir\r |
457 | */\r |
458 | public static String[] getLibraryClassHeaderFiles(\r |
459 | PackageIdentification[] packages, String name)\r |
460 | throws BuildException {\r |
461 | if (packages == null) {\r |
462 | // throw Exception or not????\r |
463 | return new String[0];\r |
464 | }\r |
465 | String[] result = null;\r |
466 | for (int i = 0; i < packages.length; i++) {\r |
467 | Spd spd = spdTable.get(packages[i]);\r |
468 | //\r |
469 | // If find one package defined the library class\r |
470 | //\r |
471 | if ((result = spd.getLibClassIncluder(name)) != null) {\r |
472 | return result;\r |
473 | }\r |
474 | }\r |
475 | //\r |
476 | // If can't find library class declaration in every package\r |
477 | //\r |
478 | throw new BuildException("Can not find library class [" + name\r |
479 | + "] declaration in every packages. ");\r |
878ddf1f |
480 | }\r |
481 | \r |
482 | /**\r |
a29c47e0 |
483 | * The header file path is relative to workspace dir\r |
878ddf1f |
484 | */\r |
a29c47e0 |
485 | public static String getPackageHeaderFiles(PackageIdentification packages,\r |
486 | String moduleType) throws BuildException {\r |
487 | if (packages == null) {\r |
488 | return new String("");\r |
489 | }\r |
490 | Spd spd = spdTable.get(packages);\r |
491 | //\r |
492 | // If can't find package header file, skip it\r |
493 | //\r |
494 | String temp = null;\r |
495 | if (spd != null) {\r |
496 | if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r |
497 | return temp;\r |
498 | } else {\r |
499 | temp = "";\r |
500 | return temp;\r |
878ddf1f |
501 | }\r |
a29c47e0 |
502 | } else {\r |
503 | return null;\r |
878ddf1f |
504 | }\r |
878ddf1f |
505 | }\r |
506 | \r |
a29c47e0 |
507 | /**\r |
508 | * return two values: {cName, GuidValue}\r |
509 | */\r |
510 | public static String[] getGuid(PackageIdentification[] packages, String name)\r |
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 |
517 | for (int i = 0; i < packages.length; i++) {\r |
518 | Spd spd = spdTable.get(packages[i]);\r |
519 | //\r |
520 | // If find one package defined the GUID\r |
521 | //\r |
522 | if ((result = spd.getGuid(name)) != null) {\r |
523 | return result;\r |
878ddf1f |
524 | }\r |
525 | }\r |
a29c47e0 |
526 | return null;\r |
878ddf1f |
527 | }\r |
528 | \r |
529 | /**\r |
a29c47e0 |
530 | * return two values: {cName, GuidValue}\r |
878ddf1f |
531 | */\r |
a29c47e0 |
532 | public static String[] getPpiGuid(PackageIdentification[] packages,\r |
533 | String name) throws BuildException {\r |
534 | if (packages == null) {\r |
535 | return new String[0];\r |
536 | }\r |
537 | String[] result = null;\r |
538 | for (int i = 0; i < packages.length; i++) {\r |
539 | Spd spd = spdTable.get(packages[i]);\r |
540 | //\r |
541 | // If find one package defined the Ppi GUID\r |
542 | //\r |
543 | if ((result = spd.getPpi(name)) != null) {\r |
544 | return result;\r |
878ddf1f |
545 | }\r |
546 | }\r |
a29c47e0 |
547 | return null;\r |
548 | \r |
878ddf1f |
549 | }\r |
550 | \r |
a29c47e0 |
551 | /**\r |
552 | * return two values: {cName, GuidValue}\r |
553 | */\r |
554 | public static String[] getProtocolGuid(PackageIdentification[] packages,\r |
555 | String name) throws BuildException {\r |
556 | if (packages == null) {\r |
557 | return new String[0];\r |
558 | }\r |
559 | String[] result = null;\r |
560 | for (int i = 0; i < packages.length; i++) {\r |
561 | Spd spd = spdTable.get(packages[i]);\r |
562 | //\r |
563 | // If find one package defined the protocol GUID\r |
564 | //\r |
565 | if ((result = spd.getProtocol(name)) != null) {\r |
566 | return result;\r |
567 | }\r |
568 | }\r |
569 | return null;\r |
878ddf1f |
570 | \r |
a29c47e0 |
571 | }\r |
572 | \r |
573 | /////////////////////////// Update!! Update!! Update!!\r |
574 | // public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
575 | // return pcdDbManager;\r |
576 | // }\r |
577 | ///////////////////////////\r |
578 | public synchronized static PlatformIdentification getPlatform(String name) throws BuildException {\r |
579 | Iterator iter = platformList.iterator();\r |
580 | while(iter.hasNext()){\r |
581 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r |
582 | if (platformId.getName().equalsIgnoreCase(name)) {\r |
583 | // GlobalData.log.info("Platform: " + platformId + platformId.getFpdFile());\r |
584 | return platformId;\r |
878ddf1f |
585 | }\r |
a29c47e0 |
586 | }\r |
587 | throw new BuildException("Can't find platform [" + name + "] in current workspace. ");\r |
588 | }\r |
589 | \r |
590 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r |
591 | Iterator iter = packageList.iterator();\r |
592 | while(iter.hasNext()){\r |
593 | PackageIdentification packageItem = (PackageIdentification)iter.next();\r |
594 | if (packageItem.equals(packageId)) {\r |
595 | packageId.setName(packageItem.getName());\r |
596 | packageId.setSpdFile(packageItem.getSpdFile());\r |
597 | return packageId;\r |
878ddf1f |
598 | }\r |
599 | }\r |
a29c47e0 |
600 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r |
601 | }\r |
602 | \r |
603 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r |
604 | // System.out.println("1");\r |
605 | // System.out.println("##" + moduleId.getGuid());\r |
606 | PackageIdentification packageId = getPackageForModule(moduleId);\r |
607 | // System.out.println("" + packageId.getGuid());\r |
608 | moduleId.setPackage(packageId);\r |
609 | Spd spd = spdTable.get(packageId);\r |
610 | if (spd == null) {\r |
611 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r |
612 | }\r |
613 | Set<ModuleIdentification> modules = spd.getModules();\r |
614 | Iterator<ModuleIdentification> iter = modules.iterator();\r |
615 | while (iter.hasNext()) {\r |
616 | ModuleIdentification item = iter.next();\r |
617 | if (item.equals(moduleId)) {\r |
618 | moduleId.setName(item.getName());\r |
619 | moduleId.setModuleType(item.getModuleType());\r |
620 | moduleId.setMsaFile(item.getMsaFile());\r |
621 | return moduleId;\r |
622 | }\r |
623 | }\r |
624 | throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");\r |
625 | }\r |
626 | \r |
627 | public synchronized static Set<PackageIdentification> getPackageList(){\r |
628 | return packageList;\r |
629 | }\r |
630 | ///// remove!!\r |
631 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r |
632 | if ( object == null) {\r |
633 | return null;\r |
634 | }\r |
635 | XmlObject result = null;\r |
636 | try {\r |
637 | result = XmlObject.Factory.parse(object.getDomNode()\r |
638 | .cloneNode(deep));\r |
639 | } catch (Exception ex) {\r |
640 | throw new BuildException(ex.getMessage());\r |
641 | }\r |
642 | return result;\r |
878ddf1f |
643 | }\r |
644 | \r |
a29c47e0 |
645 | ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r |
878ddf1f |
646 | \r |
a29c47e0 |
647 | public static ToolChainInfo getToolChainInfo() {\r |
648 | // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r |
649 | if (toolChainInfo == null) {\r |
650 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r |
651 | if (toolChainPlatformInfo != null) {\r |
652 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r |
878ddf1f |
653 | }\r |
a29c47e0 |
654 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r |
655 | toolChainInfo.normalize();\r |
656 | GlobalData.log.info(toolChainInfo + "");\r |
878ddf1f |
657 | }\r |
a29c47e0 |
658 | return toolChainInfo;\r |
659 | }\r |
660 | \r |
661 | \r |
878ddf1f |
662 | \r |
a29c47e0 |
663 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r |
664 | platformToolChainFamilyOption = map;\r |
878ddf1f |
665 | }\r |
666 | \r |
a29c47e0 |
667 | public static void setPlatformToolChainOption(ToolChainMap map) {\r |
668 | platformToolChainOption = map;\r |
669 | }\r |
878ddf1f |
670 | \r |
a29c47e0 |
671 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r |
672 | ToolChainMap toolChainOption) {\r |
673 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
674 | }\r |
675 | \r |
a29c47e0 |
676 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r |
677 | ToolChainMap toolChainOption) {\r |
678 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
679 | }\r |
680 | \r |
a29c47e0 |
681 | public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
682 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r |
683 | ToolChainMap toolChainConfig = toolsDef.getConfig(); \r |
684 | String setting = null;\r |
685 | \r |
686 | if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r |
687 | setting = toolChainConfig.get(toolChainKey);\r |
688 | if (setting == null) {\r |
689 | setting = "";\r |
690 | }\r |
691 | return setting;\r |
878ddf1f |
692 | }\r |
878ddf1f |
693 | \r |
a29c47e0 |
694 | //\r |
695 | // get module specific options, if any\r |
696 | //\r |
697 | // tool tag first\r |
698 | ToolChainMap option = moduleToolChainOption.get(fpdModuleId);\r |
699 | ToolChainKey toolChainFamilyKey = null;\r |
700 | \r |
701 | if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {\r |
702 | //\r |
703 | // then tool chain family\r |
704 | //\r |
705 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r |
706 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r |
707 | String family = toolChainConfig.get(toolChainFamilyKey);\r |
708 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r |
709 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r |
710 | \r |
711 | option = moduleToolChainFamilyOption.get(fpdModuleId);\r |
712 | if (option != null) { \r |
713 | setting = option.get(toolChainFamilyKey);\r |
714 | }\r |
878ddf1f |
715 | }\r |
878ddf1f |
716 | \r |
a29c47e0 |
717 | //\r |
718 | // get platform options, if any\r |
719 | //\r |
720 | if (setting == null) {\r |
721 | // tool tag first\r |
722 | if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {\r |
723 | // then tool chain family\r |
724 | if (toolChainFamilyKey == null) {\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 | \r |
732 | setting = platformToolChainFamilyOption.get(toolChainFamilyKey);\r |
733 | }\r |
734 | }\r |
735 | \r |
736 | if (setting == null) {\r |
737 | setting = "";\r |
738 | }\r |
739 | \r |
740 | return setting;\r |
741 | }\r |
742 | \r |
743 | public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r |
744 | toolChainEnvInfo = envInfo;\r |
745 | }\r |
746 | public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r |
747 | toolChainPlatformInfo = platformInfo;\r |
878ddf1f |
748 | }\r |
a29c47e0 |
749 | \r |
750 | //\r |
751 | // for PCD\r |
752 | //\r |
753 | // public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
754 | // return pcdDbManager;\r |
755 | // }\r |
756 | \r |
757 | //\r |
758 | // For PCD\r |
759 | //\r |
760 | /**\r |
761 | * \r |
762 | * @param guidName\r |
763 | * @return\r |
764 | */\r |
765 | // public synchronized static String[] getGuidInfoGuid(String guidName) {\r |
766 | // String[] cNameGuid = null;\r |
767 | // Set set = spdTable.keySet();\r |
768 | // Iterator iter = set.iterator();\r |
769 | //\r |
770 | // while (iter.hasNext()) {\r |
771 | // Spd spd = (Spd) spdTable.get(iter.next());\r |
772 | // cNameGuid = spd.getGuidNameArray(guidName);\r |
773 | // if (cNameGuid != null) {\r |
774 | // break;\r |
775 | // }\r |
776 | // }\r |
777 | // return cNameGuid;\r |
778 | // }\r |
779 | \r |
780 | //\r |
781 | // For PCD\r |
782 | //\r |
783 | // public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r |
784 | // String xmlObjectName) {\r |
785 | // Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r |
786 | // Iterator item = fpdModuleSASet.iterator();\r |
787 | //\r |
788 | // Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r |
789 | // Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r |
790 | // FpdModuleIdentification moduleId;\r |
791 | // while (item.hasNext()) {\r |
792 | // moduleId = (FpdModuleIdentification) item.next();\r |
793 | // SANode = fpdModuleSA.get(item.next());\r |
794 | // SAPcdBuildDef.put(moduleId,\r |
795 | // (PcdBuildDefinitionDocument.PcdBuildDefinition) SANode\r |
796 | // .get(xmlObjectName));\r |
797 | // }\r |
798 | // return SAPcdBuildDef;\r |
799 | // }\r |
878ddf1f |
800 | }\r |
a29c47e0 |
801 | \r |