2 # This file contained the parser for define sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
10 InfDefineSectionParser
17 from Library
import DataType
as DT
18 from Library
import GlobalData
19 from Library
.Parsing
import MacroParser
20 from Library
.Misc
import GetSplitValueList
21 from Library
.ParserValidate
import IsValidArch
22 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
23 from Object
.Parser
.InfDefineObject
import InfDefMember
24 from Parser
.InfParserMisc
import InfExpandMacro
25 from Object
.Parser
.InfMisc
import ErrorInInf
26 from Logger
import StringTable
as ST
27 from Parser
.InfParserMisc
import InfParserSectionRoot
29 ## __GetValidateArchList
32 def GetValidateArchList(LineContent
):
36 ValidateAcrhPatten
= re
.compile(r
"^\s*#\s*VALID_ARCHITECTURES\s*=\s*.*$", re
.DOTALL
)
38 if ValidateAcrhPatten
.match(LineContent
):
39 TempArch
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)[1]
41 TempArch
= GetSplitValueList(TempArch
, '(', 1)[0]
43 ArchList
= re
.split('\s+', TempArch
)
47 NewArchList
.append(Arch
)
49 ArchList
= NewArchList
53 class InfDefinSectionParser(InfParserSectionRoot
):
54 def InfDefineParser(self
, SectionString
, InfSectionObject
, FileName
, SectionComment
):
59 # Parser Defines section content and fill self._ContentList dict.
61 StillCommentFalg
= False
68 # Add WORKSPACE to global Marco dict.
70 self
.FileLocalMacros
['WORKSPACE'] = GlobalData
.gWORKSPACE
72 for Line
in SectionString
:
78 LineInfo
= ['', -1, '']
79 LineInfo
[0] = FileName
81 LineInfo
[2] = LineContent
83 if LineContent
.strip() == '':
86 # The first time encountered VALIDATE_ARCHITECHERS will be considered as support arch list.
89 ArchList
= GetValidateArchList(LineContent
)
94 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
96 # Last line is comments, and this line go on.
99 HeaderComments
.append(Line
)
100 SectionContent
+= LineContent
+ DT
.END_OF_LINE
103 # First time encounter comment
107 # Clear original data
110 HeaderComments
.append(Line
)
111 StillCommentFalg
= True
112 SectionContent
+= LineContent
+ DT
.END_OF_LINE
115 StillCommentFalg
= False
117 if len(HeaderComments
) >= 1:
118 LineComment
= InfLineCommentObject()
119 LineCommentContent
= ''
120 for Item
in HeaderComments
:
121 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
122 LineComment
.SetHeaderComments(LineCommentContent
)
127 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
128 TailComments
= LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
129 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
130 if LineComment
is None:
131 LineComment
= InfLineCommentObject()
132 LineComment
.SetTailComments(TailComments
)
137 Name
, Value
= MacroParser((LineContent
, LineNo
),
139 DT
.MODEL_META_DATA_HEADER
,
140 self
.FileLocalMacros
)
142 self
.FileLocalMacros
[Name
] = Value
146 # Replace with [Defines] section Macro
148 LineContent
= InfExpandMacro(LineContent
,
149 (FileName
, LineContent
, LineNo
),
150 self
.FileLocalMacros
,
153 SectionContent
+= LineContent
+ DT
.END_OF_LINE
155 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)
156 if len(TokenList
) < 2:
157 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
159 _ValueList
[0:len(TokenList
)] = TokenList
160 if not _ValueList
[0]:
161 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME
,
163 if not _ValueList
[1]:
164 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
167 Name
, Value
= _ValueList
[0], _ValueList
[1]
169 InfDefMemberObj
= InfDefMember(Name
, Value
)
170 if (LineComment
is not None):
171 InfDefMemberObj
.Comments
.SetHeaderComments(LineComment
.GetHeaderComments())
172 InfDefMemberObj
.Comments
.SetTailComments(LineComment
.GetTailComments())
174 InfDefMemberObj
.CurrentLine
.SetFileName(self
.FullPath
)
175 InfDefMemberObj
.CurrentLine
.SetLineString(LineContent
)
176 InfDefMemberObj
.CurrentLine
.SetLineNo(LineNo
)
178 _ContentList
.append(InfDefMemberObj
)
183 # Current Define section archs
186 ArchList
= ['COMMON']
188 InfSectionObject
.SetAllContent(SectionContent
)
190 InfSectionObject
.SetDefines(_ContentList
, Arch
=ArchList
)