2 # This file contained the parser for [Libraries] 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.
15 InfLibrarySectionParser
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 Library
import GlobalData
30 from Parser
.InfParserMisc
import IsLibInstanceInfo
31 from Parser
.InfAsBuiltProcess
import GetLibInstanceInfo
32 from Parser
.InfParserMisc
import InfParserSectionRoot
34 class InfLibrarySectionParser(InfParserSectionRoot
):
38 def InfLibraryParser(self
, SectionString
, InfSectionObject
, FileName
):
42 if not GlobalData
.gIS_BINARY_INF
:
44 # Macro defined in this section
49 LibStillCommentFalg
= False
50 LibHeaderComments
= []
53 # Parse section content
55 for Line
in SectionString
:
56 LibLineContent
= Line
[0]
59 if LibLineContent
.strip() == '':
63 # Found Header Comments
65 if LibLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
67 # Last line is comments, and this line go on.
69 if LibStillCommentFalg
:
70 LibHeaderComments
.append(Line
)
73 # First time encounter comment
79 LibHeaderComments
= []
80 LibHeaderComments
.append(Line
)
81 LibStillCommentFalg
= True
84 LibStillCommentFalg
= False
86 if len(LibHeaderComments
) >= 1:
87 LibLineComment
= InfLineCommentObject()
88 LineCommentContent
= ''
89 for Item
in LibHeaderComments
:
90 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
91 LibLineComment
.SetHeaderComments(LineCommentContent
)
96 if LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
97 LibTailComments
= LibLineContent
[LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
98 LibLineContent
= LibLineContent
[:LibLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
99 if LibLineComment
== None:
100 LibLineComment
= InfLineCommentObject()
101 LibLineComment
.SetTailComments(LibTailComments
)
106 Name
, Value
= MacroParser((LibLineContent
, LibLineNo
),
108 DT
.MODEL_EFI_LIBRARY_CLASS
,
109 self
.FileLocalMacros
)
111 SectionMacros
[Name
] = Value
112 LibLineComment
= None
113 LibHeaderComments
= []
116 TokenList
= GetSplitValueList(LibLineContent
, DT
.TAB_VALUE_SPLIT
, 1)
117 ValueList
[0:len(TokenList
)] = TokenList
120 # Replace with Local section Macro and [Defines] section Macro.
122 ValueList
= [InfExpandMacro(Value
, (FileName
, LibLineContent
, LibLineNo
),
123 self
.FileLocalMacros
, SectionMacros
, True)
124 for Value
in ValueList
]
126 LibraryList
.append((ValueList
, LibLineComment
,
127 (LibLineContent
, LibLineNo
, FileName
)))
129 LibLineComment
= None
131 LibHeaderComments
= []
136 # Current section archs
139 for Item
in self
.LastSectionHeaderContent
:
140 if (Item
[1], Item
[2]) not in KeyList
:
141 KeyList
.append((Item
[1], Item
[2]))
143 if not InfSectionObject
.SetLibraryClasses(LibraryList
, KeyList
= KeyList
):
144 Logger
.Error('InfParser',
146 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Library]"),
153 self
.InfAsBuiltLibraryParser(SectionString
, InfSectionObject
, FileName
)
155 def InfAsBuiltLibraryParser(self
, SectionString
, InfSectionObject
, FileName
):
158 for Line
in SectionString
:
159 LineContent
= Line
[0]
162 if LineContent
.strip() == '':
166 if not LineContent
.strip().startswith("#"):
167 Logger
.Error('InfParser',
169 ST
.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON
,
172 ExtraData
=LineContent
)
174 if IsLibInstanceInfo(LineContent
):
179 LibGuid
, LibVer
= GetLibInstanceInfo(LineContent
, GlobalData
.gWORKSPACE
, LineNo
)
181 # If the VERSION_STRING is missing from the INF file, tool should default to "0".
186 LibraryList
.append((LibGuid
, LibVer
))
188 Logger
.Error('InfParser',
190 ST
.ERR_LIB_INSTANCE_MISS_GUID
,
193 ExtraData
=LineContent
)
196 # Current section archs
200 for Item
in self
.LastSectionHeaderContent
:
201 if (Item
[1], Item
[2]) not in KeyList
:
202 KeyList
.append((Item
[1], Item
[2]))
204 if not InfSectionObject
.SetLibraryClasses(LibraryList
, KeyList
= KeyList
):
205 Logger
.Error('InfParser',
207 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Library]"),