2 # This file contained the parser for [Binaries] sections in INF file
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
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
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.
15 InfBinarySectionParser
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
32 class InfBinarySectionParser(InfParserSectionRoot
):
36 def InfBinaryParser(self
, SectionString
, InfSectionObject
, FileName
):
38 # Macro defined in this section
43 # For UI (UI, SEC_UI, UNI_UI) binaries
44 # One and only one UI section can be included
48 # For Version (VER, SEC_VER, UNI_VER).
49 # One and only one VER section on be included
53 # For other common type binaries
57 StillCommentFalg
= False
61 AllSectionContent
= ''
63 # Parse section content
65 for Line
in SectionString
:
66 BinLineContent
= Line
[0]
69 if BinLineContent
.strip() == '':
72 CurrentLineObj
= CurrentLine()
73 CurrentLineObj
.FileName
= FileName
74 CurrentLineObj
.LineString
= BinLineContent
75 CurrentLineObj
.LineNo
= BinLineNo
77 # Found Header Comments
79 if BinLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
81 # Last line is comments, and this line go on.
84 HeaderComments
.append(Line
)
85 AllSectionContent
+= BinLineContent
+ DT
.END_OF_LINE
88 # First time encounter comment
95 HeaderComments
.append(Line
)
96 AllSectionContent
+= BinLineContent
+ DT
.END_OF_LINE
97 StillCommentFalg
= True
100 StillCommentFalg
= False
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
)
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
)
122 MacroDef
= MacroParser((BinLineContent
, BinLineNo
),
124 DT
.MODEL_EFI_BINARY_FILE
,
125 self
.FileLocalMacros
)
126 if MacroDef
[0] != None:
127 SectionMacros
[MacroDef
[0]] = MacroDef
[1]
133 # Replace with Local section Macro and [Defines] section Macro.
135 LineContent
= InfExpandMacro(BinLineContent
,
136 (FileName
, BinLineContent
, BinLineNo
),
137 self
.FileLocalMacros
,
140 AllSectionContent
+= LineContent
+ DT
.END_OF_LINE
141 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
142 ValueList
[0:len(TokenList
)] = TokenList
145 # Should equal to UI/SEC_UI/UNI_UI
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],
156 NewValueList
.append(ValueList
[0])
157 for Item
in TokenList
:
158 NewValueList
.append(Item
)
159 UiBinaryList
.append((NewValueList
,
163 # Should equal to VER/SEC_VER/UNI_VER
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],
173 NewValueList
.append(ValueList
[0])
174 for Item
in TokenList
:
175 NewValueList
.append(Item
)
176 VerBinaryList
.append((NewValueList
,
180 if len(ValueList
) == 2:
181 TokenList
= GetSplitValueList(ValueList
[1],
185 NewValueList
.append(ValueList
[0])
186 for Item
in TokenList
:
187 NewValueList
.append(Item
)
188 ComBinaryList
.append((NewValueList
,
199 # Current section archs
202 for Item
in self
.LastSectionHeaderContent
:
203 if Item
[1] not in ArchList
:
204 ArchList
.append(Item
[1])
205 InfSectionObject
.SetSupArchList(Item
[1])
207 InfSectionObject
.SetAllContent(AllSectionContent
)
208 if not InfSectionObject
.SetBinary(UiBinaryList
,
212 Logger
.Error('InfParser',
214 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[Binaries]"),