BaseTools: Fixed the issue of structure pcd filed sku inherit override
authorLiming Gao <liming.gao@intel.com>
Fri, 22 Dec 2017 12:53:01 +0000 (20:53 +0800)
committerLiming Gao <liming.gao@intel.com>
Mon, 25 Dec 2017 03:05:54 +0000 (11:05 +0800)
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Feng Bob C <bob.c.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/Common/Misc.py
BaseTools/Source/Python/Workspace/DscBuildData.py

index 549c879..0374be0 100644 (file)
@@ -2145,12 +2145,21 @@ class SkuClass():
     def __init__(self,SkuIdentifier='', SkuIds=None):\r
         if SkuIds is None:\r
             SkuIds = {}\r
+\r
+        for SkuName in SkuIds:\r
+            SkuId = SkuIds[SkuName][0]\r
+            skuid_num = int(SkuId,16) if SkuId.upper().startswith("0X") else int(SkuId)\r
+            if skuid_num > 0xFFFF:\r
+                EdkLogger.error("build", PARAMETER_INVALID,\r
+                            ExtraData = "SKU-ID [%s] must less than 65535"\r
+                                      % (SkuName))\r
         \r
         self.AvailableSkuIds = sdict()\r
         self.SkuIdSet = []\r
         self.SkuIdNumberSet = []\r
         self.SkuData = SkuIds\r
         self.__SkuInherit = {}\r
+        self.__SkuIdentifier = SkuIdentifier\r
         if SkuIdentifier == '' or SkuIdentifier is None:\r
             self.SkuIdSet = ['DEFAULT']\r
             self.SkuIdNumberSet = ['0U']\r
@@ -2189,14 +2198,48 @@ class SkuClass():
             for item in self.SkuData.values():\r
                 self.__SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT"\r
         return self.__SkuInherit.get(skuname,"DEFAULT")\r
+\r
+    def GetSkuChain(self,sku):\r
+        skulist = [sku]\r
+        nextsku = sku\r
+        while 1:\r
+            nextsku = self.GetNextSkuId(nextsku)\r
+            skulist.append(nextsku)\r
+            if nextsku == "DEFAULT":\r
+                break\r
+        skulist.reverse()\r
+        return skulist\r
+    def SkuOverrideOrder(self):\r
+        skuorderset = []\r
+        for skuname in self.SkuIdSet:\r
+            skuorderset.append(self.GetSkuChain(skuname))\r
         \r
+        skuorder = []\r
+        for index in range(max([len(item) for item in skuorderset])):\r
+            for subset in skuorderset:\r
+                if index > len(subset)-1:\r
+                    continue\r
+                if subset[index] in skuorder:\r
+                    continue\r
+                skuorder.append(subset[index])\r
+\r
+        return skuorder\r
+\r
     def __SkuUsageType(self): \r
         \r
+        if self.__SkuIdentifier.upper() == "ALL":\r
+            return SkuClass.MULTIPLE\r
+\r
         if len(self.SkuIdSet) == 1:\r
             if self.SkuIdSet[0] == 'DEFAULT':\r
                 return SkuClass.DEFAULT\r
             else:\r
                 return SkuClass.SINGLE\r
+        elif len(self.SkuIdSet) == 2:\r
+            if 'DEFAULT' in self.SkuIdSet:\r
+                return SkuClass.SINGLE\r
+            else:\r
+                return SkuClass.MULTIPLE\r
         else:\r
             return SkuClass.MULTIPLE\r
     def DumpSkuIdArrary(self):\r
@@ -2219,7 +2262,10 @@ class SkuClass():
     \r
     def __GetSystemSkuID(self):\r
         if self.__SkuUsageType() == SkuClass.SINGLE:\r
-            return self.SkuIdSet[0]\r
+            if len(self.SkuIdSet) == 1:\r
+                return self.SkuIdSet[0]\r
+            else:\r
+                return self.SkuIdSet[0] if self.SkuIdSet[0] != 'DEFAULT' else self.SkuIdSet[1]\r
         else:\r
             return 'DEFAULT'\r
     def __GetAvailableSkuIdNumber(self):\r
