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