]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Modify PCD tool according to final PCD schema modification.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PCDAutoGenAction.java
1 /** @file
2 PCDAutoGenAction class.
3
4 This class is to manage how to generate the PCD information into Autogen.c and
5 Autogen.h.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17 package org.tianocore.build.pcd.action;
18
19 import java.io.File;
20 import java.util.List;
21 import java.util.UUID;
22
23 import org.tianocore.build.global.GlobalData;
24 import org.tianocore.build.pcd.entity.MemoryDatabaseManager;
25 import org.tianocore.build.pcd.entity.Token;
26 import org.tianocore.build.pcd.entity.UsageInstance;
27 import org.tianocore.build.pcd.exception.BuildActionException;
28 import org.tianocore.build.pcd.exception.EntityException;
29
30 /** This class is to manage how to generate the PCD information into Autogen.c and
31 Autogen.h.
32 **/
33 public class PCDAutoGenAction extends BuildAction {
34 ///
35 /// The reference of DBManager in GlobalData class.
36 ///
37 private MemoryDatabaseManager dbManager;
38 ///
39 /// The name of module which is analysised currently.
40 ///
41 private String moduleName;
42 ///
43 /// The Guid of module which is analyzed currently.
44 ///
45 private UUID moduleGuid;
46 ///
47 /// The name of package whose module is analysized currently.
48 ///
49 private String packageName;
50 ///
51 /// The Guid of package whose module is analyszed curretnly.
52 ///
53 private UUID packageGuid;
54 ///
55 /// The arch of current module
56 ///
57 private String arch;
58 ///
59 /// The version of current module
60 ///
61 private String version;
62 ///
63 /// Wheter current module is PCD emulated driver. It is only for
64 /// emulated PCD driver and will be kept until PCD IMAGE tool ready.
65 ///
66 private boolean isEmulatedPCDDriver;
67 ///
68 /// Whether current autogen is for building library used by current module.
69 ///
70 private boolean isBuildUsedLibrary;
71 ///
72 /// The generated string for header file.
73 ///
74 private String hAutoGenString;
75 ///
76 /// The generated string for C code file.
77 ///
78 private String cAutoGenString;
79
80 /**
81 Set parameter ModuleName
82
83 @param moduleName the module name parameter.
84 **/
85 public void setModuleName(String moduleName) {
86 this.moduleName = moduleName;
87 }
88
89 public void setModuleGuid(UUID moduleGuid) {
90 this.moduleGuid = moduleGuid;
91 }
92
93 public void setPackageName(String packageName) {
94 this.packageName = packageName;
95 }
96
97 public void setPackageGuid(UUID packageGuid) {
98 this.packageGuid = packageGuid;
99 }
100
101 public void setArch(String arch) {
102 this.arch = arch;
103 }
104
105 public void setVersion(String version) {
106 this.version = version;
107 }
108
109 /**
110 Set parameter isEmulatedPCDDriver
111
112 @param isEmulatedPCDDriver whether this module is PeiEmulatedPCD driver
113 **/
114 public void setIsEmulatedPCDDriver(boolean isEmulatedPCDDriver) {
115 this.isEmulatedPCDDriver = isEmulatedPCDDriver;
116 }
117
118 public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {
119 this.isBuildUsedLibrary = isBuildUsedLibrary;
120 }
121
122 /**
123 Get the output of generated string for header file.
124
125 @return the string of header file for PCD
126 **/
127 public String OutputH() {
128 return hAutoGenString;
129 }
130
131 /**
132 Get the output of generated string for C Code file.
133
134 @return the string of C code file for PCD
135 **/
136 public String OutputC() {
137 return cAutoGenString;
138 }
139
140 /**
141 Construct function
142
143 This function mainly initialize some member variable.
144
145 @param moduleName Parameter of this action class.
146 @param isEmulatedPCDDriver Parameter of this action class.
147 **/
148 public PCDAutoGenAction(String moduleName,
149 UUID moduleGuid,
150 String packageName,
151 UUID packageGuid,
152 String arch,
153 String version,
154 boolean isEmulatedPCDDriver,
155 boolean isBuildUsedLibrary) {
156 dbManager = null;
157 hAutoGenString = "";
158 cAutoGenString = "";
159
160 setIsEmulatedPCDDriver(isEmulatedPCDDriver);
161 setModuleName(moduleName);
162 setModuleGuid(moduleGuid);
163 setPackageName(packageName);
164 setPackageGuid(packageGuid);
165 setArch(arch);
166 setVersion(version);
167 setIsBuildUsedLibrary(isBuildUsedLibrary);
168 }
169
170 /**
171 check the parameter for action class.
172
173 @throws BuildActionException Bad parameter.
174 **/
175 void checkParameter() throws BuildActionException {
176 if(!isEmulatedPCDDriver &&(moduleName == null)) {
177 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
178 }
179
180 if(!isEmulatedPCDDriver && moduleName.length() == 0) {
181 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
182 }
183 }
184
185 /**
186 Core execution function for this action class.
187
188 All PCD information of this module comes from memory dabase. The collection
189 work should be done before this action execution.
190 Currently, we should generated all PCD information(maybe all dynamic) as array
191 in Pei emulated driver for simulating PCD runtime database.
192
193 @throws BuildActionException Failed to execute this aciton class.
194 **/
195 void performAction() throws BuildActionException {
196 ActionMessage.debug(this,
197 "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");
198 //
199 // Check the PCD memory database manager is valid.
200 //
201 if(GlobalData.getPCDMemoryDBManager() == null) {
202 throw new BuildActionException("Memory database has not been initlizated!");
203 }
204
205 dbManager = GlobalData.getPCDMemoryDBManager();
206
207 if(dbManager.getDBSize() == 0) {
208 return;
209 }
210
211 ActionMessage.debug(this,
212 "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");
213
214
215
216 generateAutogenForModule();
217 }
218
219 /**
220 Generate the autogen string for a common module.
221
222 All PCD information of this module comes from memory dabase. The collection
223 work should be done before this action execution.
224 **/
225 private void generateAutogenForModule()
226 {
227 int index;
228 List<UsageInstance> usageInstanceArray;
229
230 if (!isBuildUsedLibrary) {
231 usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,
232 moduleGuid,
233 packageName,
234 packageGuid,
235 arch,
236 version);
237 dbManager.UsageInstanceContext = usageInstanceArray;
238 dbManager.CurrentModuleName = moduleName;
239 } else {
240 usageInstanceArray = dbManager.UsageInstanceContext;
241 //
242 // For building MDE package, although all module are library, but PCD entries of
243 // these library should be used to autogen.
244 //
245 if (usageInstanceArray == null) {
246 usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,
247 moduleGuid,
248 packageName,
249 packageGuid,
250 arch,
251 version);
252 }
253 }
254
255 if(usageInstanceArray.size() != 0) {
256 //
257 // Add "#include 'PcdLib.h'" for Header file
258 //
259 hAutoGenString = "#include <MdePkg/Include/Library/PcdLib.h>\r\n";
260 }
261
262 for(index = 0; index < usageInstanceArray.size(); index ++) {
263 ActionMessage.debug(this,
264 "Module " + moduleName + "'s PCD [" + Integer.toHexString(index) +
265 "]: " + usageInstanceArray.get(index).parentToken.cName);
266 try {
267 usageInstanceArray.get(index).generateAutoGen(isBuildUsedLibrary);
268 hAutoGenString += usageInstanceArray.get(index).getHAutogenStr() + "\r\n";
269 cAutoGenString += usageInstanceArray.get(index).getCAutogenStr() + "\r\n";
270 } catch(EntityException exp) {
271 throw new BuildActionException(exp.getMessage());
272 }
273 }
274
275 //
276 // Work around code, In furture following code should be modified that get
277 // these information from Uplevel Autogen tools.
278 //
279 if (moduleName.equalsIgnoreCase("PcdPeim")) {
280 hAutoGenString += dbManager.PcdPeimHString;
281 cAutoGenString += dbManager.PcdPeimCString;
282 } else if (moduleName.equalsIgnoreCase("PcdDxe")) {
283 hAutoGenString += dbManager.PcdDxeHString;
284 cAutoGenString += dbManager.PcdDxeCString;
285 }
286
287 ActionMessage.debug(this,
288 "Module " + moduleName + "'s PCD header file:\r\n" + hAutoGenString + "\r\n"
289 );
290 ActionMessage.debug(this,
291 "Module " + moduleName + "'s PCD C file:\r\n" + cAutoGenString + "\r\n"
292 );
293 }
294
295 /**
296 Test case function
297
298 @param argv paramter from command line
299 **/
300 public static void main(String argv[]) {
301
302 String WorkSpace = "M:/ForPcd/edk2";
303 String logFilePath = WorkSpace + "/MdePkg/MdePkg.fpd";
304
305 //
306 // At first, CollectPCDAction should be invoked to collect
307 // all PCD information from SPD, MSA, FPD.
308 //
309 CollectPCDAction collectionAction = new CollectPCDAction();
310 GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",
311 WorkSpace);
312
313 try {
314 collectionAction.perform(WorkSpace,
315 logFilePath,
316 ActionMessage.MAX_MESSAGE_LEVEL);
317 } catch(Exception e) {
318 e.printStackTrace();
319 }
320
321 //
322 // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c
323 //
324 PCDAutoGenAction autogenAction = new PCDAutoGenAction("BaseLib",
325 null,
326 null,
327 null,
328 null,
329 null,
330 false,
331 false
332 );
333 autogenAction.execute();
334
335 System.out.println(autogenAction.OutputH());
336 System.out.println("WQWQWQWQWQ");
337 System.out.println(autogenAction.OutputC());
338
339
340 System.out.println (autogenAction.hAutoGenString);
341 System.out.println (autogenAction.cAutoGenString);
342
343 }
344 }