X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fplatform%2Fui%2FFpdFileContents.java;h=6ca15710c291dc6b05879f6fad3fb533bf5c1f8c;hp=9ca0509d3cf0441cd0783b921087e8ef5bbda1a9;hb=5342724213d3797764f4deddcaf5677d7340b23a;hpb=7242606411f2b8e74e0bd7dd16c62824ebfef815 diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java index 9ca0509d3c..6ca15710c2 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java @@ -70,6 +70,7 @@ import org.tianocore.frameworkwizard.packaging.PackageIdentification; public class FpdFileContents { static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0"; + static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*"; private PlatformSurfaceAreaDocument fpdd = null; @@ -91,6 +92,11 @@ public class FpdFileContents { private HashMap defaultPcdValue = new HashMap(); + private String itemType (String pcdInfo) { + + return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1); + } + /** * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings. */ @@ -184,7 +190,7 @@ public class FpdFileContents { return fpdFrameworkModules; } - public void getFrameworkModuleGuid (String fvName, Vector vGuid) { + public void getFrameworkModuleSAByFvBinding (String fvName, Vector vGuid) { if (getFrameworkModulesCount() == 0){ return; } @@ -202,8 +208,15 @@ public class FpdFileContents { String[] fvNames = fvBinding.split(" "); for (int i = 0; i < fvNames.length; ++i) { + // + // BugBug : underscore "_" should not be replaced!!! + // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file. + // if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) { - vGuid.add(moduleSa.getModuleGuid()); + String[] sa = new String[] {moduleSa.getModuleGuid(), moduleSa.getModuleVersion(), + moduleSa.getPackageGuid(), moduleSa.getPackageVersion(), + listToString(moduleSa.getSupArchList())}; + vGuid.add(sa); break; } } @@ -251,12 +264,22 @@ public class FpdFileContents { } public ModuleSADocument.ModuleSA getModuleSA(String key) { - String[] s = key.split(" "); + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) { removeElement(getfpdFrameworkModules()); fpdFrameworkModules = null; return null; } + String[] s = key.split(" "); + String archsInKey = ""; + if (s.length > 4) { + for (int i = 4; i < s.length; ++i) { + archsInKey += s[i]; + archsInKey += " "; + } + archsInKey = archsInKey.trim(); + } + ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); while(li.hasNext()) { ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); @@ -271,13 +294,17 @@ public class FpdFileContents { continue; } } - //ToDo add arch check for s[4] + //ToDo add arch check . if (moduleSa.getSupArchList() != null) { - if (!listToString(moduleSa.getSupArchList()).equals(s[4])) { - continue; + if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) { + return moduleSa; + } + } + else { + if (archsInKey.length() == 0) { + return moduleSa; } } - return moduleSa; } } return null; @@ -326,10 +353,21 @@ public class FpdFileContents { } cursor.push(); - cursor.toPrevToken(); + while (cursor.hasPrevToken()) { + cursor.toPrevToken(); + if (!cursor.isText()) { + break; + } + String s = cursor.getTextValue(); + if (s.matches(regExpNewLineAndSpaces)) { + continue; + } + } + if (cursor.isComment()) { cursor.removeXml(); } + cursor.pop(); cursor.removeXml(); if (getFrameworkModulesCount() == 0) { @@ -370,7 +408,6 @@ public class FpdFileContents { vMi.add(libMi); } - try { nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) { for (int j = 0; j < vMi.size(); ++j) { @@ -382,16 +419,10 @@ public class FpdFileContents { removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]); dataModified = true; } - } - catch (Exception e) { - throw e; - } // // add new Pcd from MSA file to ModuleSA. // - try { - - for (int i = 0; i < vMi.size(); ++i) { + for (int i = 0; i < vMi.size(); ++i) { ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile .getModuleXmlObject(vMi .get(i)); @@ -431,10 +462,6 @@ public class FpdFileContents { } } - } - catch (Exception e){ - throw e; - } return dataModified; } @@ -543,6 +570,9 @@ public class FpdFileContents { do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject(); if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) { + // + // change item type while not updating dynPcdData???? + // pcdData.setItemType(PcdItemTypes.Enum.forString(itemType)); if(pcdData.getDatumType().equals("VOID*")) { pcdData.setMaxDatumSize(new Integer(maxSize)); @@ -600,6 +630,7 @@ public class FpdFileContents { // sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText(); sa[1] = msaPcd.getPcdItemType()+""; + sa[2] = msa.getModuleDefinitions().getBinaryModule()+""; return true; } @@ -613,12 +644,44 @@ public class FpdFileContents { return false; } + private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) { + int libCount = getLibraryInstancesCount(moduleKey); + String[][] saaLib = new String[libCount][5]; + getLibraryInstances(moduleKey, saaLib); + ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey); + Vector vMi = new Vector(); + // + // create vector for module & library instance MIs. + // + vMi.add(mi); + for (int j = 0; j < saaLib.length; ++j) { + String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4]; + ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey); + vMi.add(libMi); + } + + int pcdSourceCount = 0; + for (int i = 0; i < vMi.size(); ++i) { + if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) { + pcdSourceCount++; + } + } + + if (pcdSourceCount < 2) { + return false; + } + else { + return true; + } + + } + /**Remove PCDBuildDefinition entries from ModuleSA * @param moduleKey identifier of ModuleSA. * @param consumer where these entries come from. */ public void removePcdData(String moduleKey, ModuleIdentification consumer) { - try { + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer); if (msa.getPcdCoded() == null) { return; @@ -632,12 +695,15 @@ public class FpdFileContents { ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey); if (moduleSA.getPcdBuildDefinition() != null) { XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor(); + cursor.push(); if (cursor.toFirstChild()) { do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor .getObject(); - if (msaPcd.getCName().equals(pcdData.getCName()) - && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) { + String cName = msaPcd.getCName(); + String tsGuidCName = msaPcd.getTokenSpaceGuidCName(); + if (cName.equals(pcdData.getCName()) + && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) { maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey); @@ -646,15 +712,15 @@ public class FpdFileContents { } } while (cursor.toNextSibling()); } + + cursor.pop(); + if (moduleSA.getPcdBuildDefinition().getPcdDataList().size() == 0) { + cursor.removeXml(); + } cursor.dispose(); } } - - } - catch (Exception e){ - e.printStackTrace(); - - } + } // // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch" @@ -695,7 +761,17 @@ public class FpdFileContents { cursor.toNextSibling(); } cursor.push(); - cursor.toPrevToken(); + while (cursor.hasPrevToken()) { + cursor.toPrevToken(); + if (!cursor.isText()) { + break; + } + String s = cursor.getTextValue(); + if (s.matches(regExpNewLineAndSpaces)) { + continue; + } + } + if (cursor.isComment()) { cursor.removeXml(); } @@ -895,14 +971,9 @@ public class FpdFileContents { setFvBinding (moduleSa, newFvNameList.trim()); } - public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) { - Vector vSupArchs = new Vector(); - getPlatformDefsSupportedArchs(vSupArchs); - String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion(); - for (int i = 0; i < vSupArchs.size(); ++i) { - String moduleKey = moduleInfo + " " + vSupArchs.get(i); - appendFvBinding (moduleKey, fvName); - } + public void updateFvBindingInModuleSA (String moduleKey, String fvName) { + + appendFvBinding (moduleKey, fvName); } public String getFfsFileNameGuid(String moduleKey){ @@ -1176,15 +1247,24 @@ public class FpdFileContents { pcdConsumer = new ArrayList(); } // + // Check whether this PCD has already added to ModuleSA, if so, just return. + // + String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() + + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()); + for (int i = 0; i < pcdConsumer.size(); ++i) { + String pcdInfo = pcdConsumer.get(i); + if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){ + return; + } + } + // // Using existing Pcd type, if this pcd already exists in other ModuleSA // if (pcdConsumer.size() > 0) { - String[] valPart = pcdConsumer.get(0).split(" "); - itemType = valPart[5]; + + itemType = itemType (pcdConsumer.get(0)); } - String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() - + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()) - + " " + itemType; + String listValue = moduleInfo + " " + itemType; pcdConsumer.add(listValue); dynPcdMap.put(cName + " " + tsGuid, pcdConsumer); @@ -1681,7 +1761,15 @@ public class FpdFileContents { for (int i = 0; i < includeModules.size(); ++i) { cursor.beginElement(elementModule); cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]); - cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]); + if (!includeModules.get(i)[1].equals("null") && includeModules.get(i)[1].length() != 0) { + cursor.insertAttributeWithValue("ModuleVersion", includeModules.get(i)[1]); + } + cursor.insertAttributeWithValue("PackageGuid", includeModules.get(i)[2]); + if (!includeModules.get(i)[3].equals("null") && includeModules.get(i)[3].length() != 0) { + cursor.insertAttributeWithValue("PackageVersion", includeModules.get(i)[3]); + } + + cursor.insertAttributeWithValue("Arch", includeModules.get(i)[4]); cursor.toEndToken(); cursor.toNextToken(); } @@ -1729,7 +1817,10 @@ public class FpdFileContents { QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName attribModuleGuid = new QName("ModuleGuid"); - QName attribBaseName = new QName("BaseName"); + QName attribModuleVersion = new QName("ModuleVersion"); + QName attribPackageGuid = new QName("PackageGuid"); + QName attribPackageVersion = new QName("PackageVersion"); + QName attribArch = new QName("Arch"); if (cursor.toChild(elementUserExts)) { do { @@ -1743,7 +1834,10 @@ public class FpdFileContents { int i = 0; do { saa[i][0] = cursor.getAttributeText(attribModuleGuid); - saa[i][1] = cursor.getAttributeText(attribBaseName); + saa[i][1] = cursor.getAttributeText(attribModuleVersion); + saa[i][2] = cursor.getAttributeText(attribPackageGuid); + saa[i][3] = cursor.getAttributeText(attribPackageVersion); + saa[i][4] = cursor.getAttributeText(attribArch); ++i; }while (cursor.toNextSibling()); } @@ -2608,7 +2702,7 @@ public class FpdFileContents { } } - public void AddFvImageFvImageNames (String[] fvNames) { + public void addFvImageFvImageNames (String[] fvNames) { FvImagesDocument.FvImages fis = getfpdFlash().getFvImages(); if (fis == null || fis.getFvImageList() == null) { genFvImagesFvImage (fvNames, "ImageName", null); @@ -2619,14 +2713,35 @@ public class FpdFileContents { while (li.hasNext()) { FvImagesDocument.FvImages.FvImage fi = li.next(); if (fi.getType().toString().equals("ImageName")) { - for (int i = 0; i < fvNames.length; ++i) { - fi.addFvImageNames(fvNames[i]); - } + addFvImageNamesInFvImage (fi, fvNames); return; } } - genFvImagesFvImage (fvNames, "ImageName", null); + genFvImagesFvImage (fvNames, "ImageName", null); + } + + public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) { + for (int i = 0; i < fvNames.length; ++i) { + fi.addFvImageNames(fvNames[i]); + } + } + + public void addFvImageNamesInFvImage (int i, String[] fvNames) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + addFvImageNamesInFvImage(fi, fvNames); + } + cursor.dispose(); } public void genFvImagesFvImage(String[] names, String types, Map options) { @@ -2706,6 +2821,22 @@ public class FpdFileContents { } } + public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + updateFvImageNamesInFvImage (fi, oldFvName, newFvName); + } + cursor.dispose(); + } /** * @param fi * @param oldFvName The FV Name to be replaced. @@ -2723,7 +2854,7 @@ public class FpdFileContents { cursor.setTextValue(newFvName); } else { - cursor.removeXml(); + cursor.removeXml(); } } }while (cursor.toNextSibling(qFvImageNames)); @@ -2870,6 +3001,22 @@ public class FpdFileContents { } } + public void removeFvImageNameValue (int i, String attributeName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + removeFvImageNameValue (fi, attributeName); + } + cursor.dispose(); + } /**Remove from fi the attribute pair with attributeName in FvImageOptions. * @param fi * @param attributeName @@ -2953,6 +3100,23 @@ public class FpdFileContents { } + public void setFvImagesFvImageNameValue (int i, String name, String value) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + setFvImagesFvImageNameValue (fi, name, value, null); + } + cursor.dispose(); + } + /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before. * @param fi * @param name @@ -2961,6 +3125,12 @@ public class FpdFileContents { */ public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) { if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue(); + nv.setName(name); + nv.setValue(value); + if (newName != null) { + nv.setName(newName); + } return; } @@ -3013,7 +3183,7 @@ public class FpdFileContents { } int pos = -1; - String[] fvNameArray = fvNameList.split(" "); + String[] fvNameArray = fvNameList.trim().split(" "); Vector vFvNames = new Vector();