BaseTool: Error handling for PCD datumtype.
authorFeng, Bob C <bob.c.feng@intel.com>
Mon, 19 Mar 2018 04:05:19 +0000 (12:05 +0800)
committerLiming Gao <liming.gao@intel.com>
Mon, 19 Mar 2018 04:28:05 +0000 (12:28 +0800)
Report error if the Pcd DatumType is wrong.

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/Workspace/BuildClassObject.py
BaseTools/Source/Python/Workspace/DecBuildData.py

index 1352fa2..a306dc0 100644 (file)
@@ -69,6 +69,7 @@ class PcdClassObject(object):
         if IsDsc:\r
             self.DscDefaultValue = Value\r
         self.PcdValueFromComm = ""\r
+        self.DefinitionPosition = ("","")\r
 \r
     ## Convert the class to a string\r
     #\r
@@ -178,6 +179,7 @@ class StructurePcd(PcdClassObject):
         self.expressions = PcdObject.expressions if PcdObject.expressions else self.expressions\r
         self.DscRawValue = PcdObject.DscRawValue if PcdObject.DscRawValue else self.DscRawValue\r
         self.PcdValueFromComm = PcdObject.PcdValueFromComm if PcdObject.PcdValueFromComm else self.PcdValueFromComm\r
+        self.DefinitionPosition = PcdObject.DefinitionPosition if PcdObject.DefinitionPosition else self.DefinitionPosition\r
         if type(PcdObject) is StructurePcd:\r
             self.StructuredPcdIncludeFile = PcdObject.StructuredPcdIncludeFile if PcdObject.StructuredPcdIncludeFile else self.StructuredPcdIncludeFile\r
             self.PackageDecs = PcdObject.PackageDecs if PcdObject.PackageDecs else self.PackageDecs\r
index ee00ec0..4d6edad 100644 (file)
@@ -394,11 +394,7 @@ class DecBuildData(PackageBuildClassObject):
                     struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue,self.MetaFile.File,LineNo)\r
 \r
             struct_pcd.PackageDecs = dep_pkgs\r
-            if not struct_pcd.StructuredPcdIncludeFile:\r
-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "The structure Pcd %s.%s header file is not found in %s line %s \n" % (struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName,self.MetaFile.File,LineNo ))\r
-\r
             str_pcd_set.append(struct_pcd)\r
-\r
         return str_pcd_set\r
 \r
     ## Retrieve PCD declarations for given type\r
@@ -446,6 +442,7 @@ class DecBuildData(PackageBuildClassObject):
                                         list(validlists),\r
                                         list(expressions)\r
                                         )\r
+            PcdObj.DefinitionPosition = (self.MetaFile.File,LineNo)\r
             if "." in TokenSpaceGuid:\r
                 StrPcdSet.append((PcdObj,LineNo))\r
             else:\r
@@ -454,6 +451,14 @@ class DecBuildData(PackageBuildClassObject):
         StructurePcds = self.ProcessStructurePcd(StrPcdSet)\r
         for pcd in StructurePcds:\r
             Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd\r
+        StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')\r
+        for pcd in Pcds.values():\r
+            if pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
+                if StructPattern.match(pcd.DatumType) == None:\r
+                    EdkLogger.error('build', FORMAT_INVALID, "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.", pcd.DefinitionPosition[0],pcd.DefinitionPosition[1])\r
+        for struct_pcd in Pcds.values():\r
+            if isinstance(struct_pcd,StructurePcd) and not struct_pcd.StructuredPcdIncludeFile:\r
+                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "The structure Pcd %s.%s header file is not found in %s line %s \n" % (struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName,struct_pcd.DefinitionPosition[0],struct_pcd.DefinitionPosition[1] ))\r
 \r
         return Pcds\r
     @property\r