BaseTools: StructurePcd array Value support flexible format
authorFeng, YunhuaX </o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Feng, YunhuaX4e1>
Fri, 2 Feb 2018 06:49:24 +0000 (14:49 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 4 Feb 2018 03:16:01 +0000 (11:16 +0800)
if StructurePcd set item value is array, support flexible format
like as:
gEfiStructuredPcdPkgTokenSpaceGuid.Test.Array | {flexible format}
{flexible format} = {L"ABC"} | {L'ABC'} | {"ABC"} | {UINT8(0x10)}
                  | {UINT16(0x10)} | {UINT32(0x10)} | {UINT64(0x10)}
                  | {DEVICE_PATH("PciRoot(0)/Pci(0,0)")}
                  | {GUID(gPcdPkgTokenSpaceGuid)}
                  | {L"ABC", L'ABC', UINT8(0x10)....}

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Workspace/DscBuildData.py

index ad5b267..1da4f03 100644 (file)
@@ -1528,7 +1528,12 @@ class DscBuildData(PlatformBuildClassObject):
                     FieldName = "." + FieldName\r
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                     if IsArray:\r
                     FieldName = "." + FieldName\r
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                     if IsArray:\r
-                        Value, ValueSize = ParseFieldValue (FieldList[FieldName.strip(".")][0])\r
+                        try:\r
+                            Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "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.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
+                        Value, ValueSize = ParseFieldValue(Value)\r
                         CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                     else:\r
                         NewFieldName = ''\r
                         CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0));  // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                     else:\r
                         NewFieldName = ''\r
@@ -1550,7 +1555,12 @@ class DscBuildData(PlatformBuildClassObject):
                         FieldName = "." + FieldName\r
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                         if IsArray:\r
                         FieldName = "." + FieldName\r
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0])\r
                         if IsArray:\r
-                            Value, ValueSize = ParseFieldValue (FieldList[FieldName.strip(".")][0])\r
+                            try:\r
+                                Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "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.strip('.'))), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2]))\r
+                            Value, ValueSize = ParseFieldValue(Value)\r
                             CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                         else:\r
                             NewFieldName = ''\r
                             CApp = CApp + '  __FLEXIBLE_SIZE(Size, %s, %s, %d / __ARRAY_ELEMENT_SIZE(%s, %s) + ((%d %% __ARRAY_ELEMENT_SIZE(%s, %s)) ? 1 : 0)); // From %s Line %d Value %s\n' % (Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), ValueSize, Pcd.DatumType, FieldName.strip("."), FieldList[FieldName.strip(".")][1], FieldList[FieldName.strip(".")][2], FieldList[FieldName.strip(".")][0]);\r
                         else:\r
                             NewFieldName = ''\r
@@ -1588,6 +1598,13 @@ class DscBuildData(PlatformBuildClassObject):
                     continue\r
                 for FieldName in FieldList:\r
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
                     continue\r
                 for FieldName in FieldList:\r
                     IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                    if IsArray:\r
+                        try:\r
+                            FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "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
+\r
                     try:\r
                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
                     except Exception:\r
                     try:\r
                         Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
                     except Exception:\r
@@ -1613,6 +1630,13 @@ class DscBuildData(PlatformBuildClassObject):
                         continue\r
                     if Pcd.DefaultFromDSC and FieldList == Pcd.DefaultFromDSC:\r
                         IsArray = self.IsFieldValueAnArray(FieldList)\r
                         continue\r
                     if Pcd.DefaultFromDSC and FieldList == Pcd.DefaultFromDSC:\r
                         IsArray = self.IsFieldValueAnArray(FieldList)\r
+                        if IsArray:\r
+                            try:\r
+                                FieldList = ValueExpressionEx(FieldList, "VOID*")(True)\r
+                            except BadExpression:\r
+                                EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" %\r
+                                                (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList))\r
+\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
                         Value, ValueSize = ParseFieldValue (FieldList)\r
                         if isinstance(Value, str):\r
                             CApp = CApp + '  Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC)\r
@@ -1626,6 +1650,13 @@ class DscBuildData(PlatformBuildClassObject):
 \r
                     for FieldName in FieldList:\r
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
 \r
                     for FieldName in FieldList:\r
                         IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0])\r
+                        if IsArray:\r
+                            try:\r
+                                FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "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
+\r
                         try:\r
                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
                         except Exception:\r
                         try:\r
                             Value, ValueSize = ParseFieldValue (FieldList[FieldName][0])\r
                         except Exception:\r