]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfDepexSectionParser.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfDepexSectionParser.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the parser for [Depex] sections in INF file \r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials are licensed and made available \r
7# under the terms and conditions of the BSD License which accompanies this \r
8# distribution. The full text of the license may be found at \r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14'''\r
15InfDepexSectionParser\r
16'''\r
17##\r
18# Import Modules\r
19#\r
20import re\r
21import Logger.Log as Logger\r
22from Logger import StringTable as ST\r
23from Logger.ToolError import FORMAT_INVALID\r
24from Parser.InfParserMisc import InfExpandMacro\r
25from Library import DataType as DT\r
26from Library.Misc import GetSplitValueList\r
27from Parser.InfParserMisc import InfParserSectionRoot\r
28\r
29class InfDepexSectionParser(InfParserSectionRoot):\r
30 ## InfDepexParser\r
31 #\r
32 # For now, only separate Depex String and comments. \r
33 # Have two types of section header.\r
34 # 1. [Depex.Arch.ModuleType, ...]\r
35 # 2. [Depex.Arch|FFE, ...]\r
36 #\r
37 def InfDepexParser(self, SectionString, InfSectionObject, FileName):\r
38 DepexContent = []\r
39 DepexComment = []\r
40 ValueList = []\r
41 #\r
42 # Parse section content\r
43 #\r
44 for Line in SectionString:\r
45 LineContent = Line[0]\r
46 LineNo = Line[1]\r
47 \r
48 #\r
49 # Found comment\r
50 #\r
51 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
52 DepexComment.append((LineContent, LineNo))\r
53 continue\r
54 #\r
55 # Replace with [Defines] section Macro\r
56 #\r
57 LineContent = InfExpandMacro(LineContent, \r
58 (FileName, LineContent, Line[1]), \r
59 self.FileLocalMacros, \r
60 None, True)\r
61 \r
62 CommentCount = LineContent.find(DT.TAB_COMMENT_SPLIT)\r
63 \r
64 if CommentCount > -1:\r
65 DepexComment.append((LineContent[CommentCount:], LineNo)) \r
66 LineContent = LineContent[:CommentCount-1]\r
67 \r
68 \r
69 CommentCount = -1\r
70 DepexContent.append((LineContent, LineNo))\r
71 \r
72 TokenList = GetSplitValueList(LineContent, DT.TAB_COMMENT_SPLIT)\r
73 ValueList[0:len(TokenList)] = TokenList\r
74 \r
75 #\r
76 # Current section archs\r
77 # \r
78 KeyList = []\r
79 LastItem = ''\r
80 for Item in self.LastSectionHeaderContent:\r
81 LastItem = Item\r
82 if (Item[1], Item[2], Item[3]) not in KeyList:\r
83 KeyList.append((Item[1], Item[2], Item[3])) \r
84 \r
85 NewCommentList = []\r
86 FormatCommentLn = -1\r
87 ReFormatComment = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL)\r
88 for CommentItem in DepexComment:\r
89 CommentContent = CommentItem[0]\r
4231a819 90 if ReFormatComment.match(CommentContent) is not None:\r
4234283c
LG
91 FormatCommentLn = CommentItem[1] + 1\r
92 continue\r
93 \r
94 if CommentItem[1] != FormatCommentLn:\r
95 NewCommentList.append(CommentContent)\r
96 else:\r
97 FormatCommentLn = CommentItem[1] + 1\r
98 \r
99 if not InfSectionObject.SetDepex(DepexContent, KeyList = KeyList, CommentList = NewCommentList):\r
100 Logger.Error('InfParser', \r
101 FORMAT_INVALID,\r
102 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Depex]"),\r
103 File=FileName, \r
104 Line=LastItem[3])