2 # This file contained the parser for BuildOption 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.
16 InfBuildOptionSectionParser
21 from Library
import DataType
as DT
22 from Library
import GlobalData
23 import Logger
.Log
as Logger
24 from Logger
import StringTable
as ST
25 from Logger
.ToolError
import FORMAT_INVALID
26 from Parser
.InfParserMisc
import InfExpandMacro
27 from Library
.Misc
import GetSplitValueList
28 from Parser
.InfParserMisc
import IsAsBuildOptionInfo
29 from Library
.Misc
import GetHelpStringByRemoveHashKey
30 from Library
.ParserValidate
import IsValidFamily
31 from Library
.ParserValidate
import IsValidBuildOptionName
32 from Parser
.InfParserMisc
import InfParserSectionRoot
34 class InfBuildOptionSectionParser(InfParserSectionRoot
):
35 ## InfBuildOptionParser
38 def InfBuildOptionParser(self
, SectionString
, InfSectionObject
, FileName
):
43 if not GlobalData
.gIS_BINARY_INF
:
47 for Line
in SectionString
:
53 if LineContent
.strip() == '':
54 SectionContent
+= LineContent
+ DT
.END_OF_LINE
59 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
60 SectionContent
+= LineContent
+ DT
.END_OF_LINE
66 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
67 TailComments
= LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
68 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
70 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_DEQUAL_SPLIT
, 1)
71 if len(TokenList
) == 2:
73 # "Replace" type build option
75 TokenList
.append('True')
78 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)
80 # "Append" type build option
82 if len(TokenList
) == 2:
83 TokenList
.append('False')
85 Logger
.Error('InfParser',
87 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
88 ExtraData
=LineContent
,
92 ValueList
[0:len(TokenList
)] = TokenList
95 # Replace with [Defines] section Macro
97 ValueList
[0] = InfExpandMacro(ValueList
[0], (FileName
, LineContent
, LineNo
),
98 self
.FileLocalMacros
, None)
99 ValueList
[1] = InfExpandMacro(ValueList
[1], (FileName
, LineContent
, LineNo
),
100 self
.FileLocalMacros
, None, True)
107 SectionContent
+= ValueList
[0] + EqualString
+ ValueList
[1] + TailComments
+ DT
.END_OF_LINE
109 Family
= GetSplitValueList(ValueList
[0], DT
.TAB_COLON_SPLIT
, 1)
111 if not IsValidFamily(Family
[0]):
112 Logger
.Error('InfParser',
114 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
115 ExtraData
=LineContent
,
118 if not IsValidBuildOptionName(Family
[1]):
119 Logger
.Error('InfParser',
121 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
122 ExtraData
=LineContent
,
126 if not IsValidBuildOptionName(Family
[0]):
127 Logger
.Error('InfParser',
129 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
130 ExtraData
=LineContent
,
134 BuildOptionList
.append(ValueList
)
138 BuildOptionList
= InfAsBuiltBuildOptionParser(SectionString
, FileName
)
141 # Current section archs
145 for Item
in self
.LastSectionHeaderContent
:
147 if not (Item
[1] == '' or Item
[1] == '') and Item
[1] not in ArchList
:
148 ArchList
.append(Item
[1])
149 InfSectionObject
.SetSupArchList(Item
[1])
151 InfSectionObject
.SetAllContent(SectionContent
)
152 if not InfSectionObject
.SetBuildOptions(BuildOptionList
, ArchList
, SectionContent
):
153 Logger
.Error('InfParser',
155 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[BuilOptions]"),
159 ## InfBuildOptionParser
162 def InfAsBuiltBuildOptionParser(SectionString
, FileName
):
165 # AsBuild Binary INF file.
167 AsBuildOptionFlag
= False
170 for Line
in SectionString
:
172 LineContent
= Line
[0]
178 if len(SectionString
) == Count
:
179 if LineContent
.strip().startswith("##") and AsBuildOptionFlag
:
180 BuildOptionList
.append(BuildOptionItem
)
181 BuildOptionList
.append([GetHelpStringByRemoveHashKey(LineContent
)])
182 elif LineContent
.strip().startswith("#") and AsBuildOptionFlag
:
183 BuildOptionInfo
= GetHelpStringByRemoveHashKey(LineContent
)
184 BuildOptionItem
.append(BuildOptionInfo
)
185 BuildOptionList
.append(BuildOptionItem
)
187 if len(BuildOptionItem
) > 0:
188 BuildOptionList
.append(BuildOptionItem
)
192 if LineContent
.strip() == '':
193 AsBuildOptionFlag
= False
196 if LineContent
.strip().startswith("##") and AsBuildOptionFlag
:
197 if len(BuildOptionItem
) > 0:
198 BuildOptionList
.append(BuildOptionItem
)
202 if not LineContent
.strip().startswith("#"):
203 Logger
.Error('InfParser',
205 ST
.ERR_BO_CONTATIN_ASBUILD_AND_COMMON
,
208 ExtraData
=LineContent
)
210 if IsAsBuildOptionInfo(LineContent
):
211 AsBuildOptionFlag
= True
214 if AsBuildOptionFlag
:
215 BuildOptionInfo
= GetHelpStringByRemoveHashKey(LineContent
)
216 BuildOptionItem
.append(BuildOptionInfo
)
218 return BuildOptionList