2 # This file contained the parser for [Sources] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
.Parsing
import MacroParser
21 from Library
.Misc
import GetSplitValueList
22 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
23 from Parser
.InfParserMisc
import InfParserSectionRoot
25 class InfSourceSectionParser(InfParserSectionRoot
):
29 def InfSourceParser(self
, SectionString
, InfSectionObject
, FileName
):
33 StillCommentFalg
= False
37 for Line
in SectionString
:
38 SrcLineContent
= Line
[0]
41 if SrcLineContent
.strip() == '':
45 # Found Header Comments
47 if SrcLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
49 # Last line is comments, and this line go on.
52 HeaderComments
.append(Line
)
53 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
56 # First time encounter comment
63 HeaderComments
.append(Line
)
64 StillCommentFalg
= True
65 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
68 StillCommentFalg
= False
70 if len(HeaderComments
) >= 1:
71 LineComment
= InfLineCommentObject()
72 LineCommentContent
= ''
73 for Item
in HeaderComments
:
74 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
75 LineComment
.SetHeaderComments(LineCommentContent
)
80 if SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
81 TailComments
= SrcLineContent
[SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
82 SrcLineContent
= SrcLineContent
[:SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
83 if LineComment
is None:
84 LineComment
= InfLineCommentObject()
85 LineComment
.SetTailComments(TailComments
)
90 Name
, Value
= MacroParser((SrcLineContent
, SrcLineNo
),
92 DT
.MODEL_EFI_SOURCE_FILE
,
95 SectionMacros
[Name
] = Value
101 # Replace with Local section Macro and [Defines] section Macro.
103 SrcLineContent
= InfExpandMacro(SrcLineContent
,
104 (FileName
, SrcLineContent
, SrcLineNo
),
105 self
.FileLocalMacros
,
108 TokenList
= GetSplitValueList(SrcLineContent
, DT
.TAB_VALUE_SPLIT
, 4)
109 ValueList
[0:len(TokenList
)] = TokenList
112 # Store section content string after MACRO replaced.
114 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
116 SourceList
.append((ValueList
, LineComment
,
117 (SrcLineContent
, SrcLineNo
, FileName
)))
125 # Current section archs
128 for Item
in self
.LastSectionHeaderContent
:
129 if Item
[1] not in ArchList
:
130 ArchList
.append(Item
[1])
131 InfSectionObject
.SetSupArchList(Item
[1])
133 InfSectionObject
.SetAllContent(SectionContent
)
134 if not InfSectionObject
.SetSources(SourceList
, Arch
= ArchList
):
135 Logger
.Error('InfParser',
137 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Sources]"),