]>
Commit | Line | Data |
---|---|---|
af98370e | 1 | /** @file\r |
2 | PlatformPcdPreprocessActionForBuilding class.\r | |
3 | \r | |
4 | This action class is to collect PCD information from MSA, SPD, FPD xml file.\r | |
5 | This class will be used for wizard and build tools, So it can *not* inherit\r | |
6 | from buildAction or wizardAction.\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 | **/\r | |
18 | package org.tianocore.build.pcd.action;\r | |
19 | \r | |
20 | import java.io.File;\r | |
21 | import java.io.IOException;\r | |
af98370e | 22 | import java.util.ArrayList;\r |
23 | import java.util.Iterator;\r | |
24 | import java.util.List;\r | |
25 | import java.util.Map;\r | |
26 | \r | |
27 | import org.apache.xmlbeans.XmlException;\r | |
28 | import org.apache.xmlbeans.XmlObject;\r | |
29 | import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r | |
e55d8a3c | 30 | import org.tianocore.PcdBuildDefinitionDocument;\r |
af98370e | 31 | import org.tianocore.PlatformSurfaceAreaDocument;\r |
e55d8a3c | 32 | import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;\r |
af98370e | 33 | import org.tianocore.build.global.GlobalData;\r |
34 | import org.tianocore.build.id.FpdModuleIdentification;\r | |
e55d8a3c | 35 | import org.tianocore.pcd.action.PlatformPcdPreprocessAction;\r |
af98370e | 36 | import org.tianocore.pcd.entity.MemoryDatabaseManager;\r |
e55d8a3c | 37 | import org.tianocore.pcd.entity.ModulePcdInfoFromFpd;\r |
af98370e | 38 | import org.tianocore.pcd.entity.Token;\r |
39 | import org.tianocore.pcd.entity.UsageIdentification;\r | |
40 | import org.tianocore.pcd.exception.EntityException;\r | |
8b7bd455 | 41 | import org.tianocore.pcd.exception.PlatformPcdPreprocessException;\r |
af98370e | 42 | \r |
43 | /**\r | |
44 | This action class is to collect PCD information from MSA, SPD, FPD xml file.\r | |
45 | This class will be used for wizard and build tools, So it can *not* inherit\r | |
46 | from buildAction or UIAction.\r | |
47 | **/\r | |
48 | public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction {\r | |
af98370e | 49 | ///\r |
11eb278a | 50 | /// FPD file path.\r |
af98370e | 51 | ///\r |
52 | private String fpdFilePath;\r | |
53 | \r | |
54 | ///\r | |
55 | /// Message level for CollectPCDAction.\r | |
56 | ///\r | |
57 | private int originalMessageLevel;\r | |
58 | \r | |
59 | ///\r | |
60 | /// Cache the fpd docment instance for private usage.\r | |
61 | ///\r | |
62 | private PlatformSurfaceAreaDocument fpdDocInstance;\r | |
63 | \r | |
af98370e | 64 | /**\r |
65 | Set FPDFileName parameter for this action class.\r | |
66 | \r | |
67 | @param fpdFilePath fpd file path\r | |
68 | **/\r | |
69 | public void setFPDFilePath(String fpdFilePath) {\r | |
70 | this.fpdFilePath = fpdFilePath;\r | |
71 | }\r | |
72 | \r | |
73 | /**\r | |
74 | Common function interface for outer.\r | |
75 | \r | |
11eb278a | 76 | @param fpdFilePath The fpd file path of current build or processing.\r |
af98370e | 77 | \r |
8b7bd455 | 78 | @throws PlatformPreprocessBuildException \r |
79 | The exception of this function. Because it can *not* be predict\r | |
80 | where the action class will be used. So only Exception can be throw.\r | |
af98370e | 81 | \r |
82 | **/\r | |
e8c0c170 | 83 | public void perform(String fpdFilePath) \r |
8b7bd455 | 84 | throws PlatformPcdPreprocessBuildException {\r |
11eb278a | 85 | this.fpdFilePath = fpdFilePath;\r |
af98370e | 86 | checkParameter();\r |
87 | execute();\r | |
af98370e | 88 | }\r |
89 | \r | |
90 | /**\r | |
91 | Core execution function for this action class.\r | |
92 | \r | |
93 | This function work flows will be:\r | |
94 | 1) Collect and prepocess PCD information from FPD file, all PCD\r | |
95 | information will be stored into memory database.\r | |
96 | 2) Generate 3 strings for\r | |
97 | a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r | |
98 | b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r | |
99 | c) DXE PCD Database (C structure) for PCD Service DXE.\r | |
100 | \r | |
101 | \r | |
102 | @throws EntityException Exception indicate failed to execute this action.\r | |
103 | \r | |
104 | **/\r | |
8b7bd455 | 105 | public void execute() throws PlatformPcdPreprocessBuildException {\r |
391dbbb1 | 106 | String errorMessageHeader = "Failed to initialize the Pcd memory database because: ";\r |
e55d8a3c | 107 | String errorsForPreprocess = null;\r |
108 | \r | |
af98370e | 109 | //\r |
110 | // Get memoryDatabaseManager instance from GlobalData.\r | |
8b7bd455 | 111 | // The memoryDatabaseManager should be initialized as static variable\r |
112 | // in some Pre-process class.\r | |
af98370e | 113 | //\r |
8b7bd455 | 114 | setPcdDbManager(GlobalData.getPCDMemoryDBManager());\r |
af98370e | 115 | \r |
116 | //\r | |
117 | // Collect all PCD information defined in FPD file.\r | |
118 | // Evenry token defind in FPD will be created as an token into\r | |
119 | // memory database.\r | |
120 | //\r | |
8b7bd455 | 121 | try {\r |
122 | initPcdMemoryDbWithPlatformInfo();\r | |
123 | } catch (PlatformPcdPreprocessException exp) {\r | |
124 | throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage());\r | |
125 | }\r | |
e55d8a3c | 126 | errorsForPreprocess = this.getErrorString();\r |
127 | if (errorsForPreprocess != null) {\r | |
128 | throw new PlatformPcdPreprocessBuildException(errorMessageHeader + "\r\n" + errorsForPreprocess);\r | |
129 | }\r | |
af98370e | 130 | \r |
131 | //\r | |
132 | // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r | |
133 | //\r | |
8b7bd455 | 134 | try {\r |
135 | genPcdDatabaseSourceCode ();\r | |
136 | } catch (EntityException exp) {\r | |
11eb278a | 137 | throw new PlatformPcdPreprocessBuildException(errorMessageHeader + "\r\n" + exp.getMessage());\r |
8b7bd455 | 138 | }\r |
af98370e | 139 | }\r |
140 | \r | |
141 | /**\r | |
142 | Override function: implementate the method of get Guid string information from SPD file.\r | |
143 | \r | |
144 | @param guidCName Guid CName string.\r | |
145 | \r | |
20c5c53f | 146 | @return String Guid information from SPD file.\r |
8b7bd455 | 147 | @throws PlatformPcdPreprocessException\r |
148 | Fail to get Guid information from SPD file.\r | |
af98370e | 149 | **/\r |
20c5c53f | 150 | public String getGuidInfoFromSpd(String guidCName) throws PlatformPcdPreprocessException {\r |
151 | String tokenSpaceStrRet = null;\r | |
af98370e | 152 | try {\r |
153 | tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName);\r | |
154 | } catch ( Exception e ) {\r | |
391dbbb1 | 155 | throw new PlatformPcdPreprocessException ("Failed to get Guid CName " + guidCName + " from the SPD file!");\r |
af98370e | 156 | }\r |
157 | return tokenSpaceStrRet;\r | |
158 | }\r | |
159 | \r | |
160 | /**\r | |
161 | This function generates source code for PCD Database.\r | |
162 | \r | |
af98370e | 163 | @throws EntityException If the token does *not* exist in memory database.\r |
164 | \r | |
165 | **/\r | |
166 | private void genPcdDatabaseSourceCode()\r | |
167 | throws EntityException {\r | |
168 | String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r | |
169 | \r | |
170 | ArrayList<Token> alPei = new ArrayList<Token> ();\r | |
171 | ArrayList<Token> alDxe = new ArrayList<Token> ();\r | |
172 | \r | |
173 | getPcdDbManager().getTwoPhaseDynamicRecordArray(alPei, alDxe);\r | |
174 | PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r | |
175 | pcdPeiDatabase.genCode();\r | |
176 | MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() +\r | |
177 | PcdDatabase.getPcdPeiDatabaseDefinitions();\r | |
178 | MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r | |
179 | \r | |
180 | PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r | |
181 | pcdDxeDatabase.genCode();\r | |
182 | MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() +\r | |
183 | PcdDatabase.getPcdDxeDatabaseDefinitions();\r | |
184 | MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r | |
185 | }\r | |
186 | \r | |
187 | /**\r | |
188 | Override function: Get component array from FPD.\r | |
189 | \r | |
190 | This function maybe provided by some Global class.\r | |
191 | \r | |
8b7bd455 | 192 | @return List<ModuleInfo> the component array.\r |
193 | @throws PlatformPcdPreprocessException get all modules in <ModuleSA> in FPD file.\r | |
af98370e | 194 | \r |
8b7bd455 | 195 | **/\r |
af98370e | 196 | public List<ModulePcdInfoFromFpd> getComponentsFromFpd()\r |
8b7bd455 | 197 | throws PlatformPcdPreprocessException {\r |
af98370e | 198 | List<ModulePcdInfoFromFpd> allModules = new ArrayList<ModulePcdInfoFromFpd>();\r |
199 | Map<FpdModuleIdentification, XmlObject> pcdBuildDefinitions = null;\r | |
200 | UsageIdentification usageId = null;\r | |
201 | \r | |
202 | pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r | |
203 | if (pcdBuildDefinitions == null) {\r | |
204 | return null;\r | |
205 | }\r | |
206 | \r | |
207 | //\r | |
208 | // Loop map to retrieve all PCD build definition and Module id\r | |
209 | //\r | |
210 | Iterator item = pcdBuildDefinitions.keySet().iterator();\r | |
211 | while (item.hasNext()){\r | |
212 | FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r | |
213 | usageId = new UsageIdentification(id.getModule().getName(),\r | |
214 | id.getModule().getGuid(),\r | |
215 | id.getModule().getPackage().getName(),\r | |
216 | id.getModule().getPackage().getGuid(),\r | |
217 | id.getArch(),\r | |
218 | id.getModule().getVersion(),\r | |
219 | id.getModule().getModuleType());\r | |
e55d8a3c | 220 | allModules.add(\r |
221 | new ModulePcdInfoFromFpd(\r | |
222 | usageId, \r | |
223 | ((PcdBuildDefinitionDocument)pcdBuildDefinitions.get(id)).getPcdBuildDefinition()));\r | |
af98370e | 224 | }\r |
225 | return allModules;\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | Override function: Verify the datum value according its datum size and datum type, this\r | |
230 | function maybe moved to FPD verification tools in future.\r | |
231 | \r | |
8b7bd455 | 232 | @param cName The token name\r |
233 | @param moduleName The module who use this PCD token\r | |
234 | @param datum The PCD's datum\r | |
235 | @param datumType The PCD's datum type\r | |
236 | @param maxDatumSize The max size for PCD's Datum.\r | |
af98370e | 237 | \r |
8b7bd455 | 238 | @return String exception strings.\r |
af98370e | 239 | */\r |
af98370e | 240 | public String verifyDatum(String cName,\r |
241 | String moduleName,\r | |
242 | String datum,\r | |
243 | Token.DATUM_TYPE datumType,\r | |
244 | int maxDatumSize) {\r | |
4d1939b8 | 245 | //\r |
246 | // In building system, datum should not be checked, the checking work\r | |
247 | // should be done by wizard tools or PCD verification tools.\r | |
248 | // \r | |
af98370e | 249 | return null;\r |
250 | }\r | |
251 | \r | |
252 | /**\r | |
253 | Override function: Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r | |
254 | \r | |
255 | This function should be implemented in GlobalData in future.\r | |
256 | \r | |
257 | @param token The token instance which has hold module's PCD information\r | |
258 | @param moduleName The name of module who will use this Dynamic PCD.\r | |
259 | \r | |
260 | @return DynamicPcdBuildDefinitions.PcdBuildData\r | |
261 | **/\r | |
262 | public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token token,\r | |
263 | String moduleName)\r | |
8b7bd455 | 264 | throws PlatformPcdPreprocessException {\r |
af98370e | 265 | int index = 0;\r |
266 | String exceptionString = null;\r | |
267 | String dynamicPrimaryKey = null;\r | |
268 | DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r | |
269 | List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray = null;\r | |
20c5c53f | 270 | String tokenSpaceStrRet = null;\r |
af98370e | 271 | \r |
272 | //\r | |
273 | // If FPD document is not be opened, open and initialize it.\r | |
274 | // BUGBUG: The code should be moved into GlobalData in future.\r | |
275 | //\r | |
276 | if (fpdDocInstance == null) {\r | |
277 | try {\r | |
278 | fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r | |
279 | } catch(IOException ioE) {\r | |
8b7bd455 | 280 | throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r |
af98370e | 281 | } catch(XmlException xmlE) {\r |
8b7bd455 | 282 | throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r |
af98370e | 283 | }\r |
284 | }\r | |
285 | \r | |
286 | dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r | |
287 | if (dynamicPcdBuildDefinitions == null) {\r | |
391dbbb1 | 288 | exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> elements in FPD file but there are Dynamic type "+\r |
289 | "PCD entries %s in module %s!",\r | |
af98370e | 290 | token.cName,\r |
291 | moduleName);\r | |
e55d8a3c | 292 | putError(exceptionString);\r |
293 | return null;\r | |
af98370e | 294 | }\r |
295 | \r | |
296 | dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r | |
297 | for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r | |
20c5c53f | 298 | tokenSpaceStrRet = getGuidInfoFromSpd(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r |
af98370e | 299 | \r |
300 | if (tokenSpaceStrRet == null) {\r | |
e55d8a3c | 301 | exceptionString = "Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName();\r |
302 | putError(exceptionString);\r | |
303 | continue;\r | |
af98370e | 304 | }\r |
305 | \r | |
306 | dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r | |
20c5c53f | 307 | tokenSpaceStrRet);\r |
11eb278a | 308 | if (dynamicPrimaryKey.equals(token.getPrimaryKeyString())) {\r |
af98370e | 309 | return dynamicPcdBuildDataArray.get(index);\r |
310 | }\r | |
311 | }\r | |
312 | \r | |
313 | return null;\r | |
314 | }\r | |
315 | \r | |
316 | /**\r | |
317 | Override function: get all <DynamicPcdBuildDefinition> from FPD file.\r | |
318 | \r | |
8b7bd455 | 319 | @return List<DynamicPcdBuildDefinitions.PcdBuildData> All DYNAMIC PCD list in <DynamicPcdBuildDefinitions> in FPD file.\r |
320 | @throws PlatformPcdPreprocessBuildException Failure to get dynamic information list.\r | |
321 | \r | |
af98370e | 322 | **/\r |
323 | public List<DynamicPcdBuildDefinitions.PcdBuildData>\r | |
324 | getAllDynamicPcdInfoFromFpd()\r | |
8b7bd455 | 325 | throws PlatformPcdPreprocessException {\r |
af98370e | 326 | DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r |
327 | \r | |
328 | //\r | |
329 | // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r | |
330 | // BUGBUG: the function should be move GlobalData in furture.\r | |
331 | //\r | |
332 | if (fpdDocInstance == null) {\r | |
333 | try {\r | |
334 | fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r | |
335 | } catch(IOException ioE) {\r | |
8b7bd455 | 336 | throw new PlatformPcdPreprocessException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r |
af98370e | 337 | } catch(XmlException xmlE) {\r |
8b7bd455 | 338 | throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r |
af98370e | 339 | }\r |
340 | }\r | |
341 | \r | |
342 | dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r | |
343 | if (dynamicPcdBuildDefinitions == null) {\r | |
344 | return null;\r | |
345 | }\r | |
346 | \r | |
347 | return dynamicPcdBuildDefinitions.getPcdBuildDataList();\r | |
348 | }\r | |
349 | \r | |
350 | /**\r | |
351 | check parameter for this action.\r | |
352 | \r | |
8b7bd455 | 353 | @throws PlatformPcdPreprocessBuildException Bad parameter.\r |
af98370e | 354 | **/\r |
8b7bd455 | 355 | private void checkParameter() throws PlatformPcdPreprocessBuildException {\r |
af98370e | 356 | File file = null;\r |
357 | \r | |
8b7bd455 | 358 | if (fpdFilePath == null) {\r |
11eb278a | 359 | throw new PlatformPcdPreprocessBuildException("FPDFileName should be empty for CollectPCDAtion!");\r |
af98370e | 360 | }\r |
361 | \r | |
8b7bd455 | 362 | if (fpdFilePath.length() == 0) {\r |
11eb278a | 363 | throw new PlatformPcdPreprocessBuildException("FPDFileName should be empty for CollectPCDAtion!");\r |
af98370e | 364 | }\r |
365 | \r | |
366 | file = new File(fpdFilePath);\r | |
367 | \r | |
368 | if(!file.exists()) {\r | |
8b7bd455 | 369 | throw new PlatformPcdPreprocessBuildException("FPD File " + fpdFilePath + " does not exist!");\r |
af98370e | 370 | }\r |
371 | }\r | |
af98370e | 372 | }\r |