ea77d915a2080e03c1672833c54df52503910298
[people/mcb30/basetools.git] / Source / Python / Workspace / WorkspaceDatabase.py
1 ## @file\r
2 # This file is used to create a database used by build tool\r
3 #\r
4 # Copyright (c) 2008, Intel Corporation\r
5 # All rights reserved. This program and the accompanying materials\r
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
17 import sqlite3\r
18 import os\r
19 import os.path\r
20 \r
21 import Common.EdkLogger as EdkLogger\r
22 from CommonDataClass.DataClass import *\r
23 from CommonDataClass.ModuleClass import *\r
24 from Common.String import *\r
25 from Common.DataType import *\r
26 from Common.Misc import tdict\r
27 from Common.Misc import sdict\r
28 \r
29 from MetaDataTable import *\r
30 from MetaFileTable import *\r
31 from MetaFileParser import *\r
32 from BuildClassObject import *\r
33 \r
34 ## Check if gvien file exists or not\r
35\r
36 #   @param      File    File name or path to be checked\r
37 #   @param      Dir     The directory the file is relative to\r
38\r
39 #   @retval     True    if file exists\r
40 #   @retval     False   if file doesn't exists\r
41\r
42 def ValidFile(File, Dir='.'):\r
43     Wd = os.getcwd()\r
44     os.chdir(Dir)\r
45     if not os.path.exists(File):\r
46         os.chdir(Wd)\r
47         return False\r
48     os.chdir(Wd)\r
49     return True\r
50 \r
51 ## Get GUID value from given packages\r
52\r
53 #   @param      CName           The CName of the GUID\r
54 #   @param      PackageList     List of packages looking-up in\r
55\r
56 #   @retval     GuidValue   if the CName is found in any given package\r
57 #   @retval     None        if the CName is not found in all given packages\r
58\r
59 def GuidValue(CName, PackageList):\r
60     for P in PackageList:\r
61         if CName in P.Guids:\r
62             return P.Guids[CName]\r
63         if CName in P.Protocols:\r
64             return P.Protocols[CName]\r
65         if CName in P.Ppis:\r
66             return P.Ppis[CName]\r
67     return None\r
68 \r
69 ## Platform build information from DSC file\r
70 #\r
71 #  This class is used to retrieve information stored in database and convert them\r
72 # into PlatformBuildClassObject form for easier use for AutoGen.\r
73 #\r
74 class DscBuildData(PlatformBuildClassObject):\r
75     # dict used to convert PCD type in database to string used by build tool\r
76     _PCD_TYPE_STRING_ = {\r
77         MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
78         MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
79         MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
80         MODEL_PCD_DYNAMIC               :   "Dynamic",\r
81         MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
82         MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
83         MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
84         MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
85         MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
86         MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
87         MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
88     }\r
89 \r
90     # used to compose dummy library class name for those forced library instances\r
91     _NullLibraryNumber = 0\r
92 \r
93     def __init__(self, FilePath, Table, Db, Arch='COMMON', Macros={}):\r
94         self.DescFilePath = FilePath\r
95         self._Table = Table\r
96         self._Db = Db\r
97         self._Arch = Arch\r
98         self._Macros = Macros\r
99         self._Clear()\r
100 \r
101     def __repr__(self):\r
102         S = '[Platform.%s]\n' % self.Arch\r
103         S += "\tName = %s\n" % self.PlatformName\r
104         S += "\tGuid = %s\n" % self.Guid\r
105         S += "\tVer = %s\n" % self.Version\r
106         S += "\n"\r
107         S += "\tSpecification = %s\n" % self.DscSpecification\r
108         S += "\tOutputDirectory = %s\n" % self.OutputDirectory \r
109         S += "\tSupArchList = %s\n" % self.SupArchList     \r
110         S += "\tBuildTargets = %s\n" % self.BuildTargets    \r
111         S += "\tSkuName = %s\n" % self.SkuName           \r
112         S += "\tFlashDefinition = %s\n" % self.FlashDefinition \r
113         S += "\tBuildNumber = %s\n" % self.BuildNumber     \r
114         S += "\tMakefileName = %s\n" % self.MakefileName    \r
115         S += "\tBsBaseAddress = %s\n" % self.BsBaseAddress   \r
116         S += "\tRtBaseAddress = %s\n" % self.RtBaseAddress   \r
117 \r
118         S += '  <SkuId>\n'\r
119         for SkuName in self.SkuIds:\r
120             S += "\t%s = %s\n" % (SkuName, self.SkuIds[SkuName])\r
121 \r
122         #S += '  <LibraryClass>\n'\r
123         #ModuleTypeList = set()\r
124         #LibraryClassList = set()\r
125         #for LibraryClass,ModuleType in self.LibraryClasses:\r
126         #    LibraryClassList.add(LibraryClass)\r
127         #    ModuleTypeList.add(ModuleType)\r
128         #LibraryClassList = list(LibraryClassList)\r
129         #ModuleTypeList = list(ModuleTypeList)\r
130         #LibraryClassList.sort()\r
131         #ModuleTypeList.sort()\r
132         #for LibraryClass in LibraryClassList:\r
133         #    for ModuleType in ModuleTypeList:\r
134         #        if not (LibraryClass,ModuleType) in self.LibraryClasses:\r
135         #            continue \r
136         #        S += "\t%32s, %-24s = %s\n" % (LibraryClass, ModuleType, self.LibraryClasses[LibraryClass,ModuleType])\r
137         \r
138         S += '  <PCD>\n'\r
139         for Name, Guid in self.Pcds:\r
140             S += "\t%s.%s\n\t\t%s\n" % (Guid, Name, str(self.Pcds[Name, Guid]))\r
141         \r
142         S += '  <BuildOption>\n'\r
143         for ToolChainFamily,ToolChain in self.BuildOptions:\r
144             S += "\t%s:%s = %s\n" % (ToolChainFamily, ToolChain, self.BuildOptions[ToolChainFamily, ToolChain])\r
145 \r
146         S += '  <Module>\n'\r
147         S += "\t" + "\n\t".join([str(M) for M in self.Modules]) + '\n'\r
148         return S\r
149 \r
150     def _Clear(self):\r
151         self._PlatformName      = None\r
152         self._Guid              = None\r
153         self._Version           = None\r
154         self._DscSpecification  = None\r
155         self._OutputDirectory   = None\r
156         self._SupArchList       = None\r
157         self._BuildTargets      = None\r
158         self._SkuName           = None\r
159         self._FlashDefinition   = None\r
160         self._BuildNumber       = None\r
161         self._MakefileName      = None\r
162         self._BsBaseAddress     = None\r
163         self._RtBaseAddress     = None\r
164         self._SkuIds            = None\r
165         self._Modules           = None\r
166         self._LibraryInstances  = None\r
167         self._LibraryClasses    = None\r
168         self._Libraries         = None\r
169         self._Pcds              = None\r
170         self._BuildOptions      = None\r
171 \r
172     def _GetArch(self):\r
173         return self._Arch\r
174 \r
175     def _SetArch(self, Value):\r
176         if self._Arch == Value:\r
177             return\r
178         self._Arch = Value\r
179         self._Clear()\r
180 \r
181     def _GetPlatformName(self):\r
182         if self._PlatformName == None:\r
183             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_PLATFORM_NAME, self.Arch)\r
184             if len(RecordList) == 0 or RecordList[0][0] == None:\r
185                 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.DescFilePath)\r
186             self._PlatformName = RecordList[0][0]\r
187         return self._PlatformName\r
188 \r
189     def _GetFileGuid(self):\r
190         if self._Guid == None:\r
191             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_PLATFORM_GUID, self.Arch)\r
192             if len(RecordList) == 0 or RecordList[0][0] == None:\r
193                 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No FILE_GUID", File=self.DescFilePath)\r
194             self._Guid = RecordList[0][0]\r
195         return self._Guid\r
196 \r
197     def _GetVersion(self):\r
198         if self._Version == None:\r
199             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_PLATFORM_VERSION, self.Arch)\r
200             if len(RecordList) == 0 or RecordList[0][0] == None:\r
201                 self._Version = 0.0\r
202             else:\r
203                 self._Version = RecordList[0][0]\r
204         return self._Version\r
205 \r
206     def _GetDscSpec(self):\r
207         if self._DscSpecification == None:\r
208             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_DSC_SPECIFICATION, self.Arch)\r
209             if len(RecordList) == 0 or RecordList[0][0] == None:\r
210                 self._DscSpecification = ''\r
211             else:\r
212                 self._DscSpecification = RecordList[0][0]\r
213         return self._DscSpecification\r
214 \r
215     def _GetOutpuDir(self):\r
216         if self._OutputDirectory == None:\r
217             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_OUTPUT_DIRECTORY, self.Arch)\r
218             if len(RecordList) == 0 or RecordList[0][0] == None:\r
219                 self._OutputDirectory = os.path.join("Build", self.PlatformName)\r
220             else:\r
221                 File = NormPath(RecordList[0][0], self._Macros)\r
222                 LineNo = RecordList[0][-1]\r
223                 self._OutputDirectory = File\r
224         return self._OutputDirectory\r
225 \r
226     def _GetSupArch(self):\r
227         if self._SupArchList == None:\r
228             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES, self.Arch)\r
229             if len(RecordList) == 0 or RecordList[0][0] == None:\r
230                 self._SupArchList = ARCH_LIST\r
231             else:\r
232                 self._SupArchList = GetSplitValueList(RecordList[0][0], TAB_VALUE_SPLIT)\r
233         return self._SupArchList\r
234 \r
235     def _GetBuildTarget(self):\r
236         if self._BuildTargets == None:\r
237             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_BUILD_TARGETS, self.Arch)\r
238             if len(RecordList) == 0 or RecordList[0][0] == None:\r
239                 self._BuildTargets = ['DEBUG', 'RELEASE']\r
240             else:\r
241                 self._BuildTargets = GetSplitValueList(RecordList[0][0])\r
242         return self._BuildTargets\r
243 \r
244     def _GetSkuName(self):\r
245         if self._SkuName == None:\r
246             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_SKUID_IDENTIFIER, self.Arch)\r
247             if len(RecordList) > 0:\r
248                 self._SkuName = RecordList[0][0]\r
249                 if self._SkuName not in self.SkuIds:\r
250                     self._SkuName = 'DEFAULT'\r
251             else:\r
252                 self._SkuName = 'DEFAULT'\r
253         return self._SkuName\r
254 \r
255     def _GetFdfFile(self):\r
256         if self._FlashDefinition == None:\r
257             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_FLASH_DEFINITION, self.Arch)\r
258             if len(RecordList) > 0:\r
259                 self._FlashDefinition = NormPath(RecordList[0][0])\r
260             else:\r
261                 self._FlashDefinition = ''\r
262         return self._FlashDefinition\r
263 \r
264     def _GetBuildNumber(self):\r
265         if self._BuildNumber == None:\r
266             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_BUILD_NUMBER, self.Arch)\r
267             if len(RecordList) > 0 and RecordList[0][0] != None:\r
268                 self._BuildNumber = RecordList[0][0]\r
269             else:\r
270                 self._BuildNumber = ''\r
271         return self._BuildNumber\r
272 \r
273     def _GetMakefileName(self):\r
274         if self._MakefileName == None:\r
275             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_MAKEFILE_NAME, self.Arch)\r
276             if len(RecordList) > 0 and RecordList[0][0] != None:\r
277                 self._MakefileName = RecordList[0][0]\r
278             else:\r
279                 self._MakefileName = ''\r
280         return self._MakefileName\r
281 \r
282     def _GetBsBaseAddress(self):\r
283         if self._BsBaseAddress == None:\r
284             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_BS_BASE_ADDRESS, self.Arch)\r
285             if len(RecordList) > 0 and RecordList[0][0] != None:\r
286                 self._BsBaseAddress = RecordList[0][0]\r
287             else:\r
288                 self._BsBaseAddress = ''\r
289         return self._BsBaseAddress\r
290 \r
291     def _GetRtBaseAddress(self):\r
292         if self._RtBaseAddress == None:\r
293             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DSC_DEFINES_RT_BASE_ADDRESS, self.Arch)\r
294             if len(RecordList) > 0 and RecordList[0][0] != None:\r
295                 self._RtBaseAddress = RecordList[0][0]\r
296             else:\r
297                 self._RtBaseAddress = ''\r
298         return self._RtBaseAddress\r
299 \r
300     def _GetSkuIds(self):\r
301         if self._SkuIds == None:\r
302             self._SkuIds = {}\r
303             RecordList = self._Table.Query(MODEL_EFI_SKU_ID)\r
304             for Record in RecordList:\r
305                 if Record[0] in [None, '']:\r
306                     EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',\r
307                                     File=self.DescFilePath, Line=Record[-1])\r
308                 if Record[1] in [None, '']:\r
309                     EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',\r
310                                     File=self.DescFilePath, Line=Record[-1])\r
311                 self._SkuIds[Record[1]] = Record[0]\r
312             if 'DEFAULT' not in self._SkuIds:\r
313                 self._SkuIds['DEFAULT'] = 0\r
314         return self._SkuIds\r
315 \r
316     def _GetModules(self):\r
317         if self._Modules == None:\r
318             self._Modules = []\r
319             RecordList = self._Table.Query(MODEL_META_DATA_COMPONENT, Scope1=self.Arch)\r
320             for Record in RecordList:\r
321                 ModuleFile = NormPath(Record[0], self._Macros)\r
322                 ModuleId = Record[5]\r
323                 LineNo = Record[6]\r
324                 if not ValidFile(ModuleFile):\r
325                     EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath, \r
326                                     ExtraData=ModuleFile, Line=LineNo)\r
327                 if ModuleFile in self._Modules:\r
328                     continue\r
329                 Module = self._Db.BuildObject[ModuleFile, MODEL_FILE_INF, self._Arch]\r
330                 # only merge library classes and PCD for non-library module\r
331                 if Module.LibraryClass == None or Module.LibraryClass == []:\r
332                     if Module.AutoGenVersion < 0x00010005:\r
333                         self._ResolveLibraryReference(Module)\r
334                     else:\r
335                         self._MergeModuleInfo(Module, ModuleId)\r
336                 self._UpdateModulePcd(Module, ModuleId)\r
337                 self._MergeModuleBuildOption(Module, ModuleId)\r
338                 self._Modules.append(Module)\r
339         return self._Modules\r
340 \r
341     def _MergeModuleInfo(self, Module, ModuleId):\r
342         ModuleType = Module.ModuleType\r
343         # merge library class/instance information\r
344         for LibraryClass in Module.LibraryClasses:\r
345             if self.LibraryClasses[LibraryClass, ModuleType] == None: continue\r
346             Module.LibraryClasses[LibraryClass] = self.LibraryClasses[LibraryClass, ModuleType]\r
347         RecordList = self._Table.Query(MODEL_EFI_LIBRARY_CLASS, Scope1=self.Arch, BelongsToItem=ModuleId)\r
348         for Record in RecordList:\r
349             LibraryClass = Record[0]\r
350             LibraryPath = NormPath(Record[1], self._Macros)\r
351             LineNo = Record[-1]\r
352             if not ValidFile(LibraryPath):\r
353                 EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=LibraryPath,\r
354                                 File=self.DescFilePath, Line=LineNo)\r
355             if LibraryClass == '' or LibraryClass == 'NULL':\r
356                 LibraryClass = 'NULL%d' % (self._NullLibraryNumber + 1)\r
357                 LibraryInstance = self._Db.BuildObject[LibraryPath, MODEL_FILE_INF, self._Arch]\r
358                 LibraryInstance.LibraryClass.append(LibraryClassObject(LibraryClass, [ModuleType]))\r
359             Module.LibraryClasses[LibraryClass] = LibraryPath\r
360 \r
361         # R9 module\r
362         LibraryConsumerList = [Module]\r
363         Constructor         = []\r
364         ConsumedByList      = sdict()\r
365         LibraryInstance     = sdict()\r
366 \r
367         EdkLogger.verbose("")\r
368         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
369         while len(LibraryConsumerList) > 0:\r
370             M = LibraryConsumerList.pop()\r
371             for LibraryClassName in M.LibraryClasses:\r
372                 LibraryPath = M.LibraryClasses[LibraryClassName]\r
373                 if LibraryPath == None or LibraryPath == "":\r
374                     LibraryPath = self.LibraryClasses[LibraryClassName, ModuleType]\r
375                     if LibraryPath == None and LibraryClassName not in LibraryInstance:\r
376                         LibraryInstance[LibraryClassName] = None\r
377                         continue\r
378                 if LibraryClassName not in LibraryInstance:\r
379                     LibraryModule = self._Db.BuildObject[LibraryPath, MODEL_FILE_INF, self._Arch]\r
380                     LibraryInstance[LibraryClassName] = LibraryModule\r
381                     LibraryConsumerList.append(LibraryModule)\r
382                     EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
383                 else:\r
384                     LibraryModule = LibraryInstance[LibraryClassName]\r
385 \r
386                 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
387                     Constructor.append(LibraryModule)\r
388 \r
389                 if LibraryModule not in ConsumedByList:\r
390                     ConsumedByList[LibraryModule] = []\r
391                 if M != Module:\r
392                     if M in ConsumedByList[LibraryModule]:\r
393                         continue\r
394                     ConsumedByList[LibraryModule].append(M)\r
395         #\r
396         # Initialize the sorted output list to the empty set\r
397         #\r
398         SortedLibraryList = []\r
399         #\r
400         # Q <- Set of all nodes with no incoming edges\r
401         #\r
402         LibraryList = [] #LibraryInstance.values()\r
403         Q = []\r
404         for LibraryClassName in LibraryInstance:\r
405             M = LibraryInstance[LibraryClassName]\r
406             if M == None:\r
407                 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
408                                 "\tLibrary instance of library class [%s] is not found" % LibraryClassName,\r
409                                 File=self.DescFilePath, ExtraData="consumed by [%s] [%s]" % (str(Module), self._Arch))\r
410             LibraryList.append(M)\r
411             #\r
412             # check if there're duplicate library classes\r
413             #\r
414             for Lc in M.LibraryClass:\r
415                 if Lc.SupModList != None and ModuleType not in Lc.SupModList:\r
416                     EdkLogger.error("build", OPTION_MISSING,\r
417                                     "Module type [%s] is not supported by library instance [%s]" % (ModuleType, str(M)),\r
418                                     File=self.DescFilePath, ExtraData="\tconsumed by [%s]" % str(Module))\r
419 \r
420                 if Lc.LibraryClass in LibraryInstance and str(M) != str(LibraryInstance[Lc.LibraryClass]):\r
421                     EdkLogger.error("build", OPTION_CONFLICT,\r
422                                     "More than one library instance found for library class [%s] in module [%s]" % (Lc.LibraryClass, str(Module)),\r
423                                     ExtraData="\t%s\n\t%s" % (LibraryInstance[Lc.LibraryClass], str(M))\r
424                                     )\r
425             if ConsumedByList[M] == []:\r
426                 Q.insert(0, M)\r
427 \r
428         #\r
429         # start the  DAG algorithm\r
430         #\r
431         while True:\r
432             EdgeRemoved = True\r
433             while Q == [] and EdgeRemoved:\r
434                 EdgeRemoved = False\r
435                 # for each node Item with a Constructor\r
436                 for Item in LibraryList:\r
437                     if Item not in Constructor:\r
438                         continue\r
439                     # for each Node without a constructor with an edge e from Item to Node\r
440                     for Node in ConsumedByList[Item]:\r
441                         if Node in Constructor:\r
442                             continue\r
443                         # remove edge e from the graph if Node has no constructor\r
444                         ConsumedByList[Item].remove(Node)\r
445                         EdgeRemoved = True\r
446                         if ConsumedByList[Item] == []:\r
447                             # insert Item into Q\r
448                             Q.insert(0, Item)\r
449                             break\r
450                     if Q != []:\r
451                         break\r
452             # DAG is done if there's no more incoming edge for all nodes\r
453             if Q == []:\r
454                 break\r
455 \r
456             # remove node from Q\r
457             Node = Q.pop()\r
458             # output Node\r
459             SortedLibraryList.append(Node)\r
460 \r
461             # for each node Item with an edge e from Node to Item do\r
462             for Item in LibraryList:\r
463                 if Node not in ConsumedByList[Item]:\r
464                     continue\r
465                 # remove edge e from the graph\r
466                 ConsumedByList[Item].remove(Node)\r
467 \r
468                 if ConsumedByList[Item] != []:\r
469                     continue\r
470                 # insert Item into Q, if Item has no other incoming edges\r
471                 Q.insert(0, Item)\r
472 \r
473         #\r
474         # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
475         #\r
476         for Item in LibraryList:\r
477             if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
478                 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
479                 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
480                                 ExtraData=ErrorMessage, File=self.DescFilePath)\r
481             if Item not in SortedLibraryList:\r
482                 SortedLibraryList.append(Item)\r
483 \r
484         #\r
485         # Build the list of constructor and destructir names\r
486         # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
487         #\r
488         SortedLibraryList.reverse()\r
489         Module.LibraryClasses = sdict()\r
490         for L in SortedLibraryList:\r
491             Module.LibraryClasses[L.LibraryClass[0].LibraryClass, ModuleType] = L\r
492             #\r
493             # Merge PCDs from library instance\r
494             #\r
495             for Key in L.Pcds:\r
496                 if Key not in Module.Pcds:\r
497                     Module.Pcds[Key] = L.Pcds[Key]\r
498             #\r
499             # Merge GUIDs from library instance\r
500             #\r
501             for CName in L.Guids:\r
502                 if CName not in Module.Guids:\r
503                     Module.Guids[CName] = L.Guids[CName]\r
504             #\r
505             # Merge Protocols from library instance\r
506             #\r
507             for CName in L.Protocols:\r
508                 if CName not in Module.Protocols:\r
509                     Module.Protocols[CName] = L.Protocols[CName]\r
510             #\r
511             # Merge Ppis from library instance\r
512             #\r
513             for CName in L.Ppis:\r
514                 if CName not in Module.Ppis:\r
515                     Module.Ppis[CName] = L.Ppis[CName]\r
516 \r
517     ##\r
518     # for R8.x modules\r
519     # \r
520     def _ResolveLibraryReference(self, Module):\r
521         EdkLogger.verbose("")\r
522         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self._Arch))\r
523         LibraryConsumerList = [Module]\r
524 \r
525         # "CompilerStub" is a must for R8 modules\r
526         Module.Libraries.append("CompilerStub")\r
527         while len(LibraryConsumerList) > 0:\r
528             M = LibraryConsumerList.pop()\r
529             for LibraryName in M.Libraries:\r
530                 if LibraryName not in self.Libraries:\r
531                     EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
532                                     ExtraData="\t%s [%s]" % (str(Module), self._Arch))\r
533                     continue\r
534 \r
535                 Library = self.Libraries[LibraryName]\r
536                 if (LibraryName, Module.ModuleType) not in Module.LibraryClasses:\r
537                     Module.LibraryClasses[LibraryName, Module.ModuleType] = Library\r
538                     LibraryConsumerList.append(Library)\r
539                     EdkLogger.verbose("\t" + LibraryName + " : " + str(Library))\r
540 \r
541     def _UpdateModulePcd(self, Module, ModuleId):\r
542         for Name,Guid in Module.Pcds:\r
543             PcdInModule = Module.Pcds[Name,Guid]\r
544             if (Name,Guid) in self.Pcds:\r
545                 PcdInPlatform = self.Pcds[Name,Guid]\r
546                 # \r
547                 # in case there's PCDs coming from FDF file, which have no type given.\r
548                 # at this point, PcdInModule.Type has the type found from dependent\r
549                 # package\r
550                 # \r
551                 if PcdInPlatform.Type != None and PcdInPlatform.Type != '':\r
552                     PcdInModule.Type = PcdInPlatform.Type\r
553                 PcdInModule.MaxDatumSize = PcdInPlatform.MaxDatumSize\r
554                 PcdInModule.SkuInfoList = PcdInPlatform.SkuInfoList\r
555                 if PcdInPlatform.DefaultValue not in [None, '']:\r
556                     PcdInModule.DefaultValue = PcdInPlatform.DefaultValue\r
557                 if PcdInPlatform.TokenValue not in [None, '']:\r
558                     PcdInModule.TokenValue = PcdInPlatform.TokenValue\r
559                 if PcdInPlatform.MaxDatumSize not in [None, '']:\r
560                     PcdInModule.MaxDatumSize = PcdInPlatform.MaxDatumSize\r
561                 if PcdInPlatform.DatumType not in [None, '']:\r
562                     PcdInModule.DatumType = PcdInPlatform.DatumType\r
563 \r
564             if PcdInModule.DatumType == "VOID*" and PcdInModule.MaxDatumSize in ['', None]:\r
565                 EdkLogger.verbose("No MaxDatumSize specified for PCD %s.%s in module [%s]" % (Guid, Name, str(Module)))\r
566                 Value = PcdInModule.DefaultValue\r
567                 if Value[0] == 'L':\r
568                     PcdInModule.MaxDatumSize = str(len(Value) * 2)\r
569                 elif Value[0] == '{':\r
570                     PcdInModule.MaxDatumSize = str(len(Value.split(',')))\r
571                 else:\r
572                     PcdInModule.MaxDatumSize = str(len(Value))\r
573 \r
574             # apply default SKU for dynamic PCDS if specified one is not available\r
575             if (PcdInModule.Type in PCD_DYNAMIC_TYPE_LIST or PcdInModule.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
576                 and PcdInModule.SkuInfoList in [None, {}, '']:\r
577                 if self.SkuName in self.SkuIds:\r
578                     SkuName = self.SkuName\r
579                 else:\r
580                     SkuName = 'DEFAULT'\r
581                 PcdInModule.SkuInfoList = {\r
582                     SkuName : SkuInfoClass(SkuName, self.SkuIds[SkuName], '', '', '', '', '', PcdInModule.DefaultValue)\r
583                 }\r
584 \r
585         RecordList = self._Table.Query(MODEL_PCD_FIXED_AT_BUILD, Scope1=self.Arch, BelongsToItem=ModuleId)\r
586         for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
587             if (PcdCName, TokenSpaceGuid) not in Module.Pcds:\r
588                 continue\r
589             TokenList = GetSplitValueList(Setting)\r
590             Pcd = Module.Pcds[PcdCName, TokenSpaceGuid]\r
591             Pcd.DefaultValue = TokenList[0]\r
592             if len(TokenList) > 1:\r
593                 Pcd.MaxDatumSize = TokenList[1]\r
594             Pcd.Type = self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD]\r
595 \r
596         RecordList = self._Table.Query(MODEL_PCD_PATCHABLE_IN_MODULE, Scope1=self.Arch, BelongsToItem=ModuleId)\r
597         for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
598             if (PcdCName, TokenSpaceGuid) not in Module.Pcds:\r
599                 continue\r
600             TokenList = GetSplitValueList(Setting)\r
601             Pcd = Module.Pcds[PcdCName, TokenSpaceGuid]\r
602             Pcd.DefaultValue = TokenList[0]\r
603             if len(TokenList) > 1:\r
604                 Pcd.MaxDatumSize = TokenList[1]\r
605             Pcd.Type = self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]\r
606 \r
607         RecordList = self._Table.Query(MODEL_PCD_FEATURE_FLAG, Scope1=self.Arch, BelongsToItem=ModuleId)\r
608         for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
609             if (PcdCName, TokenSpaceGuid) not in Module.Pcds:\r
610                 continue\r
611             TokenList = GetSplitValueList(Setting)\r
612             Pcd = Module.Pcds[PcdCName, TokenSpaceGuid]\r
613             Pcd.DefaultValue = TokenList[0]\r
614             if len(TokenList) > 1:\r
615                 Pcd.MaxDatumSize = TokenList[1]\r
616             Pcd.Type = self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]\r
617 \r
618         RecordList = self._Table.Query(MODEL_PCD_DYNAMIC, Scope1=self.Arch, BelongsToItem=ModuleId)\r
619         for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
620             if (PcdCName, TokenSpaceGuid) not in Module.Pcds:\r
621                 continue\r
622             Pcd.DefaultValue = Setting\r
623             Pcd.Type = self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC]\r
624 \r
625         RecordList = self._Table.Query(MODEL_PCD_DYNAMIC_EX, Scope1=self.Arch, BelongsToItem=ModuleId)\r
626         for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
627             if (PcdCName, TokenSpaceGuid) not in Module.Pcds:\r
628                 continue\r
629             Pcd.DefaultValue = Setting\r
630             Pcd.Type = self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX]\r
631 \r
632     def _MergeModuleBuildOption(self, Module, ModuleId):\r
633         RecordList = self._Table.Query(MODEL_META_DATA_BUILD_OPTION, Scope1=self.Arch, BelongsToItem=ModuleId)\r
634         for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
635             if (ToolChainFamily, ToolChain) not in Module.BuildOptions:\r
636                 Module.BuildOptions[ToolChainFamily, ToolChain] = Option\r
637             else:\r
638                 OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]\r
639                 Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option\r
640 \r
641     def _GetLibraryInstances(self):\r
642         if self._LibraryInstances == None:\r
643             self._LibraryInstances = []\r
644             for Module in self.Modules:\r
645                 for Key in Module.LibraryClasses:\r
646                     Lib = Module.LibraryClasses[Key]\r
647                     if Lib in [None, ''] or Lib in self._LibraryInstances:\r
648                         continue\r
649                     self._LibraryInstances.append(Lib)\r
650         return self._LibraryInstances\r
651 \r
652     def _GetLibraryClasses(self):\r
653         if self._LibraryClasses == None:\r
654             LibraryClassDict = tdict(True, 3)\r
655             LibraryClassSet = set()\r
656             ModuleTypeSet = set()\r
657             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_CLASS, Scope1=self.Arch)\r
658             for LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo in RecordList:\r
659                 LibraryClassSet.add(LibraryClass)\r
660                 ModuleTypeSet.add(ModuleType)\r
661                 LibraryInstance = NormPath(LibraryInstance, self._Macros)\r
662                 if not ValidFile(LibraryInstance):\r
663                     EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath, \r
664                                     ExtraData=LibraryInstance, Line=LineNo)\r
665                 LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance\r
666 \r
667             self._LibraryClasses = tdict(True)\r
668             for LibraryClass in LibraryClassSet:\r
669                 for ModuleType in ModuleTypeSet:\r
670                     LibraryInstance = LibraryClassDict[self.Arch, ModuleType, LibraryClass]\r
671                     if LibraryInstance == None:\r
672                         continue\r
673                     self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance\r
674         return self._LibraryClasses\r
675 \r
676     def _GetLibraries(self):\r
677         if self._Libraries == None:\r
678             self._Libraries = sdict()\r
679             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_INSTANCE, Scope1=self.Arch)\r
680             for Record in RecordList:\r
681                 File = NormPath(Record[0], self._Macros)\r
682                 LineNo = Record[-1]\r
683                 if not ValidFile(File):\r
684                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
685                                     File=self.DescFilePath, Line=LineNo)\r
686                 Library = self._Db.BuildObject[File, MODEL_FILE_INF, self._Arch]\r
687                 self._Libraries[Library.BaseName] = Library\r
688         return self._Libraries\r
689 \r
690     def _GetPcds(self):\r
691         if self._Pcds == None:\r
692             self._Pcds = {}\r
693             self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
694             self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
695             self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
696             self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))\r
697             self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))\r
698             self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))\r
699             self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))\r
700             self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))\r
701             self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))\r
702         return self._Pcds\r
703 \r
704     def _GetBuildOptions(self):\r
705         if self._BuildOptions == None:\r
706             self._BuildOptions = {}\r
707             RecordList = self._Table.Query(MODEL_META_DATA_BUILD_OPTION)\r
708             for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
709                 self._BuildOptions[ToolChainFamily, ToolChain] = Option\r
710         return self._BuildOptions\r
711 \r
712     def _GetPcd(self, Type):\r
713         Pcds = {}\r
714         PcdDict = tdict(True, 3)\r
715         PcdSet = set()\r
716         # Find out all possible PCD candidates for self.Arch\r
717         RecordList = self._Table.Query(Type, Scope1=self.Arch)\r
718         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
719             PcdSet.add((PcdCName, TokenSpaceGuid))\r
720             PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting\r
721         # Remove redundant PCD candidates\r
722         for PcdCName, TokenSpaceGuid in PcdSet:\r
723             ValueList = ['', '', '']\r
724             Setting = PcdDict[self.Arch, PcdCName, TokenSpaceGuid]\r
725             if Setting == None:\r
726                 continue\r
727             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
728             ValueList[0:len(TokenList)] = TokenList\r
729             PcdValue, DatumType, MaxDatumSize = ValueList\r
730             Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
731                                                 PcdCName,\r
732                                                 TokenSpaceGuid,\r
733                                                 self._PCD_TYPE_STRING_[Type],\r
734                                                 DatumType,\r
735                                                 PcdValue,\r
736                                                 '',\r
737                                                 MaxDatumSize,\r
738                                                 {},\r
739                                                 True\r
740                                                 )\r
741         return Pcds\r
742 \r
743     def _GetDynamicPcd(self, Type):\r
744         Pcds = {}\r
745         PcdDict = tdict(True, 4)\r
746         PcdSet = set()\r
747         RecordList = self._Table.Query(Type, Scope1=self.Arch)\r
748         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
749             PcdSet.add((PcdCName, TokenSpaceGuid))\r
750             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
751 \r
752         for PcdCName, TokenSpaceGuid in PcdSet:\r
753             ValueList = ['', '', '']\r
754             Setting = PcdDict[self.Arch, self.SkuName, PcdCName, TokenSpaceGuid]\r
755             if Setting == None:\r
756                 continue\r
757             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
758             ValueList[0:len(TokenList)] = TokenList\r
759             PcdValue, DatumType, MaxDatumSize = ValueList\r
760 \r
761             SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', '', PcdValue)\r
762             Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
763                                                 PcdCName,\r
764                                                 TokenSpaceGuid,\r
765                                                 self._PCD_TYPE_STRING_[Type],\r
766                                                 DatumType,\r
767                                                 PcdValue,\r
768                                                 '',\r
769                                                 MaxDatumSize,\r
770                                                 {self.SkuName : SkuInfo},\r
771                                                 True\r
772                                                 )\r
773         return Pcds\r
774 \r
775     def _GetDynamicHiiPcd(self, Type):\r
776         Pcds = {}\r
777         PcdDict = tdict(True, 4)\r
778         PcdSet = set()\r
779         RecordList = self._Table.Query(Type, Scope1=self.Arch)\r
780         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
781             PcdSet.add((PcdCName, TokenSpaceGuid))\r
782             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
783 \r
784         for PcdCName, TokenSpaceGuid in PcdSet:\r
785             ValueList = ['', '', '', '']\r
786             Setting = PcdDict[self.Arch, self.SkuName, PcdCName, TokenSpaceGuid]\r
787             if Setting == None:\r
788                 continue\r
789             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
790             ValueList[0:len(TokenList)] = TokenList\r
791             VariableName, VariableGuid, VariableOffset, DefaultValue = ValueList\r
792             SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue)\r
793             Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
794                                                 PcdCName,\r
795                                                 TokenSpaceGuid,\r
796                                                 self._PCD_TYPE_STRING_[Type],\r
797                                                 '',\r
798                                                 DefaultValue,\r
799                                                 '',\r
800                                                 '',\r
801                                                 {self.SkuName : SkuInfo},\r
802                                                 True\r
803                                                 )\r
804         return Pcds\r
805 \r
806     def _GetDynamicVpdPcd(self, Type):\r
807         Pcds = {}\r
808         PcdDict = tdict(True, 4)\r
809         PcdSet = set()\r
810         RecordList = self._Table.Query(Type, Scope1=self.Arch)\r
811         for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
812             PcdSet.add((PcdCName, TokenSpaceGuid))\r
813             PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
814 \r
815         for PcdCName, TokenSpaceGuid in PcdSet:\r
816             ValueList = ['', '']\r
817             Setting = PcdDict[self.Arch, self.SkuName, PcdCName, TokenSpaceGuid]\r
818             if Setting == None:\r
819                 continue\r
820             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
821             ValueList[0:len(TokenList)] = TokenList\r
822             VpdOffset, MaxDatumSize = ValueList\r
823 \r
824             SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', VpdOffset)\r
825             Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
826                                                 PcdCName,\r
827                                                 TokenSpaceGuid,\r
828                                                 self._PCD_TYPE_STRING_[Type],\r
829                                                 '',\r
830                                                 '',\r
831                                                 '',\r
832                                                 MaxDatumSize,\r
833                                                 {self.SkuName : SkuInfo},\r
834                                                 True\r
835                                                 )\r
836         return Pcds\r
837 \r
838     def AddModule(self, FilePath):\r
839         Module = self._Db.BuildObject[FilePath, MODEL_FILE_INF, self._Arch]\r
840         self._Modules.append(NormPath(Module))\r
841 \r
842     def AddPcd(self, Name, Guid, Value):\r
843         if (Name, Guid) not in self.Pcds:\r
844             self.Pcds[Name, Guid] = PcdClassObject(\r
845                                         Name,\r
846                                         Guid,\r
847                                         '',\r
848                                         '',\r
849                                         '',\r
850                                         '',\r
851                                         '',\r
852                                         {},\r
853                                         True\r
854                                         )\r
855         self.Pcds[Name, Guid].DefaultValue = Value\r
856 \r
857     Arch                = property(_GetArch, _SetArch)\r
858     Platform            = property(_GetPlatformName)\r
859     PlatformName        = property(_GetPlatformName)\r
860     Guid                = property(_GetFileGuid)\r
861     Version             = property(_GetVersion)\r
862     DscSpecification    = property(_GetDscSpec)\r
863     OutputDirectory     = property(_GetOutpuDir)\r
864     SupArchList         = property(_GetSupArch)\r
865     BuildTargets        = property(_GetBuildTarget)\r
866     SkuName             = property(_GetSkuName)\r
867     FlashDefinition     = property(_GetFdfFile)\r
868     BuildNumber         = property(_GetBuildNumber)\r
869     MakefileName        = property(_GetMakefileName)\r
870     BsBaseAddress       = property(_GetBsBaseAddress)\r
871     RtBaseAddress       = property(_GetRtBaseAddress)\r
872 \r
873     SkuIds              = property(_GetSkuIds)\r
874     Modules             = property(_GetModules)\r
875     LibraryInstances    = property(_GetLibraryInstances)\r
876     LibraryClasses      = property(_GetLibraryClasses)\r
877     Libraries           = property(_GetLibraries)\r
878     Pcds                = property(_GetPcds)\r
879     BuildOptions        = property(_GetBuildOptions)\r
880 \r
881 class DecBuildData(PackageBuildClassObject):\r
882     _PCD_TYPE_STRING_ = {\r
883         MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
884         MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
885         MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
886         MODEL_PCD_DYNAMIC               :   "Dynamic",\r
887         MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
888         MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
889         MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
890         MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
891         MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
892         MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
893         MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
894     }\r
895 \r
896     def __init__(self, FilePath, Table, Db, Arch='COMMON', Macros={}):\r
897         self.DescFilePath = FilePath\r
898         self._PackageDir = os.path.dirname(FilePath)\r
899         self._Table = Table\r
900         self._Arch = Arch\r
901         self._Macros = Macros\r
902         self._Clear()\r
903 \r
904     def __repr__(self):\r
905         S = "[Package]\n"\r
906         S += "\tNAME = %s\n" % self.PackageName\r
907         S += "\tGUID = %s\n" % self.Guid\r
908         S += "\tVER  = %s\n" % self.Version\r
909 \r
910         S += '  <Protocol>\n'\r
911         for Name in self.Protocols:\r
912             S += "\t%s = %s\n" % (Name, self.Protocols[Name])\r
913 \r
914         S += '  <Ppi>\n'\r
915         for Name in self.Ppis:\r
916             S += "\t%s = %s\n" % (Name, self.Ppis[Name])\r
917 \r
918         S += '  <Guid>\n'\r
919         for Name in self.Guids:\r
920             S += "\t%s = %s\n" % (Name, self.Guids[Name])\r
921 \r
922         S += '  <Include>\n\t'\r
923         S += "\n\t".join(self.Includes) + '\n'\r
924 \r
925         S += '  <LibraryClass>\n'\r
926         for LibraryClass in self.LibraryClasses:\r
927             S += "\t%s = %s\n" % (LibraryClass, self.LibraryClasses[LibraryClass])\r
928 \r
929         S += '  <PCD>\n'\r
930         for Name,Guid,Type in self.Pcds:\r
931             S += "\t%s.%s-%s\n\t\t%s\n" % (Guid, Name, Type, str(self.Pcds[Name, Guid, Type]))\r
932         return S\r
933 \r
934     def _Clear(self):\r
935         self._PackageName       = None\r
936         self._Guid              = None\r
937         self._Version           = None\r
938         self._Protocols         = None\r
939         self._Ppis              = None\r
940         self._Guids             = None\r
941         self._Includes          = None\r
942         self._LibraryClasses    = None\r
943         self._Pcds              = None\r
944 \r
945     def _GetArch(self):\r
946         return self._Arch\r
947 \r
948     def _SetArch(self, Value):\r
949         if self._Arch == Value:\r
950             return\r
951         self._Arch = Value\r
952         self._Clear()\r
953 \r
954     def _GetPackageName(self):\r
955         if self._PackageName == None:\r
956             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DEC_DEFINES_PACKAGE_NAME)\r
957             if len(RecordList) == 0:\r
958                 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.DescFilePath)\r
959             self._PackageName = RecordList[0][0]\r
960         return self._PackageName\r
961 \r
962     def _GetFileGuid(self):\r
963         if self._Guid == None:\r
964             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DEC_DEFINES_PACKAGE_GUID)\r
965             if len(RecordList) == 0:\r
966                 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.DescFilePath)\r
967             self._Guid = RecordList[0][0]\r
968         return self._Guid\r
969 \r
970     def _GetVersion(self):\r
971         if self._Version == None:\r
972             RecordList = self._Table.Query(MODEL_META_DATA_HEADER, TAB_DEC_DEFINES_PACKAGE_VERSION)\r
973             if len(RecordList) == 0:\r
974                 self._Version = ''\r
975             self._Version = RecordList[0][0]\r
976         return self._Version\r
977 \r
978     def _GetProtocol(self):\r
979         if self._Protocols == None:\r
980             ProtocolDict = tdict(True)\r
981             NameList = []\r
982             RecordList = self._Table.Query(MODEL_EFI_PROTOCOL, Arch=self.Arch)\r
983             for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
984                 if Name not in NameList:\r
985                     NameList.append(Name)\r
986                 ProtocolDict[Arch, Name] = Guid\r
987             self._Protocols = sdict()\r
988             for Name in NameList:\r
989                 self._Protocols[Name] = ProtocolDict[self.Arch, Name]\r
990         return self._Protocols\r
991 \r
992     def _GetPpi(self):\r
993         if self._Ppis == None:\r
994             PpiDict = tdict(True)\r
995             NameList = []\r
996             RecordList = self._Table.Query(MODEL_EFI_PPI, Arch=self.Arch)\r
997             for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
998                 if Name not in NameList:\r
999                     NameList.append(Name)\r
1000                 PpiDict[Arch, Name] = Guid\r
1001             self._Ppis = sdict()\r
1002             for Name in NameList:\r
1003                 self._Ppis[Name] = PpiDict[self.Arch, Name]\r
1004         return self._Ppis\r
1005 \r
1006     def _GetGuid(self):\r
1007         if self._Guids == None:\r
1008             GuidDict = tdict(True)\r
1009             NameList = []\r
1010             RecordList = self._Table.Query(MODEL_EFI_GUID, Arch=self.Arch)\r
1011             for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
1012                 if Name not in NameList:\r
1013                     NameList.append(Name)\r
1014                 GuidDict[Arch, Name] = Guid\r
1015             self._Guids = sdict()\r
1016             for Name in NameList:\r
1017                 self._Guids[Name] = GuidDict[self.Arch, Name]\r
1018         return self._Guids\r
1019 \r
1020     def _GetInclude(self):\r
1021         if self._Includes == None:\r
1022             self._Includes = []\r
1023             RecordList = self._Table.Query(MODEL_EFI_INCLUDE, Arch=self.Arch)\r
1024             for Record in RecordList:\r
1025                 File = NormPath(Record[0], self._Macros)\r
1026                 LineNo = Record[-1]\r
1027                 if not ValidFile(File, self._PackageDir):\r
1028                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1029                                     File=self.DescFilePath, Line=LineNo)\r
1030                 if File not in self._Includes:\r
1031                     self._Includes.append(File)\r
1032         return self._Includes\r
1033 \r
1034     def _GetLibraryClass(self):\r
1035         if self._LibraryClasses == None:\r
1036             LibraryClassDict = tdict(True)\r
1037             LibraryClassSet = set()\r
1038             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_CLASS, Arch=self.Arch)\r
1039             for LibraryClass, File, Dummy, Arch, ID, LineNo in RecordList:\r
1040                 File = NormPath(File, self._Macros)\r
1041                 if not ValidFile(File, self._PackageDir):\r
1042                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1043                                     File=self.DescFilePath, Line=LineNo)\r
1044                 LibraryClassSet.add(LibraryClass)\r
1045                 LibraryClassDict[Arch, LibraryClass] = File\r
1046             self._LibraryClasses = sdict()\r
1047             for LibraryClass in LibraryClassSet:\r
1048                 self._LibraryClasses[LibraryClass] = LibraryClassDict[self.Arch, LibraryClass]\r
1049         return self._LibraryClasses\r
1050 \r
1051     def _GetPcds(self):\r
1052         if self._Pcds == None:\r
1053             self._Pcds = {}\r
1054             self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
1055             self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
1056             self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
1057             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))\r
1058             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))\r
1059         return self._Pcds\r
1060 \r
1061     def _GetPcd(self, Type):\r
1062         Pcds = {}\r
1063         PcdDict = tdict(True, 3)\r
1064         PcdSet = set()\r
1065         RecordList = self._Table.Query(Type, Arch=self._Arch)\r
1066         for TokenSpaceGuid, PcdCName, Setting, Arch, Dummy1, Dummy2 in RecordList:\r
1067             PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting\r
1068             PcdSet.add((PcdCName, TokenSpaceGuid))\r
1069 \r
1070         for PcdCName, TokenSpaceGuid in PcdSet:\r
1071             ValueList = ['', '', '']\r
1072             Setting = PcdDict[self.Arch, PcdCName, TokenSpaceGuid]\r
1073             if Setting == None:\r
1074                 continue\r
1075             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
1076             ValueList[0:len(TokenList)] = TokenList\r
1077             DefaultValue, DatumType, TokenNumber = ValueList\r
1078             Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdClassObject(\r
1079                                                                             PcdCName,\r
1080                                                                             TokenSpaceGuid,\r
1081                                                                             self._PCD_TYPE_STRING_[Type],\r
1082                                                                             DatumType,\r
1083                                                                             DefaultValue,\r
1084                                                                             TokenNumber,\r
1085                                                                             '',\r
1086                                                                             {},\r
1087                                                                             True\r
1088                                                                             )\r
1089         return Pcds\r
1090 \r
1091 \r
1092     Arch            = property(_GetArch, _SetArch)\r
1093     PackageName     = property(_GetPackageName)\r
1094     Guid            = property(_GetFileGuid)\r
1095     Version         = property(_GetVersion)\r
1096 \r
1097     Protocols       = property(_GetProtocol)\r
1098     Ppis            = property(_GetPpi)\r
1099     Guids           = property(_GetGuid)\r
1100     Includes        = property(_GetInclude)\r
1101     LibraryClasses  = property(_GetLibraryClass)\r
1102     Pcds            = property(_GetPcds)\r
1103 \r
1104 class InfBuildData(ModuleBuildClassObject):\r
1105     _PCD_TYPE_STRING_ = {\r
1106         MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
1107         MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
1108         MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
1109         MODEL_PCD_DYNAMIC               :   "Dynamic",\r
1110         MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
1111         MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
1112         MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
1113         MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
1114         MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
1115         MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
1116         MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
1117     }\r
1118 \r
1119     _PROPERTY_ = {\r
1120         #\r
1121         # Required Fields\r
1122         #\r
1123         TAB_INF_DEFINES_BASE_NAME                   : "_BaseName",\r
1124         TAB_INF_DEFINES_FILE_GUID                   : "_Guid",\r
1125         TAB_INF_DEFINES_MODULE_TYPE                 : "_ModuleType",\r
1126         #\r
1127         # Optional Fields\r
1128         #\r
1129         TAB_INF_DEFINES_INF_VERSION                 : "_AutoGenVersion",\r
1130         TAB_INF_DEFINES_COMPONENT_TYPE              : "_ComponentType",\r
1131         TAB_INF_DEFINES_MAKEFILE_NAME               : "_MakefileName",\r
1132         #TAB_INF_DEFINES_CUSTOM_MAKEFILE             : "_CustomMakefile",\r
1133         TAB_INF_DEFINES_VERSION_NUMBER              : "_Version",\r
1134         TAB_INF_DEFINES_VERSION_STRING              : "_Version",\r
1135         TAB_INF_DEFINES_VERSION                     : "_Version",\r
1136         TAB_INF_DEFINES_PCD_IS_DRIVER               : "_PcdIsDriver",\r
1137         TAB_INF_DEFINES_SHADOW                      : "_Shadow",\r
1138     }\r
1139 \r
1140     _MODULE_TYPE_ = {\r
1141         "LIBRARY"               :   "BASE",\r
1142         "SECURITY_CORE"         :   "SEC",\r
1143         "PEI_CORE"              :   "PEI_CORE",\r
1144         "COMBINED_PEIM_DRIVER"  :   "PEIM",\r
1145         "PIC_PEIM"              :   "PEIM",\r
1146         "RELOCATABLE_PEIM"      :   "PEIM",\r
1147         "PE32_PEIM"             :   "PEIM",\r
1148         "BS_DRIVER"             :   "DXE_DRIVER",\r
1149         "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",\r
1150         "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",\r
1151     #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",\r
1152     #    "BS_DRIVER"             :   "UEFI_DRIVER",\r
1153         "APPLICATION"           :   "UEFI_APPLICATION",\r
1154         "LOGO"                  :   "BASE",\r
1155     }\r
1156     \r
1157     _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
1158     _TOOL_CODE_ = {\r
1159         "C"         :   "CC",\r
1160         "LIB"       :   "SLINK",\r
1161         "LINK"      :   "DLINK",\r
1162     }\r
1163     \r
1164 \r
1165     def __init__(self, FilePath, Table, Db, Arch='COMMON', Macros={}):\r
1166         self.DescFilePath = FilePath\r
1167         self._ModuleDir = os.path.dirname(FilePath)\r
1168         self._Table = Table\r
1169         self._Db = Db\r
1170         self._Arch = Arch\r
1171         self._Platform = 'COMMON'\r
1172         self._Macros = Macros\r
1173         self._Clear()\r
1174 \r
1175     def Print(self):\r
1176         S = '[%s.%s]\n' % (self.DescFilePath, self.Arch)\r
1177         S += '\tName = ' + self.BaseName + '\n'\r
1178         S += '\tGuid = ' + self.Guid + '\n'\r
1179         S += '\tVer  = ' + self.Version + '\n'\r
1180         S += '\tInfVersion = ' + self.AutoGenVersion + '\n'\r
1181         S += '\tModuleType = ' + self.ModuleType + '\n'\r
1182         S += '\tComponentType = ' + self.ComponentType + '\n'\r
1183         S += '\tPcdIsDriver = ' + str(self.PcdIsDriver) + '\n'\r
1184         S += '\tCustomMakefile = ' + self.CustomMakefile + '\n'\r
1185         S += '\tSpecification = ' + str(self.Specification) + '\n'\r
1186         S += '\tShadow = ' + str(self.Shadow) + '\n'\r
1187         S += '\tPcdIsDriver = ' + str(self.PcdIsDriver) + '\n'\r
1188         for Lib in self.LibraryClass:\r
1189             S += '\tLibraryClassDefinition = ' + str(Lib.LibraryClass) + ' SupModList = ' + str(Lib.SupModList) + '\n'\r
1190         S += '\tModuleEntryPointList = ' + str(self.ModuleEntryPointList) + '\n'\r
1191         S += '\tModuleUnloadImageList = ' + str(self.ModuleUnloadImageList) + '\n'\r
1192         S += '\tConstructorList = ' + str(self.ConstructorList) + '\n'\r
1193         S += '\tDestructorList = ' + str(self.DestructorList) + '\n'\r
1194 \r
1195         S += '  <Binaries>\n'\r
1196         for item in self.Binaries:\r
1197             S += "\t" + item.BinaryFile + item.FeatureFlag + item.SupArchList + '\n'\r
1198 \r
1199         S += '  <Sources>\n'\r
1200         for item in self.Sources:\r
1201             S += "\t" + item.SourceFile + '\n'\r
1202 \r
1203         S += '  <LibraryClasses>\n'\r
1204         S += '\t' + '\n\t'.join([Key for Key in self.LibraryClasses]) + '\n'\r
1205 \r
1206         S += '  <Protocols>\n'\r
1207         S += '\t' + '\n\t'.join(self.Protocols) + '\n'\r
1208 \r
1209         S += '  <Ppis>\n'\r
1210         S += '\t' + '\n\t'.join(self.Ppis) + '\n'\r
1211 \r
1212         S += '  <Guids>\n'\r
1213         S += '\t' + '\n\t'.join(self.Guids) + '\n'\r
1214 \r
1215         S += '  <Includes>\n'\r
1216         S += '\t' + '\n\t'.join(self.Includes) + '\n'\r
1217 \r
1218         S += '  <Packages>\n'\r
1219         S += '\t' + '\n\t'.join([str(P) for P in self.Packages]) + '\n'\r
1220 \r
1221         S += '  <Pcds>\n'\r
1222         for Name,Guid in self.Pcds.keys():\r
1223             S += "\t%s.%s\n\t\t%s\n" % (Guid, Name, str(self.Pcds[Name,Guid]))\r
1224 \r
1225         S += '  <BuildOptions\n'\r
1226         S += '\t' + '\n\t'.join(self.BuildOptions.values()) + '\n'\r
1227 \r
1228         S += '  <Depex>\n'\r
1229         S += '\t' + str(self.Depex) + '\n'\r
1230 \r
1231         S += '\n'\r
1232         return S\r
1233 \r
1234     ## XXX[key] = value\r
1235     def __setitem__(self, key, value):\r
1236         self.__dict__[self._PROPERTY_[key]] = value\r
1237     ## value = XXX[key]\r
1238     def __getitem__(self, key):\r
1239         return self.__dict__[self._PROPERTY_[key]]\r
1240     ## "in" test support\r
1241     def __contains__(self, key):\r
1242         return key in self._PROPERTY_\r
1243 \r
1244     def _Clear(self):\r
1245         self._Header_               = None\r
1246         self._AutoGenVersion        = None\r
1247         self._DescFilePath          = None\r
1248         self._BaseName              = None\r
1249         self._ModuleType            = None\r
1250         self._ComponentType         = None\r
1251         self._Guid                  = None\r
1252         self._Version               = None\r
1253         self._PcdIsDriver           = None\r
1254         self._BinaryModule          = None\r
1255         self._Shadow                = None\r
1256         self._MakefileName          = None\r
1257         self._CustomMakefile        = None\r
1258         self._Specification         = None\r
1259         self._LibraryClass          = None\r
1260         self._ModuleEntryPointList  = None\r
1261         self._ModuleUnloadImageList = None\r
1262         self._ConstructorList       = None\r
1263         self._DestructorList        = None\r
1264         self._Binaries              = None\r
1265         self._Sources               = None\r
1266         self._LibraryClasses        = None\r
1267         self._Libraries             = None\r
1268         self._Protocols             = None\r
1269         self._Ppis                  = None\r
1270         self._Guids                 = None\r
1271         self._Includes              = None\r
1272         self._Packages              = None\r
1273         self._Pcds                  = None\r
1274         self._BuildOptions          = None\r
1275         self._Depex                 = None\r
1276 \r
1277     def _GetArch(self):\r
1278         return self._Arch\r
1279 \r
1280     def _SetArch(self, Value):\r
1281         if self._Arch == Value:\r
1282             return\r
1283         self._Arch = Value\r
1284         self._Clear()\r
1285 \r
1286     def _GetPlatform(self):\r
1287         return self._Platform\r
1288 \r
1289     def _SetPlatform(self, Value):\r
1290         self._Platform = Value\r
1291 \r
1292     def _GetHeaderInfo(self):\r
1293         RecordList = self._Table.Query(MODEL_META_DATA_HEADER, Arch=self._Arch, Platform=self._Platform)\r
1294         for Record in RecordList:\r
1295             Name = Record[0]\r
1296             if Name in self:\r
1297                 self[Name] = Record[1]\r
1298             elif Name == 'EFI_SPECIFICATION_VERSION':\r
1299                 if self._Specification == None:\r
1300                     self._Specification = sdict()\r
1301                 self._Specification[Name] = Record[1]\r
1302             elif Name == 'EDK_RELEASE_VERSION':\r
1303                 if self._Specification == None:\r
1304                     self._Specification = sdict()\r
1305                 self._Specification[Name] = Record[1]\r
1306             elif Name == 'LIBRARY_CLASS':\r
1307                 if self._LibraryClass == None:\r
1308                     self._LibraryClass = []\r
1309                 ValueList = GetSplitValueList(Record[1])\r
1310                 LibraryClass = ValueList[0]\r
1311                 if len(ValueList) > 1:\r
1312                     SupModuleList = GetSplitValueList(ValueList[1], ' ')\r
1313                 else:\r
1314                     SupModuleList = SUP_MODULE_LIST\r
1315                 self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))\r
1316             elif Name == 'ENTRY_POINT':\r
1317                 if self._ModuleEntryPointList == None:\r
1318                     self._ModuleEntryPointList = []\r
1319                 self._ModuleEntryPointList.append(Record[1])\r
1320             elif Name == 'UNLOAD_IMAGE':\r
1321                 if self._ModuleUnloadImageList == None:\r
1322                     self._ModuleUnloadImageList = []\r
1323                 if Record[1] == '':\r
1324                     continue\r
1325                 self._ModuleUnloadImageList.append(Record[1])\r
1326             elif Name == 'CONSTRUCTOR':\r
1327                 if self._ConstructorList == None:\r
1328                     self._ConstructorList = []\r
1329                 if Record[1] == '':\r
1330                     continue\r
1331                 self._ConstructorList.append(Record[1])\r
1332             elif Name == 'DESTRUCTOR':\r
1333                 if self._DestructorList == None:\r
1334                     self._DestructorList = []\r
1335                 if Record[1] == '':\r
1336                     continue\r
1337                 self._DestructorList.append(Record[1])\r
1338             elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:\r
1339                 TokenList = GetSplitValueList(Record[1])\r
1340                 self._CustomMakefile = {}\r
1341                 if len(TokenList) < 2:\r
1342                     self._CustomMakefile['MSFT'] = TokenList[0]\r
1343                     self._CustomMakefile['GCC'] = TokenList[0]\r
1344                 else:\r
1345                     if TokenList[0] not in ['MSFT', 'GCC']:\r
1346                         EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
1347                                         "No supported family [%s]" % TokenList[0], \r
1348                                         File=self.DescFilePath, Line=Record[-1])\r
1349                     self._CustomMakefile[TokenList[0]] = TokenList[1]\r
1350         # \r
1351         # R8.x modules\r
1352         # \r
1353         if self._AutoGenVersion < 0x00010005:   # _AutoGenVersion may be None, which is less than anything\r
1354             if self._ComponentType in self._MODULE_TYPE_:\r
1355                 self._ModuleType = self._MODULE_TYPE_[self._ComponentType]\r
1356             if self._ComponentType == 'LIBRARY':\r
1357                 self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]\r
1358             # make use some [nmake] section macros\r
1359             RecordList = self._Table.Query(MODEL_META_DATA_NMAKE, Arch=self._Arch, Platform=self._Platform)\r
1360             for Name,Value,Dummy,Arch,Platform,ID,LineNo in RecordList:\r
1361                 if Name == "IMAGE_ENTRY_POINT":\r
1362                     if self._ModuleEntryPointList == None:\r
1363                         self._ModuleEntryPointList = []\r
1364                     self._ModuleEntryPointList.append(Value)\r
1365                 elif Name == "DPX_SOURCE":\r
1366                     File = NormPath(Value, self._Macros)\r
1367                     if not ValidFile(File, self._ModuleDir):\r
1368                         EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1369                                         File=self.DescFilePath, Line=LineNo)\r
1370                     if self._Sources == None:\r
1371                         self._Sources = []\r
1372                     self._Sources.append(ModuleSourceFileClass(File, "", "", "", ""))\r
1373                 else:\r
1374                     ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)\r
1375                     if len(ToolList) == 0 or len(ToolList) != 1:\r
1376                         EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name, \r
1377                                        File=self.DescFilePath, Line=LineNo)\r
1378                     else:\r
1379                         if self._BuildOptions == None:\r
1380                             self._BuildOptions = sdict()\r
1381 \r
1382                         if ToolList[0] in self._TOOL_CODE_:\r
1383                             Tool = self._TOOL_CODE_[ToolList[0]]\r
1384                         else:\r
1385                             Tool = ToolList[0]\r
1386                         ToolChain = "*_*_*_%s_FLAGS" % Tool\r
1387                         ToolChainFamily = 'MSFT'    # R8.x only support MSFT tool chain\r
1388                         if (ToolChainFamily, ToolChain) not in self._BuildOptions:\r
1389                             self._BuildOptions[ToolChainFamily, ToolChain] = Value\r
1390                         else:\r
1391                             OptionString = self._BuildOptions[ToolChainFamily, ToolChain]\r
1392                             self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value\r
1393 \r
1394         self._Header_ = 'DUMMY'\r
1395 \r
1396     def _GetInfVersion(self):\r
1397         if self._AutoGenVersion == None:\r
1398             if self._Header_ == None:\r
1399                 self._GetHeaderInfo()\r
1400             if self._AutoGenVersion == None:\r
1401                 self._AutoGenVersion = 0x00010000\r
1402         return self._AutoGenVersion\r
1403 \r
1404     def _GetBaseName(self):\r
1405         if self._BaseName == None:\r
1406             if self._Header_ == None:\r
1407                 self._GetHeaderInfo()\r
1408             if self._BaseName == None:\r
1409                 EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.DescFilePath)\r
1410         return self._BaseName\r
1411 \r
1412     def _GetModuleType(self):\r
1413         if self._ModuleType == None:\r
1414             if self._Header_ == None:\r
1415                 self._GetHeaderInfo()\r
1416             if self._ModuleType == None:\r
1417                 self._ModuleType = 'BASE'\r
1418         return self._ModuleType\r
1419 \r
1420     def _GetComponentType(self):\r
1421         if self._ComponentType == None:\r
1422             if self._Header_ == None:\r
1423                 self._GetHeaderInfo()\r
1424             if self._ComponentType == None:\r
1425                 self._ComponentType = ''\r
1426         return self._ComponentType\r
1427 \r
1428     def _GetFileGuid(self):\r
1429         if self._Guid == None:\r
1430             if self._Header_ == None:\r
1431                 self._GetHeaderInfo()\r
1432             if self._Guid == None:\r
1433                 self._Guid = '00000000-0000-0000-000000000000'\r
1434         return self._Guid\r
1435 \r
1436     def _GetVersion(self):\r
1437         if self._Version == None:\r
1438             if self._Header_ == None:\r
1439                 self._GetHeaderInfo()\r
1440             if self._Version == None:\r
1441                 self._Version = '0.0'\r
1442         return self._Version\r
1443 \r
1444     def _GetPcdIsDriver(self):\r
1445         if self._PcdIsDriver == None:\r
1446             if self._Header_ == None:\r
1447                 self._GetHeaderInfo()\r
1448             if self._PcdIsDriver == None:\r
1449                 self._PcdIsDriver = ''\r
1450         return self._PcdIsDriver\r
1451 \r
1452     def _GetShadow(self):\r
1453         if self._Shadow == None:\r
1454             if self._Header_ == None:\r
1455                 self._GetHeaderInfo()\r
1456             if self._Shadow != None and self._Shadow.upper() == 'TRUE':\r
1457                 self._Shadow = True\r
1458             else:\r
1459                 self._Shadow = False\r
1460         return self._Shadow\r
1461 \r
1462     def _GetMakefile(self):\r
1463         if self._CustomMakefile == None:\r
1464             if self._Header_ == None:\r
1465                 self._GetHeaderInfo()\r
1466             if self._CustomMakefile == None:\r
1467                 self._CustomMakefile = {}\r
1468         return self._CustomMakefile\r
1469 \r
1470     def _GetSpec(self):\r
1471         if self._Specification == None:\r
1472             if self._Header_ == None:\r
1473                 self._GetHeaderInfo()\r
1474             if self._Specification == None:\r
1475                 self._Specification = {}\r
1476         return self._Specification\r
1477 \r
1478     def _GetLibraryClass(self):\r
1479         if self._LibraryClass == None:\r
1480             if self._Header_ == None:\r
1481                 self._GetHeaderInfo()\r
1482             if self._LibraryClass == None:\r
1483                 self._LibraryClass = []\r
1484         return self._LibraryClass\r
1485 \r
1486     def _GetEntryPoint(self):\r
1487         if self._ModuleEntryPointList == None:\r
1488             if self._Header_ == None:\r
1489                 self._GetHeaderInfo()\r
1490             if self._ModuleEntryPointList == None:\r
1491                 self._ModuleEntryPointList = []\r
1492         return self._ModuleEntryPointList\r
1493 \r
1494     def _GetUnloadImage(self):\r
1495         if self._ModuleUnloadImageList == None:\r
1496             if self._Header_ == None:\r
1497                 self._GetHeaderInfo()\r
1498             if self._ModuleUnloadImageList == None:\r
1499                 self._ModuleUnloadImageList = []\r
1500         return self._ModuleUnloadImageList\r
1501 \r
1502     def _GetConstructor(self):\r
1503         if self._ConstructorList == None:\r
1504             if self._Header_ == None:\r
1505                 self._GetHeaderInfo()\r
1506             if self._ConstructorList == None:\r
1507                 self._ConstructorList = []\r
1508         return self._ConstructorList\r
1509 \r
1510     def _GetDestructor(self):\r
1511         if self._DestructorList == None:\r
1512             if self._Header_ == None:\r
1513                 self._GetHeaderInfo()\r
1514             if self._DestructorList == None:\r
1515                 self._DestructorList = []\r
1516         return self._DestructorList\r
1517                         \r
1518     def _GetBinaryFiles(self):\r
1519         if self._Binaries == None:\r
1520             self._Binaries = []\r
1521             RecordList = self._Table.Query(MODEL_EFI_BINARY_FILE, Arch=self._Arch, Platform=self._Platform)\r
1522             for Record in RecordList:\r
1523                 FileType = Record[0]\r
1524                 File = NormPath(Record[1], self._Macros)\r
1525                 LineNo = Record[-1]\r
1526                 if not ValidFile(File, self._ModuleDir):\r
1527                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1528                                     File=self.DescFilePath, Line=LineNo)\r
1529                 Target = Record[2]\r
1530                 FeatureFlag = Record[3]\r
1531                 self._Binaries.append(ModuleBinaryFileClass(File, FileType, Target, FeatureFlag, self._Arch))\r
1532         return self._Binaries\r
1533 \r
1534     def _GetSourceFiles(self):\r
1535         if self._Sources == None:\r
1536             self._Sources = []\r
1537             RecordList = self._Table.Query(MODEL_EFI_SOURCE_FILE, Arch=self._Arch, Platform=self._Platform)\r
1538             for Record in RecordList:\r
1539                 File = NormPath(Record[0], self._Macros)\r
1540                 LineNo = Record[-1]\r
1541                 if not ValidFile(File, self._ModuleDir):\r
1542                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1543                                     File=self.DescFilePath, Line=LineNo)\r
1544                 ToolChainFamily = Record[1]\r
1545                 TagName = Record[2]\r
1546                 ToolCode = Record[3]\r
1547                 FeatureFlag = Record[4]\r
1548                 self._Sources.append(ModuleSourceFileClass(File, TagName, ToolCode, ToolChainFamily, FeatureFlag))\r
1549         return self._Sources\r
1550 \r
1551     def _GetLibraryClassUses(self):\r
1552         if self._LibraryClasses == None:\r
1553             self._LibraryClasses = sdict()\r
1554             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_CLASS, Arch=self._Arch, Platform=self._Platform)\r
1555             for Record in RecordList:\r
1556                 Lib = Record[0]\r
1557                 Instance = Record[1]\r
1558                 if Instance != None and Instance != '':\r
1559                     Instance = NormPath(Instance, self._Macros)\r
1560                 self._LibraryClasses[Lib] = Instance\r
1561         return self._LibraryClasses\r
1562 \r
1563     def _SetLibraryClassUses(self, Value):\r
1564         self._LibraryClasses = Value\r
1565 \r
1566     def _GetLibraryNames(self):\r
1567         if self._Libraries == None:\r
1568             self._Libraries = []\r
1569             RecordList = self._Table.Query(MODEL_EFI_LIBRARY_INSTANCE, Arch=self._Arch, Platform=self._Platform)\r
1570             for Record in RecordList:\r
1571                 # in case of name with '.lib' extension, which is unusual in R8.x inf\r
1572                 LibraryName = os.path.splitext(Record[0])[0]\r
1573                 if LibraryName not in self._Libraries:\r
1574                     self._Libraries.append(LibraryName)\r
1575         return self._Libraries\r
1576 \r
1577     def _GetProtocols(self):\r
1578         if self._Protocols == None:\r
1579             self._Protocols = sdict()\r
1580             RecordList = self._Table.Query(MODEL_EFI_PROTOCOL, Arch=self._Arch, Platform=self._Platform)\r
1581             for Record in RecordList:\r
1582                 CName = Record[0]\r
1583                 Value = GuidValue(CName, self.Packages)\r
1584                 if Value == None:\r
1585                     PackageList = '\t' + "\n\t".join([str(P) for P in self.Packages])\r
1586                     EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Value of [%s] is not found in" % CName,\r
1587                                     ExtraData=PackageList, File=self.DescFilePath, Line=Record[-1])\r
1588                 self._Protocols[CName] = Value\r
1589         return self._Protocols\r
1590 \r
1591     def _GetPpis(self):\r
1592         if self._Ppis == None:\r
1593             self._Ppis = sdict()\r
1594             RecordList = self._Table.Query(MODEL_EFI_PPI, Arch=self._Arch, Platform=self._Platform)\r
1595             for Record in RecordList:\r
1596                 CName = Record[0]\r
1597                 Value = GuidValue(CName, self.Packages)\r
1598                 if Value == None:\r
1599                     PackageList = '\t' + "\n\t".join([str(P) for P in self.Packages])\r
1600                     EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Value of [%s] is not found in " % CName,\r
1601                                     ExtraData=PackageList, File=self.DescFilePath, Line=Record[-1])\r
1602                 self._Ppis[CName] = Value\r
1603         return self._Ppis\r
1604 \r
1605     def _GetGuids(self):\r
1606         if self._Guids == None:\r
1607             self._Guids = sdict()\r
1608             RecordList = self._Table.Query(MODEL_EFI_GUID, Arch=self._Arch, Platform=self._Platform)\r
1609             for Record in RecordList:\r
1610                 CName = Record[0]\r
1611                 Value = GuidValue(CName, self.Packages)\r
1612                 if Value == None:\r
1613                     PackageList = '\t' + "\n\t".join([str(P) for P in self.Packages])\r
1614                     EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Value of [%s] is not found in" % CName,\r
1615                                     ExtraData=PackageList, File=self.DescFilePath, Line=Record[-1])\r
1616                 self._Guids[CName] = Value\r
1617         return self._Guids\r
1618 \r
1619     def _GetIncludes(self):\r
1620         if self._Includes == None:\r
1621             self._Includes = []\r
1622             RecordList = self._Table.Query(MODEL_EFI_INCLUDE, Arch=self._Arch, Platform=self._Platform)\r
1623             # [includes] section must be used only in old (R8.x) inf file\r
1624             if self.AutoGenVersion >= 0x00010005 and len(RecordList) > 0:\r
1625                 EdkLogger.error('build', FORMAT_NOT_SUPPORTED, "No [include] section allowed",\r
1626                                 File=self.DescFilePath, Line=RecordList[0][-1]-1)\r
1627             for Record in RecordList:\r
1628                 File = NormPath(Record[0], self._Macros)\r
1629                 LineNo = Record[-1]\r
1630                 #if File[0] == '.':\r
1631                 #    if not ValidFile(File, self._ModuleDir):\r
1632                 #        EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1633                 #                        File=self.DescFilePath, Line=LineNo)\r
1634                 #else:\r
1635                 #    if not ValidFile(File):\r
1636                 #        EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1637                 #                        File=self.DescFilePath, Line=LineNo)\r
1638                 if File in self._Includes:\r
1639                     continue\r
1640                 self._Includes.append(File)\r
1641         return self._Includes\r
1642 \r
1643     def _GetPackages(self):\r
1644         if self._Packages == None:\r
1645             self._Packages = []\r
1646             RecordList = self._Table.Query(MODEL_META_DATA_PACKAGE, Arch=self._Arch, Platform=self._Platform)\r
1647             for Record in RecordList:\r
1648                 File = NormPath(Record[0], self._Macros)\r
1649                 LineNo = Record[-1]\r
1650                 if not ValidFile(File):\r
1651                     EdkLogger.error('build', FILE_NOT_FOUND, ExtraData=File,\r
1652                                     File=self.DescFilePath, Line=LineNo)\r
1653                 Package = self._Db.BuildObject[File, MODEL_FILE_DEC, self._Arch]\r
1654                 self._Packages.append(Package)\r
1655         return self._Packages\r
1656 \r
1657     def _GetPcds(self):\r
1658         if self._Pcds == None:\r
1659             self._Pcds = {}\r
1660             self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
1661             self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
1662             self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
1663             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))\r
1664             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))\r
1665         return self._Pcds\r
1666 \r
1667     def _GetBuildOptions(self):\r
1668         if self._BuildOptions == None:\r
1669             self._BuildOptions = sdict()\r
1670             RecordList = self._Table.Query(MODEL_META_DATA_BUILD_OPTION, Arch=self._Arch, Platform=self._Platform)\r
1671             for Record in RecordList:\r
1672                 ToolChainFamily = Record[0]\r
1673                 ToolChain = Record[1]\r
1674                 Option = Record[2]\r
1675                 if (ToolChainFamily, ToolChain) not in self._BuildOptions:\r
1676                     self._BuildOptions[ToolChainFamily, ToolChain] = Option\r
1677                 else:\r
1678                     OptionString = self._BuildOptions[ToolChainFamily, ToolChain]\r
1679                     self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option\r
1680         return self._BuildOptions\r
1681 \r
1682     def _GetDepex(self):\r
1683         if self._Depex == None:\r
1684             self._Depex = ''\r
1685             RecordList = self._Table.Query(MODEL_EFI_DEPEX, Arch=self._Arch, Platform=self._Platform)\r
1686             for Record in RecordList:\r
1687                 self._Depex += ' ' + Record[0]\r
1688         return self._Depex\r
1689 \r
1690     def _GetPcd(self, Type):\r
1691         Pcds = {}\r
1692         PcdDict = tdict(True, 4)\r
1693         PcdSet = set()\r
1694         RecordList = self._Table.Query(Type, Arch=self.Arch, Platform=self.Platform)\r
1695         for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Dummy1, LineNo in RecordList:\r
1696             PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = Setting\r
1697             PcdSet.add((PcdCName, TokenSpaceGuid))\r
1698             if TokenSpaceGuid not in self.Guids:\r
1699                 Value = GuidValue(TokenSpaceGuid, self.Packages)\r
1700                 if Value == None:\r
1701                     PackageList = '\t' + "\n\t".join([str(P) for P in self.Packages])\r
1702                     EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Value of [%s] is not found in" % CName,\r
1703                                     ExtraData=PackageList, File=self.DescFilePath, Line=LineNo)\r
1704                 self._Guids[TokenSpaceGuid] = Value\r
1705 \r
1706         for PcdCName, TokenSpaceGuid in PcdSet:\r
1707             ValueList = ['', '']\r
1708             Setting = PcdDict[self.Arch, self.Platform, PcdCName, TokenSpaceGuid]\r
1709             if Setting == None:\r
1710                 continue\r
1711             TokenList = Setting.split(TAB_VALUE_SPLIT)\r
1712             ValueList[0:len(TokenList)] = TokenList\r
1713             DefaultValue = ValueList[0]\r
1714             Pcd = PcdClassObject(\r
1715                     PcdCName,\r
1716                     TokenSpaceGuid,\r
1717                     '',\r
1718                     '',\r
1719                     DefaultValue,\r
1720                     '',\r
1721                     '',\r
1722                     {},\r
1723                     True\r
1724                     )\r
1725 \r
1726             # get necessary info from package declaring this PCD\r
1727             for Package in self.Packages:\r
1728                 # \r
1729                 # 'dynamic' in INF means its type is determined by platform;\r
1730                 # if platform doesn't give its type, use 'lowest' one in the \r
1731                 # following order, if any\r
1732                 # \r
1733                 #   "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"\r
1734                 # \r
1735                 PcdType = self._PCD_TYPE_STRING_[Type]\r
1736                 if Type in [MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:\r
1737                     for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:\r
1738                         if (PcdCName, TokenSpaceGuid, T) in Package.Pcds:\r
1739                             PcdType = T\r
1740                             break\r
1741 \r
1742                 if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:\r
1743                     PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]\r
1744                     Pcd.Type = PcdType\r
1745                     Pcd.TokenValue = PcdInPackage.TokenValue\r
1746                     Pcd.DatumType = PcdInPackage.DatumType\r
1747                     Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize\r
1748                     if Pcd.DefaultValue in [None, '']:\r
1749                         Pcd.DefaultValue = PcdInPackage.DefaultValue\r
1750                     break\r
1751             else:\r
1752                 EdkLogger.error(\r
1753                             'build', \r
1754                             PARSER_ERROR,\r
1755                             "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.DescFilePath),\r
1756                             ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])\r
1757                             )\r
1758             Pcds[PcdCName, TokenSpaceGuid] = Pcd\r
1759         return Pcds\r
1760 \r
1761     Arch                    = property(_GetArch, _SetArch)\r
1762     Platform                = property(_GetPlatform, _SetPlatform)\r
1763 \r
1764     AutoGenVersion          = property(_GetInfVersion)\r
1765     BaseName                = property(_GetBaseName)\r
1766     ModuleType              = property(_GetModuleType)\r
1767     ComponentType           = property(_GetComponentType)\r
1768     Guid                    = property(_GetFileGuid)\r
1769     Version                 = property(_GetVersion)\r
1770     PcdIsDriver             = property(_GetPcdIsDriver)\r
1771     Shadow                  = property(_GetShadow)\r
1772     CustomMakefile          = property(_GetMakefile)\r
1773     Specification           = property(_GetSpec)\r
1774     LibraryClass            = property(_GetLibraryClass)\r
1775     ModuleEntryPointList    = property(_GetEntryPoint)\r
1776     ModuleUnloadImageList   = property(_GetUnloadImage)\r
1777     ConstructorList         = property(_GetConstructor)\r
1778     DestructorList          = property(_GetDestructor)\r
1779 \r
1780     Binaries                = property(_GetBinaryFiles)\r
1781     Sources                 = property(_GetSourceFiles)\r
1782     LibraryClasses          = property(_GetLibraryClassUses, _SetLibraryClassUses)\r
1783     Libraries               = property(_GetLibraryNames)\r
1784     Protocols               = property(_GetProtocols)\r
1785     Ppis                    = property(_GetPpis)\r
1786     Guids                   = property(_GetGuids)\r
1787     Includes                = property(_GetIncludes)\r
1788     Packages                = property(_GetPackages)\r
1789     Pcds                    = property(_GetPcds)\r
1790     BuildOptions            = property(_GetBuildOptions)\r
1791     Depex                   = property(_GetDepex)\r
1792 \r
1793 \r
1794 ## Database\r
1795 #\r
1796 # This class defined the build databse\r
1797 # During the phase of initialization, the database will create all tables and\r
1798 # insert all records of table DataModel\r
1799\r
1800 # @param object:      Inherited from object class\r
1801 # @param DbPath:      A string for the path of the ECC database\r
1802 #\r
1803 # @var Conn:          Connection of the ECC database\r
1804 # @var Cur:           Cursor of the connection\r
1805 # @var TblDataModel:  Local instance for TableDataModel\r
1806 #\r
1807 class WorkspaceDatabase(object):\r
1808     _FILE_TYPE_ = {\r
1809         ".INF"  : MODEL_FILE_INF,\r
1810         ".DEC"  : MODEL_FILE_DEC,\r
1811         ".DSC"  : MODEL_FILE_DSC,\r
1812         ".FDF"  : MODEL_FILE_FDF,\r
1813     }\r
1814 \r
1815     _FILE_PARSER_ = {\r
1816         MODEL_FILE_INF  :   InfParser,\r
1817         MODEL_FILE_DEC  :   DecParser,\r
1818         MODEL_FILE_DSC  :   DscParser,\r
1819         MODEL_FILE_FDF  :   None, #FdfParser,\r
1820     }\r
1821 \r
1822     _FILE_TABLE_ = {\r
1823         MODEL_FILE_INF  :   ModuleTable,\r
1824         MODEL_FILE_DEC  :   PackageTable,\r
1825         MODEL_FILE_DSC  :   PlatformTable,\r
1826     }\r
1827 \r
1828     class BuildObjectFactory(object):\r
1829         _GENERATOR_ = {\r
1830             MODEL_FILE_INF  :   InfBuildData,\r
1831             MODEL_FILE_DEC  :   DecBuildData,\r
1832             MODEL_FILE_DSC  :   DscBuildData,\r
1833             MODEL_FILE_FDF  :   None #FlashDefTable,\r
1834         }\r
1835 \r
1836         _CACHE_ = {}    # FilePath  : <object>\r
1837 \r
1838         def __init__(self, WorkspaceDb):\r
1839             self.WorkspaceDb = WorkspaceDb\r
1840 \r
1841         # key = (FilePath, FileType, Arch='COMMON', Platform='COMMON')\r
1842         def __getitem__(self, Key):\r
1843             FilePath = Key[0]\r
1844             FileType = Key[1]\r
1845             if len(Key) > 2:\r
1846                 Arch = Key[2]\r
1847             else:\r
1848                 Arch = 'COMMON'\r
1849             Key = (FilePath, Arch)\r
1850             if Key in self._CACHE_:\r
1851                 return self._CACHE_[Key]\r
1852 \r
1853             self.WorkspaceDb[FilePath] = FileType\r
1854             if FileType not in self._GENERATOR_:\r
1855                 return None\r
1856 \r
1857             # create temp table for current file\r
1858             Table = self.WorkspaceDb[FilePath]\r
1859             BuildObject = self._GENERATOR_[FileType](\r
1860                                     FilePath, \r
1861                                     Table, \r
1862                                     self.WorkspaceDb, \r
1863                                     Arch, \r
1864                                     self.WorkspaceDb._GlobalMacros\r
1865                                     )\r
1866             self._CACHE_[Key] = BuildObject\r
1867             return BuildObject\r
1868 \r
1869     class TransformObjectFactory:\r
1870         def __init__(self, WorkspaceDb):\r
1871             self.WorkspaceDb = WorkspaceDb\r
1872 \r
1873         # key = FilePath\r
1874         def __getitem__(self, Key):\r
1875             pass\r
1876 \r
1877     def __init__(self, DbPath, GlobalMacros={}, RenewDb=False):\r
1878         self._GlobalMacros = GlobalMacros\r
1879 \r
1880         DbDir = os.path.split(DbPath)[0]\r
1881         if not os.path.exists(DbDir):\r
1882             os.makedirs(DbDir)\r
1883 \r
1884         if RenewDb and os.path.exists(DbPath):\r
1885             os.remove(DbPath)\r
1886 \r
1887         self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r
1888         self.Conn.execute("PRAGMA synchronous=OFF")\r
1889         self.Conn.execute("PRAGMA temp_store=MEMORY")\r
1890         self.Conn.execute("PRAGMA count_changes=OFF")\r
1891         self.Conn.execute("PRAGMA cache_size=8192")\r
1892         #self.Conn.execute("PRAGMA page_size=8192")\r
1893 \r
1894         # to avoid non-ascii character conversion issue\r
1895         self.Conn.text_factory = str\r
1896         self.Cur = self.Conn.cursor()\r
1897 \r
1898         self.TblDataModel = TableDataModel(self.Cur)\r
1899         self.TblFile = TableFile(self.Cur)\r
1900 \r
1901         self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)\r
1902         self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)\r
1903     \r
1904     ## Initialize build database\r
1905     #\r
1906     # 1. Delete all old existing tables\r
1907     # 2. Create new tables\r
1908     # 3. Initialize table DataModel\r
1909     #\r
1910     def InitDatabase(self):\r
1911         EdkLogger.verbose("\nInitialize ECC database started ...")\r
1912         \r
1913         #\r
1914         # Create new tables\r
1915         #\r
1916         self.TblDataModel.Create(False)\r
1917         self.TblFile.Create(False)\r
1918         \r
1919         #\r
1920         # Initialize table DataModel\r
1921         #\r
1922         self.TblDataModel.InitTable()\r
1923         EdkLogger.verbose("Initialize build database ... DONE!")\r
1924 \r
1925     ## Query a table\r
1926     #\r
1927     # @param Table:  The instance of the table to be queried\r
1928     #\r
1929     def QueryTable(self, Table):\r
1930         Table.Query()\r
1931     \r
1932     ## Close entire database\r
1933     #\r
1934     # Commit all first \r
1935     # Close the connection and cursor\r
1936     #\r
1937     def Close(self):\r
1938         self.Conn.commit()\r
1939         self.Cur.close()\r
1940         self.Conn.close()\r
1941 \r
1942     def GetFileId(self, FilePath):\r
1943         return self.TblFile.GetFileId(FilePath)\r
1944 \r
1945     def GetFileType(self, FileId):\r
1946         return self.TblFile.GetFileType(FileId)\r
1947 \r
1948     def GetTimeStamp(self, FileId):\r
1949         return self.TblFile.GetFileTimeStamp(FileId)\r
1950 \r
1951     def SetTimeStamp(self, FileId, TimeStamp):\r
1952         return self.TblFile.SetFileTimeStamp(FileId, TimeStamp)\r
1953 \r
1954     def CheckIntegrity(self, TableName):\r
1955         Result = self.Cur.execute("select min(ID) from %s" % (TableName)).fetchall()\r
1956         if Result[0][0] != -1:\r
1957             return False\r
1958         return True\r
1959 \r
1960     def GetTableName(self, FileType, FileId):\r
1961         return "_%s_%s" % (FileType, FileId)\r
1962 \r
1963     ## TRICK: \r
1964     # Key = FilePath\r
1965     # Value = FileType\r
1966     def __setitem__(self, FilePath, FileType):\r
1967         FileId = self.GetFileId(FilePath)\r
1968         if FileId != None:\r
1969             TimeStamp = os.stat(FilePath)[8]\r
1970             TableName = self.GetTableName(FileType, FileId)\r
1971             if TimeStamp != self.GetTimeStamp(FileId):\r
1972                 self.SetTimeStamp(FileId, TimeStamp)\r
1973             else:\r
1974                 if self.CheckIntegrity(TableName) == True:\r
1975                     return\r
1976         else:\r
1977             FileId = self.TblFile.InsertFile(FilePath, FileType)\r
1978             TableName = self.GetTableName(FileType, FileId)\r
1979 \r
1980         FileTable = self._FILE_TABLE_[FileType](self.Cur, TableName, FileId)\r
1981         FileTable.Create()\r
1982         Parser = self._FILE_PARSER_[FileType](FilePath, FileId, FileType, FileTable)\r
1983         Parser.Start()\r
1984 \r
1985     ## Return a temp table containing all content of the given file\r
1986     # \r
1987     def __getitem__(self, FileInfo):\r
1988         if type(FileInfo) == type(''):\r
1989             FileId = self.GetFileId(FileInfo)\r
1990         else:\r
1991             FileId = FileInfo\r
1992         if FileId == None:\r
1993             return None\r
1994         FileType = self.GetFileType(FileId)\r
1995         if FileType not in self._FILE_TABLE_:\r
1996             return None\r
1997 \r
1998         TableName = "_%s_%s" % (FileType, FileId)\r
1999         FileTable = self._FILE_TABLE_[FileType](self.Cur, TableName, FileId)\r
2000         return FileTable\r
2001 \r
2002     ## Resolve cross-references between platfor, packages and modules\r
2003     def _PostFix(self):\r
2004         pass\r
2005 \r
2006 ##\r
2007 #\r
2008 # This acts like the main() function for the script, unless it is 'import'ed into another\r
2009 # script.\r
2010 #\r
2011 if __name__ == '__main__':\r
2012     EdkLogger.Initialize()\r
2013     EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
2014     \r
2015     Db = WorkspaceDatabase(DATABASE_PATH)\r
2016     Db.InitDatabase()\r
2017     Db.QueryTable(Db.TblDataModel)   \r
2018     Db.QueryTable(Db.TblFile)\r
2019     Db.QueryTable(Db.TblDsc)\r
2020     Db.Close()\r
2021