]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to create/update/query/erase a meta file table\r | |
3 | #\r | |
c28d2e10 | 4 | # Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 5 | # This program and the accompanying materials\r |
30fdf114 LG |
6 | # are licensed and made available under the terms and conditions of the BSD License\r |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | #\r | |
13 | \r | |
14 | ##\r | |
15 | # Import Modules\r | |
16 | #\r | |
0d2711a6 LG |
17 | import uuid\r |
18 | \r | |
30fdf114 | 19 | import Common.EdkLogger as EdkLogger\r |
901fd822 | 20 | from Common.BuildToolError import FORMAT_INVALID\r |
0d2711a6 LG |
21 | \r |
22 | from MetaDataTable import Table, TableFile\r | |
30fdf114 | 23 | from MetaDataTable import ConvertToSqlString\r |
0d2711a6 LG |
24 | from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \\r |
25 | MODEL_FILE_OTHERS\r | |
8518bf0b | 26 | from Common.DataType import *\r |
30fdf114 | 27 | \r |
0d2711a6 | 28 | class MetaFileTable(Table):\r |
30fdf114 | 29 | # TRICK: use file ID as the part before '.'\r |
0d2711a6 LG |
30 | _ID_STEP_ = 0.00000001\r |
31 | _ID_MAX_ = 0.99999999\r | |
32 | \r | |
33 | ## Constructor\r | |
34 | def __init__(self, Cursor, MetaFile, FileType, Temporary):\r | |
35 | self.MetaFile = MetaFile\r | |
36 | \r | |
37 | self._FileIndexTable = TableFile(Cursor)\r | |
38 | self._FileIndexTable.Create(False)\r | |
39 | \r | |
40 | FileId = self._FileIndexTable.GetFileId(MetaFile)\r | |
41 | if not FileId:\r | |
42 | FileId = self._FileIndexTable.InsertFile(MetaFile, FileType)\r | |
43 | \r | |
44 | if Temporary:\r | |
45 | TableName = "_%s_%s_%s" % (FileType, FileId, uuid.uuid4().hex)\r | |
46 | else:\r | |
47 | TableName = "_%s_%s" % (FileType, FileId)\r | |
48 | \r | |
49 | #Table.__init__(self, Cursor, TableName, FileId, False)\r | |
50 | Table.__init__(self, Cursor, TableName, FileId, Temporary)\r | |
51 | self.Create(not self.IsIntegrity())\r | |
52 | \r | |
53 | def IsIntegrity(self):\r | |
54 | try:\r | |
64b2609f | 55 | TimeStamp = self.MetaFile.TimeStamp\r |
0d2711a6 LG |
56 | Result = self.Cur.execute("select ID from %s where ID<0" % (self.Table)).fetchall()\r |
57 | if not Result:\r | |
64b2609f LG |
58 | # update the timestamp in database\r |
59 | self._FileIndexTable.SetFileTimeStamp(self.IdBase, TimeStamp) \r | |
0d2711a6 LG |
60 | return False\r |
61 | \r | |
0d2711a6 LG |
62 | if TimeStamp != self._FileIndexTable.GetFileTimeStamp(self.IdBase):\r |
63 | # update the timestamp in database\r | |
64 | self._FileIndexTable.SetFileTimeStamp(self.IdBase, TimeStamp)\r | |
65 | return False\r | |
66 | except Exception, Exc:\r | |
67 | EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc))\r | |
68 | return False\r | |
69 | return True\r | |
70 | \r | |
71 | ## Python class representation of table storing module data\r | |
72 | class ModuleTable(MetaFileTable):\r | |
30fdf114 LG |
73 | _ID_STEP_ = 0.00000001\r |
74 | _ID_MAX_ = 0.99999999\r | |
75 | _COLUMN_ = '''\r | |
76 | ID REAL PRIMARY KEY,\r | |
77 | Model INTEGER NOT NULL,\r | |
78 | Value1 TEXT NOT NULL,\r | |
79 | Value2 TEXT,\r | |
80 | Value3 TEXT,\r | |
81 | Scope1 TEXT,\r | |
82 | Scope2 TEXT,\r | |
83 | BelongsToItem REAL NOT NULL,\r | |
84 | StartLine INTEGER NOT NULL,\r | |
85 | StartColumn INTEGER NOT NULL,\r | |
86 | EndLine INTEGER NOT NULL,\r | |
87 | EndColumn INTEGER NOT NULL,\r | |
88 | Enabled INTEGER DEFAULT 0\r | |
89 | '''\r | |
90 | # used as table end flag, in case the changes to database is not committed to db file\r | |
91 | _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r | |
92 | \r | |
93 | ## Constructor\r | |
0d2711a6 LG |
94 | def __init__(self, Cursor, MetaFile, Temporary):\r |
95 | MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_INF, Temporary)\r | |
30fdf114 LG |
96 | \r |
97 | ## Insert a record into table Inf\r | |
98 | #\r | |
99 | # @param Model: Model of a Inf item\r | |
100 | # @param Value1: Value1 of a Inf item\r | |
101 | # @param Value2: Value2 of a Inf item\r | |
102 | # @param Value3: Value3 of a Inf item\r | |
103 | # @param Scope1: Arch of a Inf item\r | |
104 | # @param Scope2 Platform os a Inf item\r | |
105 | # @param BelongsToItem: The item belongs to which another item\r | |
106 | # @param StartLine: StartLine of a Inf item\r | |
107 | # @param StartColumn: StartColumn of a Inf item\r | |
108 | # @param EndLine: EndLine of a Inf item\r | |
109 | # @param EndColumn: EndColumn of a Inf item\r | |
110 | # @param Enabled: If this item enabled\r | |
111 | #\r | |
112 | def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r | |
113 | BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r | |
114 | (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r | |
115 | return Table.Insert(\r | |
116 | self, \r | |
117 | Model, \r | |
118 | Value1, \r | |
119 | Value2, \r | |
120 | Value3, \r | |
121 | Scope1, \r | |
122 | Scope2,\r | |
123 | BelongsToItem, \r | |
124 | StartLine, \r | |
125 | StartColumn, \r | |
126 | EndLine, \r | |
127 | EndColumn, \r | |
128 | Enabled\r | |
129 | )\r | |
130 | \r | |
131 | ## Query table\r | |
132 | #\r | |
133 | # @param Model: The Model of Record \r | |
134 | # @param Arch: The Arch attribute of Record \r | |
135 | # @param Platform The Platform attribute of Record \r | |
136 | #\r | |
137 | # @retval: A recordSet of all found records \r | |
138 | #\r | |
e8a47801 | 139 | def Query(self, Model, Arch=None, Platform=None, BelongsToItem=None):\r |
30fdf114 LG |
140 | ConditionString = "Model=%s AND Enabled>=0" % Model\r |
141 | ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r | |
142 | \r | |
143 | if Arch != None and Arch != 'COMMON':\r | |
144 | ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r | |
145 | if Platform != None and Platform != 'COMMON':\r | |
146 | ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform\r | |
e8a47801 LG |
147 | if BelongsToItem != None:\r |
148 | ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r | |
30fdf114 LG |
149 | \r |
150 | SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r | |
151 | return self.Exec(SqlCommand)\r | |
152 | \r | |
153 | ## Python class representation of table storing package data\r | |
0d2711a6 | 154 | class PackageTable(MetaFileTable):\r |
30fdf114 LG |
155 | _COLUMN_ = '''\r |
156 | ID REAL PRIMARY KEY,\r | |
157 | Model INTEGER NOT NULL,\r | |
158 | Value1 TEXT NOT NULL,\r | |
159 | Value2 TEXT,\r | |
160 | Value3 TEXT,\r | |
161 | Scope1 TEXT,\r | |
162 | Scope2 TEXT,\r | |
163 | BelongsToItem REAL NOT NULL,\r | |
164 | StartLine INTEGER NOT NULL,\r | |
165 | StartColumn INTEGER NOT NULL,\r | |
166 | EndLine INTEGER NOT NULL,\r | |
167 | EndColumn INTEGER NOT NULL,\r | |
168 | Enabled INTEGER DEFAULT 0\r | |
169 | '''\r | |
170 | # used as table end flag, in case the changes to database is not committed to db file\r | |
171 | _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r | |
172 | \r | |
173 | ## Constructor\r | |
0d2711a6 LG |
174 | def __init__(self, Cursor, MetaFile, Temporary):\r |
175 | MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DEC, Temporary)\r | |
30fdf114 LG |
176 | \r |
177 | ## Insert table\r | |
178 | #\r | |
179 | # Insert a record into table Dec\r | |
180 | #\r | |
181 | # @param Model: Model of a Dec item\r | |
182 | # @param Value1: Value1 of a Dec item\r | |
183 | # @param Value2: Value2 of a Dec item\r | |
184 | # @param Value3: Value3 of a Dec item\r | |
185 | # @param Scope1: Arch of a Dec item\r | |
186 | # @param Scope2: Module type of a Dec item\r | |
187 | # @param BelongsToItem: The item belongs to which another item\r | |
188 | # @param StartLine: StartLine of a Dec item\r | |
189 | # @param StartColumn: StartColumn of a Dec item\r | |
190 | # @param EndLine: EndLine of a Dec item\r | |
191 | # @param EndColumn: EndColumn of a Dec item\r | |
192 | # @param Enabled: If this item enabled\r | |
193 | #\r | |
194 | def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r | |
195 | BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r | |
196 | (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r | |
197 | return Table.Insert(\r | |
198 | self, \r | |
199 | Model, \r | |
200 | Value1, \r | |
201 | Value2, \r | |
202 | Value3, \r | |
203 | Scope1, \r | |
204 | Scope2,\r | |
205 | BelongsToItem, \r | |
206 | StartLine, \r | |
207 | StartColumn, \r | |
208 | EndLine, \r | |
209 | EndColumn, \r | |
210 | Enabled\r | |
211 | )\r | |
212 | \r | |
213 | ## Query table\r | |
214 | #\r | |
215 | # @param Model: The Model of Record \r | |
216 | # @param Arch: The Arch attribute of Record \r | |
217 | #\r | |
218 | # @retval: A recordSet of all found records \r | |
219 | #\r | |
220 | def Query(self, Model, Arch=None):\r | |
221 | ConditionString = "Model=%s AND Enabled>=0" % Model\r | |
c28d2e10 | 222 | ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r |
30fdf114 LG |
223 | \r |
224 | if Arch != None and Arch != 'COMMON':\r | |
225 | ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r | |
226 | \r | |
227 | SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r | |
228 | return self.Exec(SqlCommand)\r | |
229 | \r | |
82a6a960 | 230 | def GetValidExpression(self, TokenSpaceGuid, PcdCName):\r |
901fd822 | 231 | SqlCommand = "select Value1,StartLine from %s WHERE Value2='%s' and Value3='%s'" % (self.Table, TokenSpaceGuid, PcdCName)\r |
82a6a960 BF |
232 | self.Cur.execute(SqlCommand)\r |
233 | validateranges = []\r | |
234 | validlists = []\r | |
235 | expressions = []\r | |
901fd822 BF |
236 | try:\r |
237 | for row in self.Cur:\r | |
238 | comment = row[0]\r | |
239 | \r | |
240 | LineNum = row[1]\r | |
241 | comment = comment.strip("#")\r | |
242 | comment = comment.strip()\r | |
243 | oricomment = comment\r | |
244 | if comment.startswith("@ValidRange"):\r | |
245 | comment = comment.replace("@ValidRange", "", 1)\r | |
246 | validateranges.append(comment.split("|")[1].strip())\r | |
247 | if comment.startswith("@ValidList"):\r | |
248 | comment = comment.replace("@ValidList", "", 1)\r | |
249 | validlists.append(comment.split("|")[1].strip())\r | |
250 | if comment.startswith("@Expression"):\r | |
251 | comment = comment.replace("@Expression", "", 1)\r | |
252 | expressions.append(comment.split("|")[1].strip())\r | |
253 | except Exception, Exc:\r | |
254 | ValidType = ""\r | |
255 | if oricomment.startswith("@ValidRange"):\r | |
256 | ValidType = "@ValidRange"\r | |
257 | if oricomment.startswith("@ValidList"):\r | |
258 | ValidType = "@ValidList"\r | |
259 | if oricomment.startswith("@Expression"):\r | |
260 | ValidType = "@Expression"\r | |
261 | EdkLogger.error('Parser', FORMAT_INVALID, "The syntax for %s of PCD %s.%s is incorrect" % (ValidType,TokenSpaceGuid, PcdCName),\r | |
262 | ExtraData=oricomment,File=self.MetaFile, Line=LineNum)\r | |
263 | return set(), set(), set()\r | |
82a6a960 | 264 | return set(validateranges), set(validlists), set(expressions)\r |
30fdf114 | 265 | ## Python class representation of table storing platform data\r |
0d2711a6 | 266 | class PlatformTable(MetaFileTable):\r |
30fdf114 LG |
267 | _COLUMN_ = '''\r |
268 | ID REAL PRIMARY KEY,\r | |
269 | Model INTEGER NOT NULL,\r | |
270 | Value1 TEXT NOT NULL,\r | |
271 | Value2 TEXT,\r | |
272 | Value3 TEXT,\r | |
273 | Scope1 TEXT,\r | |
274 | Scope2 TEXT,\r | |
8518bf0b | 275 | Scope3 TEXT,\r |
30fdf114 LG |
276 | BelongsToItem REAL NOT NULL,\r |
277 | FromItem REAL NOT NULL,\r | |
278 | StartLine INTEGER NOT NULL,\r | |
279 | StartColumn INTEGER NOT NULL,\r | |
280 | EndLine INTEGER NOT NULL,\r | |
281 | EndColumn INTEGER NOT NULL,\r | |
282 | Enabled INTEGER DEFAULT 0\r | |
283 | '''\r | |
284 | # used as table end flag, in case the changes to database is not committed to db file\r | |
8518bf0b | 285 | _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====','====', -1, -1, -1, -1, -1, -1, -1"\r |
30fdf114 LG |
286 | \r |
287 | ## Constructor\r | |
0d2711a6 LG |
288 | def __init__(self, Cursor, MetaFile, Temporary):\r |
289 | MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary)\r | |
30fdf114 LG |
290 | \r |
291 | ## Insert table\r | |
292 | #\r | |
293 | # Insert a record into table Dsc\r | |
294 | #\r | |
295 | # @param Model: Model of a Dsc item\r | |
296 | # @param Value1: Value1 of a Dsc item\r | |
297 | # @param Value2: Value2 of a Dsc item\r | |
298 | # @param Value3: Value3 of a Dsc item\r | |
299 | # @param Scope1: Arch of a Dsc item\r | |
300 | # @param Scope2: Module type of a Dsc item\r | |
301 | # @param BelongsToItem: The item belongs to which another item\r | |
302 | # @param FromItem: The item belongs to which dsc file\r | |
303 | # @param StartLine: StartLine of a Dsc item\r | |
304 | # @param StartColumn: StartColumn of a Dsc item\r | |
305 | # @param EndLine: EndLine of a Dsc item\r | |
306 | # @param EndColumn: EndColumn of a Dsc item\r | |
307 | # @param Enabled: If this item enabled\r | |
308 | #\r | |
8518bf0b | 309 | def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', Scope3=TAB_DEFAULT_STORES_DEFAULT,BelongsToItem=-1,\r |
30fdf114 | 310 | FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):\r |
8518bf0b | 311 | (Value1, Value2, Value3, Scope1, Scope2,Scope3) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2,Scope3))\r |
30fdf114 LG |
312 | return Table.Insert(\r |
313 | self, \r | |
314 | Model, \r | |
315 | Value1, \r | |
316 | Value2, \r | |
317 | Value3, \r | |
318 | Scope1, \r | |
319 | Scope2,\r | |
8518bf0b | 320 | Scope3,\r |
30fdf114 LG |
321 | BelongsToItem, \r |
322 | FromItem,\r | |
323 | StartLine, \r | |
324 | StartColumn, \r | |
325 | EndLine, \r | |
326 | EndColumn, \r | |
327 | Enabled\r | |
328 | )\r | |
329 | \r | |
330 | ## Query table\r | |
331 | #\r | |
332 | # @param Model: The Model of Record \r | |
333 | # @param Scope1: Arch of a Dsc item\r | |
334 | # @param Scope2: Module type of a Dsc item\r | |
335 | # @param BelongsToItem: The item belongs to which another item\r | |
336 | # @param FromItem: The item belongs to which dsc file\r | |
337 | #\r | |
338 | # @retval: A recordSet of all found records \r | |
339 | #\r | |
340 | def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):\r | |
0d2711a6 | 341 | ConditionString = "Model=%s AND Enabled>0" % Model\r |
8518bf0b | 342 | ValueString = "Value1,Value2,Value3,Scope1,Scope2,Scope3,ID,StartLine"\r |
30fdf114 LG |
343 | \r |
344 | if Scope1 != None and Scope1 != 'COMMON':\r | |
345 | ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1\r | |
346 | if Scope2 != None and Scope2 != 'COMMON':\r | |
35dc964b YZ |
347 | # Cover the case that CodeBase is 'COMMON' for BuildOptions section\r |
348 | if '.' in Scope2:\r | |
349 | Index = Scope2.index('.')\r | |
350 | NewScope = 'COMMON'+ Scope2[Index:]\r | |
351 | ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT' OR Scope2='%s')" % (Scope2, NewScope)\r | |
352 | else:\r | |
353 | ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2\r | |
30fdf114 LG |
354 | \r |
355 | if BelongsToItem != None:\r | |
356 | ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r | |
357 | else:\r | |
358 | ConditionString += " AND BelongsToItem<0"\r | |
359 | \r | |
360 | if FromItem != None:\r | |
361 | ConditionString += " AND FromItem=%s" % FromItem\r | |
362 | \r | |
363 | SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r | |
364 | return self.Exec(SqlCommand)\r | |
365 | \r | |
0d2711a6 LG |
366 | ## Factory class to produce different storage for different type of meta-file\r |
367 | class MetaFileStorage(object):\r | |
368 | _FILE_TABLE_ = {\r | |
369 | MODEL_FILE_INF : ModuleTable,\r | |
370 | MODEL_FILE_DEC : PackageTable,\r | |
371 | MODEL_FILE_DSC : PlatformTable,\r | |
372 | MODEL_FILE_OTHERS : MetaFileTable,\r | |
373 | }\r | |
374 | \r | |
375 | _FILE_TYPE_ = {\r | |
376 | ".inf" : MODEL_FILE_INF,\r | |
377 | ".dec" : MODEL_FILE_DEC,\r | |
378 | ".dsc" : MODEL_FILE_DSC,\r | |
379 | }\r | |
380 | \r | |
381 | ## Constructor\r | |
382 | def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):\r | |
383 | # no type given, try to find one\r | |
384 | if not FileType:\r | |
385 | if MetaFile.Type in self._FILE_TYPE_:\r | |
386 | FileType = Class._FILE_TYPE_[MetaFile.Type]\r | |
387 | else:\r | |
388 | FileType = MODEL_FILE_OTHERS\r | |
389 | \r | |
390 | # don't pass the type around if it's well known\r | |
391 | if FileType == MODEL_FILE_OTHERS:\r | |
392 | Args = (Cursor, MetaFile, FileType, Temporary)\r | |
393 | else:\r | |
394 | Args = (Cursor, MetaFile, Temporary)\r | |
395 | \r | |
396 | # create the storage object and return it to caller\r | |
397 | return Class._FILE_TABLE_[FileType](*Args)\r | |
398 | \r |