BaseTools: Structure Pcd value override incorrect.
authorFeng, Bob C <bob.c.feng@intel.com>
Tue, 4 Sep 2018 06:13:18 +0000 (14:13 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 12 Sep 2018 03:25:20 +0000 (11:25 +0800)
This patch is going to fix the issue that
The Pcd field value is override incorrectly when there
is no Pcd overall value assignment in Dsc file.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/Workspace/BuildClassObject.py
BaseTools/Source/Python/Workspace/DscBuildData.py

index 95370d1..ac3cf7e 100644 (file)
@@ -1655,6 +1655,7 @@ class PlatformAutoGen(AutoGen):
                         continue\r
                     pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList[TAB_DEFAULT])\r
                     pcd.SkuInfoList[SkuName].SkuId = SkuId\r
+                    pcd.SkuInfoList[SkuName].SkuIdName = SkuName\r
         self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
 \r
     def FixVpdOffset(self, VpdFile ):\r
index 88465c5..7e96370 100644 (file)
@@ -61,7 +61,7 @@ class PcdClassObject(object):
         self.validlists = validlists\r
         self.expressions = expressions\r
         self.DscDefaultValue = None\r
-        self.DscRawValue = None\r
+        self.DscRawValue = {}\r
         if IsDsc:\r
             self.DscDefaultValue = Value\r
         self.PcdValueFromComm = ""\r
index aaef404..19ab221 100644 (file)
@@ -1410,7 +1410,7 @@ class DscBuildData(PlatformBuildClassObject):
                             NoDefault = True\r
                             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} if DefaultStores else {TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues})\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} if DefaultStores else {}) #{TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues})\r
                     if not NoDefault:\r
                         stru_pcd.ValueChain.add((skuid, ''))\r
             if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
@@ -1563,7 +1563,9 @@ class DscBuildData(PlatformBuildClassObject):
                                                 None,\r
                                                 IsDsc=True)\r
 \r
-\r
+            if self.SkuIdMgr.SystemSkuId not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:\r
+                Pcds[PcdCName, TokenSpaceGuid].DscRawValue[self.SkuIdMgr.SystemSkuId] = {}\r
+            Pcds[PcdCName, TokenSpaceGuid].DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = PcdValue\r
         return Pcds\r
 \r
     def GetStructurePcdMaxSize(self, str_pcd):\r
@@ -1795,11 +1797,8 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT)\r
         inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
         if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT):\r
-            pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue\r
+            pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT) if Pcd.DefaultFromDSC else None\r
         else:\r
-            if not Pcd.DscRawValue:\r
-                # handle the case that structure pcd is not appear in DSC\r
-                self.CopyDscRawValue(Pcd)\r
             pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName)\r
         for FieldList in [pcddefaultvalue, inherit_OverrideValues.get(DefaultStoreName)]:\r
             if not FieldList:\r
@@ -2001,6 +2000,8 @@ class DscBuildData(PlatformBuildClassObject):
         OverrideValues = {DefaultStore:""}\r
         if Pcd.SkuOverrideValues:\r
             OverrideValues = Pcd.SkuOverrideValues[SkuName]\r
+        if not OverrideValues:\r
+            OverrideValues = {TAB_DEFAULT_STORES_DEFAULT:Pcd.DefaultValues}\r
         for DefaultStoreName in OverrideValues:\r
             CApp = CApp + 'void\n'\r
             CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
@@ -2082,6 +2083,13 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + '}\n'\r
             CApp = CApp + '\n'\r
         return InitByteValue, CApp\r
+    def SkuOverrideValuesEmpty(self,OverrideValues):\r
+        if not OverrideValues:\r
+            return True\r
+        for key in OverrideValues:\r
+            if OverrideValues[key]:\r
+                return False\r
+        return True\r
 \r
     def GenerateByteArrayValue (self, StructuredPcds):\r
         #\r
@@ -2107,7 +2115,7 @@ class DscBuildData(PlatformBuildClassObject):
             CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)\r
             CApp = CApp + self.GenerateFdfValue(Pcd)\r
             CApp = CApp + self.GenerateCommandLineValue(Pcd)\r
-            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
+            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
                 CApp = CApp + self.GenerateInitValueFunction(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)\r
             else:\r
@@ -2116,7 +2124,7 @@ class DscBuildData(PlatformBuildClassObject):
                         continue\r
                     for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
                         CApp = CApp + self.GenerateInitValueFunction(Pcd, SkuName, DefaultStoreName)\r
-            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
+            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],\r
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)\r
             else:\r
@@ -2133,7 +2141,7 @@ class DscBuildData(PlatformBuildClassObject):
         CApp = CApp + '  )\n'\r
         CApp = CApp + '{\n'\r
         for Pcd in StructuredPcds.values():\r
-            if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
+            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
                 CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
             else:\r
                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
@@ -2414,6 +2422,10 @@ class DscBuildData(PlatformBuildClassObject):
                                                     None,\r
                                                     IsDsc=True)\r
 \r
+            if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:\r
+                Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
+            Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = PcdValue\r
+\r
         for pcd in Pcds.values():\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
             # Only fix the value while no value provided in DSC file.\r
@@ -2461,20 +2473,6 @@ class DscBuildData(PlatformBuildClassObject):
         else:\r
             return False\r
 \r
-    def CopyDscRawValue(self, Pcd):\r
-        if Pcd.DscRawValue is None:\r
-            Pcd.DscRawValue = dict()\r
-        if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:\r
-            if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue:\r
-                Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {}\r
-            Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue\r
-        for skuname in Pcd.SkuInfoList:\r
-            Pcd.DscRawValue[skuname] = {}\r
-            if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
-                for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:\r
-                    Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]\r
-            else:\r
-                Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue\r
     def CompletePcdValues(self, PcdSet):\r
         Pcds = {}\r
         DefaultStoreObj = DefaultStore(self._GetDefaultStores())\r
@@ -2482,7 +2480,7 @@ class DscBuildData(PlatformBuildClassObject):
         DefaultStores = set(storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict)\r
         for PcdCName, TokenSpaceGuid in PcdSet:\r
             PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]\r
-            self.CopyDscRawValue(PcdObj)\r
+\r
             if PcdObj.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
@@ -2618,7 +2616,9 @@ class DscBuildData(PlatformBuildClassObject):
                                                 pcdDecObject.expressions,\r
                                                 IsDsc=True)\r
 \r
-\r
+            if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:\r
+                Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
+            Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][DefaultStore] = DefaultValue\r
         for pcd in Pcds.values():\r
             SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
@@ -2753,6 +2753,10 @@ class DscBuildData(PlatformBuildClassObject):
                                                 False,\r
                                                 None,\r
                                                 IsDsc=True)\r
+\r
+            if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue:\r
+                Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
+            Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = InitialValue\r
         for pcd in Pcds.values():\r
             SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r