X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fpcd%2Faction%2FCollectPCDAction.java;h=e0a3eb6fd3642716394fdc35db6b286895827c3e;hp=4d3aadd9619a3f91116e6473bae15c27de76e478;hb=d14ebb43742f411f2a013996b8e76bcab2420552;hpb=6ab88a7c86ac8bdadf87a56ca041b816bd8da453 diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index 4d3aadd961..e0a3eb6fd3 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -41,17 +41,19 @@ import org.tianocore.ModuleSADocument; import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition; import org.tianocore.PlatformSurfaceAreaDocument; -import org.tianocore.build.autogen.CommonDefinition; import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.global.GlobalData; import org.tianocore.build.id.FpdModuleIdentification; -import org.tianocore.build.pcd.action.ActionMessage; -import org.tianocore.build.pcd.entity.DynamicTokenValue; -import org.tianocore.build.pcd.entity.MemoryDatabaseManager; -import org.tianocore.build.pcd.entity.SkuInstance; -import org.tianocore.build.pcd.entity.Token; -import org.tianocore.build.pcd.entity.UsageInstance; -import org.tianocore.build.pcd.exception.EntityException; +import org.tianocore.build.id.ModuleIdentification; +import org.tianocore.pcd.action.ActionMessage; +import org.tianocore.pcd.entity.CommonDefinition; +import org.tianocore.pcd.entity.DynamicTokenValue; +import org.tianocore.pcd.entity.MemoryDatabaseManager; +import org.tianocore.pcd.entity.SkuInstance; +import org.tianocore.pcd.entity.Token; +import org.tianocore.pcd.entity.UsageIdentification; +import org.tianocore.pcd.entity.UsageInstance; +import org.tianocore.pcd.exception.EntityException; /** CStructTypeDeclaration @@ -1124,7 +1126,7 @@ class PcdDatabase { if (t.isDynamicEx()) { exMapTable.add((int)t.tokenNumber, t.dynamicExTokenNumber, - guidTable.add(t.tokenSpaceName, t.getPrimaryKeyString()), + guidTable.add(translateSchemaStringToUUID(t.tokenSpaceName), t.getPrimaryKeyString()), t.getPrimaryKeyString() ); } @@ -1387,7 +1389,7 @@ class PcdDatabase { } private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId) - throws EntityException { + throws EntityException { String typeStr; @@ -1565,28 +1567,119 @@ class PcdDatabase { return retStr; } + /** + Translate the schema string to UUID instance. + + In schema, the string of UUID is defined as following two types string: + 1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( + )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})? + + 2) GuidNamingConvention: pattern = + [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} + + This function will convert string and create uuid instance. + + @param uuidString UUID string in XML file + + @return UUID UUID instance + **/ + private UUID translateSchemaStringToUUID(String uuidString) + throws EntityException { + String temp; + String[] splitStringArray; + int index; + int chIndex; + int chLen; + + if (uuidString == null) { + return null; + } + + if (uuidString.length() == 0) { + return null; + } + + if (uuidString.equals("0") || + uuidString.equalsIgnoreCase("0x0")) { + return new UUID(0, 0); + } + + uuidString = uuidString.replaceAll("\\{", ""); + uuidString = uuidString.replaceAll("\\}", ""); + + // + // If the UUID schema string is GuidArrayType type then need translate + // to GuidNamingConvention type at first. + // + if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) { + splitStringArray = uuidString.split("," ); + if (splitStringArray.length != 11) { + throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString); + } + + // + // Remove blank space from these string and remove header string "0x" + // + for (index = 0; index < 11; index ++) { + splitStringArray[index] = splitStringArray[index].trim(); + splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length()); + } + + // + // Add heading '0' to normalize the string length + // + for (index = 3; index < 11; index ++) { + chLen = splitStringArray[index].length(); + for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) { + splitStringArray[index] = "0" + splitStringArray[index]; + } + } + + // + // construct the final GuidNamingConvention string + // + temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s", + splitStringArray[0], + splitStringArray[1], + splitStringArray[2], + splitStringArray[3], + splitStringArray[4], + splitStringArray[5], + splitStringArray[6], + splitStringArray[7], + splitStringArray[8], + splitStringArray[9], + splitStringArray[10]); + uuidString = temp; + } + + return UUID.fromString(uuidString); + } } +/** Module Info class is the data structure to hold information got from GlobalData. +*/ class ModuleInfo { - private String type; - private FpdModuleIdentification moduleId; + /// + /// Module's ID for a + /// + private FpdModuleIdentification moduleId; + /// + /// xmlobject in FPD file for a + /// private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef; - - - public ModuleInfo (FpdModuleIdentification moduleId, String type, XmlObject pcdDef) { - this.moduleId = moduleId; - this.type = type; - this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition(); - } - public String getModuleType (){ - return this.type; + public ModuleInfo (FpdModuleIdentification moduleId, XmlObject pcdDef) { + this.moduleId = moduleId; + this.pcdBuildDef = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition(); } + public FpdModuleIdentification getModuleId (){ - return this.moduleId; + return moduleId; } + public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){ - return this.pcdBuildDef; + return pcdBuildDef; } } @@ -1595,22 +1688,29 @@ class ModuleInfo { from buildAction or UIAction. **/ public class CollectPCDAction { + /// /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD. + /// private MemoryDatabaseManager dbManager; - + /// /// Workspacepath hold the workspace information. + /// private String workspacePath; - + /// /// FPD file is the root file. + /// private String fpdFilePath; - + /// /// Message level for CollectPCDAction. + /// private int originalMessageLevel; - + /// /// Cache the fpd docment instance for private usage. + /// private PlatformSurfaceAreaDocument fpdDocInstance; - + /// /// xmlObject name + /// private static String xmlObjectName = "PcdBuildDefinition"; /** @@ -1697,8 +1797,7 @@ public class CollectPCDAction { createTokenInDBFromFPD(); // - // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver - // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization. + // Generate for PEI, DXE PCD DATABASE's definition and initialization. // genPcdDatabaseSourceCode (); @@ -1713,7 +1812,7 @@ public class CollectPCDAction { **/ private void genPcdDatabaseSourceCode() throws EntityException { - String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions (); + String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions(); ArrayList alPei = new ArrayList (); ArrayList alDxe = new ArrayList (); @@ -1721,17 +1820,14 @@ public class CollectPCDAction { dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe); PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0); pcdPeiDatabase.genCode(); - MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() - + PcdDatabase.getPcdPeiDatabaseDefinitions(); + MemoryDatabaseManager.PcdPeimHString = PcdCommonHeaderString + pcdPeiDatabase.getHString() + + PcdDatabase.getPcdPeiDatabaseDefinitions(); MemoryDatabaseManager.PcdPeimCString = pcdPeiDatabase.getCString(); - PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, - "DXE", - alPei.size() - ); + PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size()); pcdDxeDatabase.genCode(); - MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() - + PcdDatabase.getPcdDxeDatabaseDefinitions(); + MemoryDatabaseManager.PcdDxeHString = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() + + PcdDatabase.getPcdDxeDatabaseDefinitions(); MemoryDatabaseManager.PcdDxeCString = pcdDxeDatabase.getCString(); } @@ -1745,30 +1841,23 @@ public class CollectPCDAction { */ private List getComponentsFromFPD() throws EntityException { - List allModules = new ArrayList(); - ModuleInfo current = null; - int index = 0; - FrameworkModulesDocument.FrameworkModules fModules = null; - ModuleSADocument.ModuleSA[] modules = null; - HashMap map = new HashMap(); - - if (fpdDocInstance == null) { - try { - fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath)); - } catch(IOException ioE) { - throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage()); - } catch(XmlException xmlE) { - throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage()); - } + List allModules = new ArrayList(); + FrameworkModulesDocument.FrameworkModules fModules = null; + ModuleSADocument.ModuleSA[] modules = null; + Map pcdBuildDefinitions = null; + pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions(); + if (pcdBuildDefinitions == null) { + return null; } - MappcdBuildDef = GlobalData.getFpdModuleSaXmlObject(CollectPCDAction.xmlObjectName); - Set pcdBuildKeySet = pcdBuildDef.keySet(); - Iterator item = pcdBuildKeySet.iterator(); + // + // Loop map to retrieve all PCD build definition and Module id + // + Iterator item = pcdBuildDefinitions.keySet().iterator(); while (item.hasNext()){ - FpdModuleIdentification id = (FpdModuleIdentification)item.next(); - allModules.add(new ModuleInfo(id, id.getModule().getModuleType(),pcdBuildDef.get(id))); + FpdModuleIdentification id = (FpdModuleIdentification) item.next(); + allModules.add(new ModuleInfo(id, pcdBuildDefinitions.get(id))); } return allModules; @@ -1806,6 +1895,8 @@ public class CollectPCDAction { String datum = null; int maxDatumSize = 0; String[] tokenSpaceStrRet = null; + UsageIdentification usageId = null; + ModuleIdentification moduleId = null; // // ---------------------------------------------- @@ -1824,34 +1915,6 @@ public class CollectPCDAction { // ------------------------------------------------------------------- // for (index = 0; index < modules.size(); index ++) { - isDuplicate = false; - for (index2 = 0; index2 < index; index2 ++) { - // - // BUGBUG: For transition schema, we can *not* get module's version from - // , It is work around code. - // - primaryKey1 = UsageInstance.getPrimaryKey(modules.get(index).getModuleId().getModule().getName(), - null, - null, - null, - modules.get(index).getModuleId().getArch(), - null); - primaryKey2 = UsageInstance.getPrimaryKey(modules.get(index2).getModuleId().getModule().getName(), - null, - null, - null, - modules.get(index2).getModuleId().getArch(), - null); - if (primaryKey1.equalsIgnoreCase(primaryKey2)) { - isDuplicate = true; - break; - } - } - - if (isDuplicate) { - continue; - } - // // It is legal for a module does not contains ANY pcd build definitions. // @@ -1881,8 +1944,7 @@ public class CollectPCDAction { throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName()); } - primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), - translateSchemaStringToUUID(tokenSpaceStrRet[1])); + primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), tokenSpaceStrRet[1]); pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString()); datumType = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString()); tokenNumber = Long.decode(pcdBuildData.getToken().toString()); @@ -2021,8 +2083,7 @@ public class CollectPCDAction { throw new EntityException("Fail to get token space guid for token " + token.cName); } - token = new Token(pcdBuildData.getCName(), - translateSchemaStringToUUID(tokenSpaceStrRet[1])); + token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]); token.datumType = datumType; token.tokenNumber = tokenNumber; @@ -2055,15 +2116,17 @@ public class CollectPCDAction { // 2.1.4), Create an usage instance for this token. // ------------------------------------------------ // + moduleId = modules.get(index).getModuleId().getModule(); + usageId = new UsageIdentification (moduleId.getName(), + moduleId.getGuid(), + moduleId.getPackage().getName(), + moduleId.getPackage().getGuid(), + modules.get(index).getModuleId().getArch(), + moduleId.getVersion(), + moduleId.getModuleType()); usageInstance = new UsageInstance(token, - moduleName, - null, - null, - null, - CommonDefinition.getModuleType(modules.get(index).getModuleType()), + usageId, pcdType, - modules.get(index).getModuleId().getArch(), - null, datum, maxDatumSize); token.addUsageInstance(usageInstance); @@ -2103,7 +2166,8 @@ public class CollectPCDAction { String variableGuidString[]; // - // If FPD document is not be opened, open and initialize it. + // Open fpd document to get Section. + // BUGBUG: the function should be move GlobalData in furture. // if (fpdDocInstance == null) { try { @@ -2134,7 +2198,7 @@ public class CollectPCDAction { } primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(), - translateSchemaStringToUUID(tokenSpaceStrRet[1])); + tokenSpaceStrRet[1]); if (dbManager.isTokenInDatabase(primaryKey)) { continue; @@ -2149,7 +2213,7 @@ public class CollectPCDAction { // // Create new token for unreference dynamic PCD token // - token = new Token(pcdBuildData.getCName(), translateSchemaStringToUUID(tokenSpaceStrRet[1])); + token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]); token.datumSize = pcdBuildData.getMaxDatumSize(); @@ -2662,6 +2726,7 @@ public class CollectPCDAction { // // If FPD document is not be opened, open and initialize it. + // BUGBUG: The code should be moved into GlobalData in future. // if (fpdDocInstance == null) { try { @@ -2697,7 +2762,7 @@ public class CollectPCDAction { } dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(), - translateSchemaStringToUUID(tokenSpaceStrRet[1])); + tokenSpaceStrRet[1]); if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) { return dynamicPcdBuildDataArray.get(index); }