]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/MetaFileCommentParser.py
BaseTools: DSC Components section support flexible PCD
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileCommentParser.py
index ee6f5ac2b8d3f1397218a1a2425b17a562eb8a23..df1e90faf5a0b35758ae15745197554e545405e6 100644 (file)
@@ -25,4 +25,27 @@ import Common.EdkLogger as EdkLogger
 UsageList = ("PRODUCES", "PRODUCED", "ALWAYS_PRODUCES", "ALWAYS_PRODUCED", "SOMETIMES_PRODUCES",\r
              "SOMETIMES_PRODUCED", "CONSUMES", "CONSUMED", "ALWAYS_CONSUMES", "ALWAYS_CONSUMED",\r
              "SOMETIMES_CONSUMES", "SOMETIMES_CONSUMED", "SOMETIME_CONSUMES")\r
+ErrorMsgMap = {\r
+    MODEL_EFI_GUID      : "The usage for this GUID is not listed in this INF: %s[%d]:%s",\r
+    MODEL_EFI_PPI       : "The usage for this PPI is not listed in this INF: %s[%d]:%s.",\r
+    MODEL_EFI_PROTOCOL  : "The usage for this Protocol is not listed in this INF: %s[%d]:%s.",\r
+    MODEL_PCD_DYNAMIC   : "The usage for this PCD is not listed in this INF: %s[%d]:%s."\r
+}\r
 \r
+def CheckInfComment(SectionType, Comments, InfFile, LineNo, ValueList):\r
+    if SectionType in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_EX, MODEL_PCD_DYNAMIC]:\r
+        CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0]+'.'+ValueList[1], ErrorMsgMap[MODEL_PCD_DYNAMIC])\r
+    elif SectionType in [MODEL_EFI_GUID, MODEL_EFI_PPI]:\r
+        CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])\r
+    elif SectionType == MODEL_EFI_PROTOCOL:\r
+        CheckUsage(Comments, UsageList + ("TO_START", "BY_START"), InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])\r
+\r
+def CheckUsage(Comments, Usages, InfFile, LineNo, Value, ErrorMsg):\r
+    for Comment in Comments:\r
+        for Word in Comment[0].replace('#', ' ').split():\r
+            if Word in Usages:\r
+                return\r
+    EdkLogger.error(\r
+        "Parser", FORMAT_INVALID,\r
+        ErrorMsg % (InfFile, LineNo, Value)\r
+    )\r