BaseTools: Fixed the issue of Multiple Skus are always disables
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / DscBuildData.py
index a5fceb9..a2979ce 100644 (file)
@@ -845,14 +845,14 @@ class DscBuildData(PlatformBuildClassObject):
             for pcdname in Pcds:\r
                 pcd = Pcds[pcdname]\r
                 Pcds[pcdname].SkuInfoList = {"DEFAULT":pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}\r
-                if type(pcd) is StructurePcd and pcd.OverrideValues:\r
-                    Pcds[pcdname].OverrideValues = {"DEFAULT":pcd.OverrideValues[skuid] for skuid in pcd.OverrideValues if skuid in available_sku}\r
+                if type(pcd) is StructurePcd and pcd.SkuOverrideValues:\r
+                    Pcds[pcdname].SkuOverrideValues = {"DEFAULT":pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}\r
         else:\r
             for pcdname in Pcds:\r
                 pcd = Pcds[pcdname]\r
                 Pcds[pcdname].SkuInfoList = {skuid:pcd.SkuInfoList[skuid] for skuid in pcd.SkuInfoList if skuid in available_sku}\r
-                if type(pcd) is StructurePcd and pcd.OverrideValues:\r
-                    Pcds[pcdname].OverrideValues = {skuid:pcd.OverrideValues[skuid] for skuid in pcd.OverrideValues if skuid in available_sku}\r
+                if type(pcd) is StructurePcd and pcd.SkuOverrideValues:\r
+                    Pcds[pcdname].SkuOverrideValues = {skuid:pcd.SkuOverrideValues[skuid] for skuid in pcd.SkuOverrideValues if skuid in available_sku}\r
         return Pcds\r
     def CompleteHiiPcdsDefaultStores(self,Pcds):\r
         HiiPcd = [Pcds[pcd] for pcd in Pcds if Pcds[pcd].Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]]\r
@@ -945,9 +945,18 @@ class DscBuildData(PlatformBuildClassObject):
         return structure_pcd_data\r
 \r
     def UpdateStructuredPcds(self, TypeList, AllPcds):\r
+\r
+        DynamicPcdType = [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
+                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
+                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
+                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
+                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
+                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]\r
+\r
         Pcds = AllPcds\r
         DefaultStoreMgr = DefaultStore(self.DefaultStores)\r
-        SkuIds = set([skuid for pcdobj in AllPcds.values() for skuid in pcdobj.SkuInfoList.keys()])\r
+        SkuIds = self.SkuIdMgr.AvailableSkuIdSet\r
+        SkuIds.update({'DEFAULT':0})\r
         DefaultStores = set([storename for pcdobj in AllPcds.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict.keys()])\r
 \r
         S_PcdSet = []\r
@@ -1003,12 +1012,7 @@ class DscBuildData(PlatformBuildClassObject):
         if S_pcd_set:\r
             GlobalData.gStructurePcd[self.Arch] = S_pcd_set\r
         for stru_pcd in S_pcd_set.values():\r
-            if stru_pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_DEFAULT],\r
-                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],\r
-                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_VPD],\r
-                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_DEFAULT],\r
-                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII],\r
-                        self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_VPD]]:\r
+            if stru_pcd.Type not in DynamicPcdType:\r
                 continue\r
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
                 for skuid in SkuIds:\r
@@ -1040,6 +1044,7 @@ class DscBuildData(PlatformBuildClassObject):
                         break\r
                     nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
                 stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores})\r
+\r
         Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)\r
         if Str_Pcd_Values:\r
             for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:\r
@@ -1059,7 +1064,16 @@ class DscBuildData(PlatformBuildClassObject):
                         str_pcd_obj.DefaultValue = PcdValue\r
                 else:\r
                     if skuname not in str_pcd_obj.SkuInfoList:\r
-                        str_pcd_obj.SkuInfoList[skuname] = SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], DefaultValue=PcdValue)\r
+                        nextskuid = self.SkuIdMgr.GetNextSkuId(skuname)\r
+                        NoDefault = False\r
+                        while nextskuid not in str_pcd_obj.SkuInfoList:\r
+                            if nextskuid == "DEFAULT":\r
+                                NoDefault = True\r
+                                break\r
+                            nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid)\r
+                        str_pcd_obj.SkuInfoList[skuname] = copy.deepcopy(str_pcd_obj.SkuInfoList[nextskuid]) if not NoDefault else SkuInfoClass(SkuIdName=skuname, SkuId=self.SkuIds[skuname][0], DefaultValue=PcdValue)\r
+                        str_pcd_obj.SkuInfoList[skuname].SkuId = self.SkuIds[skuname][0]\r
+                        str_pcd_obj.SkuInfoList[skuname].SkuIdName = skuname\r
                     else:\r
                         str_pcd_obj.SkuInfoList[skuname].DefaultValue = PcdValue\r
             for str_pcd_obj in S_pcd_set.values():\r
