]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | PCDAutoGenAction class.\r | |
3 | \r | |
4 | This class is to manage how to generate the PCD information into Autogen.c and\r | |
5 | Autogen.h.\r | |
af98370e | 6 | \r |
878ddf1f | 7 | Copyright (c) 2006, Intel Corporation\r |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
af98370e | 12 | \r |
878ddf1f | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | package org.tianocore.build.pcd.action;\r | |
18 | \r | |
11e7b0f6 | 19 | import java.util.ArrayList;\r |
878ddf1f | 20 | import java.util.List;\r |
11e7b0f6 | 21 | import java.util.regex.Matcher;\r |
22 | import java.util.regex.Pattern;\r | |
878ddf1f | 23 | \r |
2eb7d78d | 24 | import org.tianocore.build.FrameworkBuildTask;\r |
5f907e4a | 25 | import org.tianocore.build.autogen.CommonDefinition;\r |
878ddf1f | 26 | import org.tianocore.build.global.GlobalData;\r |
eece174a | 27 | import org.tianocore.build.id.ModuleIdentification;\r |
e8c0c170 | 28 | import org.tianocore.common.logger.EdkLog;\r |
5f907e4a | 29 | import org.tianocore.pcd.action.BuildAction;\r |
d14ebb43 | 30 | import org.tianocore.pcd.entity.MemoryDatabaseManager;\r |
31 | import org.tianocore.pcd.entity.Token;\r | |
5f907e4a | 32 | import org.tianocore.pcd.entity.UsageIdentification;\r |
d14ebb43 | 33 | import org.tianocore.pcd.entity.UsageInstance;\r |
34 | import org.tianocore.pcd.exception.BuildActionException;\r | |
878ddf1f | 35 | \r |
11eb278a | 36 | /**\r |
37 | This class is to manage how to generate the PCD information into Autogen.c\r | |
38 | and Autogen.h.\r | |
878ddf1f | 39 | **/\r |
40 | public class PCDAutoGenAction extends BuildAction {\r | |
41 | ///\r | |
42 | /// The reference of DBManager in GlobalData class.\r | |
43 | ///\r | |
44 | private MemoryDatabaseManager dbManager;\r | |
af98370e | 45 | \r |
878ddf1f | 46 | ///\r |
d14ebb43 | 47 | /// The identification for a UsageInstance.\r |
8840ad58 | 48 | ///\r |
af98370e | 49 | private UsageIdentification usageId;\r |
50 | \r | |
8840ad58 | 51 | ///\r |
8840ad58 | 52 | /// Whether current autogen is for building library used by current module.\r |
af98370e | 53 | ///\r |
8840ad58 | 54 | private boolean isBuildUsedLibrary;\r |
af98370e | 55 | \r |
5f907e4a | 56 | ///\r |
57 | /// One of PEI_PCD_DRIVER, DXE_PCD_DRIVER, NOT_PCD_DRIVER \r | |
58 | /// \r | |
59 | private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r | |
60 | \r | |
8840ad58 | 61 | ///\r |
878ddf1f | 62 | /// The generated string for header file.\r |
63 | ///\r | |
64 | private String hAutoGenString;\r | |
af98370e | 65 | \r |
878ddf1f | 66 | ///\r |
67 | /// The generated string for C code file.\r | |
68 | ///\r | |
ad82307c | 69 | private String cAutoGenString;\r |
af98370e | 70 | \r |
ad82307c | 71 | ///\r |
72 | /// The name array of <PcdCoded> in a module.\r | |
af98370e | 73 | ///\r |
eece174a | 74 | private String[] pcdNameArrayInMsa;\r |
af98370e | 75 | \r |
2eb7d78d | 76 | private UsageIdentification parentId = null;\r |
878ddf1f | 77 | /**\r |
eece174a | 78 | Set parameter moduleId\r |
af98370e | 79 | \r |
878ddf1f | 80 | @param moduleName the module name parameter.\r |
81 | **/\r | |
d14ebb43 | 82 | public void setUsageId(UsageIdentification usageId) {\r |
83 | this.usageId = usageId;\r | |
8840ad58 | 84 | }\r |
85 | \r | |
5f907e4a | 86 | /**\r |
87 | Set paramter pcdDriverType\r | |
88 | \r | |
89 | @param pcdDriverType the driver type for PCD\r | |
90 | **/\r | |
91 | public void setPcdDriverType(CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {\r | |
92 | this.pcdDriverType = pcdDriverType;\r | |
93 | }\r | |
878ddf1f | 94 | /**\r |
ad82307c | 95 | set isBuildUsedLibrary parameter.\r |
af98370e | 96 | \r |
ad82307c | 97 | @param isBuildUsedLibrary\r |
eece174a | 98 | **/\r |
8840ad58 | 99 | public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r |
100 | this.isBuildUsedLibrary = isBuildUsedLibrary;\r | |
101 | }\r | |
eece174a | 102 | \r |
ad82307c | 103 | /**\r |
eece174a | 104 | set pcdNameArrayInMsa parameter.\r |
af98370e | 105 | \r |
eece174a | 106 | @param pcdNameArrayInMsa\r |
ad82307c | 107 | */\r |
eece174a | 108 | public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r |
109 | this.pcdNameArrayInMsa = pcdNameArrayInMsa;\r | |
ad82307c | 110 | }\r |
8840ad58 | 111 | \r |
878ddf1f | 112 | /**\r |
113 | Get the output of generated string for header file.\r | |
af98370e | 114 | \r |
878ddf1f | 115 | @return the string of header file for PCD\r |
116 | **/\r | |
11eb278a | 117 | public String getHAutoGenString() {\r |
878ddf1f | 118 | return hAutoGenString;\r |
119 | }\r | |
120 | \r | |
121 | /**\r | |
122 | Get the output of generated string for C Code file.\r | |
af98370e | 123 | \r |
878ddf1f | 124 | @return the string of C code file for PCD\r |
125 | **/\r | |
11eb278a | 126 | public String getCAutoGenString() {\r |
878ddf1f | 127 | return cAutoGenString;\r |
128 | }\r | |
129 | \r | |
af98370e | 130 | \r |
878ddf1f | 131 | /**\r |
eece174a | 132 | Construct function\r |
136adffc | 133 | \r |
eece174a | 134 | This function mainly initialize some member variable.\r |
af98370e | 135 | \r |
eece174a | 136 | @param moduleId the identification for module\r |
137 | @param arch the architecture for module\r | |
138 | @param isBuildUsedLibary Is the current module library.\r | |
139 | @param pcdNameArrayInMsa the pcd name array got from MSA file.\r | |
5f907e4a | 140 | @param pcdDriverType one of PEI_PCD_DRIVER, DXE_PCD_DRIVER,\r |
141 | NOT_PCD_DRIVER\r | |
eece174a | 142 | **/\r |
af98370e | 143 | public PCDAutoGenAction(ModuleIdentification moduleId,\r |
eece174a | 144 | String arch,\r |
145 | boolean isBuildUsedLibrary,\r | |
5f907e4a | 146 | String[] pcdNameArrayInMsa,\r |
2eb7d78d | 147 | CommonDefinition.PCD_DRIVER_TYPE pcdDriverType,\r |
148 | ModuleIdentification parentId) {\r | |
eece174a | 149 | dbManager = null;\r |
150 | hAutoGenString = "";\r | |
151 | cAutoGenString = "";\r | |
152 | \r | |
af98370e | 153 | setUsageId(new UsageIdentification(moduleId.getName(),\r |
154 | moduleId.getGuid(),\r | |
155 | moduleId.getPackage().getName(),\r | |
156 | moduleId.getPackage().getGuid(),\r | |
157 | arch,\r | |
158 | moduleId.getVersion(),\r | |
159 | moduleId.getModuleType()));\r | |
2eb7d78d | 160 | if (parentId != null) {\r |
161 | this.parentId = new UsageIdentification(parentId.getName(),\r | |
162 | parentId.getGuid(),\r | |
163 | parentId.getPackage().getName(),\r | |
164 | parentId.getPackage().getGuid(),\r | |
165 | arch,\r | |
166 | parentId.getVersion(),\r | |
167 | parentId.getModuleType());\r | |
168 | }\r | |
eece174a | 169 | setIsBuildUsedLibrary(isBuildUsedLibrary);\r |
170 | setPcdNameArrayInMsa(pcdNameArrayInMsa);\r | |
5f907e4a | 171 | setPcdDriverType(pcdDriverType);\r |
eece174a | 172 | }\r |
173 | \r | |
878ddf1f | 174 | /**\r |
8b7bd455 | 175 | Override function: check the parameter for action class.\r |
af98370e | 176 | \r |
878ddf1f | 177 | @throws BuildActionException Bad parameter.\r |
178 | **/\r | |
af98370e | 179 | public void checkParameter() {\r |
878ddf1f | 180 | }\r |
181 | \r | |
182 | /**\r | |
183 | Core execution function for this action class.\r | |
af98370e | 184 | \r |
878ddf1f | 185 | All PCD information of this module comes from memory dabase. The collection\r |
186 | work should be done before this action execution.\r | |
af98370e | 187 | Currently, we should generated all PCD information(maybe all dynamic) as array\r |
188 | in Pei emulated driver for simulating PCD runtime database.\r | |
189 | \r | |
878ddf1f | 190 | @throws BuildActionException Failed to execute this aciton class.\r |
191 | **/\r | |
af98370e | 192 | public void performAction() {\r |
e8c0c170 | 193 | EdkLog.log(EdkLog.EDK_DEBUG, "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r |
845fdeba | 194 | \r |
195 | dbManager = GlobalData.getPCDMemoryDBManager();\r | |
196 | \r | |
197 | if(dbManager.getDBSize() == 0) {\r | |
8840ad58 | 198 | return;\r |
845fdeba | 199 | }\r |
200 | \r | |
e8c0c170 | 201 | EdkLog.log(EdkLog.EDK_DEBUG, "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens.");\r |
878ddf1f | 202 | \r |
8840ad58 | 203 | generateAutogenForModule();\r |
878ddf1f | 204 | }\r |
205 | \r | |
206 | /**\r | |
207 | Generate the autogen string for a common module.\r | |
af98370e | 208 | \r |
878ddf1f | 209 | All PCD information of this module comes from memory dabase. The collection\r |
210 | work should be done before this action execution.\r | |
211 | **/\r | |
212 | private void generateAutogenForModule()\r | |
213 | {\r | |
ad82307c | 214 | int index, index2;\r |
215 | List<UsageInstance> usageInstanceArray, usageContext;\r | |
11e7b0f6 | 216 | String[] guidStringArray = null;\r |
217 | String guidStringCName = null;\r | |
218 | String guidString = null;\r | |
d14ebb43 | 219 | String moduleName = usageId.moduleName;\r |
11e7b0f6 | 220 | UsageInstance usageInstance = null;\r |
a1eb6401 | 221 | boolean found = false;\r |
878ddf1f | 222 | \r |
a1eb6401 | 223 | usageInstanceArray = null;\r |
2eb7d78d | 224 | \r |
225 | if (FrameworkBuildTask.multithread) {\r | |
226 | if (parentId == null) {\r | |
b6297711 | 227 | usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);\r |
2eb7d78d | 228 | } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r |
229 | usageContext = dbManager.getUsageInstanceArrayById(parentId);\r | |
ad82307c | 230 | //\r |
2eb7d78d | 231 | // For building library package, although all module are library, but PCD entries of\r |
232 | // these library should be used to autogen.\r | |
af98370e | 233 | //\r |
2eb7d78d | 234 | if (usageContext == null) {\r |
235 | usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);\r | |
236 | } else {\r | |
237 | usageInstanceArray = new ArrayList<UsageInstance>();\r | |
238 | \r | |
239 | //\r | |
240 | // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r | |
241 | // <ModuleSA> in FPD file.\r | |
242 | //\r | |
243 | for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r | |
244 | found = false;\r | |
245 | for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r | |
246 | if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r | |
247 | usageInstanceArray.add(usageContext.get(index2));\r | |
248 | found = true;\r | |
249 | break;\r | |
250 | }\r | |
ad82307c | 251 | }\r |
a1eb6401 | 252 | \r |
2eb7d78d | 253 | if (!found) {\r |
254 | //\r | |
255 | // All library's PCD should instanted in module's <ModuleSA> who\r | |
256 | // use this library instance. If not, give errors.\r | |
257 | //\r | |
258 | throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +\r | |
259 | "is required by this library instance, but can not be found " +\r | |
260 | "in the %s's <ModuleSA> in the FPD file!",\r | |
261 | MemoryDatabaseManager.CurrentModuleName,\r | |
262 | moduleName,\r | |
263 | pcdNameArrayInMsa[index],\r | |
264 | MemoryDatabaseManager.CurrentModuleName\r | |
265 | ));\r | |
266 | }\r | |
267 | }\r | |
268 | }\r | |
269 | }\r | |
270 | } else {\r | |
271 | if (!isBuildUsedLibrary) {\r | |
272 | usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);\r | |
273 | MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r | |
274 | MemoryDatabaseManager.CurrentModuleName = moduleName;\r | |
275 | } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r | |
276 | usageContext = MemoryDatabaseManager.UsageInstanceContext;\r | |
277 | //\r | |
278 | // For building library package, although all module are library, but PCD entries of\r | |
279 | // these library should be used to autogen.\r | |
280 | //\r | |
281 | if (usageContext == null) {\r | |
282 | usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);\r | |
283 | } else {\r | |
284 | usageInstanceArray = new ArrayList<UsageInstance>();\r | |
285 | \r | |
286 | //\r | |
287 | // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r | |
288 | // <ModuleSA> in FPD file.\r | |
289 | //\r | |
290 | for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r | |
291 | found = false;\r | |
292 | for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r | |
293 | if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r | |
294 | usageInstanceArray.add(usageContext.get(index2));\r | |
295 | found = true;\r | |
296 | break;\r | |
297 | }\r | |
298 | }\r | |
299 | \r | |
300 | if (!found) {\r | |
301 | //\r | |
302 | // All library's PCD should instanted in module's <ModuleSA> who\r | |
303 | // use this library instance. If not, give errors.\r | |
304 | //\r | |
305 | throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +\r | |
306 | "is required by this library instance, but can not be found " +\r | |
307 | "in the %s's <ModuleSA> in the FPD file!",\r | |
308 | MemoryDatabaseManager.CurrentModuleName,\r | |
309 | moduleName,\r | |
310 | pcdNameArrayInMsa[index],\r | |
311 | MemoryDatabaseManager.CurrentModuleName\r | |
312 | ));\r | |
313 | }\r | |
a1eb6401 | 314 | }\r |
ad82307c | 315 | }\r |
8840ad58 | 316 | }\r |
317 | }\r | |
a1eb6401 | 318 | if (usageInstanceArray == null) {\r |
319 | return;\r | |
320 | }\r | |
321 | \r | |
11e7b0f6 | 322 | //\r |
323 | // Generate all PCD entry for a module.\r | |
af98370e | 324 | //\r |
878ddf1f | 325 | for(index = 0; index < usageInstanceArray.size(); index ++) {\r |
eece174a | 326 | usageInstance = usageInstanceArray.get(index);\r |
327 | //\r | |
328 | // Before generate any PCD information into autogen.h/autogen.c for a module,\r | |
329 | // generate TokenSpaceGuid array variable firstly. For every dynamicEx type\r | |
af98370e | 330 | // PCD in this module the token, they are all reference to TokenSpaceGuid\r |
eece174a | 331 | // array.\r |
af98370e | 332 | //\r |
eece174a | 333 | if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r |
334 | guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r | |
af98370e | 335 | guidStringCName = "_gPcd_TokenSpaceGuid_" +\r |
eece174a | 336 | usageInstance.parentToken.tokenSpaceName.replaceAll("-", "_");\r |
337 | guidString = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r | |
338 | guidStringArray[0],\r | |
339 | guidStringArray[1],\r | |
340 | guidStringArray[2],\r | |
341 | (guidStringArray[3].substring(0, 2)),\r | |
342 | (guidStringArray[3].substring(2, 4)),\r | |
343 | (guidStringArray[4].substring(0, 2)),\r | |
344 | (guidStringArray[4].substring(2, 4)),\r | |
345 | (guidStringArray[4].substring(4, 6)),\r | |
346 | (guidStringArray[4].substring(6, 8)),\r | |
347 | (guidStringArray[4].substring(8, 10)),\r | |
348 | (guidStringArray[4].substring(10, 12)));\r | |
af98370e | 349 | \r |
eece174a | 350 | Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r |
351 | Matcher matcher = pattern.matcher(cAutoGenString + " ");\r | |
11e7b0f6 | 352 | //\r |
eece174a | 353 | // Find whether this guid array variable has been generated into autogen.c\r |
354 | // For different DyanmicEx pcd token who use same token space guid, the token space\r | |
355 | // guid array should be only generated once.\r | |
af98370e | 356 | //\r |
eece174a | 357 | if (!matcher.find()) {\r |
af98370e | 358 | hAutoGenString += String.format("extern EFI_GUID %s;\r\n", guidStringCName);\r |
eece174a | 359 | if (!isBuildUsedLibrary) {\r |
360 | cAutoGenString += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID %s = %s;\r\n",\r | |
361 | guidStringCName,\r | |
362 | guidString);\r | |
af98370e | 363 | }\r |
11e7b0f6 | 364 | }\r |
878ddf1f | 365 | }\r |
eece174a | 366 | \r |
367 | usageInstance.generateAutoGen(isBuildUsedLibrary);\r | |
368 | //\r | |
369 | // For every PCD entry for this module(usage instance), autogen string would\r | |
370 | // be appand.\r | |
af98370e | 371 | //\r |
eece174a | 372 | hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r |
373 | cAutoGenString += usageInstance.getCAutogenStr();\r | |
878ddf1f | 374 | }\r |
375 | \r | |
5f907e4a | 376 | if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER) {\r |
af98370e | 377 | hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r |
378 | cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r | |
5f907e4a | 379 | } else if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER) {\r |
af98370e | 380 | hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r |
381 | cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r | |
32648c62 | 382 | }\r |
878ddf1f | 383 | }\r |
878ddf1f | 384 | }\r |