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 |
136adffc |
24 | import org.tianocore.PcdBuildDefinitionDocument;\r |
a29c47e0 |
25 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
a29c47e0 |
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 |
136adffc |
30 | import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r |
a29c47e0 |
31 | import org.tianocore.build.toolchain.ToolChainAttribute;\r |
32 | import org.tianocore.build.toolchain.ToolChainConfig;\r |
33 | import org.tianocore.build.toolchain.ToolChainElement;\r |
34 | import org.tianocore.build.toolchain.ToolChainInfo;\r |
35 | import org.tianocore.build.toolchain.ToolChainKey;\r |
36 | import org.tianocore.build.toolchain.ToolChainMap;\r |
136adffc |
37 | import org.tianocore.exception.EdkException;\r |
38 | import org.tianocore.logger.EdkLog;\r |
a29c47e0 |
39 | \r |
878ddf1f |
40 | import java.io.File;\r |
41 | import java.util.HashMap;\r |
42 | import java.util.HashSet;\r |
43 | import java.util.Iterator;\r |
44 | import java.util.List;\r |
45 | import java.util.Map;\r |
46 | import java.util.Set;\r |
a29c47e0 |
47 | import java.util.logging.Logger;\r |
878ddf1f |
48 | \r |
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 |
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 |
878ddf1f |
56 | \r |
57 | @since GenBuild 1.0\r |
58 | **/\r |
59 | public class GlobalData {\r |
60 | \r |
a29c47e0 |
61 | public static Logger log = Logger.getAnonymousLogger();\r |
62 | \r |
878ddf1f |
63 | ///\r |
64 | /// Record current WORKSPACE Directory\r |
65 | ///\r |
66 | private static String workspaceDir = "";\r |
a29c47e0 |
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 |
72 | \r |
878ddf1f |
73 | ///\r |
a29c47e0 |
74 | /// Framework Database information: package list and platform list\r |
878ddf1f |
75 | ///\r |
a29c47e0 |
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 |
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 |
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 |
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 |
a29c47e0 |
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 |
121 | /// \r |
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 |
136adffc |
134 | private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r |
878ddf1f |
135 | \r |
878ddf1f |
136 | \r |
878ddf1f |
137 | \r |
138 | /**\r |
139 | Parse framework database (DB) and all SPD files listed in DB to initialize\r |
140 | the environment for next build. This method will only be executed only once\r |
141 | in the whole build process. \r |
a29c47e0 |
142 | \r |
878ddf1f |
143 | @param workspaceDatabaseFile the file name of framework database\r |
144 | @param workspaceDir current workspace directory path\r |
145 | @throws BuildException\r |
a29c47e0 |
146 | Framework Dababase or SPD or MSA file is not valid\r |
878ddf1f |
147 | **/\r |
a29c47e0 |
148 | public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename) throws BuildException {\r |
149 | //\r |
150 | // ensure this method will be revoked only once\r |
151 | //\r |
878ddf1f |
152 | if (globalFlag) {\r |
153 | return;\r |
154 | }\r |
155 | globalFlag = true;\r |
a29c47e0 |
156 | \r |
157 | //\r |
158 | // Backup workspace directory. It will be used by other method\r |
159 | //\r |
160 | GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r |
161 | \r |
162 | //\r |
163 | // Parse tools definition file\r |
164 | //\r |
165 | //\r |
166 | // If ToolChain has been set up before, do nothing.\r |
167 | // CONF dir + tools definition file name\r |
168 | //\r |
de4bb9f6 |
169 | File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r |
a29c47e0 |
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 |
136adffc |
344 | doc.putAll(getNativeMsa(moduleId));\r |
a29c47e0 |
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 |
136adffc |
416 | msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r |
a29c47e0 |
417 | return msaMap;\r |
418 | }\r |
419 | catch (Exception ex){\r |
420 | throw new BuildException(ex.getMessage());\r |
421 | }\r |
422 | }\r |
423 | \r |
424 | public static Map<String, XmlObject> getFpdBuildOptions() {\r |
425 | Map<String, XmlObject> map = new HashMap<String, XmlObject>();\r |
426 | map.put("BuildOptions", fpdBuildOptions);\r |
878ddf1f |
427 | return map;\r |
428 | }\r |
429 | \r |
a29c47e0 |
430 | public static void setFpdBuildOptions(XmlObject fpdBuildOptions) {\r |
431 | GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r |
432 | }\r |
433 | \r |
434 | public static XmlObject getFpdDynamicPcds() {\r |
435 | return fpdDynamicPcds;\r |
436 | }\r |
437 | \r |
438 | public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r |
439 | GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r |
440 | }\r |
441 | \r |
442 | //////////////////////////////////////////////\r |
443 | //////////////////////////////////////////////\r |
878ddf1f |
444 | \r |
a29c47e0 |
445 | public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r |
446 | Spd spd = spdTable.get(packageId);\r |
447 | if (spd == null ) {\r |
448 | Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r |
449 | return dummy;\r |
878ddf1f |
450 | }\r |
a29c47e0 |
451 | else {\r |
452 | return spd.getModules();\r |
878ddf1f |
453 | }\r |
878ddf1f |
454 | }\r |
455 | \r |
456 | /**\r |
a29c47e0 |
457 | * The header file path is relative to workspace dir\r |
458 | */\r |
459 | public static String[] getLibraryClassHeaderFiles(\r |
460 | PackageIdentification[] packages, String name)\r |
461 | throws BuildException {\r |
462 | if (packages == null) {\r |
463 | // throw Exception or not????\r |
464 | return new String[0];\r |
465 | }\r |
466 | String[] result = null;\r |
467 | for (int i = 0; i < packages.length; i++) {\r |
468 | Spd spd = spdTable.get(packages[i]);\r |
469 | //\r |
470 | // If find one package defined the library class\r |
471 | //\r |
472 | if ((result = spd.getLibClassIncluder(name)) != null) {\r |
473 | return result;\r |
474 | }\r |
475 | }\r |
476 | //\r |
477 | // If can't find library class declaration in every package\r |
478 | //\r |
479 | throw new BuildException("Can not find library class [" + name\r |
480 | + "] declaration in every packages. ");\r |
878ddf1f |
481 | }\r |
482 | \r |
483 | /**\r |
a29c47e0 |
484 | * The header file path is relative to workspace dir\r |
878ddf1f |
485 | */\r |
a29c47e0 |
486 | public static String getPackageHeaderFiles(PackageIdentification packages,\r |
487 | String moduleType) throws BuildException {\r |
488 | if (packages == null) {\r |
489 | return new String("");\r |
490 | }\r |
491 | Spd spd = spdTable.get(packages);\r |
492 | //\r |
493 | // If can't find package header file, skip it\r |
494 | //\r |
495 | String temp = null;\r |
496 | if (spd != null) {\r |
497 | if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r |
498 | return temp;\r |
499 | } else {\r |
500 | temp = "";\r |
501 | return temp;\r |
878ddf1f |
502 | }\r |
a29c47e0 |
503 | } else {\r |
504 | return null;\r |
878ddf1f |
505 | }\r |
878ddf1f |
506 | }\r |
507 | \r |
a29c47e0 |
508 | /**\r |
509 | * return two values: {cName, GuidValue}\r |
510 | */\r |
136adffc |
511 | public static String[] getGuid(List<PackageIdentification> packages, String name)\r |
a29c47e0 |
512 | throws BuildException {\r |
513 | if (packages == null) {\r |
514 | // throw Exception or not????\r |
515 | return new String[0];\r |
516 | }\r |
517 | String[] result = null;\r |
136adffc |
518 | Iterator item = packages.iterator();\r |
519 | while (item.hasNext()){\r |
520 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
521 | //\r |
522 | // If find one package defined the GUID\r |
523 | //\r |
524 | if ((result = spd.getGuid(name)) != null) {\r |
525 | return result;\r |
878ddf1f |
526 | }\r |
527 | }\r |
136adffc |
528 | \r |
a29c47e0 |
529 | return null;\r |
878ddf1f |
530 | }\r |
531 | \r |
532 | /**\r |
a29c47e0 |
533 | * return two values: {cName, GuidValue}\r |
878ddf1f |
534 | */\r |
136adffc |
535 | public static String[] getPpiGuid(List<PackageIdentification> packages,\r |
a29c47e0 |
536 | String name) throws BuildException {\r |
537 | if (packages == null) {\r |
538 | return new String[0];\r |
539 | }\r |
540 | String[] result = null;\r |
136adffc |
541 | Iterator item = packages.iterator();\r |
542 | while (item.hasNext()){\r |
543 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
544 | //\r |
545 | // If find one package defined the Ppi GUID\r |
546 | //\r |
547 | if ((result = spd.getPpi(name)) != null) {\r |
548 | return result;\r |
878ddf1f |
549 | }\r |
550 | }\r |
a29c47e0 |
551 | return null;\r |
552 | \r |
878ddf1f |
553 | }\r |
554 | \r |
a29c47e0 |
555 | /**\r |
556 | * return two values: {cName, GuidValue}\r |
557 | */\r |
136adffc |
558 | public static String[] getProtocolGuid(List<PackageIdentification> packages,\r |
a29c47e0 |
559 | String name) throws BuildException {\r |
560 | if (packages == null) {\r |
561 | return new String[0];\r |
562 | }\r |
563 | String[] result = null;\r |
136adffc |
564 | Iterator item = packages.iterator();\r |
565 | while (item.hasNext()){\r |
566 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
567 | //\r |
568 | // If find one package defined the protocol GUID\r |
569 | //\r |
136adffc |
570 | if ((result = spd.getProtocol(name))!= null){\r |
a29c47e0 |
571 | return result;\r |
572 | }\r |
573 | }\r |
574 | return null;\r |
878ddf1f |
575 | \r |
a29c47e0 |
576 | }\r |
577 | \r |
de4bb9f6 |
578 | public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException {\r |
a29c47e0 |
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 |
a29c47e0 |
583 | return platformId;\r |
878ddf1f |
584 | }\r |
a29c47e0 |
585 | }\r |
de4bb9f6 |
586 | throw new BuildException("Can't find platform [" + name + "] in current workspace database. ");\r |
587 | }\r |
588 | \r |
589 | public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException {\r |
590 | File file = new File(workspaceDir + File.separatorChar + filename);\r |
591 | Iterator iter = platformList.iterator();\r |
592 | while(iter.hasNext()){\r |
593 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r |
594 | if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r |
595 | return platformId;\r |
596 | }\r |
597 | }\r |
598 | throw new BuildException("Can't find platform file [" + filename + "] in current workspace database. ");\r |
a29c47e0 |
599 | }\r |
600 | \r |
601 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException {\r |
602 | Iterator iter = packageList.iterator();\r |
603 | while(iter.hasNext()){\r |
604 | PackageIdentification packageItem = (PackageIdentification)iter.next();\r |
605 | if (packageItem.equals(packageId)) {\r |
606 | packageId.setName(packageItem.getName());\r |
607 | packageId.setSpdFile(packageItem.getSpdFile());\r |
608 | return packageId;\r |
878ddf1f |
609 | }\r |
610 | }\r |
a29c47e0 |
611 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r |
612 | }\r |
613 | \r |
614 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException {\r |
615 | // System.out.println("1");\r |
616 | // System.out.println("##" + moduleId.getGuid());\r |
617 | PackageIdentification packageId = getPackageForModule(moduleId);\r |
618 | // System.out.println("" + packageId.getGuid());\r |
619 | moduleId.setPackage(packageId);\r |
620 | Spd spd = spdTable.get(packageId);\r |
621 | if (spd == null) {\r |
622 | throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " under current workspace. ");\r |
623 | }\r |
624 | Set<ModuleIdentification> modules = spd.getModules();\r |
625 | Iterator<ModuleIdentification> iter = modules.iterator();\r |
626 | while (iter.hasNext()) {\r |
627 | ModuleIdentification item = iter.next();\r |
628 | if (item.equals(moduleId)) {\r |
629 | moduleId.setName(item.getName());\r |
630 | moduleId.setModuleType(item.getModuleType());\r |
631 | moduleId.setMsaFile(item.getMsaFile());\r |
632 | return moduleId;\r |
633 | }\r |
634 | }\r |
635 | throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in " + packageId + " under current workspace. ");\r |
636 | }\r |
637 | \r |
638 | public synchronized static Set<PackageIdentification> getPackageList(){\r |
639 | return packageList;\r |
640 | }\r |
641 | ///// remove!!\r |
642 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException {\r |
643 | if ( object == null) {\r |
644 | return null;\r |
645 | }\r |
646 | XmlObject result = null;\r |
647 | try {\r |
648 | result = XmlObject.Factory.parse(object.getDomNode()\r |
649 | .cloneNode(deep));\r |
650 | } catch (Exception ex) {\r |
651 | throw new BuildException(ex.getMessage());\r |
652 | }\r |
653 | return result;\r |
878ddf1f |
654 | }\r |
655 | \r |
a29c47e0 |
656 | ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r |
878ddf1f |
657 | \r |
a29c47e0 |
658 | public static ToolChainInfo getToolChainInfo() {\r |
659 | // GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo);\r |
660 | if (toolChainInfo == null) {\r |
661 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r |
662 | if (toolChainPlatformInfo != null) {\r |
663 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r |
878ddf1f |
664 | }\r |
a29c47e0 |
665 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r |
666 | toolChainInfo.normalize();\r |
667 | GlobalData.log.info(toolChainInfo + "");\r |
878ddf1f |
668 | }\r |
a29c47e0 |
669 | return toolChainInfo;\r |
670 | }\r |
671 | \r |
672 | \r |
878ddf1f |
673 | \r |
a29c47e0 |
674 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r |
675 | platformToolChainFamilyOption = map;\r |
878ddf1f |
676 | }\r |
677 | \r |
a29c47e0 |
678 | public static void setPlatformToolChainOption(ToolChainMap map) {\r |
679 | platformToolChainOption = map;\r |
680 | }\r |
878ddf1f |
681 | \r |
a29c47e0 |
682 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r |
683 | ToolChainMap toolChainOption) {\r |
684 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
685 | }\r |
686 | \r |
a29c47e0 |
687 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r |
688 | ToolChainMap toolChainOption) {\r |
689 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
690 | }\r |
691 | \r |
a29c47e0 |
692 | public static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
693 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r |
694 | ToolChainMap toolChainConfig = toolsDef.getConfig(); \r |
695 | String setting = null;\r |
696 | \r |
697 | if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r |
698 | setting = toolChainConfig.get(toolChainKey);\r |
699 | if (setting == null) {\r |
700 | setting = "";\r |
701 | }\r |
702 | return setting;\r |
878ddf1f |
703 | }\r |
878ddf1f |
704 | \r |
a29c47e0 |
705 | //\r |
706 | // get module specific options, if any\r |
707 | //\r |
708 | // tool tag first\r |
709 | ToolChainMap option = moduleToolChainOption.get(fpdModuleId);\r |
710 | ToolChainKey toolChainFamilyKey = null;\r |
711 | \r |
712 | if ((option == null) || (option != null && (setting = option.get(toolChainKey)) == null)) {\r |
713 | //\r |
714 | // then tool chain family\r |
715 | //\r |
716 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r |
717 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r |
718 | String family = toolChainConfig.get(toolChainFamilyKey);\r |
719 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r |
720 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r |
721 | \r |
722 | option = moduleToolChainFamilyOption.get(fpdModuleId);\r |
723 | if (option != null) { \r |
724 | setting = option.get(toolChainFamilyKey);\r |
725 | }\r |
878ddf1f |
726 | }\r |
878ddf1f |
727 | \r |
a29c47e0 |
728 | //\r |
729 | // get platform options, if any\r |
730 | //\r |
731 | if (setting == null) {\r |
732 | // tool tag first\r |
733 | if (platformToolChainOption == null || (setting = platformToolChainOption.get(toolChainKey)) == null) {\r |
734 | // then tool chain family\r |
735 | if (toolChainFamilyKey == null) {\r |
736 | toolChainFamilyKey = new ToolChainKey(commandDescription);\r |
737 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r |
738 | String family = toolChainConfig.get(toolChainFamilyKey);\r |
739 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r |
740 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r |
741 | }\r |
742 | \r |
743 | setting = platformToolChainFamilyOption.get(toolChainFamilyKey);\r |
744 | }\r |
745 | }\r |
746 | \r |
747 | if (setting == null) {\r |
748 | setting = "";\r |
749 | }\r |
750 | \r |
751 | return setting;\r |
752 | }\r |
753 | \r |
754 | public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r |
755 | toolChainEnvInfo = envInfo;\r |
756 | }\r |
757 | public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r |
758 | toolChainPlatformInfo = platformInfo;\r |
878ddf1f |
759 | }\r |
a29c47e0 |
760 | \r |
761 | //\r |
762 | // for PCD\r |
763 | //\r |
136adffc |
764 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
765 | return pcdDbManager;\r |
766 | }\r |
a29c47e0 |
767 | \r |
768 | //\r |
136adffc |
769 | // For PCD get tokenSpaceGUid\r |
a29c47e0 |
770 | //\r |
136adffc |
771 | public synchronized static String[] getGuidInfoFromCname(String cName){\r |
772 | String cNameGuid[] = null;\r |
773 | String guid = null;\r |
774 | Set set = spdTable.keySet();\r |
775 | Iterator iter = set.iterator();\r |
548ce97a |
776 | \r |
777 | if (iter == null) {\r |
778 | return null;\r |
779 | }\r |
780 | \r |
136adffc |
781 | while (iter.hasNext()){\r |
782 | Spd spd = (Spd) spdTable.get(iter.next());\r |
783 | guid = spd.getGuidFromCname(cName);\r |
784 | if (guid != null){\r |
548ce97a |
785 | cNameGuid = new String[2];\r |
786 | cNameGuid[0] = cName;\r |
787 | cNameGuid[1] = guid;\r |
136adffc |
788 | break;\r |
789 | }\r |
790 | }\r |
791 | return cNameGuid;\r |
792 | }\r |
a29c47e0 |
793 | \r |
794 | //\r |
795 | // For PCD\r |
796 | //\r |
136adffc |
797 | public synchronized static Map<FpdModuleIdentification, XmlObject> getFpdModuleSaXmlObject(\r |
798 | String xmlObjectName) {\r |
799 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r |
800 | Iterator item = fpdModuleSASet.iterator();\r |
801 | \r |
802 | \r |
803 | Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r |
804 | Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r |
805 | FpdModuleIdentification moduleId;\r |
806 | while (item.hasNext()) {\r |
807 | \r |
808 | moduleId = (FpdModuleIdentification) item.next();\r |
809 | SANode = fpdModuleSA.get(moduleId);\r |
810 | try{\r |
811 | if (SANode.get(xmlObjectName)!= null){\r |
812 | SAPcdBuildDef.put(moduleId,\r |
813 | (XmlObject) SANode\r |
814 | .get(xmlObjectName));\r |
815 | \r |
816 | }\r |
817 | \r |
818 | \r |
819 | } catch (Exception e){\r |
820 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r |
821 | }\r |
822 | }\r |
823 | return SAPcdBuildDef;\r |
824 | }\r |
878ddf1f |
825 | }\r |
a29c47e0 |
826 | \r |