]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools: Code should not update the variable that save the raw data.
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / DscBuildData.py
index 02aae3a67ba4c7e3f1710caafe7accf2eb321f24..6106f8ee55dcd20c3fe9382d16d7689604db6f71 100644 (file)
@@ -17,6 +17,8 @@
 #  This class is used to retrieve information stored in database and convert them\r
 # into PlatformBuildClassObject form for easier use for AutoGen.\r
 #\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
 from Common.StringUtils import *\r
 from Common.DataType import *\r
 from Common.Misc import *\r
@@ -128,16 +130,9 @@ def GetDependencyList(FileStack, SearchPathList):
 \r
             if len(FileContent) == 0:\r
                 continue\r
-            IncludedFileList = []\r
+\r
             if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
-                FileContent = str(FileContent, "utf-16")\r
-                IncludedFileList = gIncludePattern.findall(FileContent)\r
-            else:\r
-                try:\r
-                    FileContent = str(FileContent, "utf-8")\r
-                    IncludedFileList = gIncludePattern.findall(FileContent)\r
-                except:\r
-                    pass\r
+                FileContent = unicode(FileContent, "utf-16")\r
             IncludedFileList = gIncludePattern.findall(FileContent)\r
 \r
             for Inc in IncludedFileList:\r
@@ -1551,7 +1546,7 @@ class DscBuildData(PlatformBuildClassObject):
                 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
                     del pcd.SkuInfoList[TAB_COMMON]\r
 \r
-        list(map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType]))\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
@@ -1601,7 +1596,7 @@ class DscBuildData(PlatformBuildClassObject):
             else:\r
                 PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}\r
 \r
-        for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.items():\r
+        for ((PcdCName, TokenSpaceGuid), PcdSetting) in PcdValueDict.iteritems():\r
             if self.SkuIdMgr.SystemSkuId in PcdSetting:\r
                 PcdValue, DatumType, MaxDatumSize = PcdSetting[self.SkuIdMgr.SystemSkuId]\r
             elif TAB_DEFAULT in PcdSetting:\r
@@ -1662,7 +1657,7 @@ class DscBuildData(PlatformBuildClassObject):
         except:\r
             EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % Command)\r
         Result = Process.communicate()\r
-        return Process.returncode, Result[0].decode(encoding='utf-8', errors='ignore'), Result[1].decode(encoding='utf-8', errors='ignore')\r
+        return Process.returncode, Result[0], Result[1]\r
 \r
     @staticmethod\r
     def IntToCString(Value, ValueSize):\r
@@ -1837,8 +1832,12 @@ class DscBuildData(PlatformBuildClassObject):
                     #\r
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
                     CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                    CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
                 else:\r
+                    if '[' in FieldName and ']' in FieldName:\r
+                        Index = int(FieldName.split('[')[1].split(']')[0])\r
+                        CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2], FieldName)\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
@@ -1900,12 +1899,15 @@ class DscBuildData(PlatformBuildClassObject):
                     IsArray = IsFieldValueAnArray(FieldList[FieldName][0])\r
                     if IsArray:\r
                         try:\r
-                            FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
+                            FieldValue = ValueExpressionEx(FieldList[FieldName][0], TAB_VOID, self._GuidDict)(True)\r
                         except BadExpression:\r
                             EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " %\r
                                             (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
                     try:\r
-                        Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
+                        if IsArray:\r
+                            Value, ValueSize = ParseFieldValue (FieldValue)\r
+                        else:\r
+                            Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
                     except Exception:\r
                         EdkLogger.error('Build', FORMAT_INVALID, "Invalid value format for %s. From %s Line %d " % (".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldName)), FieldList[FieldName][1], FieldList[FieldName][2]))\r
                     if isinstance(Value, str):\r
@@ -1916,8 +1918,12 @@ class DscBuildData(PlatformBuildClassObject):
                     #\r
                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)\r
                         CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
+                        CApp = CApp + '  __STATIC_ASSERT((__FIELD_SIZE(%s, %s) >= %d) || (__FIELD_SIZE(%s, %s) == 0), "Input buffer exceeds the buffer array"); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName, ValueSize, Pcd.DatumType, FieldName, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])\r
                         CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)\r
                     else:\r
+                        if '[' in FieldName and ']' in FieldName:\r
+                            Index = int(FieldName.split('[')[1].split(']')[0])\r
+                            CApp = CApp + '  __STATIC_ASSERT((%d < __ARRAY_SIZE(Pcd->%s)) || (__ARRAY_SIZE(Pcd->%s) == 0), "array index exceeds the array number"); // From %s Line %d Index of %s\n' % (Index, FieldName.split('[')[0], FieldName.split('[')[0], FieldList[FieldName][1], FieldList[FieldName][2], FieldName)\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
@@ -2505,7 +2511,7 @@ class DscBuildData(PlatformBuildClassObject):
             elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:\r
                 del pcd.SkuInfoList[TAB_COMMON]\r
 \r
-        list(map(self.FilterSkuSettings, Pcds.values()))\r
+        map(self.FilterSkuSettings, Pcds.values())\r
 \r
         return Pcds\r
 \r
@@ -2570,7 +2576,7 @@ class DscBuildData(PlatformBuildClassObject):
                     PcdObj.SkuInfoList[skuname].SkuId = skuid\r
                     PcdObj.SkuInfoList[skuname].SkuIdName = skuname\r
             if PcdType in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:\r
-                PcdObj.DefaultValue = list(PcdObj.SkuInfoList.values())[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
+                PcdObj.DefaultValue = PcdObj.SkuInfoList.values()[0].HiiDefaultValue if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE else PcdObj.SkuInfoList[TAB_DEFAULT].HiiDefaultValue\r
             Pcds[PcdCName, TokenSpaceGuid]= PcdObj\r
         return Pcds\r
     ## Retrieve dynamic HII PCD settings\r
@@ -2691,7 +2697,7 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
             Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][DefaultStore] = DefaultValue\r
         for pcd in Pcds.values():\r
-            SkuInfoObj = list(pcd.SkuInfoList.values())[0]\r
+            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
             pcd.DatumType = pcdDecObject.DatumType\r
             # Only fix the value while no value provided in DSC file.\r
@@ -2731,7 +2737,7 @@ class DscBuildData(PlatformBuildClassObject):
             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
-        list(map(self.FilterSkuSettings, Pcds.values()))\r
+        map(self.FilterSkuSettings, Pcds.values())\r
 \r
         return Pcds\r
 \r
@@ -2829,7 +2835,7 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {}\r
             Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = InitialValue\r
         for pcd in Pcds.values():\r
-            SkuInfoObj = list(pcd.SkuInfoList.values())[0]\r
+            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
             pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName]\r
             pcd.DatumType = pcdDecObject.DatumType\r
             # Only fix the value while no value provided in DSC file.\r
@@ -2847,7 +2853,7 @@ class DscBuildData(PlatformBuildClassObject):
                 del pcd.SkuInfoList[TAB_COMMON]\r
 \r
 \r
-        list(map(self.FilterSkuSettings, Pcds.values()))\r
+        map(self.FilterSkuSettings, Pcds.values())\r
         return Pcds\r
 \r
     ## Add external modules\r