File: MetaFileCommentParser.py

package info (click to toggle)
edk2 2025.02-8%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 271,960 kB
  • sloc: ansic: 2,110,013; asm: 263,832; perl: 227,730; python: 149,919; sh: 34,967; cpp: 21,813; makefile: 3,282; xml: 806; pascal: 721; lisp: 35; ruby: 16; sed: 6; tcl: 4
file content (45 lines) | stat: -rw-r--r-- 2,075 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## @file
# This file is used to check format of comments
#
# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#

from CommonDataClass.DataClass import (
    MODEL_PCD_PATCHABLE_IN_MODULE,
    MODEL_PCD_DYNAMIC_EX,
    MODEL_PCD_DYNAMIC,
    MODEL_EFI_GUID,
    MODEL_EFI_PPI,
    MODEL_EFI_PROTOCOL
)
from Common.BuildToolError import FORMAT_INVALID
import Common.EdkLogger as EdkLogger

UsageList = ("PRODUCES", "PRODUCED", "ALWAYS_PRODUCES", "ALWAYS_PRODUCED", "SOMETIMES_PRODUCES",
             "SOMETIMES_PRODUCED", "CONSUMES", "CONSUMED", "ALWAYS_CONSUMES", "ALWAYS_CONSUMED",
             "SOMETIMES_CONSUMES", "SOMETIMES_CONSUMED", "SOMETIME_CONSUMES")
ErrorMsgMap = {
    MODEL_EFI_GUID      : "The usage for this GUID is not listed in this INF: %s[%d]:%s",
    MODEL_EFI_PPI       : "The usage for this PPI is not listed in this INF: %s[%d]:%s.",
    MODEL_EFI_PROTOCOL  : "The usage for this Protocol is not listed in this INF: %s[%d]:%s.",
    MODEL_PCD_DYNAMIC   : "The usage for this PCD is not listed in this INF: %s[%d]:%s."
}

def CheckInfComment(SectionType, Comments, InfFile, LineNo, ValueList):
    if SectionType in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_EX, MODEL_PCD_DYNAMIC]:
        CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0]+'.'+ValueList[1], ErrorMsgMap[MODEL_PCD_DYNAMIC])
    elif SectionType in [MODEL_EFI_GUID, MODEL_EFI_PPI]:
        CheckUsage(Comments, UsageList, InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])
    elif SectionType == MODEL_EFI_PROTOCOL:
        CheckUsage(Comments, UsageList + ("TO_START", "BY_START"), InfFile, LineNo, ValueList[0], ErrorMsgMap[SectionType])

def CheckUsage(Comments, Usages, InfFile, LineNo, Value, ErrorMsg):
    for Comment in Comments:
        for Word in Comment[0].replace('#', ' ').split():
            if Word in Usages:
                return
    EdkLogger.error(
        "Parser", FORMAT_INVALID,
        ErrorMsg % (InfFile, LineNo, Value)
    )