@@ -1076,6 +1090,15 @@ class DscBuildData(PlatformBuildClassObject):
                 str_pcd_obj.MaxDatumSize = self.GetStructurePcdMaxSize(str_pcd_obj)\r
                 Pcds[str_pcd_obj.TokenCName, str_pcd_obj.TokenSpaceGuidCName] = str_pcd_obj\r
 \r
+            for pcdkey in Pcds:\r
+                pcd = Pcds[pcdkey]\r
+                if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                    pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']\r
+                    del(pcd.SkuInfoList['COMMON'])\r
+                elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                    del(pcd.SkuInfoList['COMMON'])\r
+\r
+        map(self.FilterSkuSettings,[Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])\r
         return Pcds\r
 \r
     ## Retrieve non-dynamic PCD settings\r
@@ -1553,13 +1576,26 @@ class DscBuildData(PlatformBuildClassObject):
                 del(pcd.SkuInfoList['COMMON'])\r
             elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
                 del(pcd.SkuInfoList['COMMON'])\r
-            if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
-                if 'DEFAULT' in pcd.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in pcd.SkuInfoList.keys():\r
-                    pcd.SkuInfoList[self.SkuIdMgr.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
-                del(pcd.SkuInfoList['DEFAULT'])\r
+\r
+        map(self.FilterSkuSettings,Pcds.values())\r
 \r
         return Pcds\r
 \r
+    def FilterSkuSettings(self, PcdObj):\r
+\r
+        if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
+            if 'DEFAULT' in PcdObj.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList.keys():\r
+                PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] = PcdObj.SkuInfoList['DEFAULT']\r
+            PcdObj.SkuInfoList = {'DEFAULT':PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId]}\r
+            PcdObj.SkuInfoList['DEFAULT'].SkuIdName = 'DEFAULT'\r
+            PcdObj.SkuInfoList['DEFAULT'].SkuId = '0'\r
+\r
+        elif self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.DEFAULT:\r
+            PcdObj.SkuInfoList = {'DEFAULT':PcdObj.SkuInfoList['DEFAULT']}\r
+\r
+        return PcdObj\r
+\r
+\r
     def CompareVarAttr(self, Attr1, Attr2):\r
         if not Attr1 or not Attr2:  # for empty string\r
             return True\r
@@ -1731,11 +1767,6 @@ class DscBuildData(PlatformBuildClassObject):
             elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
                 del(pcd.SkuInfoList['COMMON'])\r
 \r
-            if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
-                if 'DEFAULT' in pcd.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in pcd.SkuInfoList.keys():\r
-                    pcd.SkuInfoList[self.SkuIdMgr.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
-                del(pcd.SkuInfoList['DEFAULT'])\r
-\r
             if pcd.MaxDatumSize.strip():\r
                 MaxSize = int(pcd.MaxDatumSize, 0)\r
             else:\r
@@ -1755,6 +1786,9 @@ class DscBuildData(PlatformBuildClassObject):
         if not rt:\r
             invalidpcd = ",".join(invalidhii)\r
             EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd)\r
+\r
+        map(self.FilterSkuSettings,Pcds.values())\r
+\r
         return Pcds\r
 \r
     def CheckVariableNameAssignment(self,Pcds):\r
@@ -1854,11 +1888,9 @@ class DscBuildData(PlatformBuildClassObject):
                 del(pcd.SkuInfoList['COMMON'])\r
             elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
                 del(pcd.SkuInfoList['COMMON'])\r
-            if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:\r
-                if 'DEFAULT' in pcd.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in pcd.SkuInfoList.keys():\r
-                    pcd.SkuInfoList[self.SkuIdMgr.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
-                del(pcd.SkuInfoList['DEFAULT'])\r
 \r
+\r
+        map(self.FilterSkuSettings,Pcds.values())\r
         return Pcds\r
 \r
     ## Add external modules\r