2 # This file contained the parser for BuildOption sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
10 InfBuildOptionSectionParser
15 from Library
import DataType
as DT
16 from Library
import GlobalData
17 import Logger
.Log
as Logger
18 from Logger
import StringTable
as ST
19 from Logger
.ToolError
import FORMAT_INVALID
20 from Parser
.InfParserMisc
import InfExpandMacro
21 from Library
.Misc
import GetSplitValueList
22 from Parser
.InfParserMisc
import IsAsBuildOptionInfo
23 from Library
.Misc
import GetHelpStringByRemoveHashKey
24 from Library
.ParserValidate
import IsValidFamily
25 from Library
.ParserValidate
import IsValidBuildOptionName
26 from Parser
.InfParserMisc
import InfParserSectionRoot
28 class InfBuildOptionSectionParser(InfParserSectionRoot
):
29 ## InfBuildOptionParser
32 def InfBuildOptionParser(self
, SectionString
, InfSectionObject
, FileName
):
37 if not GlobalData
.gIS_BINARY_INF
:
41 for Line
in SectionString
:
47 if LineContent
.strip() == '':
48 SectionContent
+= LineContent
+ DT
.END_OF_LINE
53 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
54 SectionContent
+= LineContent
+ DT
.END_OF_LINE
60 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
61 TailComments
= LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
62 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
64 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_DEQUAL_SPLIT
, 1)
65 if len(TokenList
) == 2:
67 # "Replace" type build option
69 TokenList
.append('True')
72 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)
74 # "Append" type build option
76 if len(TokenList
) == 2:
77 TokenList
.append('False')
79 Logger
.Error('InfParser',
81 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
82 ExtraData
=LineContent
,
86 ValueList
[0:len(TokenList
)] = TokenList
89 # Replace with [Defines] section Macro
91 ValueList
[0] = InfExpandMacro(ValueList
[0], (FileName
, LineContent
, LineNo
),
92 self
.FileLocalMacros
, None)
93 ValueList
[1] = InfExpandMacro(ValueList
[1], (FileName
, LineContent
, LineNo
),
94 self
.FileLocalMacros
, None, True)
101 SectionContent
+= ValueList
[0] + EqualString
+ ValueList
[1] + TailComments
+ DT
.END_OF_LINE
103 Family
= GetSplitValueList(ValueList
[0], DT
.TAB_COLON_SPLIT
, 1)
105 if not IsValidFamily(Family
[0]):
106 Logger
.Error('InfParser',
108 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
109 ExtraData
=LineContent
,
112 if not IsValidBuildOptionName(Family
[1]):
113 Logger
.Error('InfParser',
115 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
116 ExtraData
=LineContent
,
120 if not IsValidBuildOptionName(Family
[0]):
121 Logger
.Error('InfParser',
123 ST
.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID
,
124 ExtraData
=LineContent
,
128 BuildOptionList
.append(ValueList
)
132 BuildOptionList
= InfAsBuiltBuildOptionParser(SectionString
, FileName
)
135 # Current section archs
139 for Item
in self
.LastSectionHeaderContent
:
141 if not (Item
[1] == '' or Item
[1] == '') and Item
[1] not in ArchList
:
142 ArchList
.append(Item
[1])
143 InfSectionObject
.SetSupArchList(Item
[1])
145 InfSectionObject
.SetAllContent(SectionContent
)
146 if not InfSectionObject
.SetBuildOptions(BuildOptionList
, ArchList
, SectionContent
):
147 Logger
.Error('InfParser',
149 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
%("[BuilOptions]"),
153 ## InfBuildOptionParser
156 def InfAsBuiltBuildOptionParser(SectionString
, FileName
):
159 # AsBuild Binary INF file.
161 AsBuildOptionFlag
= False
164 for Line
in SectionString
:
166 LineContent
= Line
[0]
172 if len(SectionString
) == Count
:
173 if LineContent
.strip().startswith("##") and AsBuildOptionFlag
:
174 BuildOptionList
.append(BuildOptionItem
)
175 BuildOptionList
.append([GetHelpStringByRemoveHashKey(LineContent
)])
176 elif LineContent
.strip().startswith("#") and AsBuildOptionFlag
:
177 BuildOptionInfo
= GetHelpStringByRemoveHashKey(LineContent
)
178 BuildOptionItem
.append(BuildOptionInfo
)
179 BuildOptionList
.append(BuildOptionItem
)
181 if len(BuildOptionItem
) > 0:
182 BuildOptionList
.append(BuildOptionItem
)
186 if LineContent
.strip() == '':
187 AsBuildOptionFlag
= False
190 if LineContent
.strip().startswith("##") and AsBuildOptionFlag
:
191 if len(BuildOptionItem
) > 0:
192 BuildOptionList
.append(BuildOptionItem
)
196 if not LineContent
.strip().startswith("#"):
197 Logger
.Error('InfParser',
199 ST
.ERR_BO_CONTATIN_ASBUILD_AND_COMMON
,
202 ExtraData
=LineContent
)
204 if IsAsBuildOptionInfo(LineContent
):
205 AsBuildOptionFlag
= True
208 if AsBuildOptionFlag
:
209 BuildOptionInfo
= GetHelpStringByRemoveHashKey(LineContent
)
210 BuildOptionItem
.append(BuildOptionInfo
)
212 return BuildOptionList