]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Parser/InfDepexSectionParser.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfDepexSectionParser.py
1 ## @file
2 # This file contained the parser for [Depex] sections in INF file
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8 '''
9 InfDepexSectionParser
10 '''
11 ##
12 # Import Modules
13 #
14 import re
15 import Logger.Log as Logger
16 from Logger import StringTable as ST
17 from Logger.ToolError import FORMAT_INVALID
18 from Parser.InfParserMisc import InfExpandMacro
19 from Library import DataType as DT
20 from Library.Misc import GetSplitValueList
21 from Parser.InfParserMisc import InfParserSectionRoot
22
23 class InfDepexSectionParser(InfParserSectionRoot):
24 ## InfDepexParser
25 #
26 # For now, only separate Depex String and comments.
27 # Have two types of section header.
28 # 1. [Depex.Arch.ModuleType, ...]
29 # 2. [Depex.Arch|FFE, ...]
30 #
31 def InfDepexParser(self, SectionString, InfSectionObject, FileName):
32 DepexContent = []
33 DepexComment = []
34 ValueList = []
35 #
36 # Parse section content
37 #
38 for Line in SectionString:
39 LineContent = Line[0]
40 LineNo = Line[1]
41
42 #
43 # Found comment
44 #
45 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
46 DepexComment.append((LineContent, LineNo))
47 continue
48 #
49 # Replace with [Defines] section Macro
50 #
51 LineContent = InfExpandMacro(LineContent,
52 (FileName, LineContent, Line[1]),
53 self.FileLocalMacros,
54 None, True)
55
56 CommentCount = LineContent.find(DT.TAB_COMMENT_SPLIT)
57
58 if CommentCount > -1:
59 DepexComment.append((LineContent[CommentCount:], LineNo))
60 LineContent = LineContent[:CommentCount-1]
61
62
63 CommentCount = -1
64 DepexContent.append((LineContent, LineNo))
65
66 TokenList = GetSplitValueList(LineContent, DT.TAB_COMMENT_SPLIT)
67 ValueList[0:len(TokenList)] = TokenList
68
69 #
70 # Current section archs
71 #
72 KeyList = []
73 LastItem = ''
74 for Item in self.LastSectionHeaderContent:
75 LastItem = Item
76 if (Item[1], Item[2], Item[3]) not in KeyList:
77 KeyList.append((Item[1], Item[2], Item[3]))
78
79 NewCommentList = []
80 FormatCommentLn = -1
81 ReFormatComment = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL)
82 for CommentItem in DepexComment:
83 CommentContent = CommentItem[0]
84 if ReFormatComment.match(CommentContent) is not None:
85 FormatCommentLn = CommentItem[1] + 1
86 continue
87
88 if CommentItem[1] != FormatCommentLn:
89 NewCommentList.append(CommentContent)
90 else:
91 FormatCommentLn = CommentItem[1] + 1
92
93 if not InfSectionObject.SetDepex(DepexContent, KeyList = KeyList, CommentList = NewCommentList):
94 Logger.Error('InfParser',
95 FORMAT_INVALID,
96 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Depex]"),
97 File=FileName,
98 Line=LastItem[3])