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