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
;
23 import java
.util
.UUID
;
24 import java
.util
.ArrayList
;
26 import org
.apache
.xmlbeans
.XmlObject
;
27 import org
.tianocore
.build
.global
.GlobalData
;
28 import org
.tianocore
.build
.global
.SurfaceAreaQuery
;
29 import org
.tianocore
.build
.pcd
.entity
.MemoryDatabaseManager
;
30 import org
.tianocore
.build
.pcd
.entity
.Token
;
31 import org
.tianocore
.build
.pcd
.entity
.UsageInstance
;
32 import org
.tianocore
.build
.pcd
.exception
.BuildActionException
;
33 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
35 /** This class is to manage how to generate the PCD information into Autogen.c and
38 public class PCDAutoGenAction
extends BuildAction
{
40 /// The reference of DBManager in GlobalData class.
42 private MemoryDatabaseManager dbManager
;
44 /// The name of module which is analysised currently.
46 private String moduleName
;
48 /// The Guid of module which is analyzed currently.
50 private UUID moduleGuid
;
52 /// The name of package whose module is analysized currently.
54 private String packageName
;
56 /// The Guid of package whose module is analyszed curretnly.
58 private UUID packageGuid
;
60 /// The arch of current module
64 /// The version of current module
66 private String version
;
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
;
80 /// The name array of <PcdCoded> in a module.
82 private String
[] pcdNameArray
;
84 Set parameter ModuleName
86 @param moduleName the module name parameter.
88 public void setModuleName(String moduleName
) {
89 this.moduleName
= moduleName
;
93 set the moduleGuid parameter.
97 public void setModuleGuid(UUID moduleGuid
) {
98 this.moduleGuid
= moduleGuid
;
102 set packageName parameter.
106 public void setPackageName(String packageName
) {
107 this.packageName
= packageName
;
111 set packageGuid parameter.
115 public void setPackageGuid(UUID packageGuid
) {
116 this.packageGuid
= packageGuid
;
124 public void setArch(String arch
) {
129 set version parameter
133 public void setVersion(String version
) {
134 this.version
= version
;
138 set isBuildUsedLibrary parameter.
140 @param isBuildUsedLibrary
142 public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary
) {
143 this.isBuildUsedLibrary
= isBuildUsedLibrary
;
146 set pcdNameArray parameter.
150 public void setPcdNameArray(String
[] pcdNameArray
) {
151 this.pcdNameArray
= pcdNameArray
;
155 Get the output of generated string for header file.
157 @return the string of header file for PCD
159 public String
OutputH() {
160 return hAutoGenString
;
164 Get the output of generated string for C Code file.
166 @return the string of C code file for PCD
168 public String
OutputC() {
169 return cAutoGenString
;
175 This function mainly initialize some member variable.
177 @param moduleName Parameter of this action class.
178 @param isEmulatedPCDDriver Parameter of this action class.
180 public PCDAutoGenAction(String moduleName
,
186 boolean isBuildUsedLibrary
,
187 String
[] pcdNameArray
) {
192 setModuleName(moduleName
);
193 setModuleGuid(moduleGuid
);
194 setPackageName(packageName
);
195 setPackageGuid(packageGuid
);
196 setPcdNameArray(pcdNameArray
);
199 setIsBuildUsedLibrary(isBuildUsedLibrary
);
203 check the parameter for action class.
205 @throws BuildActionException Bad parameter.
207 void checkParameter() throws BuildActionException
{
212 Core execution function for this action class.
214 All PCD information of this module comes from memory dabase. The collection
215 work should be done before this action execution.
216 Currently, we should generated all PCD information(maybe all dynamic) as array
217 in Pei emulated driver for simulating PCD runtime database.
219 @throws BuildActionException Failed to execute this aciton class.
221 void performAction() throws BuildActionException
{
222 ActionMessage
.debug(this,
223 "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");
225 // Check the PCD memory database manager is valid.
227 if(GlobalData
.getPCDMemoryDBManager() == null) {
228 throw new BuildActionException("Memory database has not been initlizated!");
231 dbManager
= GlobalData
.getPCDMemoryDBManager();
233 if(dbManager
.getDBSize() == 0) {
237 ActionMessage
.debug(this,
238 "PCD memory database contains " + dbManager
.getDBSize() + " PCD tokens");
242 generateAutogenForModule();
246 Generate the autogen string for a common module.
248 All PCD information of this module comes from memory dabase. The collection
249 work should be done before this action execution.
251 private void generateAutogenForModule()
254 List
<UsageInstance
> usageInstanceArray
, usageContext
;
256 if (!isBuildUsedLibrary
) {
257 usageInstanceArray
= dbManager
.getUsageInstanceArrayByModuleName(moduleName
,
263 dbManager
.UsageInstanceContext
= usageInstanceArray
;
264 dbManager
.CurrentModuleName
= moduleName
;
266 usageContext
= dbManager
.UsageInstanceContext
;
268 // For building MDE package, although all module are library, but PCD entries of
269 // these library should be used to autogen.
271 if (usageContext
== null) {
272 usageInstanceArray
= dbManager
.getUsageInstanceArrayByModuleName(moduleName
,
279 usageInstanceArray
= new ArrayList
<UsageInstance
>();
281 // Remove PCD entries which are not belong to this library.
283 for (index
= 0; index
< usageContext
.size(); index
++) {
284 if ((pcdNameArray
== null) || (pcdNameArray
.length
== 0)){
288 for (index2
= 0; index2
< pcdNameArray
.length
; index2
++) {
289 if (pcdNameArray
[index2
].equalsIgnoreCase(usageContext
.get(index
).parentToken
.cName
)) {
290 usageInstanceArray
.add(usageContext
.get(index
));
299 if(usageInstanceArray
.size() != 0) {
301 // Add "#include 'PcdLib.h'" for Header file
303 hAutoGenString
= "#include <MdePkg/Include/Library/PcdLib.h>\r\n";
306 for(index
= 0; index
< usageInstanceArray
.size(); index
++) {
307 ActionMessage
.debug(this,
308 "Module " + moduleName
+ "'s PCD [" + Integer
.toHexString(index
) +
309 "]: " + usageInstanceArray
.get(index
).parentToken
.cName
);
311 usageInstanceArray
.get(index
).generateAutoGen(isBuildUsedLibrary
);
312 hAutoGenString
+= usageInstanceArray
.get(index
).getHAutogenStr() + "\r\n";
313 cAutoGenString
+= usageInstanceArray
.get(index
).getCAutogenStr() + "\r\n";
314 } catch(EntityException exp
) {
315 throw new BuildActionException(exp
.getMessage());
320 // Work around code, In furture following code should be modified that get
321 // these information from Uplevel Autogen tools.
323 if (moduleName
.equalsIgnoreCase("PcdPeim")) {
324 hAutoGenString
+= dbManager
.PcdPeimHString
;
325 cAutoGenString
+= dbManager
.PcdPeimCString
;
326 } else if (moduleName
.equalsIgnoreCase("PcdDxe")) {
327 hAutoGenString
+= dbManager
.PcdDxeHString
;
328 cAutoGenString
+= dbManager
.PcdDxeCString
;
331 ActionMessage
.debug(this,
332 "Module " + moduleName
+ "'s PCD header file:\r\n" + hAutoGenString
+ "\r\n"
334 ActionMessage
.debug(this,
335 "Module " + moduleName
+ "'s PCD C file:\r\n" + cAutoGenString
+ "\r\n"
342 @param argv paramter from command line
344 public static void main(String argv
[]) {
346 String WorkSpace
= "M:/ForPcd/edk2";
347 String logFilePath
= WorkSpace
+ "/MdePkg/MdePkg.fpd";
348 String
[] nameArray
= null;
351 // At first, CollectPCDAction should be invoked to collect
352 // all PCD information from SPD, MSA, FPD.
354 CollectPCDAction collectionAction
= new CollectPCDAction();
355 GlobalData
.initInfo("Tools" + File
.separator
+ "Conf" + File
.separator
+ "FrameworkDatabase.db",
359 collectionAction
.perform(WorkSpace
,
361 ActionMessage
.MAX_MESSAGE_LEVEL
);
362 } catch(Exception e
) {
367 // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c
369 PCDAutoGenAction autogenAction
= new PCDAutoGenAction("BaseLib",
377 autogenAction
.execute();
379 System
.out
.println(autogenAction
.OutputH());
380 System
.out
.println("WQWQWQWQWQ");
381 System
.out
.println(autogenAction
.OutputC());
384 System
.out
.println (autogenAction
.hAutoGenString
);
385 System
.out
.println (autogenAction
.cAutoGenString
);