]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file contained the parser for [Libraries] sections in INF file\r | |
3 | #\r | |
4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
5 | #\r | |
6 | # This program and the accompanying materials are licensed and made available\r | |
7 | # under the terms and conditions of the BSD License which accompanies this\r | |
8 | # distribution. The full text of the license may be found at\r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | '''\r | |
15 | InfLibrarySectionParser\r | |
16 | '''\r | |
17 | ##\r | |
18 | # Import Modules\r | |
19 | #\r | |
20 | \r | |
21 | import Logger.Log as Logger\r | |
22 | from Logger import StringTable as ST\r | |
23 | from Logger.ToolError import FORMAT_INVALID\r | |
24 | from Parser.InfParserMisc import InfExpandMacro\r | |
25 | from Library import DataType as DT\r | |
26 | from Library.Parsing import MacroParser\r | |
27 | from Library.Misc import GetSplitValueList\r | |
28 | from Object.Parser.InfCommonObject import InfLineCommentObject\r | |
29 | from Library import GlobalData\r | |
30 | from Parser.InfParserMisc import IsLibInstanceInfo\r | |
31 | from Parser.InfAsBuiltProcess import GetLibInstanceInfo\r | |
32 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
33 | \r | |
34 | class InfLibrarySectionParser(InfParserSectionRoot):\r | |
35 | ## InfLibraryParser\r | |
36 | #\r | |
37 | #\r | |
38 | def InfLibraryParser(self, SectionString, InfSectionObject, FileName):\r | |
39 | #\r | |
40 | # For Common INF file\r | |
41 | #\r | |
42 | if not GlobalData.gIS_BINARY_INF:\r | |
43 | #\r | |
44 | # Macro defined in this section\r | |
45 | #\r | |
46 | SectionMacros = {}\r | |
47 | ValueList = []\r | |
48 | LibraryList = []\r | |
49 | LibStillCommentFalg = False\r | |
50 | LibHeaderComments = []\r | |
51 | LibLineComment = None\r | |
52 | #\r | |
53 | # Parse section content\r | |
54 | #\r | |
55 | for Line in SectionString:\r | |
56 | LibLineContent = Line[0]\r | |
57 | LibLineNo = Line[1]\r | |
58 | \r | |
59 | if LibLineContent.strip() == '':\r | |
60 | continue\r | |
61 | \r | |
62 | #\r | |
63 | # Found Header Comments\r | |
64 | #\r | |
65 | if LibLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
66 | #\r | |
67 | # Last line is comments, and this line go on.\r | |
68 | #\r | |
69 | if LibStillCommentFalg:\r | |
70 | LibHeaderComments.append(Line)\r | |
71 | continue\r | |
72 | #\r | |
73 | # First time encounter comment\r | |
74 | #\r | |
75 | else:\r | |
76 | #\r | |
77 | # Clear original data\r | |
78 | #\r | |
79 | LibHeaderComments = []\r | |
80 | LibHeaderComments.append(Line)\r | |
81 | LibStillCommentFalg = True\r | |
82 | continue\r | |
83 | else:\r | |
84 | LibStillCommentFalg = False\r | |
85 | \r | |
86 | if len(LibHeaderComments) >= 1:\r | |
87 | LibLineComment = InfLineCommentObject()\r | |
88 | LineCommentContent = ''\r | |
89 | for Item in LibHeaderComments:\r | |
90 | LineCommentContent += Item[0] + DT.END_OF_LINE\r | |
91 | LibLineComment.SetHeaderComments(LineCommentContent)\r | |
92 | \r | |
93 | #\r | |
94 | # Find Tail comment.\r | |
95 | #\r | |
96 | if LibLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
97 | LibTailComments = LibLineContent[LibLineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
98 | LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
99 | if LibLineComment is None:\r | |
100 | LibLineComment = InfLineCommentObject()\r | |
101 | LibLineComment.SetTailComments(LibTailComments)\r | |
102 | \r | |
103 | #\r | |
104 | # Find Macro\r | |
105 | #\r | |
106 | Name, Value = MacroParser((LibLineContent, LibLineNo),\r | |
107 | FileName,\r | |
108 | DT.MODEL_EFI_LIBRARY_CLASS,\r | |
109 | self.FileLocalMacros)\r | |
110 | if Name is not None:\r | |
111 | SectionMacros[Name] = Value\r | |
112 | LibLineComment = None\r | |
113 | LibHeaderComments = []\r | |
114 | continue\r | |
115 | \r | |
116 | TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1)\r | |
117 | ValueList[0:len(TokenList)] = TokenList\r | |
118 | \r | |
119 | #\r | |
120 | # Replace with Local section Macro and [Defines] section Macro.\r | |
121 | #\r | |
122 | ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo),\r | |
123 | self.FileLocalMacros, SectionMacros, True)\r | |
124 | for Value in ValueList]\r | |
125 | \r | |
126 | LibraryList.append((ValueList, LibLineComment,\r | |
127 | (LibLineContent, LibLineNo, FileName)))\r | |
128 | ValueList = []\r | |
129 | LibLineComment = None\r | |
130 | LibTailComments = ''\r | |
131 | LibHeaderComments = []\r | |
132 | \r | |
133 | continue\r | |
134 | \r | |
135 | #\r | |
136 | # Current section archs\r | |
137 | #\r | |
138 | KeyList = []\r | |
139 | for Item in self.LastSectionHeaderContent:\r | |
140 | if (Item[1], Item[2]) not in KeyList:\r | |
141 | KeyList.append((Item[1], Item[2]))\r | |
142 | \r | |
143 | if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):\r | |
144 | Logger.Error('InfParser',\r | |
145 | FORMAT_INVALID,\r | |
146 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r | |
147 | File=FileName,\r | |
148 | Line=Item[3])\r | |
149 | #\r | |
150 | # For Binary INF\r | |
151 | #\r | |
152 | else:\r | |
153 | self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)\r | |
154 | \r | |
155 | def InfAsBuiltLibraryParser(self, SectionString, InfSectionObject, FileName):\r | |
156 | LibraryList = []\r | |
157 | LibInsFlag = False\r | |
158 | for Line in SectionString:\r | |
159 | LineContent = Line[0]\r | |
160 | LineNo = Line[1]\r | |
161 | \r | |
162 | if LineContent.strip() == '':\r | |
163 | LibInsFlag = False\r | |
164 | continue\r | |
165 | \r | |
166 | if not LineContent.strip().startswith("#"):\r | |
167 | Logger.Error('InfParser',\r | |
168 | FORMAT_INVALID,\r | |
169 | ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON,\r | |
170 | File=FileName,\r | |
171 | Line=LineNo,\r | |
172 | ExtraData=LineContent)\r | |
173 | \r | |
174 | if IsLibInstanceInfo(LineContent):\r | |
175 | LibInsFlag = True\r | |
176 | continue\r | |
177 | \r | |
178 | if LibInsFlag:\r | |
179 | LibGuid, LibVer = GetLibInstanceInfo(LineContent, GlobalData.gWORKSPACE, LineNo, FileName)\r | |
180 | #\r | |
181 | # If the VERSION_STRING is missing from the INF file, tool should default to "0".\r | |
182 | #\r | |
183 | if LibVer == '':\r | |
184 | LibVer = '0'\r | |
185 | if LibGuid != '':\r | |
186 | if (LibGuid, LibVer) not in LibraryList:\r | |
187 | LibraryList.append((LibGuid, LibVer))\r | |
188 | \r | |
189 | #\r | |
190 | # Current section archs\r | |
191 | #\r | |
192 | KeyList = []\r | |
193 | Item = ['', '', '']\r | |
194 | for Item in self.LastSectionHeaderContent:\r | |
195 | if (Item[1], Item[2]) not in KeyList:\r | |
196 | KeyList.append((Item[1], Item[2]))\r | |
197 | \r | |
198 | if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):\r | |
199 | Logger.Error('InfParser',\r | |
200 | FORMAT_INVALID,\r | |
201 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r | |
202 | File=FileName,\r | |
203 | Line=Item[3])\r |