import org.tianocore.PcdBuildDefinitionDocument;\r
import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
import org.tianocore.PlatformSurfaceAreaDocument;\r
-import org.tianocore.build.autogen.CommonDefinition;\r
import org.tianocore.build.fpd.FpdParserTask;\r
import org.tianocore.build.global.GlobalData;\r
import org.tianocore.build.id.FpdModuleIdentification;\r
-import org.tianocore.build.pcd.action.ActionMessage;\r
-import org.tianocore.build.pcd.entity.DynamicTokenValue;\r
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
-import org.tianocore.build.pcd.entity.SkuInstance;\r
-import org.tianocore.build.pcd.entity.Token;\r
-import org.tianocore.build.pcd.entity.UsageInstance;\r
-import org.tianocore.build.pcd.exception.EntityException;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.pcd.action.ActionMessage;\r
+import org.tianocore.pcd.entity.CommonDefinition;\r
+import org.tianocore.pcd.entity.DynamicTokenValue;\r
+import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
+import org.tianocore.pcd.entity.SkuInstance;\r
+import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
+import org.tianocore.pcd.entity.UsageInstance;\r
+import org.tianocore.pcd.exception.EntityException;\r
\r
/**\r
CStructTypeDeclaration \r
// If so, return the GuidTable index.\r
//\r
for (int i = 0; i < al.size(); i++) {\r
- if (al.get(i).equals(uuid)) {\r
+ if (al.get(i).compareTo(uuid) == 0) {\r
return i;\r
}\r
}\r
}\r
\r
private ArrayList<ExTriplet> al;\r
- private ArrayList<String> alComment;\r
+ private Map<ExTriplet, String> alComment;\r
private String phase;\r
private int len;\r
private int bodyLineNum;\r
public ExMapTable (String phase) {\r
this.phase = phase;\r
al = new ArrayList<ExTriplet>();\r
- alComment = new ArrayList<String>();\r
+ alComment = new HashMap<ExTriplet, String>();\r
bodyLineNum = 0;\r
len = 0;\r
}\r
str += e.localTokenIdx.toString() + ", ";\r
str += e.guidTableIdx.toString();\r
\r
- str += "}" + " /* " + alComment.get(index) + " */" ;\r
+ str += "}" + " /* " + alComment.get(e) + " */" ;\r
\r
if (index != al.size() - 1) {\r
str += ",";\r
public int add (int localTokenIdx, long exTokenNum, int guidTableIdx, String name) {\r
int index = len;\r
\r
- len++; \r
- al.add(new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx));\r
- alComment.add(name);\r
+ len++;\r
+ ExTriplet et = new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx); \r
+\r
+ al.add(et);\r
+ alComment.put(et, name);\r
\r
return index;\r
}\r
if (t.isDynamicEx()) {\r
exMapTable.add((int)t.tokenNumber, \r
t.dynamicExTokenNumber, \r
- guidTable.add(t.tokenSpaceName, t.getPrimaryKeyString()), \r
+ guidTable.add(translateSchemaStringToUUID(t.tokenSpaceName), t.getPrimaryKeyString()), \r
t.getPrimaryKeyString()\r
);\r
}\r
}\r
\r
private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId) \r
- throws EntityException {\r
+ throws EntityException {\r
\r
String typeStr;\r
\r
return retStr;\r
}\r
\r
+ /**\r
+ Translate the schema string to UUID instance.\r
+ \r
+ In schema, the string of UUID is defined as following two types string:\r
+ 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
+ )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
+ \r
+ 2) GuidNamingConvention: pattern =\r
+ [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\r
+ \r
+ This function will convert string and create uuid instance.\r
+ \r
+ @param uuidString UUID string in XML file\r
+ \r
+ @return UUID UUID instance\r
+ **/\r
+ private UUID translateSchemaStringToUUID(String uuidString) \r
+ throws EntityException {\r
+ String temp;\r
+ String[] splitStringArray;\r
+ int index;\r
+ int chIndex;\r
+ int chLen;\r
+\r
+ if (uuidString == null) {\r
+ return null;\r
+ }\r
+\r
+ if (uuidString.length() == 0) {\r
+ return null;\r
+ }\r
+\r
+ if (uuidString.equals("0") ||\r
+ uuidString.equalsIgnoreCase("0x0")) {\r
+ return new UUID(0, 0);\r
+ }\r
+\r
+ uuidString = uuidString.replaceAll("\\{", "");\r
+ uuidString = uuidString.replaceAll("\\}", "");\r
+\r
+ //\r
+ // If the UUID schema string is GuidArrayType type then need translate \r
+ // to GuidNamingConvention type at first.\r
+ // \r
+ if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
+ splitStringArray = uuidString.split("," );\r
+ if (splitStringArray.length != 11) {\r
+ throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);\r
+ }\r
+\r
+ //\r
+ // Remove blank space from these string and remove header string "0x"\r
+ // \r
+ for (index = 0; index < 11; index ++) {\r
+ splitStringArray[index] = splitStringArray[index].trim();\r
+ splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
+ }\r
+\r
+ //\r
+ // Add heading '0' to normalize the string length\r
+ // \r
+ for (index = 3; index < 11; index ++) {\r
+ chLen = splitStringArray[index].length();\r
+ for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
+ splitStringArray[index] = "0" + splitStringArray[index];\r
+ }\r
+ }\r
+\r
+ //\r
+ // construct the final GuidNamingConvention string\r
+ // \r
+ temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
+ splitStringArray[0],\r
+ splitStringArray[1],\r
+ splitStringArray[2],\r
+ splitStringArray[3],\r
+ splitStringArray[4],\r
+ splitStringArray[5],\r
+ splitStringArray[6],\r
+ splitStringArray[7],\r
+ splitStringArray[8],\r
+ splitStringArray[9],\r
+ splitStringArray[10]);\r
+ uuidString = temp;\r
+ }\r
+\r
+ return UUID.fromString(uuidString);\r
+ }\r
}\r
\r
+/** Module Info class is the data structure to hold information got from GlobalData.\r
+*/\r
class ModuleInfo {\r
- private String type;\r
- private FpdModuleIdentification moduleId;\r
+ ///\r
+ /// Module's ID for a <ModuleSA>\r
+ /// \r
+ private FpdModuleIdentification moduleId;\r
+ ///\r
+ /// <PcdBuildDefinition> xmlobject in FPD file for a <ModuleSA>\r
+ /// \r
private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef;\r
- \r
- \r
\r
- public ModuleInfo (FpdModuleIdentification moduleId, String type, XmlObject pcdDef) {\r
- this.moduleId = moduleId;\r
- this.type = type;\r
- this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
- }\r
- public String getModuleType (){\r
- return this.type;\r
+ public ModuleInfo (FpdModuleIdentification moduleId, XmlObject pcdDef) {\r
+ this.moduleId = moduleId;\r
+ this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
}\r
+\r
public FpdModuleIdentification getModuleId (){\r
- return this.moduleId;\r
+ return moduleId;\r
}\r
+\r
public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){\r
- return this.pcdBuildDef;\r
+ return pcdBuildDef;\r
}\r
}\r
\r
from buildAction or UIAction.\r
**/\r
public class CollectPCDAction {\r
+ ///\r
/// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.\r
+ /// \r
private MemoryDatabaseManager dbManager;\r
-\r
+ ///\r
/// Workspacepath hold the workspace information.\r
+ /// \r
private String workspacePath;\r
-\r
+ ///\r
/// FPD file is the root file. \r
+ /// \r
private String fpdFilePath;\r
-\r
+ ///\r
/// Message level for CollectPCDAction.\r
+ /// \r
private int originalMessageLevel;\r
-\r
+ ///\r
/// Cache the fpd docment instance for private usage.\r
+ /// \r
private PlatformSurfaceAreaDocument fpdDocInstance;\r
- \r
+ ///\r
/// xmlObject name\r
+ /// \r
private static String xmlObjectName = "PcdBuildDefinition"; \r
\r
/**\r
createTokenInDBFromFPD();\r
\r
//\r
- // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
- // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
+ // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
//\r
genPcdDatabaseSourceCode ();\r
\r
**/\r
private void genPcdDatabaseSourceCode()\r
throws EntityException {\r
- String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();\r
+ String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
\r
ArrayList<Token> alPei = new ArrayList<Token> ();\r
ArrayList<Token> alDxe = new ArrayList<Token> ();\r
dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
pcdPeiDatabase.genCode();\r
- MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
- + PcdDatabase.getPcdPeiDatabaseDefinitions();\r
+ MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() + \r
+ PcdDatabase.getPcdPeiDatabaseDefinitions();\r
MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString();\r
\r
- PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
- "DXE",\r
- alPei.size()\r
- );\r
+ PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
pcdDxeDatabase.genCode();\r
- MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
- + PcdDatabase.getPcdDxeDatabaseDefinitions();\r
+ MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() + \r
+ PcdDatabase.getPcdDxeDatabaseDefinitions();\r
MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString();\r
}\r
\r
*/\r
private List<ModuleInfo> getComponentsFromFPD() \r
throws EntityException {\r
- List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
- ModuleInfo current = null;\r
- int index = 0;\r
- FrameworkModulesDocument.FrameworkModules fModules = null;\r
- ModuleSADocument.ModuleSA[] modules = null;\r
- HashMap<String, XmlObject> map = new HashMap<String, XmlObject>();\r
-\r
- if (fpdDocInstance == null) {\r
- try {\r
- fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
- } catch(IOException ioE) {\r
- throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
- } catch(XmlException xmlE) {\r
- throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
- }\r
+ List<ModuleInfo> allModules = new ArrayList<ModuleInfo>();\r
+ FrameworkModulesDocument.FrameworkModules fModules = null;\r
+ ModuleSADocument.ModuleSA[] modules = null;\r
+ Map<FpdModuleIdentification, XmlObject> pcdBuildDefinitions = null;\r
\r
+ pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
+ if (pcdBuildDefinitions == null) {\r
+ return null;\r
}\r
\r
- Map<FpdModuleIdentification,XmlObject>pcdBuildDef = GlobalData.getFpdModuleSaXmlObject(CollectPCDAction.xmlObjectName);\r
- Set<FpdModuleIdentification> pcdBuildKeySet = pcdBuildDef.keySet();\r
- Iterator item = pcdBuildKeySet.iterator();\r
+ //\r
+ // Loop map to retrieve all PCD build definition and Module id \r
+ // \r
+ Iterator item = pcdBuildDefinitions.keySet().iterator();\r
while (item.hasNext()){\r
- FpdModuleIdentification id = (FpdModuleIdentification)item.next();\r
- allModules.add(new ModuleInfo(id, id.getModule().getModuleType(),pcdBuildDef.get(id))); \r
+ FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
+ allModules.add(new ModuleInfo(id, pcdBuildDefinitions.get(id))); \r
}\r
\r
return allModules;\r
String datum = null;\r
int maxDatumSize = 0;\r
String[] tokenSpaceStrRet = null;\r
+ UsageIdentification usageId = null;\r
+ ModuleIdentification moduleId = null;\r
\r
//\r
// ----------------------------------------------\r
// -------------------------------------------------------------------\r
// \r
for (index = 0; index < modules.size(); index ++) {\r
- isDuplicate = false;\r
- for (index2 = 0; index2 < index; index2 ++) {\r
- //\r
- // BUGBUG: For transition schema, we can *not* get module's version from \r
- // <ModuleSAs>, It is work around code.\r
- // \r
- primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).getModuleId().getModule().getName(), \r
- null,\r
- null,\r
- null, \r
- modules.get(index).getModuleId().getArch(),\r
- null);\r
- primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).getModuleId().getModule().getName(), \r
- null, \r
- null, \r
- null, \r
- modules.get(index2).getModuleId().getArch(), \r
- null);\r
- if (primaryKey1.equalsIgnoreCase(primaryKey2)) {\r
- isDuplicate = true;\r
- break;\r
- }\r
- }\r
-\r
- if (isDuplicate) {\r
- continue;\r
- }\r
-\r
//\r
// It is legal for a module does not contains ANY pcd build definitions.\r
// \r
throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName());\r
} \r
\r
- primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
tokenNumber = Long.decode(pcdBuildData.getToken().toString());\r
throw new EntityException("Fail to get token space guid for token " + token.cName);\r
}\r
\r
- token = new Token(pcdBuildData.getCName(), \r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
\r
token.datumType = datumType;\r
token.tokenNumber = tokenNumber;\r
// 2.1.4), Create an usage instance for this token.\r
// ------------------------------------------------\r
// \r
+ moduleId = modules.get(index).getModuleId().getModule();\r
+ usageId = new UsageIdentification (moduleId.getName(), \r
+ moduleId.getGuid(), \r
+ moduleId.getPackage().getName(), \r
+ moduleId.getPackage().getGuid(), \r
+ modules.get(index).getModuleId().getArch(),\r
+ moduleId.getVersion(),\r
+ moduleId.getModuleType());\r
usageInstance = new UsageInstance(token, \r
- moduleName, \r
- null,\r
- null,\r
- null,\r
- CommonDefinition.getModuleType(modules.get(index).getModuleType()), \r
+ usageId,\r
pcdType,\r
- modules.get(index).getModuleId().getArch(), \r
- null,\r
datum,\r
maxDatumSize);\r
token.addUsageInstance(usageInstance);\r
String variableGuidString[];\r
\r
//\r
- // If FPD document is not be opened, open and initialize it.\r
+ // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
+ // BUGBUG: the function should be move GlobalData in furture.\r
// \r
if (fpdDocInstance == null) {\r
try {\r
} \r
\r
primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ tokenSpaceStrRet[1]);\r
\r
if (dbManager.isTokenInDatabase(primaryKey)) {\r
continue;\r
//\r
// Create new token for unreference dynamic PCD token\r
// \r
- token = new Token(pcdBuildData.getCName(), translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
token.datumSize = pcdBuildData.getMaxDatumSize();\r
\r
\r
strValue = datum.substring(start + 1, end);\r
strValue = strValue.trim();\r
if (strValue.length() == 0) {\r
- break;\r
+ exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
+ "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
+ " need use '{0}'",\r
+ cName,\r
+ moduleName);\r
+ return exceptionString;\r
}\r
strValueArray = strValue.split(",");\r
for (index = 0; index < strValueArray.length; index ++) {\r
\r
//\r
// If FPD document is not be opened, open and initialize it.\r
+ // BUGBUG: The code should be moved into GlobalData in future.\r
// \r
if (fpdDocInstance == null) {\r
try {\r
}\r
\r
dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
- translateSchemaStringToUUID(tokenSpaceStrRet[1]));\r
+ tokenSpaceStrRet[1]);\r
if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
return dynamicPcdBuildDataArray.get(index);\r
}\r
}\r
\r
pcdType = Token.getpcdTypeFromString(dynamicInfo.getItemType().toString());\r
- if (pcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
- token.dynamicExTokenNumber = tokenNumber;\r
- }\r
+ token.dynamicExTokenNumber = tokenNumber;\r
\r
skuInfoList = dynamicInfo.getSkuInfoList();\r
\r