2 # This file contained the parser for [Sources] sections in INF file
4 # Copyright (c) 2011 - 2018, 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.
15 InfSourceSectionParser
21 import Logger
.Log
as Logger
22 from Logger
import StringTable
as ST
23 from Logger
.ToolError
import FORMAT_INVALID
24 from Parser
.InfParserMisc
import InfExpandMacro
25 from Library
import DataType
as DT
26 from Library
.Parsing
import MacroParser
27 from Library
.Misc
import GetSplitValueList
28 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
29 from Parser
.InfParserMisc
import InfParserSectionRoot
31 class InfSourceSectionParser(InfParserSectionRoot
):
35 def InfSourceParser(self
, SectionString
, InfSectionObject
, FileName
):
39 StillCommentFalg
= False
43 for Line
in SectionString
:
44 SrcLineContent
= Line
[0]
47 if SrcLineContent
.strip() == '':
51 # Found Header Comments
53 if SrcLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
55 # Last line is comments, and this line go on.
58 HeaderComments
.append(Line
)
59 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
62 # First time encounter comment
69 HeaderComments
.append(Line
)
70 StillCommentFalg
= True
71 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
74 StillCommentFalg
= False
76 if len(HeaderComments
) >= 1:
77 LineComment
= InfLineCommentObject()
78 LineCommentContent
= ''
79 for Item
in HeaderComments
:
80 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
81 LineComment
.SetHeaderComments(LineCommentContent
)
86 if SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
87 TailComments
= SrcLineContent
[SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
88 SrcLineContent
= SrcLineContent
[:SrcLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
89 if LineComment
is None:
90 LineComment
= InfLineCommentObject()
91 LineComment
.SetTailComments(TailComments
)
96 Name
, Value
= MacroParser((SrcLineContent
, SrcLineNo
),
98 DT
.MODEL_EFI_SOURCE_FILE
,
101 SectionMacros
[Name
] = Value
107 # Replace with Local section Macro and [Defines] section Macro.
109 SrcLineContent
= InfExpandMacro(SrcLineContent
,
110 (FileName
, SrcLineContent
, SrcLineNo
),
111 self
.FileLocalMacros
,
114 TokenList
= GetSplitValueList(SrcLineContent
, DT
.TAB_VALUE_SPLIT
, 4)
115 ValueList
[0:len(TokenList
)] = TokenList
118 # Store section content string after MACRO replaced.
120 SectionContent
+= SrcLineContent
+ DT
.END_OF_LINE
122 SourceList
.append((ValueList
, LineComment
,
123 (SrcLineContent
, SrcLineNo
, FileName
)))
131 # Current section archs
134 for Item
in self
.LastSectionHeaderContent
:
135 if Item
[1] not in ArchList
:
136 ArchList
.append(Item
[1])
137 InfSectionObject
.SetSupArchList(Item
[1])
139 InfSectionObject
.SetAllContent(SectionContent
)
140 if not InfSectionObject
.SetSources(SourceList
, Arch
= ArchList
):
141 Logger
.Error('InfParser',
143 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Sources]"),