]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/MetaFileCommentParser.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileCommentParser.py
1 ## @file
2 # This file is used to check format of comments
3 #
4 # Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
6 #
7
8 from CommonDataClass.DataClass import (
9 MODEL_PCD_PATCHABLE_IN_MODULE,
10 MODEL_PCD_DYNAMIC_EX,
11 MODEL_PCD_DYNAMIC,
12 MODEL_EFI_GUID,
13 MODEL_EFI_PPI,
14 MODEL_EFI_PROTOCOL
15 )
16 from Common.BuildToolError import FORMAT_INVALID
17 import Common.EdkLogger as EdkLogger
18
19 UsageList = ("PRODUCES", "PRODUCED", "ALWAYS_PRODUCES", "ALWAYS_PRODUCED", "SOMETIMES_PRODUCES",
20 "SOMETIMES_PRODUCED", "CONSUMES", "CONSUMED", "ALWAYS_CONSUMES", "ALWAYS_CONSUMED",
21 "SOMETIMES_CONSUMES", "SOMETIMES_CONSUMED", "SOMETIME_CONSUMES")
22 ErrorMsgMap = {
23 MODEL_EFI_GUID : "The usage for this GUID is not listed in this INF: %s[%d]:%s",
24 MODEL_EFI_PPI : "The usage for this PPI is not listed in this INF: %s[%d]:%s.",
25 MODEL_EFI_PROTOCOL : "The usage for this Protocol is not listed in this INF: %s[%d]:%s.",
26 MODEL_PCD_DYNAMIC : "The usage for this PCD is not listed in this INF: %s[%d]:%s."
27 }
28
29 def CheckInfComment(SectionType, Comments, InfFile, LineNo, ValueList):
30 if SectionType in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_EX, MODEL_PCD_DYNAMIC]:
31 CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0]+'.'+ValueList[1], ErrorMsgMap[MODEL_PCD_DYNAMIC])
32 elif SectionType in [MODEL_EFI_GUID, MODEL_EFI_PPI]:
33 CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])
34 elif SectionType == MODEL_EFI_PROTOCOL:
35 CheckUsage(Comments, UsageList + ("TO_START", "BY_START"), InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])
36
37 def CheckUsage(Comments, Usages, InfFile, LineNo, Value, ErrorMsg):
38 for Comment in Comments:
39 for Word in Comment[0].replace('#', ' ').split():
40 if Word in Usages:
41 return
42 EdkLogger.error(
43 "Parser", FORMAT_INVALID,
44 ErrorMsg % (InfFile, LineNo, Value)
45 )