]>
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 | |
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.io.File;\r | |
20 | import java.util.List;\r | |
ad82307c | 21 | import java.util.Map;\r |
22 | import java.util.Set;\r | |
8840ad58 | 23 | import java.util.UUID;\r |
ad82307c | 24 | import java.util.ArrayList;\r |
878ddf1f | 25 | \r |
ad82307c | 26 | import org.apache.xmlbeans.XmlObject;\r |
878ddf1f | 27 | import org.tianocore.build.global.GlobalData;\r |
ad82307c | 28 | import org.tianocore.build.global.SurfaceAreaQuery;\r |
878ddf1f | 29 | import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r |
30 | import org.tianocore.build.pcd.entity.Token;\r | |
31 | import org.tianocore.build.pcd.entity.UsageInstance;\r | |
32 | import org.tianocore.build.pcd.exception.BuildActionException;\r | |
33 | import org.tianocore.build.pcd.exception.EntityException;\r | |
34 | \r | |
35 | /** This class is to manage how to generate the PCD information into Autogen.c and\r | |
36 | Autogen.h.\r | |
37 | **/\r | |
38 | public class PCDAutoGenAction extends BuildAction {\r | |
39 | ///\r | |
40 | /// The reference of DBManager in GlobalData class.\r | |
41 | ///\r | |
42 | private MemoryDatabaseManager dbManager;\r | |
43 | ///\r | |
44 | /// The name of module which is analysised currently.\r | |
45 | ///\r | |
46 | private String moduleName;\r | |
47 | ///\r | |
8840ad58 | 48 | /// The Guid of module which is analyzed currently.\r |
49 | /// \r | |
50 | private UUID moduleGuid;\r | |
51 | ///\r | |
52 | /// The name of package whose module is analysized currently.\r | |
53 | /// \r | |
54 | private String packageName;\r | |
55 | ///\r | |
56 | /// The Guid of package whose module is analyszed curretnly.\r | |
57 | /// \r | |
58 | private UUID packageGuid;\r | |
59 | ///\r | |
60 | /// The arch of current module\r | |
61 | /// \r | |
62 | private String arch;\r | |
63 | ///\r | |
64 | /// The version of current module\r | |
65 | /// \r | |
66 | private String version;\r | |
67 | ///\r | |
8840ad58 | 68 | /// Whether current autogen is for building library used by current module.\r |
69 | /// \r | |
70 | private boolean isBuildUsedLibrary;\r | |
71 | ///\r | |
878ddf1f | 72 | /// The generated string for header file.\r |
73 | ///\r | |
74 | private String hAutoGenString;\r | |
75 | ///\r | |
76 | /// The generated string for C code file.\r | |
77 | ///\r | |
ad82307c | 78 | private String cAutoGenString;\r |
79 | ///\r | |
80 | /// The name array of <PcdCoded> in a module.\r | |
81 | /// \r | |
82 | private String[] pcdNameArray;\r | |
878ddf1f | 83 | /**\r |
84 | Set parameter ModuleName\r | |
85 | \r | |
86 | @param moduleName the module name parameter.\r | |
87 | **/\r | |
88 | public void setModuleName(String moduleName) {\r | |
89 | this.moduleName = moduleName;\r | |
90 | }\r | |
91 | \r | |
ad82307c | 92 | /**\r |
93 | set the moduleGuid parameter.\r | |
94 | \r | |
95 | @param moduleGuid\r | |
96 | **/\r | |
8840ad58 | 97 | public void setModuleGuid(UUID moduleGuid) {\r |
98 | this.moduleGuid = moduleGuid;\r | |
99 | }\r | |
100 | \r | |
ad82307c | 101 | /**\r |
102 | set packageName parameter.\r | |
103 | \r | |
104 | @param packageName\r | |
105 | **/\r | |
8840ad58 | 106 | public void setPackageName(String packageName) {\r |
107 | this.packageName = packageName;\r | |
108 | }\r | |
109 | \r | |
ad82307c | 110 | /**\r |
111 | set packageGuid parameter.\r | |
112 | \r | |
113 | @param packageGuid\r | |
114 | **/\r | |
8840ad58 | 115 | public void setPackageGuid(UUID packageGuid) {\r |
116 | this.packageGuid = packageGuid;\r | |
117 | }\r | |
118 | \r | |
ad82307c | 119 | /**\r |
120 | set Arch parameter.\r | |
121 | \r | |
122 | @param arch\r | |
123 | **/\r | |
8840ad58 | 124 | public void setArch(String arch) {\r |
125 | this.arch = arch;\r | |
126 | }\r | |
127 | \r | |
ad82307c | 128 | /**\r |
129 | set version parameter\r | |
130 | \r | |
131 | @param version\r | |
132 | */\r | |
8840ad58 | 133 | public void setVersion(String version) {\r |
134 | this.version = version;\r | |
135 | }\r | |
136 | \r | |
878ddf1f | 137 | /**\r |
ad82307c | 138 | set isBuildUsedLibrary parameter.\r |
139 | \r | |
140 | @param isBuildUsedLibrary\r | |
141 | */\r | |
8840ad58 | 142 | public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r |
143 | this.isBuildUsedLibrary = isBuildUsedLibrary;\r | |
144 | }\r | |
ad82307c | 145 | /**\r |
146 | set pcdNameArray parameter.\r | |
147 | \r | |
148 | @param pcdNameArray\r | |
149 | */\r | |
150 | public void setPcdNameArray(String[] pcdNameArray) {\r | |
151 | this.pcdNameArray = pcdNameArray;\r | |
152 | }\r | |
8840ad58 | 153 | \r |
878ddf1f | 154 | /**\r |
155 | Get the output of generated string for header file.\r | |
156 | \r | |
157 | @return the string of header file for PCD\r | |
158 | **/\r | |
159 | public String OutputH() {\r | |
160 | return hAutoGenString;\r | |
161 | }\r | |
162 | \r | |
163 | /**\r | |
164 | Get the output of generated string for C Code file.\r | |
165 | \r | |
166 | @return the string of C code file for PCD\r | |
167 | **/\r | |
168 | public String OutputC() {\r | |
169 | return cAutoGenString;\r | |
170 | }\r | |
171 | \r | |
172 | /**\r | |
173 | Construct function\r | |
174 | \r | |
175 | This function mainly initialize some member variable.\r | |
176 | \r | |
177 | @param moduleName Parameter of this action class.\r | |
178 | @param isEmulatedPCDDriver Parameter of this action class.\r | |
179 | **/\r | |
ad82307c | 180 | public PCDAutoGenAction(String moduleName, \r |
181 | UUID moduleGuid, \r | |
182 | String packageName,\r | |
183 | UUID packageGuid,\r | |
184 | String arch,\r | |
185 | String version,\r | |
186 | boolean isBuildUsedLibrary,\r | |
187 | String[] pcdNameArray) {\r | |
8840ad58 | 188 | dbManager = null;\r |
189 | hAutoGenString = "";\r | |
190 | cAutoGenString = "";\r | |
191 | \r | |
878ddf1f | 192 | setModuleName(moduleName);\r |
8840ad58 | 193 | setModuleGuid(moduleGuid);\r |
194 | setPackageName(packageName);\r | |
195 | setPackageGuid(packageGuid);\r | |
ad82307c | 196 | setPcdNameArray(pcdNameArray);\r |
8840ad58 | 197 | setArch(arch);\r |
198 | setVersion(version);\r | |
199 | setIsBuildUsedLibrary(isBuildUsedLibrary);\r | |
878ddf1f | 200 | }\r |
201 | \r | |
202 | /**\r | |
203 | check the parameter for action class.\r | |
204 | \r | |
205 | @throws BuildActionException Bad parameter.\r | |
206 | **/\r | |
207 | void checkParameter() throws BuildActionException {\r | |
ad82307c | 208 | \r |
878ddf1f | 209 | }\r |
210 | \r | |
211 | /**\r | |
212 | Core execution function for this action class.\r | |
213 | \r | |
214 | All PCD information of this module comes from memory dabase. The collection\r | |
215 | work should be done before this action execution.\r | |
216 | Currently, we should generated all PCD information(maybe all dynamic) as array \r | |
217 | in Pei emulated driver for simulating PCD runtime database. \r | |
218 | \r | |
219 | @throws BuildActionException Failed to execute this aciton class.\r | |
220 | **/\r | |
221 | void performAction() throws BuildActionException {\r | |
222 | ActionMessage.debug(this, \r | |
223 | "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r | |
845fdeba | 224 | //\r |
225 | // Check the PCD memory database manager is valid.\r | |
226 | //\r | |
227 | if(GlobalData.getPCDMemoryDBManager() == null) {\r | |
228 | throw new BuildActionException("Memory database has not been initlizated!");\r | |
229 | }\r | |
230 | \r | |
231 | dbManager = GlobalData.getPCDMemoryDBManager();\r | |
232 | \r | |
233 | if(dbManager.getDBSize() == 0) {\r | |
8840ad58 | 234 | return;\r |
845fdeba | 235 | }\r |
236 | \r | |
237 | ActionMessage.debug(this,\r | |
238 | "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");\r | |
878ddf1f | 239 | \r |
878ddf1f | 240 | \r |
8840ad58 | 241 | \r |
242 | generateAutogenForModule();\r | |
878ddf1f | 243 | }\r |
244 | \r | |
245 | /**\r | |
246 | Generate the autogen string for a common module.\r | |
247 | \r | |
248 | All PCD information of this module comes from memory dabase. The collection\r | |
249 | work should be done before this action execution.\r | |
250 | **/\r | |
251 | private void generateAutogenForModule()\r | |
252 | {\r | |
ad82307c | 253 | int index, index2;\r |
254 | List<UsageInstance> usageInstanceArray, usageContext;\r | |
878ddf1f | 255 | \r |
8840ad58 | 256 | if (!isBuildUsedLibrary) {\r |
257 | usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r | |
258 | moduleGuid,\r | |
259 | packageName,\r | |
260 | packageGuid,\r | |
261 | arch,\r | |
262 | version);\r | |
263 | dbManager.UsageInstanceContext = usageInstanceArray;\r | |
264 | dbManager.CurrentModuleName = moduleName; \r | |
265 | } else {\r | |
ad82307c | 266 | usageContext = dbManager.UsageInstanceContext;\r |
8840ad58 | 267 | //\r |
268 | // For building MDE package, although all module are library, but PCD entries of \r | |
269 | // these library should be used to autogen.\r | |
270 | // \r | |
ad82307c | 271 | if (usageContext == null) {\r |
8840ad58 | 272 | usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r |
273 | moduleGuid,\r | |
274 | packageName,\r | |
275 | packageGuid,\r | |
276 | arch,\r | |
277 | version);\r | |
ad82307c | 278 | } else {\r |
279 | usageInstanceArray = new ArrayList<UsageInstance>();\r | |
280 | //\r | |
281 | // Remove PCD entries which are not belong to this library.\r | |
282 | // \r | |
283 | for (index = 0; index < usageContext.size(); index++) {\r | |
284 | if ((pcdNameArray == null) || (pcdNameArray.length == 0)){\r | |
285 | break;\r | |
286 | }\r | |
287 | \r | |
288 | for (index2 = 0; index2 < pcdNameArray.length; index2 ++) {\r | |
289 | if (pcdNameArray[index2].equalsIgnoreCase(usageContext.get(index).parentToken.cName)) {\r | |
290 | usageInstanceArray.add(usageContext.get(index));\r | |
291 | break;\r | |
292 | }\r | |
293 | }\r | |
294 | }\r | |
8840ad58 | 295 | }\r |
296 | }\r | |
878ddf1f | 297 | \r |
ad82307c | 298 | \r |
878ddf1f | 299 | if(usageInstanceArray.size() != 0) {\r |
300 | //\r | |
301 | // Add "#include 'PcdLib.h'" for Header file\r | |
302 | //\r | |
303 | hAutoGenString = "#include <MdePkg/Include/Library/PcdLib.h>\r\n";\r | |
304 | }\r | |
305 | \r | |
306 | for(index = 0; index < usageInstanceArray.size(); index ++) {\r | |
307 | ActionMessage.debug(this,\r | |
308 | "Module " + moduleName + "'s PCD [" + Integer.toHexString(index) + \r | |
309 | "]: " + usageInstanceArray.get(index).parentToken.cName);\r | |
310 | try {\r | |
8840ad58 | 311 | usageInstanceArray.get(index).generateAutoGen(isBuildUsedLibrary);\r |
878ddf1f | 312 | hAutoGenString += usageInstanceArray.get(index).getHAutogenStr() + "\r\n";\r |
313 | cAutoGenString += usageInstanceArray.get(index).getCAutogenStr() + "\r\n";\r | |
314 | } catch(EntityException exp) {\r | |
315 | throw new BuildActionException(exp.getMessage());\r | |
316 | }\r | |
317 | }\r | |
318 | \r | |
8840ad58 | 319 | //\r |
320 | // Work around code, In furture following code should be modified that get \r | |
321 | // these information from Uplevel Autogen tools.\r | |
322 | // \r | |
32648c62 | 323 | if (moduleName.equalsIgnoreCase("PcdPeim")) {\r |
324 | hAutoGenString += dbManager.PcdPeimHString;\r | |
325 | cAutoGenString += dbManager.PcdPeimCString;\r | |
326 | } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r | |
327 | hAutoGenString += dbManager.PcdDxeHString;\r | |
328 | cAutoGenString += dbManager.PcdDxeCString;\r | |
329 | }\r | |
99d2c3c4 | 330 | \r |
878ddf1f | 331 | ActionMessage.debug(this,\r |
332 | "Module " + moduleName + "'s PCD header file:\r\n" + hAutoGenString + "\r\n"\r | |
333 | );\r | |
334 | ActionMessage.debug(this,\r | |
335 | "Module " + moduleName + "'s PCD C file:\r\n" + cAutoGenString + "\r\n"\r | |
336 | );\r | |
337 | }\r | |
338 | \r | |
878ddf1f | 339 | /**\r |
340 | Test case function\r | |
341 | \r | |
342 | @param argv paramter from command line\r | |
343 | **/\r | |
344 | public static void main(String argv[]) {\r | |
99d2c3c4 | 345 | \r |
8840ad58 | 346 | String WorkSpace = "M:/ForPcd/edk2";\r |
347 | String logFilePath = WorkSpace + "/MdePkg/MdePkg.fpd";\r | |
ad82307c | 348 | String[] nameArray = null;\r |
878ddf1f | 349 | \r |
350 | //\r | |
351 | // At first, CollectPCDAction should be invoked to collect\r | |
352 | // all PCD information from SPD, MSA, FPD.\r | |
353 | //\r | |
354 | CollectPCDAction collectionAction = new CollectPCDAction();\r | |
355 | GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r | |
99d2c3c4 | 356 | WorkSpace);\r |
878ddf1f | 357 | \r |
878ddf1f | 358 | try {\r |
99d2c3c4 | 359 | collectionAction.perform(WorkSpace, \r |
878ddf1f | 360 | logFilePath,\r |
361 | ActionMessage.MAX_MESSAGE_LEVEL);\r | |
362 | } catch(Exception e) {\r | |
363 | e.printStackTrace();\r | |
364 | }\r | |
365 | \r | |
366 | //\r | |
367 | // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r | |
368 | //\r | |
8840ad58 | 369 | PCDAutoGenAction autogenAction = new PCDAutoGenAction("BaseLib",\r |
370 | null,\r | |
371 | null,\r | |
372 | null,\r | |
373 | null,\r | |
374 | null,\r | |
375 | false,\r | |
ad82307c | 376 | nameArray);\r |
32648c62 | 377 | autogenAction.execute();\r |
99d2c3c4 | 378 | \r |
32648c62 | 379 | System.out.println(autogenAction.OutputH());\r |
380 | System.out.println("WQWQWQWQWQ");\r | |
381 | System.out.println(autogenAction.OutputC());\r | |
99d2c3c4 | 382 | \r |
383 | \r | |
98fc92fc | 384 | System.out.println (autogenAction.hAutoGenString);\r |
385 | System.out.println (autogenAction.cAutoGenString);\r | |
386 | \r | |
878ddf1f | 387 | }\r |
388 | }\r |