Changed GenFds to use database based module/package/platform information retrieval...
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 21 Apr 2008 05:39:02 +0000 (05:39 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 21 Apr 2008 05:39:02 +0000 (05:39 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1165 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/GenFds/AprioriSection.py
Source/Python/GenFds/DepexSection.py
Source/Python/GenFds/FfsInfStatement.py
Source/Python/GenFds/GenFds.py
Source/Python/GenFds/GenFdsGlobalVariable.py
Source/Python/Workspace/MetaDataTable.py
Source/Python/Workspace/WorkspaceDatabase.py

index 7c7c9a1..8d7c127 100755 (executable)
@@ -78,22 +78,18 @@ class AprioriSection (AprioriSectionClassObject):
                     Dict['$(ARCH)'] = Arch\r
                 InfFileName = GenFdsGlobalVariable.MacroExtend(InfFileName, Dict, Arch)\r
 \r
-                if Arch != None and InfFileName in GenFdsGlobalVariable.WorkSpace.Build[Arch].ModuleDatabase.keys():\r
-                    Inf = GenFdsGlobalVariable.WorkSpace.Build[Arch].ModuleDatabase[InfFileName]\r
+                if Arch != None:\r
+                    Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[InfFileName, Arch]\r
                     Guid = Inf.Guid\r
         \r
-                elif InfFileName in GenFdsGlobalVariable.WorkSpace.InfDatabase.keys():\r
-                    Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[InfFileName]\r
-                    Guid = Inf.Module.Header[Arch].Guid\r
+                else:\r
+                    Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[InfFileName, 'COMMON']\r
+                    Guid = Inf.Guid\r
                     \r
                     self.BinFileList = Inf.Module.Binaries\r
                     if self.BinFileList == []:\r
                         raise Exception ("INF %s not found in build ARCH %s!" % (InfFileName, GenFdsGlobalVariable.ArchList))\r
                         sys.exit(1)\r
-        \r
-                else:\r
-                    raise Exception ("INF %s not found in database!" % InfFileName)\r
-                    sys.exit(1)\r
             \r
                 \r
             GuidPart = Guid.split('-')\r
index 41c7cd4..0b18d60 100644 (file)
@@ -37,7 +37,7 @@ class DepexSection (DepexSectionClassObject):
     \r
     def __FindGuidValue(self, CName):\r
         for Arch in GenFdsGlobalVariable.ArchList:\r
-            for PkgDb in GenFdsGlobalVariable.WorkSpace.Build[Arch].PackageDatabase.values():\r
+            for PkgDb in GenFdsGlobalVariable.WorkSpace.PackageList:\r
                 if CName in PkgDb.Ppis:\r
                     return PkgDb.Ppis[CName]\r
                 if CName in PkgDb.Protocols:\r
index 14f4602..18007a0 100644 (file)
@@ -58,9 +58,9 @@ class FfsInfStatement(FfsInfStatementClassObject):
         self.InfFileName = NormPath(self.InfFileName)\r
         self.InfFileName = GenFdsGlobalVariable.MacroExtend(self.InfFileName, Dict, self.CurrentArch)\r
         (self.SourceDir, InfName) = os.path.split(self.InfFileName)\r
-        if self.CurrentArch != None and self.InfFileName in GenFdsGlobalVariable.WorkSpace.Build[self.CurrentArch].ModuleDatabase.keys():\r
+        if self.CurrentArch != None:\r
             \r
-            Inf = GenFdsGlobalVariable.WorkSpace.Build[self.CurrentArch].ModuleDatabase[self.InfFileName]\r
+            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[self.InfFileName, self.CurrentArch]\r
             #\r
             # Set Ffs BaseName, MdouleGuid, ModuleType, Version, OutputPath\r
             #\r
@@ -68,30 +68,23 @@ class FfsInfStatement(FfsInfStatementClassObject):
             self.ModuleGuid = Inf.Guid\r
             self.ModuleType = Inf.ModuleType\r
             if Inf.AutoGenVersion < 0x00010005:\r
-                self.ModuleType = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName].Module.Header[self.CurrentArch].ComponentType\r
+                self.ModuleType = Inf.ComponentType\r
             self.VersionString = Inf.Version\r
             self.BinFileList = Inf.Binaries\r
-            if self.KeepReloc == None and Inf.Shadow != '':\r
-                if Inf.Shadow.upper() == "TRUE":\r
-                    self.ShadowFromInfFile = True\r
-                else:\r
-                    self.ShadowFromInfFile = False \r
+            if self.KeepReloc == None and Inf.Shadow:\r
+                self.ShadowFromInfFile = Inf.Shadow\r
         \r
-        elif self.InfFileName in GenFdsGlobalVariable.WorkSpace.InfDatabase.keys():\r
-            Inf = GenFdsGlobalVariable.WorkSpace.InfDatabase[self.InfFileName]\r
-            self.BaseName = Inf.Module.Header[self.CurrentArch].Name\r
-            self.ModuleGuid = Inf.Module.Header[self.CurrentArch].Guid\r
-            self.ModuleType = Inf.Module.Header[self.CurrentArch].ModuleType\r
-            self.VersionString = Inf.Module.Header[self.CurrentArch].Version\r
-            self.BinFileList = Inf.Module.Binaries\r
+        else:\r
+            Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[self.InfFileName, 'COMMON']\r
+            self.BaseName = Inf.BaseName\r
+            self.ModuleGuid = Inf.Guid\r
+            self.ModuleType = Inf.ModuleType\r
+            self.VersionString = Inf.Version\r
+            self.BinFileList = Inf.Binaries\r
             if self.BinFileList == []:\r
                 raise Exception ("INF %s specified in FDF could not be found in build ARCH %s!" % (self.InfFileName, GenFdsGlobalVariable.ArchList))\r
                 sys.exit(1)\r
         \r
-        else:\r
-            raise Exception ("INF %s specified in FDF could not be found in database!" % self.InfFileName)\r
-            sys.exit(1)\r
-        \r
         GenFdsGlobalVariable.VerboseLogger( "BaseName : %s" %self.BaseName)\r
         GenFdsGlobalVariable.VerboseLogger("ModuleGuid : %s" %self.ModuleGuid)\r
         GenFdsGlobalVariable.VerboseLogger("ModuleType : %s" %self.ModuleType)\r
@@ -233,23 +226,23 @@ class FfsInfStatement(FfsInfStatementClassObject):
     def __GetPlatformArchList__(self):\r
         TargetArchList = GenFdsGlobalVariable.ArchList\r
         if len(TargetArchList) == 0:\r
-            TargetArchList = GenFdsGlobalVariable.WorkSpace.SupArchList\r
+            TargetArchList = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList\r
         else:\r
-            TargetArchList = set(GenFdsGlobalVariable.WorkSpace.SupArchList) & set(TargetArchList)\r
+            TargetArchList = set(GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'COMMON'].SupArchList) & set(TargetArchList)\r
             \r
         InfFileKey = os.path.normpath(self.InfFileName)\r
         DscArchList = []\r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.Build.get('IA32').PlatformDatabase.get(GenFdsGlobalVariable.ActivePlatform)\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IA32']\r
         if  PlatformDataBase != None:\r
             if InfFileKey in PlatformDataBase.Modules:\r
                 DscArchList.append ('IA32')\r
                 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.Build.get('X64').PlatformDatabase.get(GenFdsGlobalVariable.ActivePlatform)\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'X64']\r
         if  PlatformDataBase != None:\r
             if InfFileKey in PlatformDataBase.Modules:\r
                 DscArchList.append ('X64')\r
                 \r
