2 PCDAutoGenAction class.
4 This class is to manage how to generate the PCD information into Autogen.c and
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
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.
17 package org
.tianocore
.build
.pcd
.action
;
20 import java
.util
.List
;
21 import java
.util
.UUID
;
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
;
30 /** This class is to manage how to generate the PCD information into Autogen.c and
33 public class PCDAutoGenAction
extends BuildAction
{
35 /// The reference of DBManager in GlobalData class.
37 private MemoryDatabaseManager dbManager
;
39 /// The name of module which is analysised currently.
41 private String moduleName
;
43 /// The Guid of module which is analyzed currently.
45 private UUID moduleGuid
;
47 /// The name of package whose module is analysized currently.
49 private String packageName
;
51 /// The Guid of package whose module is analyszed curretnly.
53 private UUID packageGuid
;
55 /// The arch of current module
59 /// The version of current module
61 private String version
;
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.
66 private boolean isEmulatedPCDDriver
;
68 /// Whether current autogen is for building library used by current module.
70 private boolean isBuildUsedLibrary
;
72 /// The generated string for header file.
74 private String hAutoGenString
;
76 /// The generated string for C code file.
78 private String cAutoGenString
;
81 Set parameter ModuleName
83 @param moduleName the module name parameter.
85 public void setModuleName(String moduleName
) {
86 this.moduleName
= moduleName
;
89 public void setModuleGuid(UUID moduleGuid
) {
90 this.moduleGuid
= moduleGuid
;
93 public void setPackageName(String packageName
) {
94 this.packageName
= packageName
;
97 public void setPackageGuid(UUID packageGuid
) {
98 this.packageGuid
= packageGuid
;
101 public void setArch(String arch
) {
105 public void setVersion(String version
) {
106 this.version
= version
;
110 Set parameter isEmulatedPCDDriver
112 @param isEmulatedPCDDriver whether this module is PeiEmulatedPCD driver
114 public void setIsEmulatedPCDDriver(boolean isEmulatedPCDDriver
) {
115 this.isEmulatedPCDDriver
= isEmulatedPCDDriver
;
118 public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary
) {
119 this.isBuildUsedLibrary
= isBuildUsedLibrary
;
123 Get the output of generated string for header file.
125 @return the string of header file for PCD
127 public String
OutputH() {
128 return hAutoGenString
;
132 Get the output of generated string for C Code file.
134 @return the string of C code file for PCD
136 public String
OutputC() {
137 return cAutoGenString
;
143 This function mainly initialize some member variable.
145 @param moduleName Parameter of this action class.
146 @param isEmulatedPCDDriver Parameter of this action class.
148 public PCDAutoGenAction(String moduleName
,
154 boolean isEmulatedPCDDriver
,
155 boolean isBuildUsedLibrary
) {
160 setIsEmulatedPCDDriver(isEmulatedPCDDriver
);
161 setModuleName(moduleName
);
162 setModuleGuid(moduleGuid
);
163 setPackageName(packageName
);
164 setPackageGuid(packageGuid
);
167 setIsBuildUsedLibrary(isBuildUsedLibrary
);
171 check the parameter for action class.
173 @throws BuildActionException Bad parameter.
175 void checkParameter() throws BuildActionException
{
176 if(!isEmulatedPCDDriver
&&(moduleName
== null)) {
177 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
180 if(!isEmulatedPCDDriver
&& moduleName
.length() == 0) {
181 throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");
186 Core execution function for this action class.
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.
193 @throws BuildActionException Failed to execute this aciton class.
195 void performAction() throws BuildActionException
{
196 ActionMessage
.debug(this,
197 "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");
199 // Check the PCD memory database manager is valid.
201 if(GlobalData
.getPCDMemoryDBManager() == null) {
202 throw new BuildActionException("Memory database has not been initlizated!");
205 dbManager
= GlobalData
.getPCDMemoryDBManager();
207 if(dbManager
.getDBSize() == 0) {
211 ActionMessage
.debug(this,
212 "PCD memory database contains " + dbManager
.getDBSize() + " PCD tokens");
216 generateAutogenForModule();
220 Generate the autogen string for a common module.
222 All PCD information of this module comes from memory dabase. The collection
223 work should be done before this action execution.
225 private void generateAutogenForModule()
228 List
<UsageInstance
> usageInstanceArray
;
230 if (!isBuildUsedLibrary
) {
231 usageInstanceArray
= dbManager
.getUsageInstanceArrayByModuleName(moduleName
,
237 dbManager
.UsageInstanceContext
= usageInstanceArray
;
238 dbManager
.CurrentModuleName
= moduleName
;
240 usageInstanceArray
= dbManager
.UsageInstanceContext
;
242 // For building MDE package, although all module are library, but PCD entries of
243 // these library should be used to autogen.
245 if (usageInstanceArray
== null) {
246 usageInstanceArray
= dbManager
.getUsageInstanceArrayByModuleName(moduleName
,
255 if(usageInstanceArray
.size() != 0) {
257 // Add "#include 'PcdLib.h'" for Header file
259 hAutoGenString
= "#include <MdePkg/Include/Library/PcdLib.h>\r\n";
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
);
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());
276 // Work around code, In furture following code should be modified that get
277 // these information from Uplevel Autogen tools.
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
;
287 ActionMessage
.debug(this,
288 "Module " + moduleName
+ "'s PCD header file:\r\n" + hAutoGenString
+ "\r\n"
290 ActionMessage
.debug(this,
291 "Module " + moduleName
+ "'s PCD C file:\r\n" + cAutoGenString
+ "\r\n"
298 @param argv paramter from command line
300 public static void main(String argv
[]) {
302 String WorkSpace
= "M:/ForPcd/edk2";
303 String logFilePath
= WorkSpace
+ "/MdePkg/MdePkg.fpd";
306 // At first, CollectPCDAction should be invoked to collect
307 // all PCD information from SPD, MSA, FPD.
309 CollectPCDAction collectionAction
= new CollectPCDAction();
310 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db",
314 collectionAction
.perform(WorkSpace
,
316 ActionMessage
.MAX_MESSAGE_LEVEL
);
317 } catch(Exception e
) {
322 // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c
324 PCDAutoGenAction autogenAction
= new PCDAutoGenAction("BaseLib",
333 autogenAction
.execute();
335 System
.out
.println(autogenAction
.OutputH());
336 System
.out
.println("WQWQWQWQWQ");
337 System
.out
.println(autogenAction
.OutputC());
340 System
.out
.println (autogenAction
.hAutoGenString
);
341 System
.out
.println (autogenAction
.cAutoGenString
);