X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fpcd%2Faction%2FPlatformPcdPreprocessActionForBuilding.java;h=e9d13720509491ff5440de763d6dfb4b55387f63;hp=2e50531d7e6111005301916093ca542cbedf7cbb;hb=4d1939b86f9a0482c512354cbb5ea11e9deea165;hpb=af98370ea4e0df114beae0707987f9426b1880cd diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java index 2e50531d7e..e9d1372050 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java @@ -28,17 +28,20 @@ import java.util.Map; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions; +import org.tianocore.PcdBuildDefinitionDocument; import org.tianocore.PlatformSurfaceAreaDocument; +import org.tianocore.build.exception.PlatformPcdPreprocessBuildException; import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.global.GlobalData; import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.pcd.action.ActionMessage; -import org.tianocore.pcd.entity.ModulePcdInfoFromFpd; +import org.tianocore.pcd.action.PlatformPcdPreprocessAction; import org.tianocore.pcd.entity.MemoryDatabaseManager; +import org.tianocore.pcd.entity.ModulePcdInfoFromFpd; import org.tianocore.pcd.entity.Token; import org.tianocore.pcd.entity.UsageIdentification; import org.tianocore.pcd.exception.EntityException; -import org.tianocore.pcd.action.PlatformPcdPreprocessAction; +import org.tianocore.pcd.exception.PlatformPcdPreprocessException; /** This action class is to collect PCD information from MSA, SPD, FPD xml file. @@ -46,11 +49,6 @@ import org.tianocore.pcd.action.PlatformPcdPreprocessAction; from buildAction or UIAction. **/ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction { - /// - /// Workspacepath hold the workspace information. - /// - private String workspacePath; - /// /// FPD file is the root file. /// @@ -66,15 +64,6 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces /// private PlatformSurfaceAreaDocument fpdDocInstance; - /** - Set WorkspacePath parameter for this action class. - - @param workspacePath parameter for this action - **/ - public void setWorkspacePath(String workspacePath) { - this.workspacePath = workspacePath; - } - /** Set action message level for CollectPcdAction tool. @@ -99,17 +88,16 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces /** Common function interface for outer. - @param workspacePath The path of workspace of current build or analysis. - @param fpdFilePath The fpd file path of current build or analysis. - @param messageLevel The message level for this Action. + @param fpdFilePath The fpd file path of current build or analysis. + @param messageLevel The message level for this Action. - @throws Exception The exception of this function. Because it can *not* be predict - where the action class will be used. So only Exception can be throw. + @throws PlatformPreprocessBuildException + The exception of this function. Because it can *not* be predict + where the action class will be used. So only Exception can be throw. **/ - public void perform(String workspacePath, String fpdFilePath, - int messageLevel) throws Exception { - setWorkspacePath(workspacePath); + public void perform(String fpdFilePath, int messageLevel) + throws PlatformPcdPreprocessBuildException { setFPDFilePath(fpdFilePath); setActionMessageLevel(messageLevel); checkParameter(); @@ -132,32 +120,40 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces @throws EntityException Exception indicate failed to execute this action. **/ - public void execute() throws EntityException { - MemoryDatabaseManager pcdDbManager = null; + public void execute() throws PlatformPcdPreprocessBuildException { + String errorMessageHeader = "Fail to initialize Pcd memory database for building. Because:"; + String errorsForPreprocess = null; // // Get memoryDatabaseManager instance from GlobalData. - // The memoryDatabaseManager should be initialized for whatever build - // tools or wizard tools + // The memoryDatabaseManager should be initialized as static variable + // in some Pre-process class. // - if((pcdDbManager = GlobalData.getPCDMemoryDBManager()) == null) { - throw new EntityException("The instance of PCD memory database manager is null"); - } - - this.setPcdDbManager(pcdDbManager); + setPcdDbManager(GlobalData.getPCDMemoryDBManager()); // // Collect all PCD information defined in FPD file. // Evenry token defind in FPD will be created as an token into // memory database. // - initPcdMemoryDbWithPlatformInfo(); + try { + initPcdMemoryDbWithPlatformInfo(); + } catch (PlatformPcdPreprocessException exp) { + throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage()); + } + errorsForPreprocess = this.getErrorString(); + if (errorsForPreprocess != null) { + throw new PlatformPcdPreprocessBuildException(errorMessageHeader + "\r\n" + errorsForPreprocess); + } // // Generate for PEI, DXE PCD DATABASE's definition and initialization. // - genPcdDatabaseSourceCode (); - + try { + genPcdDatabaseSourceCode (); + } catch (EntityException exp) { + throw new PlatformPcdPreprocessBuildException(errorMessageHeader + exp.getMessage()); + } } /** @@ -165,14 +161,16 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces @param guidCName Guid CName string. - @return String[] Guid information from SPD file. + @return String Guid information from SPD file. + @throws PlatformPcdPreprocessException + Fail to get Guid information from SPD file. **/ - public String[] getGuidInfoFromSpd(String guidCName) throws EntityException { - String[] tokenSpaceStrRet = null; + public String getGuidInfoFromSpd(String guidCName) throws PlatformPcdPreprocessException { + String tokenSpaceStrRet = null; try { tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName); } catch ( Exception e ) { - throw new EntityException ("Failed get Guid CName " + guidCName + "from SPD file!"); + throw new PlatformPcdPreprocessException ("Failed get Guid CName " + guidCName + "from SPD file!"); } return tokenSpaceStrRet; } @@ -180,7 +178,6 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces /** This function generates source code for PCD Database. - @param void @throws EntityException If the token does *not* exist in memory database. **/ @@ -210,11 +207,12 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces This function maybe provided by some Global class. - @return List the component array. + @return List the component array. + @throws PlatformPcdPreprocessException get all modules in in FPD file. - */ + **/ public List getComponentsFromFpd() - throws EntityException { + throws PlatformPcdPreprocessException { List allModules = new ArrayList(); Map pcdBuildDefinitions = null; UsageIdentification usageId = null; @@ -237,7 +235,10 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces id.getArch(), id.getModule().getVersion(), id.getModule().getModuleType()); - allModules.add(new ModulePcdInfoFromFpd(usageId, pcdBuildDefinitions.get(id))); + allModules.add( + new ModulePcdInfoFromFpd( + usageId, + ((PcdBuildDefinitionDocument)pcdBuildDefinitions.get(id)).getPcdBuildDefinition())); } return allModules; } @@ -246,329 +247,23 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces Override function: Verify the datum value according its datum size and datum type, this function maybe moved to FPD verification tools in future. - @param cName - @param moduleName - @param datum - @param datumType - @param maxDatumSize + @param cName The token name + @param moduleName The module who use this PCD token + @param datum The PCD's datum + @param datumType The PCD's datum type + @param maxDatumSize The max size for PCD's Datum. - @return String + @return String exception strings. */ - /***/ public String verifyDatum(String cName, String moduleName, String datum, Token.DATUM_TYPE datumType, int maxDatumSize) { - String exceptionString = null; - int value; - BigInteger value64; - String subStr; - int index; - - if (moduleName == null) { - moduleName = "section "; - } else { - moduleName = "module " + moduleName; - } - - if (maxDatumSize == 0) { - exceptionString = String.format("[FPD file error] You maybe miss for PCD %s in %s", - cName, - moduleName); - return exceptionString; - } - - switch (datumType) { - case UINT8: - if (maxDatumSize != 1) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is UINT8, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - return exceptionString; - } - - if (datum != null) { - try { - value = Integer.decode(datum); - } catch (NumberFormatException nfeExp) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+ - "digital format of UINT8", - cName, - moduleName); - return exceptionString; - } - if (value > 0xFF) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+ - " the max size of UINT8 - 0xFF", - cName, - moduleName, - datum); - return exceptionString; - } - } - break; - case UINT16: - if (maxDatumSize != 2) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is UINT16, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - return exceptionString; - } - if (datum != null) { - try { - value = Integer.decode(datum); - } catch (NumberFormatException nfeExp) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+ - "not valid digital of UINT16", - cName, - moduleName); - return exceptionString; - } - if (value > 0xFFFF) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+ - "which exceed the range of UINT16 - 0xFFFF", - cName, - moduleName, - datum); - return exceptionString; - } - } - break; - case UINT32: - if (maxDatumSize != 4) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is UINT32, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - return exceptionString; - } - - if (datum != null) { - try { - if (datum.length() > 2) { - if ((datum.charAt(0) == '0') && - ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){ - subStr = datum.substring(2, datum.length()); - value64 = new BigInteger(subStr, 16); - } else { - value64 = new BigInteger(datum); - } - } else { - value64 = new BigInteger(datum); - } - } catch (NumberFormatException nfeExp) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+ - "valid digital of UINT32", - cName, - moduleName); - return exceptionString; - } - - if (value64.bitLength() > 32) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+ - "exceed the range of UINT32 - 0xFFFFFFFF", - cName, - moduleName, - datum); - return exceptionString; - } - } - break; - case UINT64: - if (maxDatumSize != 8) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is UINT64, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - return exceptionString; - } - - if (datum != null) { - try { - if (datum.length() > 2) { - if ((datum.charAt(0) == '0') && - ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){ - subStr = datum.substring(2, datum.length()); - value64 = new BigInteger(subStr, 16); - } else { - value64 = new BigInteger(datum); - } - } else { - value64 = new BigInteger(datum); - } - } catch (NumberFormatException nfeExp) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+ - " digital of UINT64", - cName, - moduleName); - return exceptionString; - } - - if (value64.bitLength() > 64) { - exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+ - "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF", - cName, - moduleName, - datum); - return exceptionString; - } - } - break; - case BOOLEAN: - if (maxDatumSize != 1) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is BOOLEAN, but datum size is %d, they are not matched!", - cName, - moduleName, - maxDatumSize); - return exceptionString; - } - - if (datum != null) { - if (!(datum.equalsIgnoreCase("TRUE") || - datum.equalsIgnoreCase("FALSE"))) { - exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+ - "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'", - cName, - moduleName); - return exceptionString; - } - - } - break; - case POINTER: - if (datum == null) { - break; - } - - char ch = datum.charAt(0); - int start, end; - String strValue; - // - // For void* type PCD, only three datum is support: - // 1) Unicode: string with start char is "L" - // 2) Ansci: String start char is "" - // 3) byte array: String start char "{" - // - if (ch == 'L') { - start = datum.indexOf('\"'); - end = datum.lastIndexOf('\"'); - if ((start > end) || - (end > datum.length())|| - ((start == end) && (datum.length() > 0))) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+ - "a UNICODE string because start with L\", but format maybe"+ - "is not right, correct UNICODE string is L\"...\"!", - cName, - moduleName); - return exceptionString; - } - - strValue = datum.substring(start + 1, end); - if ((strValue.length() * 2) > maxDatumSize) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+ - "a UNICODE string, but the datum size is %d exceed to : %d", - cName, - moduleName, - strValue.length() * 2, - maxDatumSize); - return exceptionString; - } - } else if (ch == '\"'){ - start = datum.indexOf('\"'); - end = datum.lastIndexOf('\"'); - if ((start > end) || - (end > datum.length())|| - ((start == end) && (datum.length() > 0))) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+ - "a ANSCII string because start with \", but format maybe"+ - "is not right, correct ANSIC string is \"...\"!", - cName, - moduleName); - return exceptionString; - } - strValue = datum.substring(start + 1, end); - if ((strValue.length()) > maxDatumSize) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+ - "a ANSCI string, but the datum size is %d which exceed to : %d", - cName, - moduleName, - strValue.length(), - maxDatumSize); - return exceptionString; - } - } else if (ch =='{') { - String[] strValueArray; - - start = datum.indexOf('{'); - end = datum.lastIndexOf('}'); - strValue = datum.substring(start + 1, end); - strValue = strValue.trim(); - if (strValue.length() == 0) { - exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+ - "it is byte array in fact, but '{}' is not valid for NULL datam but"+ - " need use '{0}'", - cName, - moduleName); - return exceptionString; - } - strValueArray = strValue.split(","); - for (index = 0; index < strValueArray.length; index ++) { - try{ - value = Integer.decode(strValueArray[index].trim()); - } catch (NumberFormatException nfeEx) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+ - "it is byte array in fact. For every byte in array should be a valid"+ - "byte digital, but element %s is not a valid byte digital!", - cName, - moduleName, - strValueArray[index]); - return exceptionString; - } - if (value > 0xFF) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+ - "it is byte array in fact. But the element of %s exceed the byte range", - cName, - moduleName, - strValueArray[index]); - return exceptionString; - } - } - - if (strValueArray.length > maxDatumSize) { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+ - "array, but the number of bytes is %d which exceed to : %d!", - cName, - moduleName, - strValueArray.length, - maxDatumSize); - return exceptionString; - } - } else { - exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+ - "1) UNICODE string: like L\"xxxx\";\r\n"+ - "2) ANSIC string: like \"xxx\";\r\n"+ - "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+ - "But the datum in seems does not following above format!", - cName, - moduleName); - return exceptionString; - } - break; - default: - exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+ - "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN", - cName, - moduleName); - return exceptionString; - } + // + // In building system, datum should not be checked, the checking work + // should be done by wizard tools or PCD verification tools. + // return null; } @@ -584,13 +279,13 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces **/ public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token token, String moduleName) - throws EntityException { + throws PlatformPcdPreprocessException { int index = 0; String exceptionString = null; String dynamicPrimaryKey = null; DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null; List dynamicPcdBuildDataArray = null; - String[] tokenSpaceStrRet = null; + String tokenSpaceStrRet = null; // // If FPD document is not be opened, open and initialize it. @@ -600,9 +295,9 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces 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()); + throw new PlatformPcdPreprocessException("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()); + throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage()); } } @@ -612,23 +307,22 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces "PCD entry %s in module %s!", token.cName, moduleName); - throw new EntityException(exceptionString); + putError(exceptionString); + return null; } dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList(); for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) { - try { - tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName()); - } catch (Exception e) { - throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName()); - } + tokenSpaceStrRet = getGuidInfoFromSpd(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName()); if (tokenSpaceStrRet == null) { - throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName()); + exceptionString = "Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName(); + putError(exceptionString); + continue; } dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(), - tokenSpaceStrRet[1]); + tokenSpaceStrRet); if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) { return dynamicPcdBuildDataArray.get(index); } @@ -640,11 +334,13 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces /** Override function: get all from FPD file. - @return List + @return List All DYNAMIC PCD list in in FPD file. + @throws PlatformPcdPreprocessBuildException Failure to get dynamic information list. + **/ public List getAllDynamicPcdInfoFromFpd() - throws EntityException { + throws PlatformPcdPreprocessException { DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null; // @@ -655,14 +351,15 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces 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()); + throw new PlatformPcdPreprocessException("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()); + throw new PlatformPcdPreprocessException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage()); } } dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions(); if (dynamicPcdBuildDefinitions == null) { + putError("There is no in FPD file!"); return null; } @@ -672,28 +369,23 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces /** check parameter for this action. - @throws EntityException Bad parameter. + @throws PlatformPcdPreprocessBuildException Bad parameter. **/ - private void checkParameter() throws EntityException { + private void checkParameter() throws PlatformPcdPreprocessBuildException { File file = null; - if((fpdFilePath == null) ||(workspacePath == null)) { - throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!"); + if (fpdFilePath == null) { + throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!"); } - if(fpdFilePath.length() == 0 || workspacePath.length() == 0) { - throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!"); - } - - file = new File(workspacePath); - if(!file.exists()) { - throw new EntityException("WorkpacePath " + workspacePath + " does not exist!"); + if (fpdFilePath.length() == 0) { + throw new PlatformPcdPreprocessBuildException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!"); } file = new File(fpdFilePath); if(!file.exists()) { - throw new EntityException("FPD File " + fpdFilePath + " does not exist!"); + throw new PlatformPcdPreprocessBuildException("FPD File " + fpdFilePath + " does not exist!"); } } @@ -702,10 +394,9 @@ public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreproces @param argv parameter from command line **/ - public static void main(String argv[]) throws EntityException { + public static void main(String argv[]) throws PlatformPcdPreprocessBuildException { PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding(); String projectDir = "x:/edk2"; - ca.setWorkspacePath(projectDir); ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd"); ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL); GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",