2 # This file contained the parser for [Libraries] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
9 InfLibrarySectionParser
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 Library
import GlobalData
24 from Parser
.InfParserMisc
import IsLibInstanceInfo
25 from Parser
.InfAsBuiltProcess
import GetLibInstanceInfo
26 from Parser
.InfParserMisc
import InfParserSectionRoot
28 class InfLibrarySectionParser(InfParserSectionRoot
):
32 def InfLibraryParser(self
, SectionString
, InfSectionObject
, FileName
):
36 if not GlobalData
.gIS_BINARY_INF
:
38 # Macro defined in this section
43 LibStillCommentFalg
= False
44 LibHeaderComments
= []
47 # Parse section content
49 for Line
in SectionString
:
50 LibLineContent
= Line
[0]
53 if LibLineContent
.strip() == '':
57 # Found Header Comments
59 if LibLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
61 # Last line is comments, and this line go on.
63 if LibStillCommentFalg
:
64 LibHeaderComments
.append(Line
)
67 # First time encounter comment
73 LibHeaderComments
= []
74 LibHeaderComments
.append(Line
)
75 LibStillCommentFalg
= True
78 LibStillCommentFalg
= False
80 if len(LibHeaderComments
) >= 1:
81 LibLineComment
= InfLineCommentObject()
82 LineCommentContent
= ''
83 for Item
in LibHeaderComments
:
84 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
85 LibLineComment
.SetHeaderComments(LineCommentContent
)
90 if LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
91 LibTailComments
= LibLineContent
[LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
92 LibLineContent
= LibLineContent
[:LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
93 if LibLineComment
is None:
94 LibLineComment
= InfLineCommentObject()
95 LibLineComment
.SetTailComments(LibTailComments
)
100 Name
, Value
= MacroParser((LibLineContent
, LibLineNo
),
102 DT
.MODEL_EFI_LIBRARY_CLASS
,
103 self
.FileLocalMacros
)
105 SectionMacros
[Name
] = Value
106 LibLineComment
= None
107 LibHeaderComments
= []
110 TokenList
= GetSplitValueList(LibLineContent
, DT
.TAB_VALUE_SPLIT
, 1)
111 ValueList
[0:len(TokenList
)] = TokenList
114 # Replace with Local section Macro and [Defines] section Macro.
116 ValueList
= [InfExpandMacro(Value
, (FileName
, LibLineContent
, LibLineNo
),
117 self
.FileLocalMacros
, SectionMacros
, True)
118 for Value
in ValueList
]
120 LibraryList
.append((ValueList
, LibLineComment
,
121 (LibLineContent
, LibLineNo
, FileName
)))
123 LibLineComment
= None
125 LibHeaderComments
= []
130 # Current section archs
133 for Item
in self
.LastSectionHeaderContent
:
134 if (Item
[1], Item
[2]) not in KeyList
:
135 KeyList
.append((Item
[1], Item
[2]))
137 if not InfSectionObject
.SetLibraryClasses(LibraryList
, KeyList
=KeyList
):
138 Logger
.Error('InfParser',
140 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Library]"),
147 self
.InfAsBuiltLibraryParser(SectionString
, InfSectionObject
, FileName
)
149 def InfAsBuiltLibraryParser(self
, SectionString
, InfSectionObject
, FileName
):
152 for Line
in SectionString
:
153 LineContent
= Line
[0]
156 if LineContent
.strip() == '':
160 if not LineContent
.strip().startswith("#"):
161 Logger
.Error('InfParser',
163 ST
.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON
,
166 ExtraData
=LineContent
)
168 if IsLibInstanceInfo(LineContent
):
173 LibGuid
, LibVer
= GetLibInstanceInfo(LineContent
, GlobalData
.gWORKSPACE
, LineNo
, FileName
)
175 # If the VERSION_STRING is missing from the INF file, tool should default to "0".
180 if (LibGuid
, LibVer
) not in LibraryList
:
181 LibraryList
.append((LibGuid
, LibVer
))
184 # Current section archs
188 for Item
in self
.LastSectionHeaderContent
:
189 if (Item
[1], Item
[2]) not in KeyList
:
190 KeyList
.append((Item
[1], Item
[2]))
192 if not InfSectionObject
.SetLibraryClasses(LibraryList
, KeyList
=KeyList
):
193 Logger
.Error('InfParser',
195 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Library]"),