]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[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
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
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
115 if LineComment == None:\r
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
126 if MacroDef[0] != None:\r
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
181 TokenList = GetSplitValueList(ValueList[1], \r
182 DT.TAB_VALUE_SPLIT, \r
183 4)\r
184 NewValueList = []\r
185 NewValueList.append(ValueList[0])\r
186 for Item in TokenList:\r
187 NewValueList.append(Item) \r
188 ComBinaryList.append((NewValueList, \r
189 LineComment, \r
190 CurrentLineObj))\r
191 \r
192 ValueList = []\r
193 LineComment = None\r
194 TailComments = ''\r
195 HeaderComments = [] \r
196 continue\r
197\r
198 #\r
199 # Current section archs\r
200 # \r
201 ArchList = []\r
202 for Item in self.LastSectionHeaderContent:\r
203 if Item[1] not in ArchList:\r
204 ArchList.append(Item[1]) \r
205 InfSectionObject.SetSupArchList(Item[1])\r
206 \r
207 InfSectionObject.SetAllContent(AllSectionContent) \r
208 if not InfSectionObject.SetBinary(UiBinaryList, \r
209 VerBinaryList, \r
210 ComBinaryList, \r
211 ArchList):\r
212 Logger.Error('InfParser', \r
213 FORMAT_INVALID,\r
214 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Binaries]"),\r
215 File=FileName,\r
216 Line=Item[3]) \r
217