]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 LG |
2 | # This file is used to define class objects of INF file [LibraryClasses] section.\r |
3 | # It will consumed by InfParser.\r | |
4234283c | 4 | #\r |
f7496d71 | 5 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 6 | #\r |
f7496d71 LG |
7 | # This program and the accompanying materials are licensed and made available\r |
8 | # under the terms and conditions of the BSD License which accompanies this\r | |
9 | # distribution. The full text of the license may be found at\r | |
4234283c LG |
10 | # http://opensource.org/licenses/bsd-license.php\r |
11 | #\r | |
12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | '''\r | |
16 | InfLibraryClassesObject\r | |
17 | '''\r | |
18 | \r | |
19 | from Logger import StringTable as ST\r | |
20 | from Logger import ToolError\r | |
21 | import Logger.Log as Logger\r | |
22 | from Library import GlobalData\r | |
23 | \r | |
24 | from Library.Misc import Sdict\r | |
25 | from Object.Parser.InfCommonObject import CurrentLine\r | |
26 | from Library.ExpressionValidate import IsValidFeatureFlagExp\r | |
27 | from Library.ParserValidate import IsValidLibName\r | |
28 | \r | |
29 | ## GetArchModuleType\r | |
30 | #\r | |
31 | # Get Arch List and ModuleType List\r | |
32 | #\r | |
33 | def GetArchModuleType(KeyList):\r | |
34 | __SupArchList = []\r | |
35 | __SupModuleList = []\r | |
36 | \r | |
37 | for (ArchItem, ModuleItem) in KeyList:\r | |
38 | #\r | |
39 | # Validate Arch\r | |
f7496d71 | 40 | #\r |
4231a819 | 41 | if (ArchItem == '' or ArchItem is None):\r |
4234283c LG |
42 | ArchItem = 'COMMON'\r |
43 | \r | |
4231a819 | 44 | if (ModuleItem == '' or ModuleItem is None):\r |
4234283c LG |
45 | ModuleItem = 'COMMON'\r |
46 | \r | |
47 | if ArchItem not in __SupArchList:\r | |
48 | __SupArchList.append(ArchItem)\r | |
49 | \r | |
50 | List = ModuleItem.split('|')\r | |
51 | for Entry in List:\r | |
52 | if Entry not in __SupModuleList:\r | |
53 | __SupModuleList.append(Entry)\r | |
54 | \r | |
55 | return (__SupArchList, __SupModuleList)\r | |
56 | \r | |
57 | \r | |
58 | class InfLibraryClassItem():\r | |
59 | def __init__(self, LibName='', FeatureFlagExp='', HelpString=None):\r | |
60 | self.LibName = LibName\r | |
61 | self.FeatureFlagExp = FeatureFlagExp\r | |
62 | self.HelpString = HelpString\r | |
63 | self.CurrentLine = CurrentLine()\r | |
64 | self.SupArchList = []\r | |
65 | self.SupModuleList = []\r | |
66 | self.FileGuid = ''\r | |
67 | self.Version = ''\r | |
68 | \r | |
69 | def SetLibName(self, LibName):\r | |
70 | self.LibName = LibName\r | |
71 | def GetLibName(self):\r | |
72 | return self.LibName\r | |
73 | \r | |
74 | def SetHelpString(self, HelpString):\r | |
75 | self.HelpString = HelpString\r | |
76 | def GetHelpString(self):\r | |
77 | return self.HelpString\r | |
78 | \r | |
79 | def SetFeatureFlagExp(self, FeatureFlagExp):\r | |
80 | self.FeatureFlagExp = FeatureFlagExp\r | |
81 | def GetFeatureFlagExp(self):\r | |
82 | return self.FeatureFlagExp\r | |
83 | \r | |
84 | def SetSupArchList(self, SupArchList):\r | |
85 | self.SupArchList = SupArchList\r | |
86 | def GetSupArchList(self):\r | |
87 | return self.SupArchList\r | |
88 | \r | |
89 | def SetSupModuleList(self, SupModuleList):\r | |
90 | self.SupModuleList = SupModuleList\r | |
91 | def GetSupModuleList(self):\r | |
92 | return self.SupModuleList\r | |
93 | \r | |
94 | #\r | |
95 | # As Build related information\r | |
96 | #\r | |
97 | def SetFileGuid(self, FileGuid):\r | |
98 | self.FileGuid = FileGuid\r | |
99 | def GetFileGuid(self):\r | |
100 | return self.FileGuid\r | |
101 | \r | |
102 | def SetVersion(self, Version):\r | |
103 | self.Version = Version\r | |
104 | def GetVersion(self):\r | |
105 | return self.Version\r | |
106 | \r | |
107 | ## INF LibraryClass Section\r | |
108 | #\r | |
109 | #\r | |
110 | #\r | |
111 | class InfLibraryClassObject():\r | |
112 | def __init__(self):\r | |
113 | self.LibraryClasses = Sdict()\r | |
114 | #\r | |
115 | # Macro defined in this section should be only used in this section.\r | |
116 | #\r | |
117 | self.Macros = {}\r | |
118 | \r | |
119 | ##SetLibraryClasses\r | |
120 | #\r | |
f7496d71 | 121 | #\r |
4234283c LG |
122 | # @param HelpString: It can be a common comment or contain a recommend\r |
123 | # instance.\r | |
124 | #\r | |
125 | def SetLibraryClasses(self, LibContent, KeyList=None):\r | |
126 | #\r | |
127 | # Validate Arch\r | |
128 | #\r | |
129 | (__SupArchList, __SupModuleList) = GetArchModuleType(KeyList)\r | |
130 | \r | |
131 | for LibItem in LibContent:\r | |
132 | LibItemObj = InfLibraryClassItem()\r | |
133 | if not GlobalData.gIS_BINARY_INF:\r | |
134 | HelpStringObj = LibItem[1]\r | |
135 | LibItemObj.CurrentLine.SetFileName(LibItem[2][2])\r | |
136 | LibItemObj.CurrentLine.SetLineNo(LibItem[2][1])\r | |
137 | LibItemObj.CurrentLine.SetLineString(LibItem[2][0])\r | |
138 | LibItem = LibItem[0]\r | |
4231a819 | 139 | if HelpStringObj is not None:\r |
4234283c LG |
140 | LibItemObj.SetHelpString(HelpStringObj)\r |
141 | if len(LibItem) >= 1:\r | |
142 | if LibItem[0].strip() != '':\r | |
143 | if IsValidLibName(LibItem[0].strip()):\r | |
144 | if LibItem[0].strip() != 'NULL':\r | |
145 | LibItemObj.SetLibName(LibItem[0])\r | |
146 | else:\r | |
147 | Logger.Error("InfParser",\r | |
148 | ToolError.FORMAT_INVALID,\r | |
149 | ST.ERR_INF_PARSER_DEFINE_LIB_NAME_INVALID,\r | |
150 | File=GlobalData.gINF_MODULE_NAME,\r | |
151 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
152 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
153 | else:\r | |
154 | Logger.Error("InfParser",\r | |
155 | ToolError.FORMAT_INVALID,\r | |
156 | ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (LibItem[0]),\r | |
157 | File=GlobalData.gINF_MODULE_NAME,\r | |
158 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
159 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
160 | else:\r | |
161 | Logger.Error("InfParser",\r | |
162 | ToolError.FORMAT_INVALID,\r | |
163 | ST.ERR_INF_PARSER_LIBRARY_SECTION_LIBNAME_MISSING,\r | |
164 | File=GlobalData.gINF_MODULE_NAME,\r | |
165 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
166 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
167 | if len(LibItem) == 2:\r | |
168 | if LibItem[1].strip() == '':\r | |
169 | Logger.Error("InfParser",\r | |
170 | ToolError.FORMAT_INVALID,\r | |
171 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
172 | File=GlobalData.gINF_MODULE_NAME,\r | |
173 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
174 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
175 | #\r | |
f7496d71 | 176 | # Validate FFE\r |
4234283c LG |
177 | #\r |
178 | FeatureFlagRtv = IsValidFeatureFlagExp(LibItem[1].strip())\r | |
179 | if not FeatureFlagRtv[0]:\r | |
180 | Logger.Error("InfParser",\r | |
181 | ToolError.FORMAT_INVALID,\r | |
182 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),\r | |
183 | File=GlobalData.gINF_MODULE_NAME,\r | |
184 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
185 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
186 | LibItemObj.SetFeatureFlagExp(LibItem[1].strip())\r | |
187 | \r | |
188 | #\r | |
189 | # Invalid strings\r | |
190 | #\r | |
191 | if len(LibItem) < 1 or len(LibItem) > 2:\r | |
192 | Logger.Error("InfParser",\r | |
193 | ToolError.FORMAT_INVALID,\r | |
194 | ST.ERR_INF_PARSER_LIBRARY_SECTION_CONTENT_ERROR,\r | |
195 | File=GlobalData.gINF_MODULE_NAME,\r | |
196 | Line=LibItemObj.CurrentLine.GetLineNo(),\r | |
197 | ExtraData=LibItemObj.CurrentLine.GetLineString())\r | |
198 | \r | |
199 | LibItemObj.SetSupArchList(__SupArchList)\r | |
200 | LibItemObj.SetSupModuleList(__SupModuleList)\r | |
201 | \r | |
202 | #\r | |
203 | # Determine Library class duplicate. Follow below rule:\r | |
204 | #\r | |
f7496d71 LG |
205 | # A library class keyword must not be duplicated within a\r |
206 | # [LibraryClasses] section. Library class keywords may appear in\r | |
207 | # multiple architectural and module type [LibraryClasses] sections.\r | |
208 | # A library class keyword listed in an architectural or module type\r | |
209 | # [LibraryClasses] section must not be listed in the common\r | |
4234283c | 210 | # architectural or module type [LibraryClasses] section.\r |
f7496d71 | 211 | #\r |
4234283c | 212 | # NOTE: This check will not report error now. But keep code for future enhancement.\r |
f7496d71 | 213 | #\r |
4234283c LG |
214 | # for Item in self.LibraryClasses:\r |
215 | # if Item.GetLibName() == LibItemObj.GetLibName():\r | |
216 | # ItemSupArchList = Item.GetSupArchList()\r | |
217 | # ItemSupModuleList = Item.GetSupModuleList()\r | |
218 | # for ItemArch in ItemSupArchList:\r | |
219 | # for ItemModule in ItemSupModuleList:\r | |
220 | # for LibItemObjArch in __SupArchList:\r | |
221 | # for LibItemObjModule in __SupModuleList:\r | |
222 | # if ItemArch == LibItemObjArch and LibItemObjModule == ItemModule:\r | |
223 | # #\r | |
224 | # # ERR_INF_PARSER_ITEM_DUPLICATE\r | |
225 | # #\r | |
226 | # pass\r | |
227 | # if (ItemArch.upper() == 'COMMON' or LibItemObjArch.upper() == 'COMMON') \\r | |
228 | # and LibItemObjModule == ItemModule:\r | |
229 | # #\r | |
230 | # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
231 | # #\r | |
232 | # pass\r | |
233 | else:\r | |
234 | #\r | |
235 | # Assume the file GUID is well formatted.\r | |
236 | #\r | |
237 | LibItemObj.SetFileGuid(LibItem[0])\r | |
238 | LibItemObj.SetVersion(LibItem[1])\r | |
421ccda3 | 239 | LibItemObj.SetSupArchList(__SupArchList)\r |
4234283c | 240 | \r |
27c4ceb4 | 241 | if (LibItemObj) in self.LibraryClasses:\r |
4234283c LG |
242 | LibraryList = self.LibraryClasses[LibItemObj]\r |
243 | LibraryList.append(LibItemObj)\r | |
244 | self.LibraryClasses[LibItemObj] = LibraryList\r | |
245 | else:\r | |
246 | LibraryList = []\r | |
247 | LibraryList.append(LibItemObj)\r | |
248 | self.LibraryClasses[LibItemObj] = LibraryList\r | |
249 | \r | |
250 | return True\r | |
251 | \r | |
252 | def GetLibraryClasses(self):\r | |
253 | return self.LibraryClasses\r |