]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfLibrarySectionParser.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the parser for [Libraries] sections in INF file \r
3#\r
4# Copyright (c) 2011, 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
15InfLibrarySectionParser\r
16'''\r
17##\r
18# Import Modules\r
19#\r
20\r
21import Logger.Log as Logger\r
22from Logger import StringTable as ST\r
23from Logger.ToolError import FORMAT_INVALID\r
24from Parser.InfParserMisc import InfExpandMacro\r
25from Library import DataType as DT\r
26from Library.Parsing import MacroParser\r
27from Library.Misc import GetSplitValueList\r
28from Object.Parser.InfCommonObject import InfLineCommentObject\r
29from Library import GlobalData\r
30from Parser.InfParserMisc import IsLibInstanceInfo\r
31from Parser.InfAsBuiltProcess import GetLibInstanceInfo\r
32from Parser.InfParserMisc import InfParserSectionRoot\r
33\r
34class 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 == 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 != 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
4afd3d04 173\r
4234283c
LG
174 if IsLibInstanceInfo(LineContent):\r
175 LibInsFlag = True\r
176 continue\r
4afd3d04 177\r
4234283c 178 if LibInsFlag:\r
4afd3d04 179 LibGuid, LibVer = GetLibInstanceInfo(LineContent, GlobalData.gWORKSPACE, LineNo, FileName)\r
4234283c
LG
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
4afd3d04
LG
186 if (LibGuid, LibVer) not in LibraryList:\r
187 LibraryList.append((LibGuid, LibVer))\r
4234283c 188 else:\r
4afd3d04 189 Logger.Error('InfParser',\r
4234283c 190 FORMAT_INVALID,\r
4afd3d04
LG
191 ST.ERR_LIB_INSTANCE_MISS_GUID,\r
192 File=FileName,\r
193 Line=LineNo,\r
194 ExtraData=LineContent)\r
195\r
4234283c
LG
196 #\r
197 # Current section archs\r
198 # \r
199 KeyList = []\r
200 Item = ['', '', '']\r
201 for Item in self.LastSectionHeaderContent:\r
202 if (Item[1], Item[2]) not in KeyList:\r
203 KeyList.append((Item[1], Item[2]))\r
204 \r
205 if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList = KeyList):\r
206 Logger.Error('InfParser', \r
207 FORMAT_INVALID,\r
208 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r
209 File=FileName, \r
210 Line=Item[3])