]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
add multi-source pcd check before adding/deleting lib instance for ModuleSA in platform.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
index b89f967fa3e53000e18993fbbb172b84a1e35dce..d9c2e69f0c931e5c822907a5d87fe9753e5ab288 100644 (file)
@@ -70,7 +70,7 @@ import org.tianocore.frameworkwizard.packaging.PackageIdentification;
 public class FpdFileContents {\r
 \r
     static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";\r
-    static final String regNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";\r
+    static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";\r
     \r
     private PlatformSurfaceAreaDocument fpdd = null;\r
     \r
@@ -352,7 +352,7 @@ public class FpdFileContents {
                     break;\r
                 }\r
                 String s = cursor.getTextValue();\r
-                if (s.matches(regNewLineAndSpaces)) {\r
+                if (s.matches(regExpNewLineAndSpaces)) {\r
                     continue;\r
                 }\r
             }\r
@@ -401,7 +401,6 @@ public class FpdFileContents {
             vMi.add(libMi);\r
         }\r
         \r
-        try {\r
     nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {\r
 \r
                 for (int j = 0; j < vMi.size(); ++j) {\r
@@ -413,16 +412,10 @@ public class FpdFileContents {
                 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);\r
                 dataModified = true;\r
             }\r
-        }\r
-        catch (Exception e) {\r
-            throw e;\r
-        }\r
         //\r
         // add new Pcd from MSA file to ModuleSA.\r
         //\r
-        try {\r
-       \r
-            for (int i = 0; i < vMi.size(); ++i) {\r
+           for (int i = 0; i < vMi.size(); ++i) {\r
                 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile\r
                                                                                                                           .getModuleXmlObject(vMi\r
                                                                                                                                                  .get(i));\r
@@ -462,10 +455,6 @@ public class FpdFileContents {
                  }\r
 \r
             }\r
-        }\r
-        catch (Exception e){\r
-           throw e;\r
-        }\r
         \r
         return dataModified;\r
     }\r
@@ -648,12 +637,44 @@ public class FpdFileContents {
         return false;\r
     }\r
     \r
+    private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) {\r
+        int libCount = getLibraryInstancesCount(moduleKey);\r
+        String[][] saaLib = new String[libCount][5];\r
+        getLibraryInstances(moduleKey, saaLib);\r
+        ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
+        Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();\r
+        //\r
+        // create vector for module & library instance MIs.\r
+        //\r
+        vMi.add(mi);\r
+        for (int j = 0; j < saaLib.length; ++j) {\r
+            String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];\r
+            ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);\r
+            vMi.add(libMi);\r
+        }\r
+        \r
+        int pcdSourceCount = 0;\r
+        for (int i = 0; i < vMi.size(); ++i) {\r
+            if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) {\r
+                pcdSourceCount++;\r
+            }\r
+        }\r
+        \r
+        if (pcdSourceCount < 2) {\r
+            return false;\r
+        }\r
+        else {\r
+            return true;\r
+        }\r
+        \r
+    }\r
+    \r
     /**Remove PCDBuildDefinition entries from ModuleSA\r
      * @param moduleKey identifier of ModuleSA.\r
      * @param consumer where these entries come from.\r
      */\r
     public void removePcdData(String moduleKey, ModuleIdentification consumer) {\r
-        try {\r
+        \r
             ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);\r
             if (msa.getPcdCoded() == null) {\r
                 return;\r
@@ -672,8 +693,10 @@ public class FpdFileContents {
                         do {\r
                             PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor\r
                                                                                                                                                           .getObject();\r
-                            if (msaPcd.getCName().equals(pcdData.getCName())\r
-                                && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {\r
+                            String cName = msaPcd.getCName();\r
+                            String tsGuidCName = msaPcd.getTokenSpaceGuidCName();\r
+                            if (cName.equals(pcdData.getCName())\r
+                                && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) {\r
 \r
                                 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),\r
                                                   moduleKey);\r
@@ -690,12 +713,7 @@ public class FpdFileContents {
                     cursor.dispose();\r
                 }\r
             }\r
-            \r
-        }\r
-        catch (Exception e){\r
-            e.printStackTrace();\r
-            \r
-        }\r
+        \r
     }\r
     //\r
     // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"\r
@@ -742,7 +760,7 @@ public class FpdFileContents {
                     break;\r
                 }\r
                 String s = cursor.getTextValue();\r
-                if (s.matches(regNewLineAndSpaces)) {\r
+                if (s.matches(regExpNewLineAndSpaces)) {\r
                     continue;\r
                 }\r
             }\r
@@ -1227,15 +1245,24 @@ public class FpdFileContents {
             pcdConsumer = new ArrayList<String>();\r
         }\r
         //\r
+        // Check whether this PCD has already added to ModuleSA, if so, just return.\r
+        //\r
+        String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() \r
+        + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());\r
+        for (int i = 0; i < pcdConsumer.size(); ++i) {\r
+            String pcdInfo = pcdConsumer.get(i);\r
+            if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){\r
+                return;\r
+            }\r
+        }\r
+        //\r
         // Using existing Pcd type, if this pcd already exists in other ModuleSA\r
         //\r
         if (pcdConsumer.size() > 0) {\r
             \r
             itemType = itemType (pcdConsumer.get(0));\r
         }\r
-        String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r
-        + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())\r
-        + " " + itemType;\r
+        String listValue = moduleInfo + " " + itemType;\r
         pcdConsumer.add(listValue);\r
         dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);\r
         \r