]> git.proxmox.com Git - mirror_edk2.git/blob - 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
1 ## @file
2 # This file contained the parser for [Binaries] sections in INF file
3 #
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14 '''
15 InfBinarySectionParser
16 '''
17 ##
18 # Import Modules
19 #
20
21 import Logger.Log as Logger
22 from Logger import StringTable as ST
23 from Logger.ToolError import FORMAT_INVALID
24 from Parser.InfParserMisc import InfExpandMacro
25 from Library import DataType as DT
26 from Library.Parsing import MacroParser
27 from Library.Misc import GetSplitValueList
28 from Object.Parser.InfCommonObject import InfLineCommentObject
29 from Object.Parser.InfCommonObject import CurrentLine
30 from Parser.InfParserMisc import InfParserSectionRoot
31
32 class InfBinarySectionParser(InfParserSectionRoot):
33 ## InfBinaryParser
34 #
35 #
36 def InfBinaryParser(self, SectionString, InfSectionObject, FileName):
37 #
38 # Macro defined in this section
39 #
40 SectionMacros = {}
41 ValueList = []
42 #
43 # For UI (UI, SEC_UI, UNI_UI) binaries
44 # One and only one UI section can be included
45 #
46 UiBinaryList = []
47 #
48 # For Version (VER, SEC_VER, UNI_VER).
49 # One and only one VER section on be included
50 #
51 VerBinaryList = []
52 #
53 # For other common type binaries
54 #
55 ComBinaryList = []
56
57 StillCommentFalg = False
58 HeaderComments = []
59 LineComment = None
60
61 AllSectionContent = ''
62 #
63 # Parse section content
64 #
65 for Line in SectionString:
66 BinLineContent = Line[0]
67 BinLineNo = Line[1]
68
69 if BinLineContent.strip() == '':
70 continue
71
72 CurrentLineObj = CurrentLine()
73 CurrentLineObj.FileName = FileName
74 CurrentLineObj.LineString = BinLineContent
75 CurrentLineObj.LineNo = BinLineNo
76 #
77 # Found Header Comments
78 #
79 if BinLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
80 #
81 # Last line is comments, and this line go on.
82 #
83 if StillCommentFalg:
84 HeaderComments.append(Line)
85 AllSectionContent += BinLineContent + DT.END_OF_LINE
86 continue
87 #
88 # First time encounter comment
89 #
90 else:
91 #
92 # Clear original data
93 #
94 HeaderComments = []
95 HeaderComments.append(Line)
96 AllSectionContent += BinLineContent + DT.END_OF_LINE
97 StillCommentFalg = True
98 continue
99 else:
100 StillCommentFalg = False
101
102 if len(HeaderComments) >= 1:
103 LineComment = InfLineCommentObject()
104 LineCommentContent = ''
105 for Item in HeaderComments:
106 LineCommentContent += Item[0] + DT.END_OF_LINE
107 LineComment.SetHeaderComments(LineCommentContent)
108
109 #
110 # Find Tail comment.
111 #
112 if BinLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
113 TailComments = BinLineContent[BinLineContent.find(DT.TAB_COMMENT_SPLIT):]
114 BinLineContent = BinLineContent[:BinLineContent.find(DT.TAB_COMMENT_SPLIT)]
115 if LineComment == None:
116 LineComment = InfLineCommentObject()
117 LineComment.SetTailComments(TailComments)
118
119 #
120 # Find Macro
121 #
122 MacroDef = MacroParser((BinLineContent, BinLineNo),
123 FileName,
124 DT.MODEL_EFI_BINARY_FILE,
125 self.FileLocalMacros)
126 if MacroDef[0] != None:
127 SectionMacros[MacroDef[0]] = MacroDef[1]
128 LineComment = None
129 HeaderComments = []
130 continue
131
132 #
133 # Replace with Local section Macro and [Defines] section Macro.
134 #
135 LineContent = InfExpandMacro(BinLineContent,
136 (FileName, BinLineContent, BinLineNo),
137 self.FileLocalMacros,
138 SectionMacros, True)
139
140 AllSectionContent += LineContent + DT.END_OF_LINE
141 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)
142 ValueList[0:len(TokenList)] = TokenList
143
144 #
145 # Should equal to UI/SEC_UI/UNI_UI
146 #
147 ValueList[0] = ValueList[0].strip()
148 if ValueList[0] == DT.BINARY_FILE_TYPE_UNI_UI or \
149 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_UI or \
150 ValueList[0] == DT.BINARY_FILE_TYPE_UI:
151 if len(ValueList) == 2:
152 TokenList = GetSplitValueList(ValueList[1],
153 DT.TAB_VALUE_SPLIT,
154 2)
155 NewValueList = []
156 NewValueList.append(ValueList[0])
157 for Item in TokenList:
158 NewValueList.append(Item)
159 UiBinaryList.append((NewValueList,
160 LineComment,
161 CurrentLineObj))
162 #
163 # Should equal to VER/SEC_VER/UNI_VER
164 #
165 elif ValueList[0] == DT.BINARY_FILE_TYPE_UNI_VER or \
166 ValueList[0] == DT.BINARY_FILE_TYPE_SEC_VER or \
167 ValueList[0] == DT.BINARY_FILE_TYPE_VER:
168 if len(ValueList) == 2:
169 TokenList = GetSplitValueList(ValueList[1],
170 DT.TAB_VALUE_SPLIT,
171 2)
172 NewValueList = []
173 NewValueList.append(ValueList[0])
174 for Item in TokenList:
175 NewValueList.append(Item)
176 VerBinaryList.append((NewValueList,
177 LineComment,
178 CurrentLineObj))
179 else:
180 if len(ValueList) == 2:
181 TokenList = GetSplitValueList(ValueList[1],
182 DT.TAB_VALUE_SPLIT,
183 4)
184 NewValueList = []
185 NewValueList.append(ValueList[0])
186 for Item in TokenList:
187 NewValueList.append(Item)
188 ComBinaryList.append((NewValueList,
189 LineComment,
190 CurrentLineObj))
191
192 ValueList = []
193 LineComment = None
194 TailComments = ''
195 HeaderComments = []
196 continue
197
198 #
199 # Current section archs
200 #
201 ArchList = []
202 for Item in self.LastSectionHeaderContent:
203 if Item[1] not in ArchList:
204 ArchList.append(Item[1])
205 InfSectionObject.SetSupArchList(Item[1])
206
207 InfSectionObject.SetAllContent(AllSectionContent)
208 if not InfSectionObject.SetBinary(UiBinaryList,
209 VerBinaryList,
210 ComBinaryList,
211 ArchList):
212 Logger.Error('InfParser',
213 FORMAT_INVALID,
214 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Binaries]"),
215 File=FileName,
216 Line=Item[3])
217