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 |
892b0e7a |
20 | import java.io.IOException;\r |
73b4e31a |
21 | import java.util.HashMap;\r |
22 | import java.util.HashSet;\r |
23 | import java.util.Iterator;\r |
24 | import java.util.List;\r |
25 | import java.util.Map;\r |
26 | import java.util.Set;\r |
0923e8b3 |
27 | import java.util.regex.Matcher;\r |
28 | import java.util.regex.Pattern;\r |
73b4e31a |
29 | \r |
892b0e7a |
30 | import org.apache.xmlbeans.XmlException;\r |
a29c47e0 |
31 | import org.apache.xmlbeans.XmlObject;\r |
ff225cbb |
32 | \r |
33 | import org.tianocore.common.exception.EdkException;\r |
34 | import org.tianocore.common.logger.EdkLog;\r |
35 | import org.tianocore.pcd.entity.MemoryDatabaseManager;\r |
a29c47e0 |
36 | import org.tianocore.DbPathAndFilename;\r |
37 | import org.tianocore.FrameworkDatabaseDocument;\r |
38 | import org.tianocore.ModuleSurfaceAreaDocument;\r |
39 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r |
a29c47e0 |
40 | import org.tianocore.build.id.FpdModuleIdentification;\r |
41 | import org.tianocore.build.id.ModuleIdentification;\r |
42 | import org.tianocore.build.id.PackageIdentification;\r |
43 | import org.tianocore.build.id.PlatformIdentification;\r |
44 | import org.tianocore.build.toolchain.ToolChainAttribute;\r |
45 | import org.tianocore.build.toolchain.ToolChainConfig;\r |
46 | import org.tianocore.build.toolchain.ToolChainElement;\r |
47 | import org.tianocore.build.toolchain.ToolChainInfo;\r |
48 | import org.tianocore.build.toolchain.ToolChainKey;\r |
49 | import org.tianocore.build.toolchain.ToolChainMap;\r |
a29c47e0 |
50 | \r |
878ddf1f |
51 | /**\r |
52 | GlobalData provide initializing, instoring, querying and update global data.\r |
53 | It is a bridge to intercommunicate between multiple component, such as AutoGen,\r |
ff225cbb |
54 | PCD and so on.\r |
55 | \r |
56 | <p>Note that all global information are initialized incrementally. All data will\r |
a29c47e0 |
57 | parse and record only of necessary during build time. </p>\r |
ff225cbb |
58 | \r |
878ddf1f |
59 | @since GenBuild 1.0\r |
60 | **/\r |
61 | public class GlobalData {\r |
878ddf1f |
62 | ///\r |
63 | /// Record current WORKSPACE Directory\r |
64 | ///\r |
65 | private static String workspaceDir = "";\r |
ff225cbb |
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 |
ff225cbb |
71 | \r |
878ddf1f |
72 | ///\r |
a29c47e0 |
73 | /// Framework Database information: package list and platform list\r |
878ddf1f |
74 | ///\r |
ff225cbb |
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 |
19bf6b15 |
93 | private static Map<String, XmlObject> fpdBuildOptionsMap = new HashMap<String, XmlObject>();\r |
94 | \r |
a29c47e0 |
95 | private static XmlObject fpdBuildOptions;\r |
878ddf1f |
96 | \r |
a29c47e0 |
97 | private static XmlObject fpdDynamicPcds;\r |
ff225cbb |
98 | \r |
878ddf1f |
99 | ///\r |
a29c47e0 |
100 | /// Parsed modules list\r |
878ddf1f |
101 | ///\r |
a29c47e0 |
102 | private static Map<FpdModuleIdentification, Map<String, XmlObject>> parsedModules = new HashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r |
ff225cbb |
103 | \r |
878ddf1f |
104 | ///\r |
a29c47e0 |
105 | /// built modules list with ARCH, TARGET, TOOLCHAIN\r |
878ddf1f |
106 | ///\r |
a29c47e0 |
107 | private static Set<FpdModuleIdentification> builtModules = new HashSet<FpdModuleIdentification>();\r |
ff225cbb |
108 | \r |
878ddf1f |
109 | ///\r |
a29c47e0 |
110 | /// PCD memory database stored all PCD information which collected from FPD,MSA and SPD.\r |
878ddf1f |
111 | ///\r |
8b7bd455 |
112 | private static final MemoryDatabaseManager pcdDbManager = new MemoryDatabaseManager();\r |
878ddf1f |
113 | \r |
114 | ///\r |
a29c47e0 |
115 | /// build target + tool chain family/tag name + arch + command types + command options\r |
878ddf1f |
116 | ///\r |
a29c47e0 |
117 | ///\r |
118 | /// Tool Chain Data\r |
119 | /// toolsDef - build tool program information\r |
120 | /// fpdBuildOption - all modules's build options for tool tag or tool chain families\r |
121 | /// moduleSaBuildOption - build options for a specific module\r |
ff225cbb |
122 | ///\r |
a29c47e0 |
123 | private static ToolChainConfig toolsDef;\r |
878ddf1f |
124 | \r |
a29c47e0 |
125 | private static ToolChainInfo toolChainInfo;\r |
126 | private static ToolChainInfo toolChainEnvInfo;\r |
127 | private static ToolChainInfo toolChainPlatformInfo;\r |
878ddf1f |
128 | \r |
a29c47e0 |
129 | private static ToolChainMap platformToolChainOption;\r |
130 | private static ToolChainMap platformToolChainFamilyOption;\r |
878ddf1f |
131 | \r |
a29c47e0 |
132 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r |
133 | private static Map<FpdModuleIdentification, ToolChainMap> moduleToolChainFamilyOption = new HashMap<FpdModuleIdentification, ToolChainMap>();\r |
878ddf1f |
134 | \r |
8c84e1b1 |
135 | private static Pattern flagPattern = Pattern.compile("[^\\\\]?(\".*?[^\\\\]\")[ \t,]+");\r |
878ddf1f |
136 | /**\r |
137 | Parse framework database (DB) and all SPD files listed in DB to initialize\r |
138 | the environment for next build. This method will only be executed only once\r |
ff225cbb |
139 | in the whole build process.\r |
140 | \r |
878ddf1f |
141 | @param workspaceDatabaseFile the file name of framework database\r |
142 | @param workspaceDir current workspace directory path\r |
143 | @throws BuildException\r |
a29c47e0 |
144 | Framework Dababase or SPD or MSA file is not valid\r |
878ddf1f |
145 | **/\r |
892b0e7a |
146 | public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException {\r |
a29c47e0 |
147 | //\r |
148 | // ensure this method will be revoked only once\r |
149 | //\r |
878ddf1f |
150 | if (globalFlag) {\r |
151 | return;\r |
152 | }\r |
153 | globalFlag = true;\r |
73b4e31a |
154 | \r |
ff225cbb |
155 | //\r |
a29c47e0 |
156 | // Backup workspace directory. It will be used by other method\r |
157 | //\r |
158 | GlobalData.workspaceDir = workspaceDir.replaceAll("(\\\\)", "/");\r |
ff225cbb |
159 | \r |
a29c47e0 |
160 | //\r |
161 | // Parse tools definition file\r |
162 | //\r |
163 | //\r |
164 | // If ToolChain has been set up before, do nothing.\r |
165 | // CONF dir + tools definition file name\r |
166 | //\r |
de4bb9f6 |
167 | File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);\r |
2eb7d78d |
168 | EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "].");\r |
892b0e7a |
169 | toolsDef = new ToolChainConfig(toolsDefFile);\r |
170 | \r |
a29c47e0 |
171 | //\r |
172 | // Parse Framework Database\r |
173 | //\r |
878ddf1f |
174 | File dbFile = new File(workspaceDir + File.separatorChar + workspaceDatabaseFile);\r |
175 | try {\r |
176 | FrameworkDatabaseDocument db = (FrameworkDatabaseDocument) XmlObject.Factory.parse(dbFile);\r |
a29c47e0 |
177 | //\r |
178 | // validate FrameworkDatabaseFile\r |
179 | //\r |
82516887 |
180 | if (!db.validate()) {\r |
892b0e7a |
181 | throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!");\r |
878ddf1f |
182 | }\r |
a29c47e0 |
183 | //\r |
184 | // Get package list\r |
185 | //\r |
186 | if (db.getFrameworkDatabase().getPackageList() != null ) {\r |
187 | List<DbPathAndFilename> packages = db.getFrameworkDatabase().getPackageList().getFilenameList();\r |
188 | Iterator<DbPathAndFilename> iter = packages.iterator();\r |
189 | while (iter.hasNext()) {\r |
83fba802 |
190 | String fileName = iter.next().getStringValue().trim();\r |
a29c47e0 |
191 | Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));\r |
192 | packageList.add(spd.getPackageId());\r |
892b0e7a |
193 | //\r |
194 | // Report warning if existing two packages with same GUID and Version\r |
195 | //\r |
196 | if (spdTable.containsKey(spd.getPackageId())) {\r |
197 | //\r |
198 | // BUGBUG\r |
199 | //\r |
200 | EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath());\r |
201 | }\r |
a29c47e0 |
202 | spdTable.put(spd.getPackageId(), spd);\r |
250258de |
203 | }\r |
204 | }\r |
205 | \r |
a29c47e0 |
206 | //\r |
207 | // Get platform list\r |
208 | //\r |
209 | if (db.getFrameworkDatabase().getPlatformList() != null) {\r |
210 | List<DbPathAndFilename> platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList();\r |
211 | Iterator<DbPathAndFilename> iter = platforms.iterator();\r |
212 | while (iter.hasNext()) {\r |
83fba802 |
213 | String fileName = iter.next().getStringValue().trim();\r |
a29c47e0 |
214 | File fpdFile = new File(workspaceDir + File.separatorChar + fileName);\r |
82516887 |
215 | if ( !fpdFile.exists() ) {\r |
892b0e7a |
216 | throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. ");\r |
250258de |
217 | }\r |
a29c47e0 |
218 | XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);\r |
219 | //\r |
220 | // Verify FPD file, if is invalid, throw Exception\r |
221 | //\r |
82516887 |
222 | if (!fpdDoc.validate()) {\r |
892b0e7a |
223 | throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!");\r |
a29c47e0 |
224 | }\r |
225 | //\r |
226 | // We can change Map to XmlObject\r |
227 | //\r |
a29c47e0 |
228 | Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();\r |
229 | fpdDocMap.put("PlatformSurfaceArea", fpdDoc);\r |
83fba802 |
230 | SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);\r |
231 | PlatformIdentification platformId = saq.getFpdHeader();\r |
a29c47e0 |
232 | platformId.setFpdFile(fpdFile);\r |
892b0e7a |
233 | //\r |
234 | // Report warning if existing two platfrom with same GUID and Version\r |
235 | //\r |
236 | if (platformList.contains(platformId)) {\r |
237 | //\r |
238 | // BUGBUG\r |
239 | //\r |
240 | EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath());\r |
241 | }\r |
a29c47e0 |
242 | platformList.add(platformId);\r |
878ddf1f |
243 | }\r |
878ddf1f |
244 | }\r |
892b0e7a |
245 | } catch(IOException ex) {\r |
246 | EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r |
247 | edkException.setStackTrace(ex.getStackTrace());\r |
248 | throw edkException;\r |
249 | } catch(XmlException ex) {\r |
250 | EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage());\r |
251 | edkException.setStackTrace(ex.getStackTrace());\r |
252 | throw edkException;\r |
878ddf1f |
253 | }\r |
254 | }\r |
ff225cbb |
255 | \r |
878ddf1f |
256 | /**\r |
ff225cbb |
257 | Get the current WORKSPACE Directory.\r |
258 | \r |
a29c47e0 |
259 | @return current workspace directory\r |
878ddf1f |
260 | **/\r |
a29c47e0 |
261 | public synchronized static String getWorkspacePath() {\r |
262 | return workspaceDir;\r |
878ddf1f |
263 | }\r |
264 | \r |
878ddf1f |
265 | \r |
266 | /**\r |
a29c47e0 |
267 | Get the MSA file name with absolute path\r |
268 | */\r |
892b0e7a |
269 | public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 |
270 | File msaFile = null;\r |
271 | //\r |
ff225cbb |
272 | // TBD. Do only when package is null.\r |
a29c47e0 |
273 | //\r |
274 | Iterator iter = packageList.iterator();\r |
275 | while (iter.hasNext()) {\r |
276 | PackageIdentification packageId = (PackageIdentification)iter.next();\r |
277 | Spd spd = spdTable.get(packageId);\r |
278 | msaFile = spd.getModuleFile(moduleId);\r |
279 | if (msaFile != null ) {\r |
280 | break ;\r |
281 | }\r |
282 | }\r |
283 | if (msaFile == null){\r |
892b0e7a |
284 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r |
82516887 |
285 | } else {\r |
a29c47e0 |
286 | return msaFile;\r |
287 | }\r |
878ddf1f |
288 | }\r |
289 | \r |
892b0e7a |
290 | public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 |
291 | //\r |
292 | // If package already defined in module\r |
293 | //\r |
294 | if (moduleId.getPackage() != null) {\r |
295 | return moduleId.getPackage();\r |
296 | }\r |
ff225cbb |
297 | \r |
a29c47e0 |
298 | PackageIdentification packageId = null;\r |
299 | Iterator iter = packageList.iterator();\r |
300 | while (iter.hasNext()) {\r |
301 | packageId = (PackageIdentification)iter.next();\r |
302 | moduleId.setPackage(packageId);\r |
303 | Spd spd = spdTable.get(packageId);\r |
89e1408f |
304 | File tempMsaFile = null;\r |
305 | if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) {\r |
306 | if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) {\r |
307 | break ;\r |
308 | }\r |
309 | tempMsaFile = null;\r |
a29c47e0 |
310 | }\r |
311 | }\r |
312 | if (packageId == null){\r |
892b0e7a |
313 | throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!");\r |
82516887 |
314 | } else {\r |
a29c47e0 |
315 | return packageId;\r |
316 | }\r |
317 | }\r |
ff225cbb |
318 | \r |
878ddf1f |
319 | /**\r |
a29c47e0 |
320 | Difference between build and parse: ToolChain and Target\r |
878ddf1f |
321 | **/\r |
a29c47e0 |
322 | public synchronized static boolean isModuleBuilt(FpdModuleIdentification moduleId) {\r |
323 | return builtModules.contains(moduleId);\r |
878ddf1f |
324 | }\r |
ff225cbb |
325 | \r |
a29c47e0 |
326 | public synchronized static void registerBuiltModule(FpdModuleIdentification fpdModuleId) {\r |
327 | builtModules.add(fpdModuleId);\r |
878ddf1f |
328 | }\r |
329 | \r |
ff225cbb |
330 | \r |
892b0e7a |
331 | public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{\r |
a29c47e0 |
332 | Map<String, XmlObject> result = new HashMap<String, XmlObject>();\r |
333 | Set keySet = doc.keySet();\r |
334 | Iterator iter = keySet.iterator();\r |
335 | while (iter.hasNext()){\r |
336 | String key = (String)iter.next();\r |
337 | XmlObject item = cloneXmlObject(doc.get(key), true);\r |
338 | result.put(key, item);\r |
339 | }\r |
340 | fpdModuleSA.put(fpdModuleId, result);\r |
878ddf1f |
341 | }\r |
57cc2ee7 |
342 | \r |
343 | public synchronized static boolean hasFpdModuleSA(FpdModuleIdentification fpdModuleId) {\r |
344 | return fpdModuleSA.containsKey(fpdModuleId);\r |
345 | }\r |
346 | \r |
878ddf1f |
347 | /**\r |
82516887 |
348 | Query module surface area information.\r |
ff225cbb |
349 | \r |
350 | <p>Note that surface area parsing is incremental. That means the method will\r |
82516887 |
351 | only parse the MSA files if necessary. </p>\r |
352 | \r |
353 | @param fpdModuleId Module ID with arch\r |
354 | @return ModuleSA info and MSA info for fpdModuleId\r |
355 | @throws BuildException Can't find MSA\r |
878ddf1f |
356 | **/\r |
892b0e7a |
357 | public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{\r |
a29c47e0 |
358 | if (parsedModules.containsKey(fpdModuleId)) {\r |
359 | return parsedModules.get(fpdModuleId);\r |
360 | }\r |
361 | Map<String, XmlObject> doc = new HashMap<String, XmlObject>();\r |
362 | ModuleIdentification moduleId = fpdModuleId.getModule();\r |
878ddf1f |
363 | //\r |
a29c47e0 |
364 | // First part: get the MSA files info\r |
878ddf1f |
365 | //\r |
136adffc |
366 | doc.putAll(getNativeMsa(moduleId));\r |
ff225cbb |
367 | \r |
a29c47e0 |
368 | //\r |
369 | // Second part: put build options\r |
370 | //\r |
371 | doc.put("BuildOptions", fpdBuildOptions);\r |
ff225cbb |
372 | \r |
a29c47e0 |
373 | //\r |
374 | // Third part: get Module info from FPD, such as Library instances, PCDs\r |
375 | //\r |
376 | if (fpdModuleSA.containsKey(fpdModuleId)){\r |
377 | //\r |
378 | // merge module info in FPD to final Doc\r |
379 | // For Library Module, do nothing here\r |
380 | //\r |
381 | doc.putAll(fpdModuleSA.get(fpdModuleId));\r |
878ddf1f |
382 | }\r |
a29c47e0 |
383 | parsedModules.put(fpdModuleId, doc);\r |
384 | return doc;\r |
878ddf1f |
385 | }\r |
386 | \r |
892b0e7a |
387 | public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{\r |
a29c47e0 |
388 | FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);\r |
389 | return getDoc(fpdModuleId);\r |
390 | }\r |
892b0e7a |
391 | \r |
878ddf1f |
392 | /**\r |
ff225cbb |
393 | Query the native MSA information with module base name.\r |
394 | \r |
395 | <p>Note that MSA parsing is incremental. That means the method will\r |
878ddf1f |
396 | only to parse the MSA files when never parsed before. </p>\r |
ff225cbb |
397 | \r |
878ddf1f |
398 | @param moduleName the base name of the module\r |
399 | @return the native MSA information\r |
400 | @throws BuildException\r |
401 | MSA file is not valid\r |
402 | **/\r |
892b0e7a |
403 | public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 |
404 | if (nativeMsa.containsKey(moduleId)) {\r |
405 | return nativeMsa.get(moduleId);\r |
406 | }\r |
407 | File msaFile = getMsaFile(moduleId);\r |
408 | Map<String, XmlObject> msaMap = getNativeMsa(msaFile);\r |
409 | nativeMsa.put(moduleId, msaMap);\r |
410 | return msaMap;\r |
411 | }\r |
ff225cbb |
412 | \r |
892b0e7a |
413 | public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {\r |
82516887 |
414 | if (!msaFile.exists()) {\r |
892b0e7a |
415 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!");\r |
a29c47e0 |
416 | }\r |
417 | try {\r |
418 | ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);\r |
419 | //\r |
420 | // Validate File if they accord with XML Schema\r |
421 | //\r |
82516887 |
422 | if ( !doc.validate()){\r |
892b0e7a |
423 | throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!");\r |
a29c47e0 |
424 | }\r |
425 | //\r |
426 | // parse MSA file\r |
427 | //\r |
428 | ModuleSurfaceArea msa= doc.getModuleSurfaceArea();\r |
429 | Map<String, XmlObject> msaMap = new HashMap<String, XmlObject>();\r |
430 | msaMap.put("MsaHeader", cloneXmlObject(msa.getMsaHeader(), true));\r |
431 | msaMap.put("ModuleDefinitions", cloneXmlObject(msa.getModuleDefinitions(), true));\r |
432 | msaMap.put("LibraryClassDefinitions", cloneXmlObject(msa.getLibraryClassDefinitions(), true));\r |
433 | msaMap.put("SourceFiles", cloneXmlObject(msa.getSourceFiles(), true));\r |
434 | msaMap.put("PackageDependencies", cloneXmlObject(msa.getPackageDependencies(), true));\r |
435 | msaMap.put("Protocols", cloneXmlObject(msa.getProtocols(), true));\r |
436 | msaMap.put("PPIs", cloneXmlObject(msa.getPPIs(), true));\r |
437 | msaMap.put("Guids", cloneXmlObject(msa.getGuids(), true));\r |
438 | msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));\r |
136adffc |
439 | msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));\r |
a29c47e0 |
440 | return msaMap;\r |
892b0e7a |
441 | } catch(IOException ex) {\r |
442 | EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r |
443 | edkException.setStackTrace(ex.getStackTrace());\r |
444 | throw edkException;\r |
445 | } catch(XmlException ex) {\r |
446 | EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());\r |
447 | edkException.setStackTrace(ex.getStackTrace());\r |
448 | throw edkException;\r |
a29c47e0 |
449 | }\r |
450 | }\r |
ff225cbb |
451 | \r |
19bf6b15 |
452 | public static Map<String, XmlObject> getFpdBuildOptionsMap() {\r |
453 | return fpdBuildOptionsMap;\r |
878ddf1f |
454 | }\r |
ff225cbb |
455 | \r |
892b0e7a |
456 | public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {\r |
a29c47e0 |
457 | GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);\r |
19bf6b15 |
458 | fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);\r |
a29c47e0 |
459 | }\r |
460 | \r |
461 | public static XmlObject getFpdDynamicPcds() {\r |
462 | return fpdDynamicPcds;\r |
463 | }\r |
464 | \r |
465 | public static void setFpdDynamicPcds(XmlObject fpdDynamicPcds) {\r |
466 | GlobalData.fpdDynamicPcds = fpdDynamicPcds;\r |
467 | }\r |
468 | \r |
a29c47e0 |
469 | public static Set<ModuleIdentification> getModules(PackageIdentification packageId){\r |
470 | Spd spd = spdTable.get(packageId);\r |
471 | if (spd == null ) {\r |
472 | Set<ModuleIdentification> dummy = new HashSet<ModuleIdentification>();\r |
473 | return dummy;\r |
82516887 |
474 | } else {\r |
a29c47e0 |
475 | return spd.getModules();\r |
878ddf1f |
476 | }\r |
878ddf1f |
477 | }\r |
478 | \r |
479 | /**\r |
a29c47e0 |
480 | * The header file path is relative to workspace dir\r |
481 | */\r |
482 | public static String[] getLibraryClassHeaderFiles(\r |
892b0e7a |
483 | PackageIdentification[] packages, String name) throws EdkException{\r |
a29c47e0 |
484 | if (packages == null) {\r |
485 | // throw Exception or not????\r |
486 | return new String[0];\r |
487 | }\r |
488 | String[] result = null;\r |
489 | for (int i = 0; i < packages.length; i++) {\r |
490 | Spd spd = spdTable.get(packages[i]);\r |
491 | //\r |
492 | // If find one package defined the library class\r |
493 | //\r |
494 | if ((result = spd.getLibClassIncluder(name)) != null) {\r |
495 | return result;\r |
496 | }\r |
497 | }\r |
498 | //\r |
499 | // If can't find library class declaration in every package\r |
500 | //\r |
892b0e7a |
501 | throw new EdkException("Can not find library class [" + name\r |
391dbbb1 |
502 | + "] declaration in any SPD package!");\r |
878ddf1f |
503 | }\r |
504 | \r |
505 | /**\r |
a29c47e0 |
506 | * The header file path is relative to workspace dir\r |
878ddf1f |
507 | */\r |
a29c47e0 |
508 | public static String getPackageHeaderFiles(PackageIdentification packages,\r |
892b0e7a |
509 | String moduleType) {\r |
a29c47e0 |
510 | if (packages == null) {\r |
511 | return new String("");\r |
512 | }\r |
513 | Spd spd = spdTable.get(packages);\r |
514 | //\r |
515 | // If can't find package header file, skip it\r |
516 | //\r |
517 | String temp = null;\r |
518 | if (spd != null) {\r |
519 | if ((temp = spd.getPackageIncluder(moduleType)) != null) {\r |
520 | return temp;\r |
521 | } else {\r |
522 | temp = "";\r |
523 | return temp;\r |
878ddf1f |
524 | }\r |
a29c47e0 |
525 | } else {\r |
526 | return null;\r |
878ddf1f |
527 | }\r |
878ddf1f |
528 | }\r |
529 | \r |
a29c47e0 |
530 | /**\r |
531 | * return two values: {cName, GuidValue}\r |
532 | */\r |
892b0e7a |
533 | public static String[] getGuid(List<PackageIdentification> packages, String name) {\r |
a29c47e0 |
534 | if (packages == null) {\r |
535 | // throw Exception or not????\r |
536 | return new String[0];\r |
537 | }\r |
538 | String[] result = null;\r |
136adffc |
539 | Iterator item = packages.iterator();\r |
540 | while (item.hasNext()){\r |
541 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
542 | //\r |
543 | // If find one package defined the GUID\r |
544 | //\r |
545 | if ((result = spd.getGuid(name)) != null) {\r |
546 | return result;\r |
878ddf1f |
547 | }\r |
548 | }\r |
136adffc |
549 | \r |
a29c47e0 |
550 | return null;\r |
878ddf1f |
551 | }\r |
552 | \r |
553 | /**\r |
a29c47e0 |
554 | * return two values: {cName, GuidValue}\r |
878ddf1f |
555 | */\r |
136adffc |
556 | public static String[] getPpiGuid(List<PackageIdentification> packages,\r |
892b0e7a |
557 | String name) {\r |
a29c47e0 |
558 | if (packages == null) {\r |
559 | return new String[0];\r |
560 | }\r |
561 | String[] result = null;\r |
136adffc |
562 | Iterator item = packages.iterator();\r |
563 | while (item.hasNext()){\r |
564 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
565 | //\r |
566 | // If find one package defined the Ppi GUID\r |
567 | //\r |
568 | if ((result = spd.getPpi(name)) != null) {\r |
569 | return result;\r |
878ddf1f |
570 | }\r |
571 | }\r |
a29c47e0 |
572 | return null;\r |
878ddf1f |
573 | }\r |
574 | \r |
a29c47e0 |
575 | /**\r |
576 | * return two values: {cName, GuidValue}\r |
577 | */\r |
136adffc |
578 | public static String[] getProtocolGuid(List<PackageIdentification> packages,\r |
892b0e7a |
579 | String name) {\r |
a29c47e0 |
580 | if (packages == null) {\r |
581 | return new String[0];\r |
582 | }\r |
583 | String[] result = null;\r |
136adffc |
584 | Iterator item = packages.iterator();\r |
585 | while (item.hasNext()){\r |
586 | Spd spd = spdTable.get(item.next());\r |
a29c47e0 |
587 | //\r |
588 | // If find one package defined the protocol GUID\r |
589 | //\r |
136adffc |
590 | if ((result = spd.getProtocol(name))!= null){\r |
a29c47e0 |
591 | return result;\r |
592 | }\r |
593 | }\r |
594 | return null;\r |
878ddf1f |
595 | \r |
a29c47e0 |
596 | }\r |
ff225cbb |
597 | \r |
892b0e7a |
598 | public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException {\r |
a29c47e0 |
599 | Iterator iter = platformList.iterator();\r |
600 | while(iter.hasNext()){\r |
601 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r |
602 | if (platformId.getName().equalsIgnoreCase(name)) {\r |
a29c47e0 |
603 | return platformId;\r |
878ddf1f |
604 | }\r |
a29c47e0 |
605 | }\r |
892b0e7a |
606 | throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!");\r |
de4bb9f6 |
607 | }\r |
ff225cbb |
608 | \r |
892b0e7a |
609 | public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException {\r |
de4bb9f6 |
610 | File file = new File(workspaceDir + File.separatorChar + filename);\r |
611 | Iterator iter = platformList.iterator();\r |
612 | while(iter.hasNext()){\r |
613 | PlatformIdentification platformId = (PlatformIdentification)iter.next();\r |
614 | if (platformId.getFpdFile().getPath().equalsIgnoreCase(file.getPath())) {\r |
615 | return platformId;\r |
616 | }\r |
617 | }\r |
892b0e7a |
618 | throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!");\r |
a29c47e0 |
619 | }\r |
ff225cbb |
620 | \r |
892b0e7a |
621 | public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException {\r |
a29c47e0 |
622 | Iterator iter = packageList.iterator();\r |
623 | while(iter.hasNext()){\r |
624 | PackageIdentification packageItem = (PackageIdentification)iter.next();\r |
625 | if (packageItem.equals(packageId)) {\r |
626 | packageId.setName(packageItem.getName());\r |
627 | packageId.setSpdFile(packageItem.getSpdFile());\r |
628 | return packageId;\r |
878ddf1f |
629 | }\r |
630 | }\r |
892b0e7a |
631 | throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r |
a29c47e0 |
632 | }\r |
ff225cbb |
633 | \r |
892b0e7a |
634 | public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException {\r |
a29c47e0 |
635 | PackageIdentification packageId = getPackageForModule(moduleId);\r |
a29c47e0 |
636 | moduleId.setPackage(packageId);\r |
637 | Spd spd = spdTable.get(packageId);\r |
638 | if (spd == null) {\r |
892b0e7a |
639 | throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");\r |
a29c47e0 |
640 | }\r |
641 | Set<ModuleIdentification> modules = spd.getModules();\r |
642 | Iterator<ModuleIdentification> iter = modules.iterator();\r |
643 | while (iter.hasNext()) {\r |
644 | ModuleIdentification item = iter.next();\r |
645 | if (item.equals(moduleId)) {\r |
646 | moduleId.setName(item.getName());\r |
647 | moduleId.setModuleType(item.getModuleType());\r |
648 | moduleId.setMsaFile(item.getMsaFile());\r |
649 | return moduleId;\r |
650 | }\r |
651 | }\r |
892b0e7a |
652 | throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");\r |
a29c47e0 |
653 | }\r |
ff225cbb |
654 | \r |
a29c47e0 |
655 | public synchronized static Set<PackageIdentification> getPackageList(){\r |
656 | return packageList;\r |
657 | }\r |
82516887 |
658 | \r |
659 | /**\r |
660 | BUGBUG: It is a walk around method. If do not clone, can't query info with\r |
661 | XPath correctly. \r |
662 | \r |
663 | @param object XmlObject\r |
664 | @param deep flag for deep clone\r |
665 | @return XmlObject after clone\r |
666 | @throws BuildException parse original XmlObject error. \r |
667 | **/\r |
892b0e7a |
668 | private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException {\r |
a29c47e0 |
669 | if ( object == null) {\r |
670 | return null;\r |
671 | }\r |
672 | XmlObject result = null;\r |
673 | try {\r |
674 | result = XmlObject.Factory.parse(object.getDomNode()\r |
675 | .cloneNode(deep));\r |
892b0e7a |
676 | } catch (XmlException ex) {\r |
677 | EdkException edkException = new EdkException(ex.getMessage());\r |
678 | edkException.setStackTrace(ex.getStackTrace());\r |
679 | throw edkException;\r |
a29c47e0 |
680 | }\r |
681 | return result;\r |
878ddf1f |
682 | }\r |
683 | \r |
4b5f5549 |
684 | ///\r |
685 | /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory\r |
686 | ///\r |
1744b047 |
687 | public synchronized static ToolChainInfo getToolChainInfo() {\r |
a29c47e0 |
688 | if (toolChainInfo == null) {\r |
689 | toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo);\r |
690 | if (toolChainPlatformInfo != null) {\r |
691 | toolChainInfo = toolChainInfo.intersection(toolChainPlatformInfo);\r |
878ddf1f |
692 | }\r |
a29c47e0 |
693 | toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands());\r |
694 | toolChainInfo.normalize();\r |
2eb7d78d |
695 | EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: ");\r |
696 | EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + "");\r |
878ddf1f |
697 | }\r |
a29c47e0 |
698 | return toolChainInfo;\r |
699 | }\r |
700 | \r |
a29c47e0 |
701 | public static void setPlatformToolChainFamilyOption(ToolChainMap map) {\r |
702 | platformToolChainFamilyOption = map;\r |
878ddf1f |
703 | }\r |
704 | \r |
a29c47e0 |
705 | public static void setPlatformToolChainOption(ToolChainMap map) {\r |
706 | platformToolChainOption = map;\r |
707 | }\r |
878ddf1f |
708 | \r |
a29c47e0 |
709 | public static void addModuleToolChainOption(FpdModuleIdentification fpdModuleId,\r |
710 | ToolChainMap toolChainOption) {\r |
711 | moduleToolChainOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
712 | }\r |
713 | \r |
a29c47e0 |
714 | public static void addModuleToolChainFamilyOption(FpdModuleIdentification fpdModuleId,\r |
715 | ToolChainMap toolChainOption) {\r |
716 | moduleToolChainFamilyOption.put(fpdModuleId, toolChainOption);\r |
878ddf1f |
717 | }\r |
718 | \r |
c773bec0 |
719 | public static boolean isCommandSet(String target, String toolchain, String arch) {\r |
720 | String[] commands = getToolChainInfo().getCommands();\r |
721 | \r |
722 | for (int i = 0; i < commands.length; ++i) {\r |
a10c0400 |
723 | String cmdName = toolsDef.getConfig().get(new String[] {target, toolchain, arch, commands[i], ToolChainAttribute.NAME.toString()});\r |
724 | if (cmdName != null && cmdName.length() != 0) {\r |
c773bec0 |
725 | return true;\r |
726 | }\r |
727 | }\r |
728 | \r |
729 | return false;\r |
730 | }\r |
731 | \r |
2f2c367a |
732 | public synchronized static String getCommandSetting(String[] commandDescription, FpdModuleIdentification fpdModuleId) throws EdkException {\r |
a29c47e0 |
733 | ToolChainKey toolChainKey = new ToolChainKey(commandDescription);\r |
ff225cbb |
734 | ToolChainMap toolChainConfig = toolsDef.getConfig();\r |
a29c47e0 |
735 | String setting = null;\r |
736 | \r |
8c84e1b1 |
737 | //\r |
738 | // Default in tools_def.txt\r |
739 | // \r |
0923e8b3 |
740 | setting = toolChainConfig.get(toolChainKey);\r |
741 | if (setting == null) {\r |
8c84e1b1 |
742 | setting = "";\r |
0923e8b3 |
743 | }\r |
a29c47e0 |
744 | if (!commandDescription[ToolChainElement.ATTRIBUTE.value].equals(ToolChainAttribute.FLAGS.toString())) {\r |
a29c47e0 |
745 | return setting;\r |
878ddf1f |
746 | }\r |
878ddf1f |
747 | \r |
a29c47e0 |
748 | //\r |
8c84e1b1 |
749 | // tool's option can be in .fpd and/or .msa file\r |
750 | //\r |
751 | String optionString;\r |
752 | ToolChainMap option = null;\r |
753 | ToolChainKey toolChainFamilyKey = new ToolChainKey(commandDescription);\r |
0923e8b3 |
754 | \r |
8c84e1b1 |
755 | toolChainFamilyKey.setKey(ToolChainAttribute.FAMILY.toString(), ToolChainElement.ATTRIBUTE.value);\r |
756 | String family = toolChainConfig.get(toolChainFamilyKey);\r |
757 | toolChainFamilyKey.setKey(family, ToolChainElement.TOOLCHAIN.value);\r |
758 | toolChainFamilyKey.setKey(ToolChainAttribute.FLAGS.toString(), ToolChainElement.ATTRIBUTE.value);\r |
0923e8b3 |
759 | \r |
0923e8b3 |
760 | //\r |
8c84e1b1 |
761 | // Platform's tool chain family option\r |
0923e8b3 |
762 | //\r |
8c84e1b1 |
763 | optionString = platformToolChainFamilyOption.get(toolChainFamilyKey);\r |
764 | if (optionString != null) {\r |
765 | setting += (" " + optionString);\r |
878ddf1f |
766 | }\r |
878ddf1f |
767 | \r |
a29c47e0 |
768 | //\r |
8c84e1b1 |
769 | // Platform's tool chain tag option\r |
a29c47e0 |
770 | //\r |
8c84e1b1 |
771 | optionString = platformToolChainOption.get(toolChainKey);\r |
772 | if (optionString != null) {\r |
773 | Matcher matcher = flagPattern.matcher(optionString + " ");\r |
774 | while (matcher.find()) {\r |
775 | setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));\r |
776 | }\r |
777 | }\r |
a29c47e0 |
778 | \r |
8c84e1b1 |
779 | //\r |
780 | // Module's tool chain family option\r |
781 | //\r |
782 | option = moduleToolChainFamilyOption.get(fpdModuleId);\r |
783 | if (option != null && (optionString = option.get(toolChainFamilyKey)) != null) {\r |
784 | Matcher matcher = flagPattern.matcher(optionString + " ");\r |
785 | while (matcher.find()) {\r |
786 | setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));\r |
a29c47e0 |
787 | }\r |
788 | }\r |
789 | \r |
8c84e1b1 |
790 | //\r |
791 | // Module's tool chain tag option\r |
792 | //\r |
793 | option = moduleToolChainOption.get(fpdModuleId);\r |
794 | if (option != null && (optionString = option.get(toolChainKey)) != null) {\r |
795 | Matcher matcher = flagPattern.matcher(optionString + " ");\r |
796 | while (matcher.find()) {\r |
797 | setting += (" " + optionString.substring(matcher.start(1), matcher.end(1)));\r |
798 | }\r |
a29c47e0 |
799 | }\r |
800 | \r |
801 | return setting;\r |
802 | }\r |
ff225cbb |
803 | \r |
a29c47e0 |
804 | public static void setToolChainEnvInfo(ToolChainInfo envInfo) {\r |
805 | toolChainEnvInfo = envInfo;\r |
806 | }\r |
807 | public static void setToolChainPlatformInfo(ToolChainInfo platformInfo) {\r |
808 | toolChainPlatformInfo = platformInfo;\r |
878ddf1f |
809 | }\r |
a29c47e0 |
810 | \r |
811 | //\r |
812 | // for PCD\r |
813 | //\r |
136adffc |
814 | public synchronized static MemoryDatabaseManager getPCDMemoryDBManager() {\r |
815 | return pcdDbManager;\r |
816 | }\r |
a29c47e0 |
817 | \r |
818 | //\r |
136adffc |
819 | // For PCD get tokenSpaceGUid\r |
a29c47e0 |
820 | //\r |
20c5c53f |
821 | public synchronized static String getGuidInfoFromCname(String cName){\r |
822 | String cNameGuid = null;\r |
136adffc |
823 | String guid = null;\r |
824 | Set set = spdTable.keySet();\r |
825 | Iterator iter = set.iterator();\r |
548ce97a |
826 | \r |
827 | if (iter == null) {\r |
828 | return null;\r |
829 | }\r |
830 | \r |
136adffc |
831 | while (iter.hasNext()){\r |
832 | Spd spd = (Spd) spdTable.get(iter.next());\r |
833 | guid = spd.getGuidFromCname(cName);\r |
834 | if (guid != null){\r |
20c5c53f |
835 | cNameGuid = guid;\r |
136adffc |
836 | break;\r |
837 | }\r |
838 | }\r |
839 | return cNameGuid;\r |
840 | }\r |
a29c47e0 |
841 | \r |
842 | //\r |
843 | // For PCD\r |
844 | //\r |
ff225cbb |
845 | public synchronized static Map<FpdModuleIdentification, XmlObject>\r |
eece174a |
846 | getFpdModuleSaXmlObject(String xmlObjectName) {\r |
136adffc |
847 | Set<FpdModuleIdentification> fpdModuleSASet = fpdModuleSA.keySet();\r |
848 | Iterator item = fpdModuleSASet.iterator();\r |
ff225cbb |
849 | \r |
136adffc |
850 | \r |
851 | Map<FpdModuleIdentification, XmlObject> SAPcdBuildDef = new HashMap<FpdModuleIdentification, XmlObject>();\r |
852 | Map<String, XmlObject> SANode = new HashMap<String, XmlObject>();\r |
853 | FpdModuleIdentification moduleId;\r |
854 | while (item.hasNext()) {\r |
ff225cbb |
855 | \r |
136adffc |
856 | moduleId = (FpdModuleIdentification) item.next();\r |
857 | SANode = fpdModuleSA.get(moduleId);\r |
858 | try{\r |
859 | if (SANode.get(xmlObjectName)!= null){\r |
860 | SAPcdBuildDef.put(moduleId,\r |
eece174a |
861 | (XmlObject) SANode.get(xmlObjectName));\r |
136adffc |
862 | \r |
863 | }\r |
136adffc |
864 | } catch (Exception e){\r |
865 | EdkLog.log(EdkLog.EDK_INFO, e.getMessage());\r |
866 | }\r |
eece174a |
867 | }\r |
136adffc |
868 | return SAPcdBuildDef;\r |
869 | }\r |
eece174a |
870 | \r |
871 | public synchronized static Map<FpdModuleIdentification,XmlObject> getFpdPcdBuildDefinitions() {\r |
872 | Map<FpdModuleIdentification,XmlObject> pcdBuildDef = getFpdModuleSaXmlObject ("PcdBuildDefinition");\r |
873 | \r |
874 | return pcdBuildDef;\r |
875 | }\r |
878ddf1f |
876 | }\r |
a29c47e0 |
877 | \r |