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