package org.tianocore.build.pcd.action;\r
\r
import java.io.File;\r
+import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
import java.util.UUID;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
+import org.apache.xmlbeans.XmlObject;\r
import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
-import org.tianocore.build.pcd.entity.Token;\r
-import org.tianocore.build.pcd.entity.UsageInstance;\r
-import org.tianocore.build.pcd.exception.BuildActionException;\r
-import org.tianocore.build.pcd.exception.EntityException;\r
+import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
+import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageInstance;\r
+import org.tianocore.pcd.exception.BuildActionException;\r
+import org.tianocore.pcd.exception.EntityException;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
+import org.tianocore.pcd.action.BuildAction;\r
+import org.tianocore.pcd.action.ActionMessage;\r
\r
/** This class is to manage how to generate the PCD information into Autogen.c and\r
Autogen.h.\r
///\r
private MemoryDatabaseManager dbManager;\r
///\r
- /// The name of module which is analysised currently.\r
- ///\r
- private String moduleName;\r
- ///\r
- /// The Guid of module which is analyzed currently.\r
- /// \r
- private UUID moduleGuid;\r
- ///\r
- /// The name of package whose module is analysized currently.\r
+ /// The identification for a UsageInstance.\r
/// \r
- private String packageName;\r
- ///\r
- /// The Guid of package whose module is analyszed curretnly.\r
- /// \r
- private UUID packageGuid;\r
+ private UsageIdentification usageId;\r
///\r
/// The arch of current module\r
/// \r
private String arch;\r
///\r
- /// The version of current module\r
- /// \r
- private String version;\r
- ///\r
- /// Wheter current module is PCD emulated driver. It is only for \r
- /// emulated PCD driver and will be kept until PCD IMAGE tool ready.\r
- ///\r
- private boolean isEmulatedPCDDriver;\r
- ///\r
/// Whether current autogen is for building library used by current module.\r
/// \r
private boolean isBuildUsedLibrary;\r
///\r
/// The generated string for C code file.\r
///\r
- private String cAutoGenString; \r
-\r
+ private String cAutoGenString;\r
+ ///\r
+ /// The name array of <PcdCoded> in a module.\r
+ /// \r
+ private String[] pcdNameArrayInMsa;\r
/**\r
- Set parameter ModuleName\r
+ Set parameter moduleId\r
\r
@param moduleName the module name parameter.\r
**/\r
- public void setModuleName(String moduleName) {\r
- this.moduleName = moduleName;\r
- }\r
-\r
- public void setModuleGuid(UUID moduleGuid) {\r
- this.moduleGuid = moduleGuid;\r
- }\r
-\r
- public void setPackageName(String packageName) {\r
- this.packageName = packageName;\r
- }\r
-\r
- public void setPackageGuid(UUID packageGuid) {\r
- this.packageGuid = packageGuid;\r
- }\r
-\r
- public void setArch(String arch) {\r
- this.arch = arch;\r
- }\r
-\r
- public void setVersion(String version) {\r
- this.version = version;\r
+ public void setUsageId(UsageIdentification usageId) {\r
+ this.usageId = usageId;\r
}\r
\r
/**\r
- Set parameter isEmulatedPCDDriver\r
- \r
- @param isEmulatedPCDDriver whether this module is PeiEmulatedPCD driver\r
+ set isBuildUsedLibrary parameter.\r
+ \r
+ @param isBuildUsedLibrary\r
**/\r
- public void setIsEmulatedPCDDriver(boolean isEmulatedPCDDriver) {\r
- this.isEmulatedPCDDriver = isEmulatedPCDDriver;\r
- }\r
-\r
public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r
this.isBuildUsedLibrary = isBuildUsedLibrary;\r
}\r
\r
+ /**\r
+ set pcdNameArrayInMsa parameter.\r
+ \r
+ @param pcdNameArrayInMsa\r
+ */\r
+ public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r
+ this.pcdNameArrayInMsa = pcdNameArrayInMsa;\r
+ }\r
+\r
/**\r
Get the output of generated string for header file.\r
\r
return cAutoGenString;\r
}\r
\r
+ \r
/**\r
- Construct function\r
- \r
- This function mainly initialize some member variable.\r
- \r
- @param moduleName Parameter of this action class.\r
- @param isEmulatedPCDDriver Parameter of this action class.\r
+ Construct function\r
+\r
+ This function mainly initialize some member variable.\r
+ \r
+ @param moduleId the identification for module\r
+ @param arch the architecture for module\r
+ @param isBuildUsedLibary Is the current module library.\r
+ @param pcdNameArrayInMsa the pcd name array got from MSA file.\r
**/\r
- public PCDAutoGenAction(String moduleName, \r
- UUID moduleGuid, \r
- String packageName,\r
- UUID packageGuid,\r
- String arch,\r
- String version,\r
- boolean isEmulatedPCDDriver, \r
- boolean isBuildUsedLibrary) {\r
+ public PCDAutoGenAction(ModuleIdentification moduleId, \r
+ String arch,\r
+ boolean isBuildUsedLibrary,\r
+ String[] pcdNameArrayInMsa) {\r
+ UsageIdentification usageId = new UsageIdentification(moduleId.getName(), \r
+ moduleId.getGuid(), \r
+ moduleId.getPackage().getName(), \r
+ moduleId.getPackage().getGuid(), \r
+ arch, \r
+ moduleId.getVersion(), \r
+ moduleId.getModuleType());\r
dbManager = null;\r
hAutoGenString = "";\r
cAutoGenString = "";\r
\r
- setIsEmulatedPCDDriver(isEmulatedPCDDriver);\r
- setModuleName(moduleName);\r
- setModuleGuid(moduleGuid);\r
- setPackageName(packageName);\r
- setPackageGuid(packageGuid);\r
- setArch(arch);\r
- setVersion(version);\r
+ setUsageId(usageId);\r
setIsBuildUsedLibrary(isBuildUsedLibrary);\r
+ setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
}\r
\r
/**\r
\r
@throws BuildActionException Bad parameter.\r
**/\r
- void checkParameter() throws BuildActionException {\r
- if(!isEmulatedPCDDriver &&(moduleName == null)) {\r
- throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");\r
- }\r
-\r
- if(!isEmulatedPCDDriver && moduleName.length() == 0) {\r
- throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");\r
- }\r
+ public void checkParameter() throws BuildActionException {\r
+ \r
}\r
\r
/**\r
\r
@throws BuildActionException Failed to execute this aciton class.\r
**/\r
- void performAction() throws BuildActionException {\r
+ public void performAction() throws BuildActionException {\r
ActionMessage.debug(this, \r
"Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
//\r
ActionMessage.debug(this,\r
"PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");\r
\r
-\r
-\r
generateAutogenForModule();\r
}\r
\r
**/\r
private void generateAutogenForModule()\r
{\r
- int index;\r
- List<UsageInstance> usageInstanceArray;\r
-\r
+ int index, index2;\r
+ List<UsageInstance> usageInstanceArray, usageContext;\r
+ String[] guidStringArray = null;\r
+ String guidStringCName = null;\r
+ String guidString = null;\r
+ String moduleName = usageId.moduleName;\r
+ UsageInstance usageInstance = null;\r
+ boolean found = false;\r
+\r
+ usageInstanceArray = null;\r
if (!isBuildUsedLibrary) {\r
- usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r
- moduleGuid,\r
- packageName,\r
- packageGuid,\r
- arch,\r
- version);\r
+ usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
dbManager.UsageInstanceContext = usageInstanceArray;\r
dbManager.CurrentModuleName = moduleName; \r
- } else {\r
- usageInstanceArray = dbManager.UsageInstanceContext;\r
+ } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
+ usageContext = dbManager.UsageInstanceContext;\r
//\r
- // For building MDE package, although all module are library, but PCD entries of \r
+ // For building library package, although all module are library, but PCD entries of \r
// these library should be used to autogen.\r
// \r
- if (usageInstanceArray == null) {\r
- usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(moduleName,\r
- moduleGuid,\r
- packageName,\r
- packageGuid,\r
- arch,\r
- version);\r
+ if (usageContext == null) {\r
+ usageInstanceArray = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
+ } else {\r
+ usageInstanceArray = new ArrayList<UsageInstance>();\r
+\r
+ //\r
+ // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's \r
+ // <ModuleSA> in FPD file.\r
+ // \r
+ for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
+ found = false;\r
+ for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
+ if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
+ usageInstanceArray.add(usageContext.get(index2));\r
+ found = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (!found) {\r
+ //\r
+ // All library's PCD should instanted in module's <ModuleSA> who\r
+ // use this library instance. If not, give errors.\r
+ // \r
+ throw new BuildActionException (String.format("[PCD Autogen Error] Module %s use library instance %s, the PCD %s " +\r
+ "is required by this library instance, but can not find " +\r
+ "it in the %s's <ModuleSA> in FPD file!",\r
+ dbManager.CurrentModuleName,\r
+ moduleName,\r
+ pcdNameArrayInMsa[index],\r
+ dbManager.CurrentModuleName\r
+ ));\r
+ }\r
+ }\r
}\r
}\r
\r
- if(usageInstanceArray.size() != 0) {\r
- //\r
- // Add "#include 'PcdLib.h'" for Header file\r
- //\r
- hAutoGenString = "#include <MdePkg/Include/Library/PcdLib.h>\r\n";\r
+ if (usageInstanceArray == null) {\r
+ return;\r
}\r
\r
+ //\r
+ // Generate all PCD entry for a module.\r
+ // \r
for(index = 0; index < usageInstanceArray.size(); index ++) {\r
- ActionMessage.debug(this,\r
- "Module " + moduleName + "'s PCD [" + Integer.toHexString(index) + \r
- "]: " + usageInstanceArray.get(index).parentToken.cName);\r
- try {\r
- usageInstanceArray.get(index).generateAutoGen(isBuildUsedLibrary);\r
- hAutoGenString += usageInstanceArray.get(index).getHAutogenStr() + "\r\n";\r
- cAutoGenString += usageInstanceArray.get(index).getCAutogenStr() + "\r\n";\r
- } catch(EntityException exp) {\r
- throw new BuildActionException(exp.getMessage());\r
+ usageInstance = usageInstanceArray.get(index);\r
+ //\r
+ // Before generate any PCD information into autogen.h/autogen.c for a module,\r
+ // generate TokenSpaceGuid array variable firstly. For every dynamicEx type\r
+ // PCD in this module the token, they are all reference to TokenSpaceGuid \r
+ // array.\r
+ // \r
+ if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
+ guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r
+ guidStringCName = "_gPcd_TokenSpaceGuid_" + \r
+ usageInstance.parentToken.tokenSpaceName.replaceAll("-", "_");\r
+ 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
+ guidStringArray[0],\r
+ guidStringArray[1],\r
+ guidStringArray[2],\r
+ (guidStringArray[3].substring(0, 2)),\r
+ (guidStringArray[3].substring(2, 4)),\r
+ (guidStringArray[4].substring(0, 2)),\r
+ (guidStringArray[4].substring(2, 4)),\r
+ (guidStringArray[4].substring(4, 6)),\r
+ (guidStringArray[4].substring(6, 8)),\r
+ (guidStringArray[4].substring(8, 10)),\r
+ (guidStringArray[4].substring(10, 12)));\r
+ \r
+ Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r
+ Matcher matcher = pattern.matcher(cAutoGenString + " ");\r
+ //\r
+ // Find whether this guid array variable has been generated into autogen.c\r
+ // For different DyanmicEx pcd token who use same token space guid, the token space\r
+ // guid array should be only generated once.\r
+ // \r
+ if (!matcher.find()) {\r
+ hAutoGenString += String.format("extern EFI_GUID %s;\r\n",\r
+ guidStringCName);\r
+ if (!isBuildUsedLibrary) {\r
+ cAutoGenString += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID %s = %s;\r\n",\r
+ guidStringCName,\r
+ guidString);\r
+ } \r
+ }\r
}\r
+\r
+ usageInstance.generateAutoGen(isBuildUsedLibrary);\r
+ //\r
+ // For every PCD entry for this module(usage instance), autogen string would\r
+ // be appand.\r
+ // \r
+ hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r
+ cAutoGenString += usageInstance.getCAutogenStr();\r
}\r
\r
//\r
hAutoGenString += dbManager.PcdDxeHString;\r
cAutoGenString += dbManager.PcdDxeCString;\r
}\r
-\r
- ActionMessage.debug(this,\r
- "Module " + moduleName + "'s PCD header file:\r\n" + hAutoGenString + "\r\n"\r
- );\r
- ActionMessage.debug(this,\r
- "Module " + moduleName + "'s PCD C file:\r\n" + cAutoGenString + "\r\n"\r
- );\r
}\r
\r
/**\r
**/\r
public static void main(String argv[]) {\r
\r
- String WorkSpace = "M:/ForPcd/edk2";\r
- String logFilePath = WorkSpace + "/MdePkg/MdePkg.fpd";\r
+ String WorkSpace = "X:/edk2";\r
+ String logFilePath = WorkSpace + "/EdkNt32Pkg/Nt32.fpd";\r
+ String[] nameArray = null;\r
\r
//\r
// At first, CollectPCDAction should be invoked to collect\r
//\r
CollectPCDAction collectionAction = new CollectPCDAction();\r
GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
- WorkSpace);\r
+ WorkSpace,null);\r
\r
try {\r
collectionAction.perform(WorkSpace, \r
} catch(Exception e) {\r
e.printStackTrace();\r
}\r
-\r
- //\r
- // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
- //\r
- PCDAutoGenAction autogenAction = new PCDAutoGenAction("BaseLib",\r
- null,\r
- null,\r
- null,\r
- null,\r
- null,\r
- false,\r
- false\r
- );\r
- autogenAction.execute();\r
-\r
- System.out.println(autogenAction.OutputH());\r
- System.out.println("WQWQWQWQWQ");\r
- System.out.println(autogenAction.OutputC());\r
-\r
-\r
- System.out.println (autogenAction.hAutoGenString);\r
- System.out.println (autogenAction.cAutoGenString);\r
-\r
}\r
}\r