index 66f1faf..135b608 100644 (file)
@@ -916,6 +916,8 @@ class DscBuildData(PlatformBuildClassObject):
             for CodeBase in (EDKII_NAME, EDK_NAME):\r
                 RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]\r
                 for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4,Dummy5 in RecordList:\r
+                    if Dummy3.upper() != 'COMMON':\r
+                        continue\r
                     CurKey = (ToolChainFamily, ToolChain, CodeBase)\r
                     #\r
                     # Only flags can be appended\r
@@ -923,7 +925,8 @@ class DscBuildData(PlatformBuildClassObject):
                     if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
                         self._BuildOptions[CurKey] = Option\r
                     else:\r
-                        self._BuildOptions[CurKey] += ' ' + Option\r
+                        if ' ' + Option not in self._BuildOptions[CurKey]:\r
+                            self._BuildOptions[CurKey] += ' ' + Option\r
         return self._BuildOptions\r
 \r
     def GetBuildOptionsByModuleType(self, Edk, ModuleType):\r
@@ -934,14 +937,16 @@ class DscBuildData(PlatformBuildClassObject):
             self._ModuleTypeOptions[Edk, ModuleType] = options\r
             DriverType = '%s.%s' % (Edk, ModuleType)\r
             CommonDriverType = '%s.%s' % ('COMMON', ModuleType)\r
-            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, DriverType]\r
-            for ToolChainFamily, ToolChain, Option, Arch, Type, Dummy3, Dummy4,Dummy5 in RecordList:\r
-                if Type == DriverType or Type == CommonDriverType:\r
+            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch]\r
+            for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4,Dummy5 in RecordList:\r
+                Type = Dummy2 + '.' + Dummy3\r
+                if Type.upper() == DriverType.upper() or Type.upper() == CommonDriverType.upper():\r
                     Key = (ToolChainFamily, ToolChain, Edk)\r
                     if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
                         options[Key] = Option\r
                     else:\r
-                        options[Key] += ' ' + Option\r
+                        if ' ' + Option not in options[Key]:\r
+                            options[Key] += ' ' + Option\r
         return self._ModuleTypeOptions[Edk, ModuleType]\r
 \r
     def GetStructurePcdInfo(self, PcdSet):\r
@@ -1021,8 +1026,6 @@ 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 DynamicPcdType:\r
-                continue\r
             for skuid in SkuIds:\r
                 if skuid in stru_pcd.SkuOverrideValues:\r
                     continue\r
@@ -1299,25 +1302,29 @@ class DscBuildData(PlatformBuildClassObject):
             # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)\r
             #\r
             CApp = CApp + '  Size = sizeof(%s);\n' % (Pcd.DatumType)\r
-            for FieldList in [Pcd.DefaultValues, OverrideValues.get(DefaultStoreName)]:\r
-                if not FieldList:\r
-                    continue\r
-                for FieldName in FieldList:\r
-                    FieldName = "." + FieldName\r
-                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
-                    if IsArray:\r
-                        Value, ValueSize = ParseFieldValue (FieldList[FieldName.strip(".")][0])\r
-                        CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s));\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."));\r
-                    else:\r
-                        NewFieldName = ''\r
-                        while '[' in  FieldName:\r
-                            NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
-                            ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
-                            FieldName = FieldName.split(']', 1)[1]\r
-                        FieldName = NewFieldName + FieldName\r
-                        while '[' in FieldName:\r
-                            FieldName = FieldName.rsplit('[', 1)[0]\r
-                            CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d);\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1)\r
+            for skuname in self.SkuIdMgr.SkuOverrideOrder():\r
+                inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]\r
+                for FieldList in [Pcd.DefaultValues, inherit_OverrideValues.get(DefaultStoreName)]:\r
+                    if not FieldList:\r
+                        continue\r
+                    for FieldName in FieldList:\r
+                        FieldName = "." + FieldName\r
+                        IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
+                        if IsArray:\r
+                            Value, ValueSize = ParseFieldValue (FieldList[FieldName.strip(".")][0])\r
+                            CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."));\r
+                        else:\r
+                            NewFieldName = ''\r
+                            while '[' in  FieldName:\r
+                                NewFieldName = NewFieldName + FieldName.split('[', 1)[0] + '[0]'\r
+                                ArrayIndex = int(FieldName.split('[', 1)[1].split(']', 1)[0])\r
+                                FieldName = FieldName.split(']', 1)[1]\r
+                            FieldName = NewFieldName + FieldName\r
+                            while '[' in FieldName:\r
+                                FieldName = FieldName.rsplit('[', 1)[0]\r
+                                CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d);\n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1)\r
+                if skuname == SkuName:\r
+                    break\r
 \r
             #\r
             # Allocate and zero buffer for the PCD\r