-        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.Build.get('IPF').PlatformDatabase.get(GenFdsGlobalVariable.ActivePlatform)\r
+        PlatformDataBase = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, 'IPF']\r
         if PlatformDataBase != None:\r
             if InfFileKey in (PlatformDataBase.Modules):\r
                 DscArchList.append ('IPF')\r
index 2fa081e..ef6a3d1 100644 (file)
@@ -21,7 +21,7 @@ import os
 import FdfParser\r
 from Common import BuildToolError\r
 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
-import Common.EdkIIWorkspaceBuild\r
+from Workspace.WorkspaceDatabase import WorkspaceDatabase\r
 import RuleComplexFile\r
 from EfiSection import EfiSection\r
 import StringIO\r
@@ -156,11 +156,11 @@ def main():
             \r
         """call Workspace build create database"""\r
         os.environ["WORKSPACE"] = Workspace\r
-        BuildWorkSpace = Common.EdkIIWorkspaceBuild.WorkspaceBuild(GenFdsGlobalVariable.ActivePlatform, GenFdsGlobalVariable.WorkSpaceDir)\r
-            \r
-#        OutputDirFromDsc = BuildWorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Defines.DefinesDictionary['OUTPUT_DIRECTORY'][0]\r
+        BuildWorkSpace = WorkspaceDatabase('', GlobalData.gGlobalDefines)\r
+        BuildWorkSpace.InitDatabase()\r
+\r
         for Arch in ArchList:\r
-            GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Platform.Header[Arch].OutputDirectory)\r
+            GenFdsGlobalVariable.OutputDirFromDscDict[Arch] = NormPath(BuildWorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].OutputDirectory)\r
         \r
         if (Options.outputDir):\r
             OutputDirFromCommandLine = GenFdsGlobalVariable.ReplaceWorkspaceMacro(Options.outputDir)\r
@@ -207,19 +207,16 @@ def main():
                 GenFds.currentFv = Options.uiFvName\r
             else:\r
                 GenFdsGlobalVariable.ErrorLogger("No such an FV in FDF file.")\r
-                sys.exit(1)\r
-       \r
-        # Disable output of parsing DSC/INF/DEC temporarily\r
-        OldLevel = EdkLogger.GetLevel()\r
-        EdkLogger.SetLevel(EdkLogger.QUIET)\r
-        BuildWorkSpace.GenBuildDatabase({}, FdfParserObj.Profile.InfList)\r
-        EdkLogger.SetLevel(OldLevel)\r
+                sys.exit(1)       \r
         \r
         """Call GenFds"""\r
         GenFds.GenFd('', FdfParserObj, BuildWorkSpace, ArchList)\r
         print "\nDone!\n"\r
     except Exception, X:\r
         EdkLogger.error("GenFds", BuildToolError.GENFDS_ERROR, X, RaiseError = False)\r
