]>
Commit | Line | Data |
---|---|---|
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 | |
6 | \r | |
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 | |
12 | \r | |
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 | |
19 | import java.util.ArrayList;\r | |
20 | import java.util.List;\r | |
21 | import java.util.regex.Matcher;\r | |
22 | import java.util.regex.Pattern;\r | |
23 | \r | |
24 | import org.tianocore.build.FrameworkBuildTask;\r | |
25 | import org.tianocore.build.autogen.CommonDefinition;\r | |
26 | import org.tianocore.build.global.GlobalData;\r | |
27 | import org.tianocore.build.id.ModuleIdentification;\r | |
28 | import org.tianocore.common.logger.EdkLog;\r | |
29 | import org.tianocore.pcd.action.BuildAction;\r | |
30 | import org.tianocore.pcd.entity.MemoryDatabaseManager;\r | |
31 | import org.tianocore.pcd.entity.Token;\r | |
32 | import org.tianocore.pcd.entity.UsageIdentification;\r | |
33 | import org.tianocore.pcd.entity.UsageInstance;\r | |
34 | import org.tianocore.pcd.exception.BuildActionException;\r | |
35 | \r | |
36 | /**\r | |
37 | This class is to manage how to generate the PCD information into Autogen.c\r | |
38 | and Autogen.h.\r | |
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 | |
45 | \r | |
46 | ///\r | |
47 | /// The identification for a UsageInstance.\r | |
48 | ///\r | |
49 | private UsageIdentification usageId;\r | |
50 | \r | |
51 | ///\r | |
52 | /// Whether current autogen is for building library used by current module.\r | |
53 | ///\r | |
54 | private boolean isBuildUsedLibrary;\r | |
55 | \r | |
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 | |
61 | ///\r | |
62 | /// The generated string for header file.\r | |
63 | ///\r | |
64 | private String hAutoGenString;\r | |
65 | \r | |
66 | ///\r | |
67 | /// The generated string for C code file.\r | |
68 | ///\r | |
69 | private String cAutoGenString;\r | |
70 | \r | |
71 | ///\r | |
72 | /// The name array of <PcdCoded> in a module.\r | |
73 | ///\r | |
74 | private String[] pcdNameArrayInMsa;\r | |
75 | \r | |
76 | private UsageIdentification parentId = null;\r | |
77 | /**\r | |
78 | Set parameter moduleId\r | |
79 | \r | |
80 | @param moduleName the module name parameter.\r | |
81 | **/\r | |
82 | public void setUsageId(UsageIdentification usageId) {\r | |
83 | this.usageId = usageId;\r | |
84 | }\r | |
85 | \r | |
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 | |
94 | /**\r | |
95 | set isBuildUsedLibrary parameter.\r | |
96 | \r | |
97 | @param isBuildUsedLibrary\r | |
98 | **/\r | |
99 | public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r | |
100 | this.isBuildUsedLibrary = isBuildUsedLibrary;\r | |
101 | }\r | |
102 | \r | |
103 | /**\r | |
104 | set pcdNameArrayInMsa parameter.\r | |
105 | \r | |
106 | @param pcdNameArrayInMsa\r | |
107 | */\r | |
108 | public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r | |
109 | this.pcdNameArrayInMsa = pcdNameArrayInMsa;\r | |
110 | }\r | |
111 | \r | |
112 | /**\r | |
113 | Get the output of generated string for header file.\r | |
114 | \r | |
115 | @return the string of header file for PCD\r | |
116 | **/\r | |
117 | public String getHAutoGenString() {\r | |
118 | return hAutoGenString;\r | |
119 | }\r | |
120 | \r | |
121 | /**\r | |
122 | Get the output of generated string for C Code file.\r | |
123 | \r | |
124 | @return the string of C code file for PCD\r | |
125 | **/\r | |
126 | public String getCAutoGenString() {\r | |
127 | return cAutoGenString;\r | |
128 | }\r | |
129 | \r | |
130 | \r | |
131 | /**\r | |
132 | Construct function\r | |
133 | \r | |
134 | This function mainly initialize some member variable.\r | |
135 | \r | |
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 | |
140 | @param pcdDriverType one of PEI_PCD_DRIVER, DXE_PCD_DRIVER,\r | |
141 | NOT_PCD_DRIVER\r | |
142 | **/\r | |
143 | public PCDAutoGenAction(ModuleIdentification moduleId,\r | |
144 | String arch,\r | |
145 | boolean isBuildUsedLibrary,\r | |
146 | String[] pcdNameArrayInMsa,\r | |
147 | CommonDefinition.PCD_DRIVER_TYPE pcdDriverType,\r | |
148 | ModuleIdentification parentId) {\r | |
149 | dbManager = null;\r | |
150 | hAutoGenString = "";\r | |
151 | cAutoGenString = "";\r | |
152 | \r | |
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 | |
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 | |
169 | setIsBuildUsedLibrary(isBuildUsedLibrary);\r | |
170 | setPcdNameArrayInMsa(pcdNameArrayInMsa);\r | |
171 | setPcdDriverType(pcdDriverType);\r | |
172 | }\r | |
173 | \r | |
174 | /**\r | |
175 | Override function: check the parameter for action class.\r | |
176 | \r | |
177 | @throws BuildActionException Bad parameter.\r | |
178 | **/\r | |
179 | public void checkParameter() {\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | Core execution function for this action class.\r | |
184 | \r | |
185 | All PCD information of this module comes from memory dabase. The collection\r | |
186 | work should be done before this action execution.\r | |
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 | |
190 | @throws BuildActionException Failed to execute this aciton class.\r | |
191 | **/\r | |
192 | public void performAction() {\r | |
193 | EdkLog.log(EdkLog.EDK_DEBUG, "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r | |
194 | \r | |
195 | dbManager = GlobalData.getPCDMemoryDBManager();\r | |
196 | \r | |
197 | if(dbManager.getDBSize() == 0) {\r | |
198 | return;\r | |
199 | }\r | |
200 | \r | |
201 | EdkLog.log(EdkLog.EDK_DEBUG, "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens.");\r | |
202 | \r | |
203 | generateAutogenForModule();\r | |
204 | }\r | |
205 | \r | |
206 | /**\r | |
207 | Generate the autogen string for a common module.\r | |
208 | \r | |
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 | |
214 | int index, index2;\r | |
215 | List<UsageInstance> usageInstanceArray, usageContext;\r | |
216 | String[] guidStringArray = null;\r | |
217 | String guidStringCName = null;\r | |
218 | String guidString = null;\r | |
219 | String moduleName = usageId.moduleName;\r | |
220 | UsageInstance usageInstance = null;\r | |
221 | boolean found = false;\r | |
222 | \r | |
223 | usageInstanceArray = null;\r | |
224 | \r | |
225 | if (FrameworkBuildTask.multithread) {\r | |
226 | if (parentId == null) {\r | |
227 | usageInstanceArray = dbManager.getUsageInstanceArrayById(usageId);\r | |
228 | } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r | |
229 | usageContext = dbManager.getUsageInstanceArrayById(parentId);\r | |
230 | //\r | |
231 | // For building library package, although all module are library, but PCD entries of\r | |
232 | // these library should be used to autogen.\r | |
233 | //\r | |
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 | |
251 | }\r | |
252 | \r | |
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 | |
314 | }\r | |
315 | }\r | |
316 | }\r | |
317 | }\r | |
318 | if (usageInstanceArray == null) {\r | |
319 | return;\r | |
320 | }\r | |
321 | \r | |
322 | //\r | |
323 | // Generate all PCD entry for a module.\r | |
324 | //\r | |
325 | for(index = 0; index < usageInstanceArray.size(); index ++) {\r | |
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 | |
330 | // PCD in this module the token, they are all reference to TokenSpaceGuid\r | |
331 | // array.\r | |
332 | //\r | |
333 | if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r | |
334 | guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r | |
335 | guidStringCName = "_gPcd_TokenSpaceGuid_" +\r | |
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 | |
349 | \r | |
350 | Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r | |
351 | Matcher matcher = pattern.matcher(cAutoGenString + " ");\r | |
352 | //\r | |
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 | |
356 | //\r | |
357 | if (!matcher.find()) {\r | |
358 | hAutoGenString += String.format("extern EFI_GUID %s;\r\n", guidStringCName);\r | |
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 | |
363 | }\r | |
364 | }\r | |
365 | }\r | |
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 | |
371 | //\r | |
372 | hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r | |
373 | cAutoGenString += usageInstance.getCAutogenStr();\r | |
374 | }\r | |
375 | \r | |
376 | if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER) {\r | |
377 | hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r | |
378 | cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r | |
379 | } else if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER) {\r | |
380 | hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r | |
381 | cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r | |
382 | }\r | |
383 | }\r | |
384 | }\r |