]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfBinarySectionParser.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the parser for [Binaries] sections in INF file \r
3#\r
421ccda3 4# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
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
15InfBinarySectionParser\r
16'''\r
17##\r
18# Import Modules\r
19#\r
20\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.Parsing import MacroParser\r
27from Library.Misc import GetSplitValueList\r
28from Object.Parser.InfCommonObject import InfLineCommentObject\r
29from Object.Parser.InfCommonObject import CurrentLine\r
30from Parser.InfParserMisc import InfParserSectionRoot\r
31\r
32class InfBinarySectionParser(InfParserSectionRoot):\r
33 ## InfBinaryParser\r
34 #\r
35 #\r
36 def InfBinaryParser(self, SectionString, InfSectionObject, FileName):\r
37 #\r
38 # Macro defined in this section \r
39 #\r
40 SectionMacros = {}\r
41 ValueList = []\r
42 #\r
43 # For UI (UI, SEC_UI, UNI_UI) binaries\r
44 # One and only one UI section can be included\r
45 #\r
46 UiBinaryList = []\r
47 #\r
48 # For Version (VER, SEC_VER, UNI_VER).\r
49 # One and only one VER section on be included\r
50 #\r
51 VerBinaryList = []\r
52 #\r
53 # For other common type binaries\r
54 #\r
55 ComBinaryList = []\r
56\r
57 StillCommentFalg = False\r
58 HeaderComments = []\r
59 LineComment = None \r
60 \r
61 AllSectionContent = ''\r
62 #\r
63 # Parse section content\r
64 #\r
65 for Line in SectionString:\r
66 BinLineContent = Line[0]\r
67 BinLineNo = Line[1]\r
68 \r
69 if BinLineContent.strip() == '':\r
70 continue\r
71 \r
72 CurrentLineObj = CurrentLine()\r
73 CurrentLineObj.FileName = FileName\r
74 CurrentLineObj.LineString = BinLineContent\r
75 CurrentLineObj.LineNo = BinLineNo\r
76 #\r
77 # Found Header Comments \r
78 #\r
79 if BinLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
80 #\r
81 # Last line is comments, and this line go on.\r
82 #\r
83 if StillCommentFalg:\r
84 HeaderComments.append(Line)\r
85 AllSectionContent += BinLineContent + DT.END_OF_LINE\r
86 continue\r
87 #\r
88 # First time encounter comment \r
89 #\r
90 else:\r
91 #\r
92 # Clear original data\r
93 #\r
94 HeaderComments = []\r
95 HeaderComments.append(Line)\r
96 AllSectionContent += BinLineContent + DT.END_OF_LINE\r
97 StillCommentFalg = True\r
98 continue\r
99 else:\r
100 StillCommentFalg = False\r
101 \r
102 if len(HeaderComments) >= 1:\r
103 LineComment = InfLineCommentObject()\r
104 LineCommentContent = ''\r
105 for Item in HeaderComments:\r
106 LineCommentContent += Item[0] + DT.END_OF_LINE\r
107 LineComment.SetHeaderComments(LineCommentContent)\r
108 \r
109 #\r
110 # Find Tail comment.\r
111 #\r
112 if BinLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
113 TailComments = BinLineContent[BinLineContent.find(DT.TAB_COMMENT_SPLIT):]\r
114 BinLineContent = BinLineContent[:BinLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
4231a819 115 if LineComment is None:\r
4234283c
LG
116 LineComment = InfLineCommentObject()\r
117 LineComment.SetTailComments(TailComments) \r
118 \r
119 #\r
120 # Find Macro\r
121 #\r
122 MacroDef = MacroParser((BinLineContent, BinLineNo),\r
123 FileName,\r
124 DT.MODEL_EFI_BINARY_FILE,\r
125 self.FileLocalMacros)\r
4231a819 126 if MacroDef[0] is not None:\r
4234283c
LG
127 SectionMacros[MacroDef[0]] = MacroDef[1]\r
128 LineComment = None\r
129 HeaderComments = [] \r
130 continue\r
131 \r
132 #\r
133 # Replace with Local section Macro and [Defines] section Macro.\r
134 # \r
135 LineContent = InfExpandMacro(BinLineContent, \r
136 (FileName, BinLineContent, BinLineNo), \r
137 self.FileLocalMacros, \r
138 SectionMacros, True)\r
139 \r
140 AllSectionContent += LineContent + DT.END_OF_LINE \r
141 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
142 ValueList[0:len(TokenList)] = TokenList\r
143 \r
144 # \r
145 # Should equal to UI/SEC_UI/UNI_UI\r
146 #\r
147 ValueList[0] = ValueList[0].strip()\r
148 if ValueList[0] == DT.BINARY_FILE_TYPE_UNI_UI or \\r
149 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_UI or \\r
150 ValueList[0] == DT.BINARY_FILE_TYPE_UI:\r
151 if len(ValueList) == 2:\r
152 TokenList = GetSplitValueList(ValueList[1], \r
153 DT.TAB_VALUE_SPLIT, \r
154 2)\r
155 NewValueList = []\r
156 NewValueList.append(ValueList[0])\r
157 for Item in TokenList:\r
158 NewValueList.append(Item)\r
159 UiBinaryList.append((NewValueList, \r
160 LineComment, \r
161 CurrentLineObj)) \r
162 # \r
163 # Should equal to VER/SEC_VER/UNI_VER\r
164 #\r
165 elif ValueList[0] == DT.BINARY_FILE_TYPE_UNI_VER or \\r
166 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_VER or \\r
167 ValueList[0] == DT.BINARY_FILE_TYPE_VER:\r
168 if len(ValueList) == 2:\r
169 TokenList = GetSplitValueList(ValueList[1], \r
170 DT.TAB_VALUE_SPLIT, \r
171 2)\r
172 NewValueList = []\r
173 NewValueList.append(ValueList[0])\r
174 for Item in TokenList:\r
175 NewValueList.append(Item) \r
176 VerBinaryList.append((NewValueList, \r
177 LineComment, \r
178 CurrentLineObj))\r
179 else:\r
180 if len(ValueList) == 2:\r
421ccda3
HC
181 if ValueList[0].strip() == 'SUBTYPE_GUID':\r
182 TokenList = GetSplitValueList(ValueList[1], \r
183 DT.TAB_VALUE_SPLIT, \r
184 5)\r
185 else:\r
186 TokenList = GetSplitValueList(ValueList[1], \r
187 DT.TAB_VALUE_SPLIT, \r
188 4)\r
189 \r
4234283c
LG
190 NewValueList = []\r
191 NewValueList.append(ValueList[0])\r
192 for Item in TokenList:\r
193 NewValueList.append(Item) \r
194 ComBinaryList.append((NewValueList, \r
195 LineComment, \r
196 CurrentLineObj))\r
421ccda3
HC
197 elif len(ValueList) == 1:\r
198 NewValueList = []\r
199 NewValueList.append(ValueList[0])\r
200 ComBinaryList.append((NewValueList, \r
201 LineComment, \r
202 CurrentLineObj))\r
203 \r
204 \r
205 \r
4234283c
LG
206 \r
207 ValueList = []\r
208 LineComment = None\r
209 TailComments = ''\r
210 HeaderComments = [] \r
211 continue\r
212\r
213 #\r
214 # Current section archs\r
215 # \r
216 ArchList = []\r
217 for Item in self.LastSectionHeaderContent:\r
218 if Item[1] not in ArchList:\r
219 ArchList.append(Item[1]) \r
220 InfSectionObject.SetSupArchList(Item[1])\r
221 \r
222 InfSectionObject.SetAllContent(AllSectionContent) \r
223 if not InfSectionObject.SetBinary(UiBinaryList, \r
224 VerBinaryList, \r
225 ComBinaryList, \r
226 ArchList):\r
227 Logger.Error('InfParser', \r
228 FORMAT_INVALID,\r
229 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Binaries]"),\r
230 File=FileName,\r
231 Line=Item[3]) \r
232