2 # This file contained the parser for [Binaries] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
.Parsing
import MacroParser
21 from Library
.Misc
import GetSplitValueList
22 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
23 from Object
.Parser
.InfCommonObject
import CurrentLine
24 from Parser
.InfParserMisc
import InfParserSectionRoot
26 class InfBinarySectionParser(InfParserSectionRoot
):
30 def InfBinaryParser(self
, SectionString
, InfSectionObject
, FileName
):
32 # Macro defined in this section
37 # For UI (UI, SEC_UI, UNI_UI) binaries
38 # One and only one UI section can be included
42 # For Version (VER, SEC_VER, UNI_VER).
43 # One and only one VER section on be included
47 # For other common type binaries
51 StillCommentFalg
= False
55 AllSectionContent
= ''
57 # Parse section content
59 for Line
in SectionString
:
60 BinLineContent
= Line
[0]
63 if BinLineContent
.strip() == '':
66 CurrentLineObj
= CurrentLine()
67 CurrentLineObj
.FileName
= FileName
68 CurrentLineObj
.LineString
= BinLineContent
69 CurrentLineObj
.LineNo
= BinLineNo
71 # Found Header Comments
73 if BinLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
75 # Last line is comments, and this line go on.
78 HeaderComments
.append(Line
)
79 AllSectionContent
+= BinLineContent
+ DT
.END_OF_LINE
82 # First time encounter comment
89 HeaderComments
.append(Line
)
90 AllSectionContent
+= BinLineContent
+ DT
.END_OF_LINE
91 StillCommentFalg
= True
94 StillCommentFalg
= False
96 if len(HeaderComments
) >= 1:
97 LineComment
= InfLineCommentObject()
98 LineCommentContent
= ''
99 for Item
in HeaderComments
:
100 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
101 LineComment
.SetHeaderComments(LineCommentContent
)
106 if BinLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
107 TailComments
= BinLineContent
[BinLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
108 BinLineContent
= BinLineContent
[:BinLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
109 if LineComment
is None:
110 LineComment
= InfLineCommentObject()
111 LineComment
.SetTailComments(TailComments
)
116 MacroDef
= MacroParser((BinLineContent
, BinLineNo
),
118 DT
.MODEL_EFI_BINARY_FILE
,
119 self
.FileLocalMacros
)
120 if MacroDef
[0] is not None:
121 SectionMacros
[MacroDef
[0]] = MacroDef
[1]
127 # Replace with Local section Macro and [Defines] section Macro.
129 LineContent
= InfExpandMacro(BinLineContent
,
130 (FileName
, BinLineContent
, BinLineNo
),
131 self
.FileLocalMacros
,
134 AllSectionContent
+= LineContent
+ DT
.END_OF_LINE
135 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
136 ValueList
[0:len(TokenList
)] = TokenList
139 # Should equal to UI/SEC_UI/UNI_UI
141 ValueList
[0] = ValueList
[0].strip()
142 if ValueList
[0] == DT
.BINARY_FILE_TYPE_UNI_UI
or \
143 ValueList
[0] == DT
.BINARY_FILE_TYPE_SEC_UI
or \
144 ValueList
[0] == DT
.BINARY_FILE_TYPE_UI
:
145 if len(ValueList
) == 2:
146 TokenList
= GetSplitValueList(ValueList
[1],
150 NewValueList
.append(ValueList
[0])
151 for Item
in TokenList
:
152 NewValueList
.append(Item
)
153 UiBinaryList
.append((NewValueList
,
157 # Should equal to VER/SEC_VER/UNI_VER
159 elif ValueList
[0] == DT
.BINARY_FILE_TYPE_UNI_VER
or \
160 ValueList
[0] == DT
.BINARY_FILE_TYPE_SEC_VER
or \
161 ValueList
[0] == DT
.BINARY_FILE_TYPE_VER
:
162 if len(ValueList
) == 2:
163 TokenList
= GetSplitValueList(ValueList
[1],
167 NewValueList
.append(ValueList
[0])
168 for Item
in TokenList
:
169 NewValueList
.append(Item
)
170 VerBinaryList
.append((NewValueList
,
174 if len(ValueList
) == 2:
175 if ValueList
[0].strip() == 'SUBTYPE_GUID':
176 TokenList
= GetSplitValueList(ValueList
[1],
180 TokenList
= GetSplitValueList(ValueList
[1],
185 NewValueList
.append(ValueList
[0])
186 for Item
in TokenList
:
187 NewValueList
.append(Item
)
188 ComBinaryList
.append((NewValueList
,
191 elif len(ValueList
) == 1:
193 NewValueList
.append(ValueList
[0])
194 ComBinaryList
.append((NewValueList
,
208 # Current section archs
211 for Item
in self
.LastSectionHeaderContent
:
212 if Item
[1] not in ArchList
:
213 ArchList
.append(Item
[1])
214 InfSectionObject
.SetSupArchList(Item
[1])
216 InfSectionObject
.SetAllContent(AllSectionContent
)
217 if not InfSectionObject
.SetBinary(UiBinaryList
,
221 Logger
.Error('InfParser',
223 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[Binaries]"),