]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Workspace/MetaFileTable.py
MdeModulePkg: Fix build warning on Xhci driver with XCode 32 tool chain.
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileTable.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase a meta file table\r
3#\r
40d841f6
LG
4# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r
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
17import uuid\r
18\r
30fdf114 19import Common.EdkLogger as EdkLogger\r
0d2711a6
LG
20\r
21from MetaDataTable import Table, TableFile\r
30fdf114 22from MetaDataTable import ConvertToSqlString\r
0d2711a6
LG
23from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \\r
24 MODEL_FILE_OTHERS\r
30fdf114 25\r
0d2711a6 26class MetaFileTable(Table):\r
30fdf114 27 # TRICK: use file ID as the part before '.'\r
0d2711a6
LG
28 _ID_STEP_ = 0.00000001\r
29 _ID_MAX_ = 0.99999999\r
30\r
31 ## Constructor\r
32 def __init__(self, Cursor, MetaFile, FileType, Temporary):\r
33 self.MetaFile = MetaFile\r
34\r
35 self._FileIndexTable = TableFile(Cursor)\r
36 self._FileIndexTable.Create(False)\r
37\r
38 FileId = self._FileIndexTable.GetFileId(MetaFile)\r
39 if not FileId:\r
40 FileId = self._FileIndexTable.InsertFile(MetaFile, FileType)\r
41\r
42 if Temporary:\r
43 TableName = "_%s_%s_%s" % (FileType, FileId, uuid.uuid4().hex)\r
44 else:\r
45 TableName = "_%s_%s" % (FileType, FileId)\r
46\r
47 #Table.__init__(self, Cursor, TableName, FileId, False)\r
48 Table.__init__(self, Cursor, TableName, FileId, Temporary)\r
49 self.Create(not self.IsIntegrity())\r
50\r
51 def IsIntegrity(self):\r
52 try:\r
53 Result = self.Cur.execute("select ID from %s where ID<0" % (self.Table)).fetchall()\r
54 if not Result:\r
55 return False\r
56\r
57 TimeStamp = self.MetaFile.TimeStamp\r
58 if TimeStamp != self._FileIndexTable.GetFileTimeStamp(self.IdBase):\r
59 # update the timestamp in database\r
60 self._FileIndexTable.SetFileTimeStamp(self.IdBase, TimeStamp)\r
61 return False\r
62 except Exception, Exc:\r
63 EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc))\r
64 return False\r
65 return True\r
66\r
67## Python class representation of table storing module data\r
68class ModuleTable(MetaFileTable):\r
30fdf114
LG
69 _ID_STEP_ = 0.00000001\r
70 _ID_MAX_ = 0.99999999\r
71 _COLUMN_ = '''\r
72 ID REAL PRIMARY KEY,\r
73 Model INTEGER NOT NULL,\r
74 Value1 TEXT NOT NULL,\r
75 Value2 TEXT,\r
76 Value3 TEXT,\r
77 Scope1 TEXT,\r
78 Scope2 TEXT,\r
79 BelongsToItem REAL NOT NULL,\r
80 StartLine INTEGER NOT NULL,\r
81 StartColumn INTEGER NOT NULL,\r
82 EndLine INTEGER NOT NULL,\r
83 EndColumn INTEGER NOT NULL,\r
84 Enabled INTEGER DEFAULT 0\r
85 '''\r
86 # used as table end flag, in case the changes to database is not committed to db file\r
87 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r
88\r
89 ## Constructor\r
0d2711a6
LG
90 def __init__(self, Cursor, MetaFile, Temporary):\r
91 MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_INF, Temporary)\r
30fdf114
LG
92\r
93 ## Insert a record into table Inf\r
94 #\r
95 # @param Model: Model of a Inf item\r
96 # @param Value1: Value1 of a Inf item\r
97 # @param Value2: Value2 of a Inf item\r
98 # @param Value3: Value3 of a Inf item\r
99 # @param Scope1: Arch of a Inf item\r
100 # @param Scope2 Platform os a Inf item\r
101 # @param BelongsToItem: The item belongs to which another item\r
102 # @param StartLine: StartLine of a Inf item\r
103 # @param StartColumn: StartColumn of a Inf item\r
104 # @param EndLine: EndLine of a Inf item\r
105 # @param EndColumn: EndColumn of a Inf item\r
106 # @param Enabled: If this item enabled\r
107 #\r
108 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
109 BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
110 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
111 return Table.Insert(\r
112 self, \r
113 Model, \r
114 Value1, \r
115 Value2, \r
116 Value3, \r
117 Scope1, \r
118 Scope2,\r
119 BelongsToItem, \r
120 StartLine, \r
121 StartColumn, \r
122 EndLine, \r
123 EndColumn, \r
124 Enabled\r
125 )\r
126\r
127 ## Query table\r
128 #\r
129 # @param Model: The Model of Record \r
130 # @param Arch: The Arch attribute of Record \r
131 # @param Platform The Platform attribute of Record \r
132 #\r
133 # @retval: A recordSet of all found records \r
134 #\r
135 def Query(self, Model, Arch=None, Platform=None):\r
136 ConditionString = "Model=%s AND Enabled>=0" % Model\r
137 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
138\r
139 if Arch != None and Arch != 'COMMON':\r
140 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
141 if Platform != None and Platform != 'COMMON':\r
142 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform\r
143\r
144 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
145 return self.Exec(SqlCommand)\r
146\r
147## Python class representation of table storing package data\r
0d2711a6 148class PackageTable(MetaFileTable):\r
30fdf114
LG
149 _COLUMN_ = '''\r
150 ID REAL PRIMARY KEY,\r
151 Model INTEGER NOT NULL,\r
152 Value1 TEXT NOT NULL,\r
153 Value2 TEXT,\r
154 Value3 TEXT,\r
155 Scope1 TEXT,\r
156 Scope2 TEXT,\r
157 BelongsToItem REAL NOT NULL,\r
158 StartLine INTEGER NOT NULL,\r
159 StartColumn INTEGER NOT NULL,\r
160 EndLine INTEGER NOT NULL,\r
161 EndColumn INTEGER NOT NULL,\r
162 Enabled INTEGER DEFAULT 0\r
163 '''\r
164 # used as table end flag, in case the changes to database is not committed to db file\r
165 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r
166\r
167 ## Constructor\r
0d2711a6
LG
168 def __init__(self, Cursor, MetaFile, Temporary):\r
169 MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DEC, Temporary)\r
30fdf114
LG
170\r
171 ## Insert table\r
172 #\r
173 # Insert a record into table Dec\r
174 #\r
175 # @param Model: Model of a Dec item\r
176 # @param Value1: Value1 of a Dec item\r
177 # @param Value2: Value2 of a Dec item\r
178 # @param Value3: Value3 of a Dec item\r
179 # @param Scope1: Arch of a Dec item\r
180 # @param Scope2: Module type of a Dec item\r
181 # @param BelongsToItem: The item belongs to which another item\r
182 # @param StartLine: StartLine of a Dec item\r
183 # @param StartColumn: StartColumn of a Dec item\r
184 # @param EndLine: EndLine of a Dec item\r
185 # @param EndColumn: EndColumn of a Dec item\r
186 # @param Enabled: If this item enabled\r
187 #\r
188 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
189 BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
190 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
191 return Table.Insert(\r
192 self, \r
193 Model, \r
194 Value1, \r
195 Value2, \r
196 Value3, \r
197 Scope1, \r
198 Scope2,\r
199 BelongsToItem, \r
200 StartLine, \r
201 StartColumn, \r
202 EndLine, \r
203 EndColumn, \r
204 Enabled\r
205 )\r
206\r
207 ## Query table\r
208 #\r
209 # @param Model: The Model of Record \r
210 # @param Arch: The Arch attribute of Record \r
211 #\r
212 # @retval: A recordSet of all found records \r
213 #\r
214 def Query(self, Model, Arch=None):\r
215 ConditionString = "Model=%s AND Enabled>=0" % Model\r
216 ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"\r
217\r
218 if Arch != None and Arch != 'COMMON':\r
219 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
220\r
221 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
222 return self.Exec(SqlCommand)\r
223\r
224## Python class representation of table storing platform data\r
0d2711a6 225class PlatformTable(MetaFileTable):\r
30fdf114
LG
226 _COLUMN_ = '''\r
227 ID REAL PRIMARY KEY,\r
228 Model INTEGER NOT NULL,\r
229 Value1 TEXT NOT NULL,\r
230 Value2 TEXT,\r
231 Value3 TEXT,\r
232 Scope1 TEXT,\r
233 Scope2 TEXT,\r
234 BelongsToItem REAL NOT NULL,\r
235 FromItem REAL NOT NULL,\r
236 StartLine INTEGER NOT NULL,\r
237 StartColumn INTEGER NOT NULL,\r
238 EndLine INTEGER NOT NULL,\r
239 EndColumn INTEGER NOT NULL,\r
240 Enabled INTEGER DEFAULT 0\r
241 '''\r
242 # used as table end flag, in case the changes to database is not committed to db file\r
243 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
244\r
245 ## Constructor\r
0d2711a6
LG
246 def __init__(self, Cursor, MetaFile, Temporary):\r
247 MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary)\r
30fdf114
LG
248\r
249 ## Insert table\r
250 #\r
251 # Insert a record into table Dsc\r
252 #\r
253 # @param Model: Model of a Dsc item\r
254 # @param Value1: Value1 of a Dsc item\r
255 # @param Value2: Value2 of a Dsc item\r
256 # @param Value3: Value3 of a Dsc item\r
257 # @param Scope1: Arch of a Dsc item\r
258 # @param Scope2: Module type of a Dsc item\r
259 # @param BelongsToItem: The item belongs to which another item\r
260 # @param FromItem: The item belongs to which dsc file\r
261 # @param StartLine: StartLine of a Dsc item\r
262 # @param StartColumn: StartColumn of a Dsc item\r
263 # @param EndLine: EndLine of a Dsc item\r
264 # @param EndColumn: EndColumn of a Dsc item\r
265 # @param Enabled: If this item enabled\r
266 #\r
267 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, \r
268 FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):\r
269 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
270 return Table.Insert(\r
271 self, \r
272 Model, \r
273 Value1, \r
274 Value2, \r
275 Value3, \r
276 Scope1, \r
277 Scope2,\r
278 BelongsToItem, \r
279 FromItem,\r
280 StartLine, \r
281 StartColumn, \r
282 EndLine, \r
283 EndColumn, \r
284 Enabled\r
285 )\r
286\r
287 ## Query table\r
288 #\r
289 # @param Model: The Model of Record \r
290 # @param Scope1: Arch of a Dsc item\r
291 # @param Scope2: Module type of a Dsc item\r
292 # @param BelongsToItem: The item belongs to which another item\r
293 # @param FromItem: The item belongs to which dsc file\r
294 #\r
295 # @retval: A recordSet of all found records \r
296 #\r
297 def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):\r
0d2711a6 298 ConditionString = "Model=%s AND Enabled>0" % Model\r
30fdf114
LG
299 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
300\r
301 if Scope1 != None and Scope1 != 'COMMON':\r
302 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1\r
303 if Scope2 != None and Scope2 != 'COMMON':\r
304 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2\r
305\r
306 if BelongsToItem != None:\r
307 ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r
308 else:\r
309 ConditionString += " AND BelongsToItem<0"\r
310\r
311 if FromItem != None:\r
312 ConditionString += " AND FromItem=%s" % FromItem\r
313\r
314 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
315 return self.Exec(SqlCommand)\r
316\r
0d2711a6
LG
317## Factory class to produce different storage for different type of meta-file\r
318class MetaFileStorage(object):\r
319 _FILE_TABLE_ = {\r
320 MODEL_FILE_INF : ModuleTable,\r
321 MODEL_FILE_DEC : PackageTable,\r
322 MODEL_FILE_DSC : PlatformTable,\r
323 MODEL_FILE_OTHERS : MetaFileTable,\r
324 }\r
325\r
326 _FILE_TYPE_ = {\r
327 ".inf" : MODEL_FILE_INF,\r
328 ".dec" : MODEL_FILE_DEC,\r
329 ".dsc" : MODEL_FILE_DSC,\r
330 }\r
331\r
332 ## Constructor\r
333 def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):\r
334 # no type given, try to find one\r
335 if not FileType:\r
336 if MetaFile.Type in self._FILE_TYPE_:\r
337 FileType = Class._FILE_TYPE_[MetaFile.Type]\r
338 else:\r
339 FileType = MODEL_FILE_OTHERS\r
340\r
341 # don't pass the type around if it's well known\r
342 if FileType == MODEL_FILE_OTHERS:\r
343 Args = (Cursor, MetaFile, FileType, Temporary)\r
344 else:\r
345 Args = (Cursor, MetaFile, Temporary)\r
346\r
347 # create the storage object and return it to caller\r
348 return Class._FILE_TABLE_[FileType](*Args)\r
349\r