+        if Options.debug != None:\r
+            import traceback\r
+            EdkLogger.quiet(traceback.format_exc())\r
         sys.exit(1)\r
 \r
 ## Parse command line options\r
index a689988..b5dd6a9 100644 (file)
@@ -81,8 +81,8 @@ class GenFdsGlobalVariable:
         FvAddressFile.writelines("[options]" + T_CHAR_LF)\r
         BsAddress = '0'\r
         for Arch in ArchList:\r
-            if GenFdsGlobalVariable.WorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Platform.Header[Arch].BsBaseAddress:\r
-                BsAddress = GenFdsGlobalVariable.WorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Platform.Header[Arch].BsBaseAddress\r
+            if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].BsBaseAddress:\r
+                BsAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].BsBaseAddress\r
                 break\r
         \r
         FvAddressFile.writelines("EFI_BOOT_DRIVER_BASE_ADDRESS = " + \\r
@@ -91,8 +91,8 @@ class GenFdsGlobalVariable:
                                        \r
         RtAddress = '0'\r
         for Arch in ArchList:\r
-            if GenFdsGlobalVariable.WorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Platform.Header[Arch].RtBaseAddress:\r
-                RtAddress = GenFdsGlobalVariable.WorkSpace.DscDatabase[GenFdsGlobalVariable.ActivePlatform].Platform.Header[Arch].RtBaseAddress\r
+            if GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].RtBaseAddress:\r
+                RtAddress = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch].RtBaseAddress\r
                 \r
         FvAddressFile.writelines("EFI_RUNTIME_DRIVER_BASE_ADDRESS = " + \\r
                                        RtAddress          + \\r
index 7b66123..8ded75e 100644 (file)
@@ -233,6 +233,12 @@ class TableFile(Table):
     def SetFileTimeStamp(self, FileId, TimeStamp):\r
         self.Exec("update %s set TimeStamp=%s where ID='%s'" % (self.Table, TimeStamp, FileId))\r
 \r
+    def GetFileList(self, FileType):\r
+        RecordList = self.Exec("select FullPath from %s where Model=%s" % (self.Table, FileType))\r
+        if len(RecordList) == 0:\r
+            return []\r
+        return [R[0] for R in RecordList]\r
+\r
 ## TableDataModel\r
 #\r
 # This class defined a table used for data model\r
index 70ce4fa..8744cf9 100644 (file)
@@ -1611,6 +1611,8 @@ class WorkspaceDatabase(object):
         MODEL_FILE_DSC  :   PlatformTable,\r
     }\r
 \r
+    _DB_PATH_ = "Conf/.cache/build.db"\r
+\r
     class BuildObjectFactory(object):\r
         _FILE_TYPE_ = {\r
             ".INF"  : MODEL_FILE_INF,\r
@@ -1687,6 +1689,9 @@ class WorkspaceDatabase(object):
     def __init__(self, DbPath, GlobalMacros={}, RenewDb=False):\r
         self._GlobalMacros = GlobalMacros\r
 \r
+        if DbPath == None or DbPath == '':\r
+            DbPath = self._DB_PATH_\r
+\r
         if DbPath != ':memory:':\r
             DbDir = os.path.split(DbPath)[0]\r
             if not os.path.exists(DbDir):\r
@@ -1822,6 +1827,43 @@ class WorkspaceDatabase(object):
 \r
         return Parser\r
 \r
+    def _GetPackageList(self):\r
+        PackageList = []\r
+        for PackageFile in self.TblFile.GetFileList(MODEL_FILE_DEC):\r
+            try:\r
+                Package = self.BuildObject[PackageFile, 'COMMON']\r
+            except:\r
+                Package = None\r
+            if Package != None:\r
+                PackageList.append(Package)\r
+        return PackageList\r
+\r
+    def _GetPlatformList(self):\r
+        PlatformList = []\r
+        for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC):\r
+            try:\r
+                Platform = self.BuildObject[PlatformFile, 'COMMON']\r
+            except:\r
+                Platform = None\r
+            if Platform != None:\r
+                PlatformList.append(Platform)\r
+        return PlatformList\r
+\r
+    def _GetModuleList(self):\r
+        ModuleList = []\r
+        for ModuleFile in self.TblFile.GetFileList(MODEL_FILE_INF):\r
+            try:\r
+                Module = self.BuildObject[ModuleFile, 'COMMON']\r
+            except:\r
+                Module = None\r
+            if Module != None:\r
+                ModuleList.append(Module)\r
+        return ModuleList\r
+\r
+    PlatformList = property(_GetPlatformList)\r
+    PackageList = property(_GetPackageList)\r
+    ModuleList = property(_GetModuleList)\r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r