2 # This file contained the parser for define 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 InfDefineSectionParser
23 from Library
import DataType
as DT
24 from Library
import GlobalData
25 from Library
.Parsing
import MacroParser
26 from Library
.Misc
import GetSplitValueList
27 from Library
.ParserValidate
import IsValidArch
28 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
29 from Object
.Parser
.InfDefineObject
import InfDefMember
30 from Parser
.InfParserMisc
import InfExpandMacro
31 from Object
.Parser
.InfMisc
import ErrorInInf
32 from Logger
import StringTable
as ST
33 from Parser
.InfParserMisc
import InfParserSectionRoot
35 ## __GetValidateArchList
38 def GetValidateArchList(LineContent
):
42 ValidateAcrhPatten
= re
.compile(r
"^\s*#\s*VALID_ARCHITECTURES\s*=\s*.*$", re
.DOTALL
)
44 if ValidateAcrhPatten
.match(LineContent
):
45 TempArch
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)[1]
47 TempArch
= GetSplitValueList(TempArch
, '(', 1)[0]
49 ArchList
= re
.split('\s+', TempArch
)
53 NewArchList
.append(Arch
)
55 ArchList
= NewArchList
59 class InfDefinSectionParser(InfParserSectionRoot
):
60 def InfDefineParser(self
, SectionString
, InfSectionObject
, FileName
, SectionComment
):
65 # Parser Defines section content and fill self._ContentList dict.
67 StillCommentFalg
= False
74 # Add WORKSPACE to global Marco dict.
76 self
.FileLocalMacros
['WORKSPACE'] = GlobalData
.gWORKSPACE
78 for Line
in SectionString
:
84 LineInfo
= ['', -1, '']
85 LineInfo
[0] = FileName
87 LineInfo
[2] = LineContent
89 if LineContent
.strip() == '':
92 # The first time encountered VALIDATE_ARCHITECHERS will be considered as support arch list.
95 ArchList
= GetValidateArchList(LineContent
)
100 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
102 # Last line is comments, and this line go on.
105 HeaderComments
.append(Line
)
106 SectionContent
+= LineContent
+ DT
.END_OF_LINE
109 # First time encounter comment
113 # Clear original data
116 HeaderComments
.append(Line
)
117 StillCommentFalg
= True
118 SectionContent
+= LineContent
+ DT
.END_OF_LINE
121 StillCommentFalg
= False
123 if len(HeaderComments
) >= 1:
124 LineComment
= InfLineCommentObject()
125 LineCommentContent
= ''
126 for Item
in HeaderComments
:
127 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
128 LineComment
.SetHeaderComments(LineCommentContent
)
133 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
134 TailComments
= LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
135 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
136 if LineComment
is None:
137 LineComment
= InfLineCommentObject()
138 LineComment
.SetTailComments(TailComments
)
143 Name
, Value
= MacroParser((LineContent
, LineNo
),
145 DT
.MODEL_META_DATA_HEADER
,
146 self
.FileLocalMacros
)
148 self
.FileLocalMacros
[Name
] = Value
152 # Replace with [Defines] section Macro
154 LineContent
= InfExpandMacro(LineContent
,
155 (FileName
, LineContent
, LineNo
),
156 self
.FileLocalMacros
,
159 SectionContent
+= LineContent
+ DT
.END_OF_LINE
161 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_EQUAL_SPLIT
, 1)
162 if len(TokenList
) < 2:
163 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
165 _ValueList
[0:len(TokenList
)] = TokenList
166 if not _ValueList
[0]:
167 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME
,
169 if not _ValueList
[1]:
170 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
173 Name
, Value
= _ValueList
[0], _ValueList
[1]
175 InfDefMemberObj
= InfDefMember(Name
, Value
)
176 if (LineComment
is not None):
177 InfDefMemberObj
.Comments
.SetHeaderComments(LineComment
.GetHeaderComments())
178 InfDefMemberObj
.Comments
.SetTailComments(LineComment
.GetTailComments())
180 InfDefMemberObj
.CurrentLine
.SetFileName(self
.FullPath
)
181 InfDefMemberObj
.CurrentLine
.SetLineString(LineContent
)
182 InfDefMemberObj
.CurrentLine
.SetLineNo(LineNo
)
184 _ContentList
.append(InfDefMemberObj
)
189 # Current Define section archs
192 ArchList
= ['COMMON']
194 InfSectionObject
.SetAllContent(SectionContent
)
196 InfSectionObject
.SetDefines(_ContentList
, Arch
=ArchList
)