@@ -1336,43 +1343,46 @@ class DscBuildData(PlatformBuildClassObject):
             #\r
             # Assign field values in PCD\r
             #\r
-            for FieldList in [Pcd.DefaultValues, Pcd.DefaultFromDSC,OverrideValues.get(DefaultStoreName)]:\r
-                if not FieldList:\r
-                    continue\r
-                if Pcd.DefaultFromDSC and FieldList == Pcd.DefaultFromDSC:\r
-                    IsArray = self.IsFieldValueAnArray(FieldList)\r
-                    Value, ValueSize = ParseFieldValue (FieldList)\r
-                    if isinstance(Value, str):\r
-                        CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC)\r
-                    elif IsArray:\r
+            for skuname in self.SkuIdMgr.SkuOverrideOrder():\r
+                inherit_OverrideValues = Pcd.SkuOverrideValues[skuname]\r
+                for FieldList in [Pcd.DefaultValues, Pcd.DefaultFromDSC,inherit_OverrideValues.get(DefaultStoreName)]:\r
+                    if not FieldList:\r
+                        continue\r
+                    if Pcd.DefaultFromDSC and FieldList == Pcd.DefaultFromDSC:\r
+                        IsArray = self.IsFieldValueAnArray(FieldList)\r
+                        Value, ValueSize = ParseFieldValue (FieldList)\r
+                        if isinstance(Value, str):\r
+                            CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC)\r
+                        elif IsArray:\r
                         #\r
                         # Use memcpy() to copy value into field\r
                         #\r
-                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC)\r
-                        CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
-                    continue\r
+                            CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC)\r
+                            CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)\r
+                        continue\r
 \r
-                for FieldName in FieldList:\r
-                    IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
-                    try:\r
-                        Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
-                    except Exception:\r
-                        print FieldList[FieldName][0]\r
-                    if isinstance(Value, str):\r
-                        CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                    elif IsArray:\r
+                    for FieldName in FieldList:\r
+                        IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                        try:\r
+                            Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
+                        except Exception:\r
+                            print FieldList[FieldName][0]\r
+                        if isinstance(Value, str):\r
+                            CApp = CApp + '  Pcd->%s = %s; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                        elif IsArray:\r
                         #\r
                         # Use memcpy() to copy value into field\r
                         #\r
-                        CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
-                        CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-                        CApp = CApp + '  memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
-                    else:\r
-                        if ValueSize > 4:\r
-                            CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                            CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
+                            CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                            CApp = CApp + '  memcpy (&Pcd->%s[0], Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
                         else:\r
-                            CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
-\r
+                            if ValueSize > 4:\r
+                                CApp = CApp + '  Pcd->%s = %dULL; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                            else:\r
+                                CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                if skuname == SkuName:\r
+                    break\r
             #\r
             # Set new PCD value and size\r
             #\r
@@ -1410,7 +1420,9 @@ class DscBuildData(PlatformBuildClassObject):
             if not Pcd.SkuOverrideValues:\r
                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp)\r
             else:\r
-                for SkuName in Pcd.SkuOverrideValues:\r
+                for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
+                    if SkuName not in Pcd.SkuOverrideValues:\r
+                        continue\r
                     for DefaultStoreName in Pcd.DefaultStoreName:\r
                         Pcd = StructuredPcds[PcdName]\r
                         InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)\r
@@ -1424,7 +1436,9 @@ class DscBuildData(PlatformBuildClassObject):
             if not Pcd.SkuOverrideValues:\r
                 CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
             else:\r
-                for SkuName in Pcd.SkuOverrideValues:\r
+                for SkuName in self.SkuIdMgr.SkuOverrideOrder():\r
+                    if SkuName not in Pcd.SkuOverrideValues:\r
+                        continue\r
                     for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:\r
                         CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
         CApp = CApp + '}\n'\r